From 3235c695394acadf8e7ad6a8ce932fffcc066da1 Mon Sep 17 00:00:00 2001 From: Steven Van Ingelgem Date: Mon, 19 Aug 2024 05:45:38 +0200 Subject: [PATCH 1/4] No changes, just reformat the code according to the `.editorconfig` files settings (#134) --- .editorconfig | 4 +- .github/workflows/build.yml | 54 +- README.md | 51 +- .../java/org/terraform/biome/BiomeBank.java | 996 +++++++---- .../org/terraform/biome/BiomeBlender.java | 112 +- .../org/terraform/biome/BiomeClimate.java | 168 +- .../org/terraform/biome/BiomeHandler.java | 40 +- .../org/terraform/biome/BiomeSection.java | 580 +++---- .../biome/BiomeSectionCacheLoader.java | 10 +- .../org/terraform/biome/BiomeSubSection.java | 6 +- .../java/org/terraform/biome/BiomeType.java | 12 +- .../HeightIndependentBiomeCacheLoader.java | 30 +- .../biome/beach/BadlandsBeachHandler.java | 23 +- .../biome/beach/BlackOceanBeachHandler.java | 40 +- .../biome/beach/BogBeachHandler.java | 47 +- .../biome/beach/CherryGroveBeachHandler.java | 45 +- .../biome/beach/DarkForestBeachHandler.java | 31 +- .../biome/beach/IcyBeachHandler.java | 30 +- .../biome/beach/MudflatsHandler.java | 32 +- .../biome/beach/MushroomBeachHandler.java | 159 +- .../org/terraform/biome/beach/OasisBeach.java | 81 +- .../biome/beach/RockBeachHandler.java | 24 +- .../biome/beach/SandyBeachHandler.java | 66 +- .../beach/ScarletForestBeachHandler.java | 25 +- .../AbstractCaveClusterPopulator.java | 105 +- .../cavepopulators/CaveClusterRegistry.java | 112 +- .../CaveFluidClusterPopulator.java | 52 +- .../CrystallineClusterCavePopulator.java | 109 +- .../cavepopulators/DeepCavePopulator.java | 103 +- .../DeepDarkClusterCavePopulator.java | 165 +- .../DripstoneClusterCavePopulator.java | 61 +- .../ForestedMountainsCavePopulator.java | 86 +- .../cavepopulators/FrozenCavePopulator.java | 32 +- .../LushClusterCavePopulator.java | 203 ++- .../MasterCavePopulatorDistributor.java | 130 +- .../cavepopulators/MossyCavePopulator.java | 133 +- .../CustomBiomeSupportedBiomeGrid.java | 12 +- .../biome/custombiomes/CustomBiomeType.java | 22 +- .../biome/flat/ArchedCliffsHandler.java | 266 +-- .../terraform/biome/flat/BadlandsHandler.java | 338 ++-- .../biome/flat/BambooForestHandler.java | 84 +- .../biome/flat/CherryGroveHandler.java | 116 +- .../biome/flat/DarkForestHandler.java | 225 ++- .../terraform/biome/flat/DesertHandler.java | 177 +- .../biome/flat/ElevatedPlainsHandler.java | 144 +- .../biome/flat/ErodedPlainsHandler.java | 119 +- .../terraform/biome/flat/ForestHandler.java | 148 +- .../terraform/biome/flat/GorgeHandler.java | 223 +-- .../biome/flat/IceSpikesHandler.java | 120 +- .../terraform/biome/flat/JungleHandler.java | 320 ++-- .../terraform/biome/flat/MangroveHandler.java | 157 +- .../terraform/biome/flat/MuddyBogHandler.java | 132 +- .../biome/flat/PetrifiedCliffsHandler.java | 209 ++- .../terraform/biome/flat/PlainsHandler.java | 120 +- .../terraform/biome/flat/SavannaHandler.java | 129 +- .../biome/flat/ScarletForestHandler.java | 109 +- .../biome/flat/SnowyTaigaHandler.java | 162 +- .../biome/flat/SnowyWastelandHandler.java | 95 +- .../terraform/biome/flat/SwampHandler.java | 67 +- .../terraform/biome/flat/TaigaHandler.java | 202 ++- .../mountainous/AbstractMountainHandler.java | 186 ++- .../mountainous/BadlandsCanyonHandler.java | 218 +-- .../mountainous/BirchMountainsHandler.java | 194 ++- .../biome/mountainous/DesertHillsHandler.java | 69 +- .../mountainous/ForestedMountainsHandler.java | 211 ++- .../biome/mountainous/JaggedPeaksHandler.java | 158 +- .../mountainous/PaintedHillsHandler.java | 247 +-- .../mountainous/RockyMountainsHandler.java | 195 ++- .../mountainous/ShatteredSavannaHandler.java | 194 ++- .../mountainous/SnowyMountainsHandler.java | 127 +- .../biome/ocean/AbstractOceanHandler.java | 30 +- .../biome/ocean/BlackOceansHandler.java | 110 +- .../biome/ocean/ColdOceansHandler.java | 99 +- .../biome/ocean/CoralReefOceanHandler.java | 148 +- .../biome/ocean/FrozenOceansHandler.java | 98 +- .../biome/ocean/LukewarmOceansHandler.java | 89 +- .../biome/ocean/MushroomIslandHandler.java | 195 ++- .../terraform/biome/ocean/OceansHandler.java | 98 +- .../biome/ocean/WarmOceansHandler.java | 89 +- .../biome/river/BadlandsRiverHandler.java | 10 +- .../biome/river/BogRiverHandler.java | 95 +- .../biome/river/CherryGroveRiverHandler.java | 34 +- .../biome/river/DarkForestRiverHandler.java | 86 +- .../biome/river/DesertRiverHandler.java | 8 +- .../biome/river/FrozenRiverHandler.java | 49 +- .../biome/river/JungleRiverHandler.java | 106 +- .../org/terraform/biome/river/OasisRiver.java | 27 +- .../terraform/biome/river/RiverHandler.java | 107 +- .../river/ScarletForestRiverHandler.java | 38 +- .../java/org/terraform/cave/CheeseCave.java | 24 +- .../org/terraform/cave/NoiseCaveAbstract.java | 2 +- .../org/terraform/cave/NoiseCaveRegistry.java | 54 +- .../java/org/terraform/cave/NoiseRavine.java | 57 +- .../command/BiomeConsoleCheckCommand.java | 28 +- .../command/BiomeDistribCommand.java | 177 +- .../command/BiomeVisualiserCommand.java | 31 +- .../org/terraform/command/CaveCommand.java | 2 +- .../terraform/command/CheckHeightCommand.java | 57 +- .../command/CrappyDebugStructureCommand.java | 4 +- .../terraform/command/DesertWellCommand.java | 7 +- .../command/FixerCacheFlushCommand.java | 8 +- .../terraform/command/FractalTreeCommand.java | 19 +- .../command/GiantPumpkinCommand.java | 2 +- .../org/terraform/command/HelpCommand.java | 176 +- .../terraform/command/IceSpikeCommand.java | 6 +- .../command/InjectorDebugTestCommand.java | 9 +- .../command/JigsawBuilderTestCommand.java | 10 +- .../terraform/command/LocateBiomeCommand.java | 3 +- .../org/terraform/command/MansionCommand.java | 9 +- .../org/terraform/command/MazeCommand.java | 2 +- .../terraform/command/MushroomCommand.java | 39 +- .../command/NMSChunkPacketRefreshCommand.java | 5 +- .../command/NMSChunkQueryCommand.java | 5 +- .../org/terraform/command/NewTreeCommand.java | 13 +- .../org/terraform/command/OreDitCommand.java | 73 +- .../org/terraform/command/PreviewCommand.java | 222 +-- .../org/terraform/command/RibCageCommand.java | 8 +- .../command/SchematicLoadCommand.java | 8 +- .../command/SchematicSaveCommand.java | 12 +- .../org/terraform/command/SeekCommand.java | 105 +- .../org/terraform/command/TimingsCommand.java | 9 +- .../org/terraform/command/ValuesCommand.java | 82 +- .../terraform/command/WitchHutCommand.java | 8 +- .../command/contants/FilenameArgument.java | 14 +- .../contants/FractalTreeTypeArgument.java | 24 +- .../contants/InvalidArgumentException.java | 19 +- .../contants/MushroomTypeArgument.java | 24 +- .../command/contants/SchematicArgument.java | 6 +- .../contants/TerraCommandArgument.java | 81 +- .../org/terraform/coregen/ChunkCache.java | 79 +- .../terraform/coregen/ChunkCacheLoader.java | 10 +- .../java/org/terraform/coregen/HeightMap.java | 94 +- .../coregen/NMSInjectorAbstract.java | 17 +- .../terraform/coregen/NaturalSpawnType.java | 2 +- .../org/terraform/coregen/TerraLootTable.java | 3 +- .../terraform/coregen/TerraformPopulator.java | 303 ++-- .../NativeGeneratorPatcherPopulator.java | 161 +- .../bukkit/PhysicsUpdaterPopulator.java | 170 +- .../bukkit/TerraformAnimalPopulator.java | 450 +++-- .../bukkit/TerraformBukkitBlockPopulator.java | 20 +- .../coregen/bukkit/TerraformChunkData.java | 164 +- .../coregen/bukkit/TerraformGenerator.java | 197 ++- .../bukkit/TerraformStructurePopulator.java | 155 +- .../IPopulatorDataBaseHeightAccess.java | 4 +- .../IPopulatorDataBeehiveEditor.java | 4 +- .../IPopulatorDataPhysicsCapable.java | 5 +- .../populatordata/PopulatorDataAbstract.java | 54 +- .../populatordata/PopulatorDataColumn.java | 48 +- .../PopulatorDataICAAbstract.java | 4 +- .../PopulatorDataICABiomeWriterAbstract.java | 13 +- .../populatordata/PopulatorDataPostGen.java | 126 +- .../PopulatorDataRecursiveICA.java | 11 +- .../populatordata/PopulatorDataSpigotAPI.java | 71 +- .../coregen/sqlite/PopulatorDataSQLite.java | 24 +- .../terraform/coregen/sqlite/SQLiteDB.java | 100 +- .../java/org/terraform/data/MegaChunk.java | 123 +- .../java/org/terraform/data/SimpleBlock.java | 559 ++++--- .../terraform/data/SimpleChunkLocation.java | 13 +- .../org/terraform/data/SimpleLocation.java | 133 +- .../org/terraform/data/TWSimpleLocation.java | 34 +- .../org/terraform/data/TerraformWorld.java | 97 +- .../main/java/org/terraform/data/Wall.java | 96 +- .../event/TerraformStructureSpawnEvent.java | 32 +- .../main/java/org/terraform/main/LangOpt.java | 3 +- .../org/terraform/main/LanguageManager.java | 95 +- .../main/java/org/terraform/main/TLogger.java | 131 +- .../main/TerraformCommandManager.java | 175 +- .../main/TerraformGeneratorPlugin.java | 144 +- .../terraform/main/config/ConfigLoader.java | 200 +-- .../terraform/main/config/TConfigOption.java | 72 +- .../populators/AmethystGeodePopulator.java | 151 +- .../terraform/populators/AnimalPopulator.java | 69 +- .../terraform/populators/OrePopulator.java | 277 +-- .../reflection/Post14PrivateFieldHandler.java | 59 +- .../reflection/Pre14PrivateFieldHandler.java | 3 +- .../reflection/PrivateFieldHandler.java | 10 +- .../schematic/SchematicListener.java | 21 +- .../terraform/schematic/SchematicParser.java | 68 +- .../terraform/schematic/TerraSchematic.java | 203 +-- .../small_items/DecorationsBuilder.java | 31 +- .../terraform/small_items/PlantBuilder.java | 65 +- .../org/terraform/structure/JigsawState.java | 30 +- .../structure/JigsawStructurePopulator.java | 2 +- .../MultiMegaChunkStructurePopulator.java | 8 +- .../SingleMegaChunkStructurePopulator.java | 20 +- .../StructureBufferDistanceHandler.java | 54 +- .../terraform/structure/StructureLocator.java | 322 ++-- .../structure/StructurePopulator.java | 12 +- .../structure/StructureRegistry.java | 114 +- .../structure/VanillaStructurePopulator.java | 4 +- .../AncientCityAbstractRoomPopulator.java | 196 +-- .../AncientCityAltarPopulator.java | 119 +- .../AncientCityCenterPlatformPopulator.java | 639 +++---- .../AncientCityLargePillarRoomPopulator.java | 198 +-- .../AncientCityPathMiniRoomPlacer.java | 120 +- .../ancientcity/AncientCityPathPopulator.java | 398 ++--- .../AncientCityPillarSchematicParser.java | 80 +- .../ancientcity/AncientCityPopulator.java | 204 +-- .../AncientCityResearchBasementHandler.java | 518 +++--- .../ancientcity/AncientCityRuinsPlatform.java | 61 +- .../AncientCitySchematicParser.java | 60 +- .../AncientCitySchematicPlatform.java | 83 +- .../ancientcity/AncientCityUtils.java | 81 +- .../CatacombsCasketRoomPopulator.java | 117 +- .../CatacombsDripstoneBasinPopulator.java | 59 +- .../catacombs/CatacombsDripstoneCavern.java | 40 +- .../catacombs/CatacombsPathPopulator.java | 204 +-- .../CatacombsPillarRoomPopulator.java | 56 +- .../catacombs/CatacombsPopulator.java | 225 ++- .../CatacombsSkeletonDungeonPopulator.java | 61 +- .../CatacombsStairwayBasePopulator.java | 52 +- .../catacombs/CatacombsStairwayPopulator.java | 23 +- .../catacombs/CatacombsStandardPopulator.java | 211 +-- .../caves/GenericLargeCavePopulator.java | 49 +- .../structure/caves/LargeCavePopulator.java | 108 +- .../structure/caves/LargeCaveRoomCarver.java | 33 +- .../structure/caves/LargeCaveRoomPiece.java | 3 +- .../caves/LargeLushCavePopulator.java | 71 +- .../caves/MushroomCavePopulator.java | 63 +- .../mineshaft/BadlandsMineEntranceParser.java | 21 +- .../mineshaft/BadlandsMinePopulator.java | 249 +-- .../mineshaft/BrokenShaftPopulator.java | 10 +- .../mineshaft/CaveSpiderDenPopulator.java | 20 +- .../mineshaft/MineshaftPathPopulator.java | 189 ++- .../mineshaft/MineshaftPopulator.java | 129 +- .../mineshaft/OreLiftSchematicParser.java | 34 +- .../mineshaft/ShaftRoomPopulator.java | 16 +- .../mineshaft/ShaftTopPopulator.java | 9 +- .../mineshaft/SmeltingHallPopulator.java | 17 +- .../structure/monument/CageRoomPopulator.java | 18 +- .../monument/CoralRoomPopulator.java | 9 +- .../DecoratedSidesElderRoomPopulator.java | 14 +- .../monument/FishCageRoomPopulator.java | 31 +- .../monument/HollowPillarRoomPopulator.java | 6 +- .../monument/LanternPillarRoomPopulator.java | 9 +- .../monument/LevelledElderRoomPopulator.java | 11 +- .../monument/LevelledRoomPopulator.java | 12 +- .../monument/MiniRoomNetworkPopulator.java | 9 +- .../structure/monument/MonumentDesign.java | 41 +- .../monument/MonumentPathPopulator.java | 18 +- .../structure/monument/MonumentPopulator.java | 147 +- .../monument/MonumentRoomPopulator.java | 45 +- .../monument/MonumentSchematicParser.java | 3 +- .../monument/MonumentWallPattern.java | 6 +- .../monument/TreasureRoomPopulator.java | 20 +- .../MansionCompoundRoomDistributor.java | 306 ++-- .../mansion/MansionEmptyRoomPopulator.java | 30 +- .../mansion/MansionInternalWallState.java | 7 +- .../mansion/MansionJigsawBuilder.java | 580 ++++--- .../pillager/mansion/MansionMazeAlgoUtil.java | 108 +- .../pillager/mansion/MansionPopulator.java | 49 +- .../pillager/mansion/MansionRoofHandler.java | 486 +++--- .../mansion/MansionRoomPopulator.java | 92 +- .../mansion/MansionRoomPopulatorRegistry.java | 128 +- .../mansion/MansionRoomSchematicParser.java | 14 +- .../pillager/mansion/MansionRoomSize.java | 57 +- .../mansion/MansionStandardRoomPiece.java | 378 +++-- .../mansion/ground/MansionEntrancePiece.java | 370 ++-- .../ground/MansionGrandStairwayPopulator.java | 153 +- .../MansionGroundFloorHallwayPopulator.java | 433 ++--- ...ansionGroundLevelBrewingRoomPopulator.java | 206 +-- ...MansionGroundLevelDiningRoomPopulator.java | 172 +- .../MansionGroundLevelForgePopulator.java | 181 +- .../MansionGroundLevelKitchenPopulator.java | 350 ++-- .../MansionGroundLevelLibraryPopulator.java | 211 +-- ...nsionGroundLevelMushroomFarmPopulator.java | 116 +- .../MansionGroundLevelWarroomPopulator.java | 118 +- .../ground/MansionGroundRoomPiece.java | 6 +- .../ground/MansionGroundWallPiece.java | 536 +++--- .../MansionStandardGroundRoomPiece.java | 184 +- .../MansionSecondFloorBedroomPopulator.java | 289 ++-- .../MansionSecondFloorBunkPopulator.java | 85 +- ...sionSecondFloorGrandStairwayPopulator.java | 179 +- .../MansionSecondFloorHallwayPopulator.java | 431 ++--- .../MansionSecondFloorHandler.java | 166 +- .../MansionSecondFloorLoungePopulator.java | 242 +-- .../MansionSecondFloorPianoRoomPopulator.java | 125 +- .../MansionSecondFloorStoreroomPopulator.java | 158 +- .../MansionSecondFloorStudyPopulator.java | 283 ++-- .../MansionSecondFloorWallPiece.java | 737 ++++---- .../MansionStandardSecondFloorPiece.java | 18 +- .../MansionTowerStairwayPopulator.java | 102 +- .../mansion/tower/MansionBaseTowerPiece.java | 75 +- .../tower/MansionBaseTowerWallPiece.java | 129 +- .../tower/MansionLookoutTowerWallPiece.java | 165 +- .../tower/MansionStandardTowerPiece.java | 262 ++- .../tower/MansionTowerPieceHandler.java | 221 +-- .../mansion/tower/MansionTowerWallPiece.java | 26 +- .../pillager/outpost/OutpostCampfire.java | 70 +- .../pillager/outpost/OutpostLogpile.java | 138 +- .../pillager/outpost/OutpostPopulator.java | 309 ++-- .../outpost/OutpostSchematicParser.java | 103 +- .../pillager/outpost/OutpostStakeCage.java | 188 ++- .../pillager/outpost/OutpostTent.java | 295 ++-- .../structure/pyramid/Antechamber.java | 82 +- .../structure/pyramid/CryptRoom.java | 69 +- .../structure/pyramid/CursedChamber.java | 43 +- .../pyramid/ElderGuardianChamber.java | 37 +- .../pyramid/EnchantmentAntechamber.java | 7 +- .../structure/pyramid/GenericAntechamber.java | 35 +- .../pyramid/GuardianChamberPopulator.java | 16 +- .../structure/pyramid/HuskTombPopulator.java | 32 +- .../pyramid/MainEntrancePopulator.java | 80 +- .../pyramid/MazeLevelMonsterRoom.java | 6 +- .../pyramid/PyramidDungeonPathPopulator.java | 3 +- .../structure/pyramid/PyramidPopulator.java | 263 ++- .../pyramid/SilverfishNestPopulator.java | 30 +- .../structure/pyramid/TerracottaRoom.java | 30 +- .../pyramid/TrapChestChamberPopulator.java | 19 +- .../pyramid/TreasureAntechamber.java | 6 +- .../structure/pyramid/WarAntechamber.java | 11 +- .../terraform/structure/room/CarvedRoom.java | 70 +- .../terraform/structure/room/CubeRoom.java | 234 +-- .../structure/room/LegacyPathGenerator.java | 134 +- .../structure/room/PathPopulatorAbstract.java | 1 + .../structure/room/PathPopulatorData.java | 22 +- .../terraform/structure/room/RoomLayout.java | 3 +- .../structure/room/RoomLayoutGenerator.java | 337 ++-- .../structure/room/RoomPopulatorAbstract.java | 10 +- .../structure/room/carver/CaveRoomCarver.java | 27 +- .../room/carver/StandardRoomCarver.java | 29 +- .../structure/room/jigsaw/JigsawBuilder.java | 311 ++-- .../room/jigsaw/JigsawStructurePiece.java | 81 +- .../structure/room/jigsaw/JigsawType.java | 5 +- .../structure/room/path/CavePathWriter.java | 20 +- .../structure/room/path/PathState.java | 76 +- .../structure/room/path/PathWriter.java | 4 +- .../structure/small/DesertWellPopulator.java | 184 +- .../small/GiantPumpkinPopulator.java | 34 +- .../structure/small/WitchHutPopulator.java | 95 +- .../BuriedTreasurePopulator.java | 205 +-- .../dungeon/DrownedDungeonPopulator.java | 36 +- .../small/dungeon/SmallDungeonPopulator.java | 41 +- .../dungeon/UndergroundDungeonPopulator.java | 106 +- .../structure/small/igloo/IglooPopulator.java | 684 ++++---- .../ruinedportal/RuinedPortalPopulator.java | 537 +++--- .../small/shipwreck/ShipwreckPopulator.java | 113 +- .../shipwreck/ShipwreckSchematicParser.java | 90 +- .../stronghold/HallwayPopulator.java | 51 +- .../stronghold/LibraryRoomPopulator.java | 85 +- .../stronghold/NetherPortalRoomPopulator.java | 26 +- .../stronghold/PortalRoomPopulator.java | 25 +- .../stronghold/PrisonRoomPopulator.java | 105 +- .../stronghold/SilverfishDenPopulator.java | 17 +- .../stronghold/StrongholdPathPopulator.java | 208 ++- .../stronghold/StrongholdPopulator.java | 127 +- .../stronghold/SupplyRoomPopulator.java | 34 +- .../stronghold/TrapChestRoomPopulator.java | 9 +- .../trailruins/TrailRuinsHutRoom.java | 53 +- .../trailruins/TrailRuinsPathPopulator.java | 8 +- .../trailruins/TrailRuinsPopulator.java | 53 +- .../trailruins/TrailRuinsTowerRoom.java | 58 +- .../trialchamber/TrialChamberPopulator.java | 11 +- .../structure/village/VillagePopulator.java | 66 +- .../plains/PlainsPathRecursiveSpawner.java | 194 ++- .../PlainsVillageAbstractRoomPopulator.java | 171 +- .../PlainsVillageAnimalPenPopulator.java | 376 +++-- .../PlainsVillageCropFarmPopulator.java | 254 +-- .../plains/PlainsVillageForgePopulator.java | 36 +- .../PlainsVillageFountainPopulator.java | 146 +- .../plains/PlainsVillagePathPopulator.java | 135 +- .../plains/PlainsVillagePondPopulator.java | 323 ++-- .../plains/PlainsVillagePopulator.java | 155 +- .../PlainsVillageStandardHousePopulator.java | 36 +- .../plains/PlainsVillageTemplePopulator.java | 34 +- .../PlainsVillageTownhallPopulator.java | 87 +- .../plains/PlainsVillageWellPopulator.java | 247 +-- .../forge/PlainsVillageForgeChimneyPiece.java | 334 ++-- .../PlainsVillageForgeEntrancePiece.java | 187 ++- .../PlainsVillageForgeJigsawBuilder.java | 157 +- .../forge/PlainsVillageForgeMasonPiece.java | 252 +-- .../plains/forge/PlainsVillageForgePiece.java | 55 +- .../forge/PlainsVillageForgeRoofHandler.java | 332 ++-- .../PlainsVillageForgeStandardPiece.java | 62 +- .../forge/PlainsVillageForgeWallPiece.java | 174 +- .../PlainsVillageForgeWeaponSmithPiece.java | 132 +- .../house/PlainsVillageBedroomPiece.java | 74 +- .../house/PlainsVillageEntrancePiece.java | 95 +- .../PlainsVillageHouseJigsawBuilder.java | 117 +- .../house/PlainsVillageHouseVariant.java | 4 +- .../house/PlainsVillageKitchenPiece.java | 63 +- .../house/PlainsVillageLibraryPiece.java | 53 +- .../house/PlainsVillageRoofHandler.java | 173 +- .../house/PlainsVillageStandardPiece.java | 50 +- .../plains/house/PlainsVillageWallPiece.java | 48 +- .../PlainsVillageTempleClericAltarPiece.java | 133 +- .../PlainsVillageTempleEntrancePiece.java | 79 +- .../PlainsVillageTempleJigsawBuilder.java | 233 ++- .../temple/PlainsVillageTempleLootPiece.java | 49 +- .../PlainsVillageTempleLoungePiece.java | 50 +- .../temple/PlainsVillageTempleRelicPiece.java | 66 +- .../PlainsVillageTempleRoofHandler.java | 246 +-- .../temple/PlainsVillageTempleStairway.java | 2 +- .../PlainsVillageTempleStandardPiece.java | 128 +- .../PlainsVillageTempleTowerSpawner.java | 14 +- .../temple/PlainsVillageTempleWallPiece.java | 155 +- .../villagehouse/VillageHousePopulator.java | 81 +- .../animalfarm/AnimalFarmPathPopulator.java | 26 +- .../animalfarm/AnimalFarmPopulator.java | 166 +- .../animalfarm/AnimalFarmSchematicParser.java | 71 +- .../farmhouse/FarmhousePopulator.java | 186 ++- .../farmhouse/FarmhouseSchematicParser.java | 41 +- .../mountainhouse/MountainhousePopulator.java | 168 +- .../MountainhouseSchematicParser.java | 73 +- .../warmoceanruins/WarmOceanAltarRoom.java | 39 +- .../warmoceanruins/WarmOceanBaseRoom.java | 33 +- .../warmoceanruins/WarmOceanDomeHutRoom.java | 87 +- .../warmoceanruins/WarmOceanLargeArcRoom.java | 260 +-- .../WarmOceanRuinsPopulator.java | 88 +- .../warmoceanruins/WarmOceanWellRoom.java | 14 +- .../org/terraform/tree/FractalLeaves.java | 172 +- .../terraform/tree/FractalTreeBuilder.java | 1293 +++++++------- .../java/org/terraform/tree/FractalTypes.java | 618 ++++--- .../org/terraform/tree/MushroomBuilder.java | 300 ++-- .../terraform/tree/NewFractalTreeBuilder.java | 461 +++-- .../org/terraform/tree/SaplingOverrider.java | 88 +- .../main/java/org/terraform/tree/TreeDB.java | 147 +- .../tree/VanillaMushroomBuilder.java | 61 +- .../org/terraform/utils/ArmorStandUtils.java | 116 +- .../java/org/terraform/utils/BannerUtils.java | 120 +- .../org/terraform/utils/BiomePainter.java | 30 +- .../java/org/terraform/utils/BlockUtils.java | 1104 +++++++----- .../java/org/terraform/utils/BoxBuilder.java | 258 +-- .../org/terraform/utils/CoralGenerator.java | 120 +- .../org/terraform/utils/CylinderBuilder.java | 203 ++- .../java/org/terraform/utils/GenUtils.java | 461 +++-- .../java/org/terraform/utils/MazeSpawner.java | 60 +- .../org/terraform/utils/PaintingUtils.java | 140 +- .../main/java/org/terraform/utils/Range.java | 202 +-- .../org/terraform/utils/SphereBuilder.java | 368 ++-- .../org/terraform/utils/StairwayBuilder.java | 398 ++--- .../terraform/utils/StalactiteBuilder.java | 237 +-- .../java/org/terraform/utils/Treetest.java | 4 +- .../java/org/terraform/utils/Vector2f.java | 16 +- .../java/org/terraform/utils/Vector3f.java | 20 +- .../java/org/terraform/utils/WoodUtils.java | 104 +- .../utils/blockdata/BarrelBuilder.java | 4 +- .../utils/blockdata/BisectedBuilder.java | 4 +- .../utils/blockdata/ChestBuilder.java | 60 +- .../utils/blockdata/OrientableBuilder.java | 15 +- .../utils/blockdata/SlabBuilder.java | 17 +- .../utils/blockdata/StairBuilder.java | 29 +- .../utils/blockdata/TrapdoorBuilder.java | 5 +- .../fixers/v1_16_R1_BlockDataFixer.java | 49 +- .../org/terraform/utils/bstats/Metrics.java | 1485 +++++++++-------- .../TerraformGeneratorMetricsHandler.java | 34 +- .../terraform/utils/noise/BezierCurve.java | 26 +- .../terraform/utils/noise/BresenhamLine.java | 10 +- .../org/terraform/utils/noise/FastNoise.java | 1317 +++++++++++---- .../utils/noise/NoiseCacheHandler.java | 267 +-- .../utils/version/BeeHiveSpawner.java | 12 +- .../utils/version/OneOneNineBlockHandler.java | 150 +- .../utils/version/OneTwentyBlockHandler.java | 52 +- .../version/OneTwentyFiveBlockHandler.java | 15 +- .../org/terraform/utils/version/Version.java | 68 +- .../watchdog/TfgWatchdogSuppressant.java | 105 +- .../terraform/v1_18_R2/BlockDataFixer.java | 71 +- .../v1_18_R2/CustomBiomeHandler.java | 301 ++-- .../terraform/v1_18_R2/EntityTypeMapper.java | 470 +++--- .../terraform/v1_18_R2/NMSChunkGenerator.java | 359 ++-- .../org/terraform/v1_18_R2/NMSInjector.java | 133 +- .../org/terraform/v1_18_R2/PopulatorData.java | 410 +++-- .../terraform/v1_18_R2/PopulatorDataICA.java | 347 ++-- .../v1_18_R2/TerraformWorldProviderBiome.java | 140 +- .../terraform/v1_19_R3/BlockDataFixer.java | 67 +- .../v1_19_R3/CustomBiomeHandler.java | 263 +-- .../terraform/v1_19_R3/EntityTypeMapper.java | 9 +- .../terraform/v1_19_R3/NMSChunkGenerator.java | 296 ++-- .../org/terraform/v1_19_R3/NMSInjector.java | 100 +- .../org/terraform/v1_19_R3/PopulatorData.java | 410 +++-- .../terraform/v1_19_R3/PopulatorDataICA.java | 197 +-- .../v1_19_R3/TerraformWorldProviderBiome.java | 166 +- .../terraform/v1_20_R1/BlockDataFixer.java | 67 +- .../v1_20_R1/CustomBiomeHandler.java | 298 ++-- .../v1_20_R1/LootTableTranslator.java | 2 +- .../v1_20_R1/MapRenderWorldProviderBiome.java | 47 +- .../terraform/v1_20_R1/NMSChunkGenerator.java | 144 +- .../org/terraform/v1_20_R1/NMSInjector.java | 99 +- .../terraform/v1_20_R1/PopulatorDataICA.java | 214 +-- .../v1_20_R1/TerraformWorldProviderBiome.java | 39 +- .../terraform/v1_20_R2/BlockDataFixer.java | 67 +- .../v1_20_R2/CustomBiomeHandler.java | 292 ++-- .../v1_20_R2/LootTableTranslator.java | 2 +- .../v1_20_R2/MapRenderWorldProviderBiome.java | 31 +- .../terraform/v1_20_R2/NMSChunkGenerator.java | 282 ++-- .../org/terraform/v1_20_R2/NMSInjector.java | 79 +- .../terraform/v1_20_R2/PopulatorDataICA.java | 220 +-- .../v1_20_R2/TerraformWorldProviderBiome.java | 39 +- .../terraform/v1_20_R3/BlockDataFixer.java | 67 +- .../v1_20_R3/CustomBiomeHandler.java | 288 ++-- .../v1_20_R3/LootTableTranslator.java | 2 +- .../v1_20_R3/MapRenderWorldProviderBiome.java | 31 +- .../terraform/v1_20_R3/NMSChunkGenerator.java | 144 +- .../org/terraform/v1_20_R3/NMSInjector.java | 74 +- .../org/terraform/v1_20_R3/PopulatorData.java | 276 +-- .../terraform/v1_20_R3/PopulatorDataICA.java | 244 +-- .../v1_20_R3/TerraformWorldProviderBiome.java | 39 +- .../terraform/v1_20_R4/BlockDataFixer.java | 67 +- .../v1_20_R4/CustomBiomeHandler.java | 298 ++-- .../v1_20_R4/LootTableTranslator.java | 2 +- .../v1_20_R4/MapRenderWorldProviderBiome.java | 27 +- .../terraform/v1_20_R4/NMSChunkGenerator.java | 140 +- .../org/terraform/v1_20_R4/NMSInjector.java | 89 +- .../org/terraform/v1_20_R4/PopulatorData.java | 278 +-- .../terraform/v1_20_R4/PopulatorDataICA.java | 212 +-- .../v1_20_R4/TerraformWorldProviderBiome.java | 30 +- .../terraform/v1_21_R1/BlockDataFixer.java | 69 +- .../v1_21_R1/CustomBiomeHandler.java | 284 ++-- .../v1_21_R1/LootTableTranslator.java | 2 +- .../v1_21_R1/MapRenderWorldProviderBiome.java | 27 +- .../terraform/v1_21_R1/NMSChunkGenerator.java | 276 +-- .../org/terraform/v1_21_R1/NMSInjector.java | 94 +- .../org/terraform/v1_21_R1/PopulatorData.java | 278 +-- .../terraform/v1_21_R1/PopulatorDataICA.java | 212 +-- .../v1_21_R1/TerraformWorldProviderBiome.java | 30 +- 515 files changed, 37618 insertions(+), 28109 deletions(-) diff --git a/.editorconfig b/.editorconfig index de68a751..ad8ad9c5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -118,7 +118,7 @@ ij_java_for_statement_wrap = on_every_item ij_java_generate_final_locals = false ij_java_generate_final_parameters = false ij_java_if_brace_force = always -ij_java_imports_layout = *,|,javax.**,java.**,|,$* +ij_java_imports_layout = *, |, javax.**, java.**, |, $* ij_java_indent_case_from_switch = true ij_java_insert_inner_class_imports = false ij_java_insert_override_annotation = true @@ -158,7 +158,7 @@ ij_java_new_line_after_lparen_in_annotation = false ij_java_new_line_after_lparen_in_deconstruction_pattern = true ij_java_new_line_after_lparen_in_record_header = false ij_java_new_line_when_body_is_presented = false -ij_java_packages_to_use_import_on_demand = java.awt.*,javax.swing.* +ij_java_packages_to_use_import_on_demand = java.awt.*, javax.swing.* ij_java_parameter_annotation_wrap = off ij_java_parameter_name_prefix = ij_java_parameter_name_suffix = diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0caf4f8d..6ae6f158 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,36 +1,36 @@ name: Gradle Build on: - push: - branches: [ master ] - pull_request: - branches: [ master ] + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 + build: + runs-on: ubuntu-latest - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' + steps: + - uses: actions/checkout@v4 - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - - name: Build with Gradle - run: ./gradlew deploy + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build with Gradle + run: ./gradlew deploy diff --git a/README.md b/README.md index 7afb0689..0febe283 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ + # Table of Contents +
Table of Contents
    @@ -31,8 +33,8 @@ git clone https://github.com/Hex27/TerraformGenerator.git cd TerraformGenerator gradlew buildProj:shadowJar ``` -The jar at `buildProj/build/libs/buildProj-all.jar` is the plugin. +The jar at `buildProj/build/libs/buildProj-all.jar` is the plugin.

    Support

    @@ -42,20 +44,27 @@ Support Discord: https://discord.gg/yW7JcqM Wiki: https://github.com/Hex27/TerraformGenerator/wiki/Configuration -TerraformGenerator is a world generator plugin that aims to provide an enhanced vanilla feel. As of now, it is in an Alpha stage, meaning some core features are not implemented yet (a list of known issues and to-dos is at the bottom). However, the world should be playable to an extent, though I will not recommend putting it on any production environment that has strict requirements, because as of now, I am in mandatory National service, and support will be bottle-necked. +TerraformGenerator is a world generator plugin that aims to provide an enhanced vanilla feel. As of now, it is in an +Alpha stage, meaning some core features are not implemented yet (a list of known issues and to-dos is at the bottom). +However, the world should be playable to an extent, though I will not recommend putting it on any production environment +that has strict requirements, because as of now, I am in mandatory National service, and support will be bottle-necked. -There are commands, but they are developer commands and only available via /op. Try not to use them unless you understand what they do. +There are commands, but they are developer commands and only available via /op. Try not to use them unless you +understand what they do. -On another note, for 1.15.2, the version released on 23rd Feb 2020 is the recommended version, as it fixes an itchy spigot issue. More details at the bottom under "bugs". 1.14.4 does not have this fix. +On another note, for 1.15.2, the version released on 23rd Feb 2020 is the recommended version, as it fixes an itchy +spigot issue. More details at the bottom under "bugs". 1.14.4 does not have this fix. -There is also support for Java 14, but be warned that it will spit some minor errors, because the plugin does some Java illegal magic to get things done. +There is also support for Java 14, but be warned that it will spit some minor errors, because the plugin does some Java +illegal magic to get things done.

    Getting started

    Step one: Install TerraformGenerator

    Make sure that you have installed the latest version of [TerraformGenerator][spigot-tfg]. -To do that, stop your server and move the jar file to your server's `plugins` directory. Afterwards can you start your server again. +To do that, stop your server and move the jar file to your server's `plugins` directory. Afterwards can you start your +server again.

    Step two: Create the world

    You can choose between two methods on how to generate the world with TerraformGenerator @@ -63,7 +72,7 @@ You can choose between two methods on how to generate the world with TerraformGe

    Method One

    1. Turn off the server if it is running -2. Open the `bukkit.yml` and add the following info to it. +2. Open the `bukkit.yml` and add the following info to it. ```yaml # By default does this section not exist within the bukkit.yml # and you have to add it yourself. @@ -76,31 +85,47 @@ You can choose between two methods on how to generate the world with TerraformGe

    Method two

    This method requires the usage of a World Management plugin. *DO METHOD ONE FIRST.* -In this example are we using Multiverse-Core. TerraformGenerator *should* work with any other World Manager, but we won't guarantee it! +In this example are we using Multiverse-Core. TerraformGenerator *should* work with any other World Manager, but we +won't guarantee it! -Before creating the world, make sure it doesn't exist already. If it does will you need to delete it using `/mvdelete ` followed by `/mvconfirm`. -To create a world with TerraformGenerator, execute `/mvcreate normal -g TerraformGenerator` where `` is the name of the world to create. +Before creating the world, make sure it doesn't exist already. If it does will you need to delete it +using `/mvdelete ` followed by `/mvconfirm`. +To create a world with TerraformGenerator, execute `/mvcreate normal -g TerraformGenerator` where `` is +the name of the world to create. **Note:** -There is a rare chance that the world might not get loaded with TerraformGenerator as the World Generator set. In those cases could newly loaded chunks break the look of the world by being normal vanilla chunks. That may mean that you haven't done method one. If you have, try doing method one alone without the world management plugin. If the problem persists, report it on github or discord. +There is a rare chance that the world might not get loaded with TerraformGenerator as the World Generator set. In those +cases could newly loaded chunks break the look of the world by being normal vanilla chunks. That may mean that you +haven't done method one. If you have, try doing method one alone without the world management plugin. If the problem +persists, report it on github or discord.

    Images

    -Find images on the wiki +Find images on the wiki https://github.com/Hex27/TerraformGenerator/wiki/Biomes https://github.com/Hex27/TerraformGenerator/wiki/Structures

    Known bugs

    -Not maintained here. You can check the issue tracker. If you've found a bug, you can open an issue, or report it on discord +Not maintained here. You can check the issue tracker. If you've found a bug, you can open an issue, or report it on +discord + [contributors-shield]: https://img.shields.io/github/contributors/Hex27/terraformgenerator.svg?style=for-the-badge + [contributors-url]: https://github.com/Hex27/terraformgenerator/graphs/contributors + [forks-shield]: https://img.shields.io/github/forks/Hex27/terraformgenerator.svg?style=for-the-badge + [forks-url]: https://github.com/Hex27/terraformgenerator/network/members + [stars-shield]: https://img.shields.io/github/stars/Hex27/terraformgenerator.svg?style=for-the-badge + [stars-url]: https://github.com/Hex27/terraformgenerator/stargazers + [issues-shield]: https://img.shields.io/github/issues/Hex27/terraformgenerator.svg?style=for-the-badge + [issues-url]: https://github.com/Hex27/terraformgenerator/issues + [spigot-tfg]: https://www.spigotmc.org/resources/75132/ diff --git a/common/src/main/java/org/terraform/biome/BiomeBank.java b/common/src/main/java/org/terraform/biome/BiomeBank.java index 5c301347..d3e9f071 100644 --- a/common/src/main/java/org/terraform/biome/BiomeBank.java +++ b/common/src/main/java/org/terraform/biome/BiomeBank.java @@ -1,14 +1,14 @@ package org.terraform.biome; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Locale; -import java.util.Random; - +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.LoadingCache; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.biome.beach.*; -import org.terraform.biome.cavepopulators.*; +import org.terraform.biome.cavepopulators.AbstractCavePopulator; +import org.terraform.biome.cavepopulators.ForestedMountainsCavePopulator; +import org.terraform.biome.cavepopulators.FrozenCavePopulator; +import org.terraform.biome.cavepopulators.MossyCavePopulator; import org.terraform.biome.flat.*; import org.terraform.biome.mountainous.*; import org.terraform.biome.ocean.*; @@ -24,85 +24,304 @@ import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.LoadingCache; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Locale; +import java.util.Random; public enum BiomeBank { // MOUNTAINOUS - SNOWY_MOUNTAINS(new SnowyMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.SNOWY, TConfigOption.BIOME_SNOWY_MOUNTAINS_WEIGHT.getInt(), new FrozenCavePopulator()), - BIRCH_MOUNTAINS(new BirchMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.COLD, TConfigOption.BIOME_BIRCH_MOUNTAINS_WEIGHT.getInt()), - ROCKY_MOUNTAINS(new RockyMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.TRANSITION, TConfigOption.BIOME_ROCKY_MOUNTAINS_WEIGHT.getInt()), - FORESTED_MOUNTAINS(new ForestedMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), new ForestedMountainsCavePopulator()), - SHATTERED_SAVANNA(new ShatteredSavannaHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt()), - PAINTED_HILLS(new PaintedHillsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_PAINTED_HILLS_WEIGHT.getInt()), - BADLANDS_CANYON(new BadlandsCanyonHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt()), + SNOWY_MOUNTAINS( + new SnowyMountainsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.SNOWY, + TConfigOption.BIOME_SNOWY_MOUNTAINS_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + BIRCH_MOUNTAINS(new BirchMountainsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.COLD, + TConfigOption.BIOME_BIRCH_MOUNTAINS_WEIGHT.getInt() + ), + ROCKY_MOUNTAINS(new RockyMountainsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_ROCKY_MOUNTAINS_WEIGHT.getInt() + ), + FORESTED_MOUNTAINS(new ForestedMountainsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), + new ForestedMountainsCavePopulator() + ), + SHATTERED_SAVANNA(new ShatteredSavannaHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt() + ), + PAINTED_HILLS(new PaintedHillsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_PAINTED_HILLS_WEIGHT.getInt() + ), + BADLANDS_CANYON(new BadlandsCanyonHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt() + ), // For now, disabled by default. - DESERT_MOUNTAINS(new DesertHillsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_DESERT_MOUNTAINS_WEIGHT.getInt()), + DESERT_MOUNTAINS( + new DesertHillsHandler(), + BiomeType.MOUNTAINOUS, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_DESERT_MOUNTAINS_WEIGHT.getInt() + ), // HIGH MOUNTAINOUS - JAGGED_PEAKS(new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.SNOWY, TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), new FrozenCavePopulator()), - COLD_JAGGED_PEAKS(new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.COLD, TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), new FrozenCavePopulator()), - TRANSITION_JAGGED_PEAKS(new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.TRANSITION, TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), new FrozenCavePopulator()), - FORESTED_PEAKS(new ForestedMountainsHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), new ForestedMountainsCavePopulator()), - SHATTERED_SAVANNA_PEAK(new ShatteredSavannaHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt()), - BADLANDS_CANYON_PEAK(new BadlandsCanyonHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt()), - + JAGGED_PEAKS( + new JaggedPeaksHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.SNOWY, + TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + COLD_JAGGED_PEAKS(new JaggedPeaksHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.COLD, + TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + TRANSITION_JAGGED_PEAKS(new JaggedPeaksHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + FORESTED_PEAKS(new ForestedMountainsHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), + new ForestedMountainsCavePopulator() + ), + SHATTERED_SAVANNA_PEAK(new ShatteredSavannaHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt() + ), + BADLANDS_CANYON_PEAK(new BadlandsCanyonHandler(), + BiomeType.HIGH_MOUNTAINOUS, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt() + ), + // OCEANIC - OCEAN(new OceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.TRANSITION, TConfigOption.BIOME_OCEAN_WEIGHT.getInt()), - BLACK_OCEAN(new BlackOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.TRANSITION, TConfigOption.BIOME_BLACK_OCEAN_WEIGHT.getInt()), - COLD_OCEAN(new ColdOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.COLD, TConfigOption.BIOME_COLD_OCEAN_WEIGHT.getInt()), - FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.SNOWY, TConfigOption.BIOME_FROZEN_OCEAN_WEIGHT.getInt(), new FrozenCavePopulator()), - WARM_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_WARM_OCEAN_WEIGHT.getInt()), - HUMID_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_HUMID_OCEAN_WEIGHT.getInt()), - DRY_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_DRY_OCEAN_WEIGHT.getInt()), - CORAL_REEF_OCEAN(new CoralReefOceanHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_CORALREEF_OCEAN_WEIGHT.getInt()), - + OCEAN( + new OceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_OCEAN_WEIGHT.getInt() + ), + BLACK_OCEAN(new BlackOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_BLACK_OCEAN_WEIGHT.getInt() + ), + COLD_OCEAN(new ColdOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.COLD, + TConfigOption.BIOME_COLD_OCEAN_WEIGHT.getInt() + ), + FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.SNOWY, + TConfigOption.BIOME_FROZEN_OCEAN_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + WARM_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_WARM_OCEAN_WEIGHT.getInt() + ), + HUMID_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_HUMID_OCEAN_WEIGHT.getInt() + ), + DRY_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_DRY_OCEAN_WEIGHT.getInt() + ), + CORAL_REEF_OCEAN(new CoralReefOceanHandler(BiomeType.OCEANIC), + BiomeType.OCEANIC, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_CORALREEF_OCEAN_WEIGHT.getInt() + ), + // RIVERS (Don't include in selectBiome) // Rivers are handled specially and will not be allocated in selectBiome - RIVER(new RiverHandler(), BiomeType.RIVER, BiomeClimate.TRANSITION), - BOG_RIVER(new BogRiverHandler(), BiomeType.RIVER, BiomeClimate.DRY_VEGETATION), - CHERRY_GROVE_RIVER(new CherryGroveRiverHandler(), BiomeType.RIVER, BiomeClimate.COLD), - SCARLET_FOREST_RIVER(new ScarletForestRiverHandler(), BiomeType.RIVER, BiomeClimate.COLD), + RIVER(new RiverHandler(), BiomeType.RIVER, BiomeClimate.TRANSITION), + BOG_RIVER(new BogRiverHandler(), BiomeType.RIVER, BiomeClimate.DRY_VEGETATION), + CHERRY_GROVE_RIVER(new CherryGroveRiverHandler(), BiomeType.RIVER, BiomeClimate.COLD), + SCARLET_FOREST_RIVER(new ScarletForestRiverHandler(), BiomeType.RIVER, BiomeClimate.COLD), JUNGLE_RIVER(new JungleRiverHandler(), BiomeType.RIVER, BiomeClimate.HUMID_VEGETATION), - FROZEN_RIVER(new FrozenRiverHandler(), BiomeType.RIVER, BiomeClimate.SNOWY, new FrozenCavePopulator()), // Special case, handle later - DARK_FOREST_RIVER(new DarkForestRiverHandler(), BiomeType.RIVER, BiomeClimate.HUMID_VEGETATION, new FrozenCavePopulator()), // Special case, handle later + FROZEN_RIVER(new FrozenRiverHandler(), + BiomeType.RIVER, + BiomeClimate.SNOWY, + new FrozenCavePopulator() + ), // Special case, handle later + DARK_FOREST_RIVER( + new DarkForestRiverHandler(), + BiomeType.RIVER, + BiomeClimate.HUMID_VEGETATION, + new FrozenCavePopulator() + ), // Special case, handle later DESERT_RIVER(new DesertRiverHandler(), BiomeType.RIVER, BiomeClimate.HOT_BARREN), BADLANDS_RIVER(new BadlandsRiverHandler(), BiomeType.RIVER, BiomeClimate.HOT_BARREN), - + // DEEP OCEANIC - DEEP_OCEAN(new OceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, TConfigOption.BIOME_DEEP_OCEAN_WEIGHT.getInt()), - DEEP_COLD_OCEAN(new ColdOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.COLD, TConfigOption.BIOME_DEEP_COLD_OCEAN_WEIGHT.getInt()), - DEEP_BLACK_OCEAN(new BlackOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, TConfigOption.BIOME_DEEP_BLACK_OCEAN_WEIGHT.getInt()), - DEEP_FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.SNOWY, TConfigOption.BIOME_DEEP_FROZEN_OCEAN_WEIGHT.getInt(), new FrozenCavePopulator()), - DEEP_WARM_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_DEEP_WARM_OCEAN_WEIGHT.getInt()), - DEEP_HUMID_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_DEEP_HUMID_OCEAN_WEIGHT.getInt()), - DEEP_DRY_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_DEEP_DRY_OCEAN_WEIGHT.getInt()), - DEEP_LUKEWARM_OCEAN(new LukewarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT.getInt()), - MUSHROOM_ISLANDS(new MushroomIslandHandler(), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, TConfigOption.BIOME_MUSHROOM_ISLAND_WEIGHT.getInt()), + DEEP_OCEAN( + new OceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_DEEP_OCEAN_WEIGHT.getInt() + ), + DEEP_COLD_OCEAN(new ColdOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.COLD, + TConfigOption.BIOME_DEEP_COLD_OCEAN_WEIGHT.getInt() + ), + DEEP_BLACK_OCEAN(new BlackOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_DEEP_BLACK_OCEAN_WEIGHT.getInt() + ), + DEEP_FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.SNOWY, + TConfigOption.BIOME_DEEP_FROZEN_OCEAN_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + DEEP_WARM_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_DEEP_WARM_OCEAN_WEIGHT.getInt() + ), + DEEP_HUMID_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_DEEP_HUMID_OCEAN_WEIGHT.getInt() + ), + DEEP_DRY_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_DEEP_DRY_OCEAN_WEIGHT.getInt() + ), + DEEP_LUKEWARM_OCEAN(new LukewarmOceansHandler(BiomeType.DEEP_OCEANIC), + BiomeType.DEEP_OCEANIC, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT.getInt() + ), + MUSHROOM_ISLANDS(new MushroomIslandHandler(), + BiomeType.DEEP_OCEANIC, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_MUSHROOM_ISLAND_WEIGHT.getInt() + ), // FLAT PLAINS(new PlainsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_PLAINS_WEIGHT.getInt()), - ELEVATED_PLAINS(new ElevatedPlainsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_ELEVATED_PLAINS_WEIGHT.getInt()), + ELEVATED_PLAINS(new ElevatedPlainsHandler(), + BiomeType.FLAT, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_ELEVATED_PLAINS_WEIGHT.getInt() + ), GORGE(new GorgeHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_GORGE_WEIGHT.getInt()), - PETRIFIED_CLIFFS(new PetrifiedCliffsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_PETRIFIEDCLIFFS_WEIGHT.getInt()), - ARCHED_CLIFFS(new ArchedCliffsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_ARCHED_CLIFFS_WEIGHT.getInt()), - SAVANNA(new SavannaHandler(), BiomeType.FLAT, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_SAVANNA_WEIGHT.getInt()), - MUDDY_BOG(new MuddyBogHandler(), BiomeType.FLAT, BiomeClimate.DRY_VEGETATION, TConfigOption.BIOME_MUDDYBOG_WEIGHT.getInt()), - FOREST(new ForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_FOREST_WEIGHT.getInt()), - JUNGLE(new JungleHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_JUNGLE_WEIGHT.getInt()), - BAMBOO_FOREST(new BambooForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_BAMBOO_FOREST_WEIGHT.getInt()), + PETRIFIED_CLIFFS(new PetrifiedCliffsHandler(), + BiomeType.FLAT, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_PETRIFIEDCLIFFS_WEIGHT.getInt() + ), + ARCHED_CLIFFS(new ArchedCliffsHandler(), + BiomeType.FLAT, + BiomeClimate.TRANSITION, + TConfigOption.BIOME_ARCHED_CLIFFS_WEIGHT.getInt() + ), + SAVANNA(new SavannaHandler(), + BiomeType.FLAT, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_SAVANNA_WEIGHT.getInt() + ), + MUDDY_BOG(new MuddyBogHandler(), + BiomeType.FLAT, + BiomeClimate.DRY_VEGETATION, + TConfigOption.BIOME_MUDDYBOG_WEIGHT.getInt() + ), + FOREST(new ForestHandler(), + BiomeType.FLAT, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_FOREST_WEIGHT.getInt() + ), + JUNGLE(new JungleHandler(), + BiomeType.FLAT, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_JUNGLE_WEIGHT.getInt() + ), + BAMBOO_FOREST(new BambooForestHandler(), + BiomeType.FLAT, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_BAMBOO_FOREST_WEIGHT.getInt() + ), DESERT(new DesertHandler(), BiomeType.FLAT, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_DESERT_WEIGHT.getInt()), - BADLANDS(new BadlandsHandler(), BiomeType.FLAT, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_BADLANDS_WEIGHT.getInt()), - ERODED_PLAINS(new ErodedPlainsHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfigOption.BIOME_ERODED_PLAINS_WEIGHT.getInt()), - SCARLET_FOREST(new ScarletForestHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfigOption.BIOME_SCARLETFOREST_WEIGHT.getInt()), - CHERRY_GROVE(new CherryGroveHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfigOption.BIOME_CHERRYGROVE_WEIGHT.getInt()), + BADLANDS(new BadlandsHandler(), + BiomeType.FLAT, + BiomeClimate.HOT_BARREN, + TConfigOption.BIOME_BADLANDS_WEIGHT.getInt() + ), + ERODED_PLAINS(new ErodedPlainsHandler(), + BiomeType.FLAT, + BiomeClimate.COLD, + TConfigOption.BIOME_ERODED_PLAINS_WEIGHT.getInt() + ), + SCARLET_FOREST(new ScarletForestHandler(), + BiomeType.FLAT, + BiomeClimate.COLD, + TConfigOption.BIOME_SCARLETFOREST_WEIGHT.getInt() + ), + CHERRY_GROVE(new CherryGroveHandler(), + BiomeType.FLAT, + BiomeClimate.COLD, + TConfigOption.BIOME_CHERRYGROVE_WEIGHT.getInt() + ), TAIGA(new TaigaHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfigOption.BIOME_TAIGA_WEIGHT.getInt()), - SNOWY_TAIGA(new SnowyTaigaHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, TConfigOption.BIOME_SNOWY_TAIGA_WEIGHT.getInt(), new FrozenCavePopulator()), - SNOWY_WASTELAND(new SnowyWastelandHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, TConfigOption.BIOME_SNOWY_WASTELAND_WEIGHT.getInt(), new FrozenCavePopulator()), - ICE_SPIKES(new IceSpikesHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, TConfigOption.BIOME_ICE_SPIKES_WEIGHT.getInt(), new FrozenCavePopulator()), - DARK_FOREST(new DarkForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_DARK_FOREST_WEIGHT.getInt()), + SNOWY_TAIGA(new SnowyTaigaHandler(), + BiomeType.FLAT, + BiomeClimate.SNOWY, + TConfigOption.BIOME_SNOWY_TAIGA_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + SNOWY_WASTELAND(new SnowyWastelandHandler(), + BiomeType.FLAT, + BiomeClimate.SNOWY, + TConfigOption.BIOME_SNOWY_WASTELAND_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + ICE_SPIKES(new IceSpikesHandler(), + BiomeType.FLAT, + BiomeClimate.SNOWY, + TConfigOption.BIOME_ICE_SPIKES_WEIGHT.getInt(), + new FrozenCavePopulator() + ), + DARK_FOREST(new DarkForestHandler(), + BiomeType.FLAT, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_DARK_FOREST_WEIGHT.getInt() + ), SWAMP(new SwampHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_SWAMP_WEIGHT.getInt()), - MANGROVE(new MangroveHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_MANGROVE_WEIGHT.getInt()), + MANGROVE(new MangroveHandler(), + BiomeType.FLAT, + BiomeClimate.HUMID_VEGETATION, + TConfigOption.BIOME_MANGROVE_WEIGHT.getInt() + ), // BEACHES (Don't include in selectBiome) SANDY_BEACH(new SandyBeachHandler(), BiomeType.BEACH, BiomeClimate.TRANSITION), @@ -116,52 +335,57 @@ public enum BiomeBank { MUDFLATS(new MudflatsHandler(), BiomeType.BEACH, BiomeClimate.HUMID_VEGETATION), // Special case, handle later CHERRY_GROVE_BEACH(new CherryGroveBeachHandler(), BiomeType.BEACH, BiomeClimate.COLD), SCARLET_FOREST_BEACH(new ScarletForestBeachHandler(), BiomeType.BEACH, BiomeClimate.COLD), - ; - // public static final BiomeBank[] VALUES = values(); - public static boolean debugPrint = false; + ; public static final ArrayList FLAT = new ArrayList<>() {{ - for(BiomeBank b : values()) { - if(b.getType() == BiomeType.FLAT) + for (BiomeBank b : values()) { + if (b.getType() == BiomeType.FLAT) { add(b); + } } }}; + private static final LoadingCache BIOMESECTION_CACHE = CacheBuilder.newBuilder() + .maximumSize(250) + .build(new BiomeSectionCacheLoader()); + // This is the most taxing calculation. Have a bigger cache. + private static final LoadingCache HEIGHTINDEPENDENTBIOME_CACHE = CacheBuilder.newBuilder() + .maximumSize( + 500) + .build(new HeightIndependentBiomeCacheLoader()); + // public static final BiomeBank[] VALUES = values(); + public static boolean debugPrint = false; + public static @Nullable BiomeBank singleLand = null; + public static @Nullable BiomeBank singleOcean = null; + public static @Nullable BiomeBank singleDeepOcean = null; + public static @Nullable BiomeBank singleMountain = null; + public static @Nullable BiomeBank singleHighMountain = null; private final BiomeHandler handler; private final BiomeType type; private final AbstractCavePopulator cavePop; private final BiomeClimate climate; private final int biomeWeight; - private static final LoadingCache BIOMESECTION_CACHE = - CacheBuilder.newBuilder() - .maximumSize(250).build(new BiomeSectionCacheLoader()); - - // This is the most taxing calculation. Have a bigger cache. - private static final LoadingCache HEIGHTINDEPENDENTBIOME_CACHE = - CacheBuilder.newBuilder() - .maximumSize(500).build(new HeightIndependentBiomeCacheLoader()); - BiomeBank(BiomeHandler handler, BiomeType type, BiomeClimate climate) { this.handler = handler; this.type = type; - + this.climate = climate; // Impossible to pick from selectBiome. this.biomeWeight = 0; - + this.cavePop = new MossyCavePopulator(); } - + BiomeBank(BiomeHandler handler, BiomeType type, BiomeClimate climate, AbstractCavePopulator cavePop) { this.handler = handler; this.type = type; this.climate = climate; - + // Impossible to pick from selectBiome. this.biomeWeight = 0; - + this.cavePop = cavePop; } - + BiomeBank(BiomeHandler handler, BiomeType type, BiomeClimate climate, int biomeWeight) { this.handler = handler; this.type = type; @@ -170,161 +394,191 @@ public enum BiomeBank { this.cavePop = new MossyCavePopulator(); } - BiomeBank(BiomeHandler handler, BiomeType type, BiomeClimate climate, int biomeWeight, AbstractCavePopulator cavePop) { + BiomeBank(BiomeHandler handler, + BiomeType type, + BiomeClimate climate, + int biomeWeight, + AbstractCavePopulator cavePop) + { this.handler = handler; this.type = type; this.climate = climate; this.cavePop = cavePop; this.biomeWeight = biomeWeight; } - + /** * @param x Block X * @param z Block Z */ public static @NotNull BiomeSection getBiomeSectionFromBlockCoords(TerraformWorld tw, int x, int z) { - BiomeSection sect = new BiomeSection(tw,x,z); -// sect.doCalculations(); - try { - sect = BIOMESECTION_CACHE.getUnchecked(sect); - } - catch(Throwable e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - sect.doCalculations(); - } - return sect; + BiomeSection sect = new BiomeSection(tw, x, z); + // sect.doCalculations(); + try { + sect = BIOMESECTION_CACHE.getUnchecked(sect); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + sect.doCalculations(); + } + return sect; } /** * ChunkX, ChunkZ + * * @return the biome section that this chunk belongs to. */ public static @NotNull BiomeSection getBiomeSectionFromChunk(TerraformWorld tw, int chunkX, int chunkZ) { - BiomeSection sect = new BiomeSection(tw,chunkX << 4, chunkZ << 4); -// sect.doCalculations(); - try { - sect = BIOMESECTION_CACHE.getUnchecked(sect); - } - catch(Throwable e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - sect.doCalculations(); - } - return sect; + BiomeSection sect = new BiomeSection(tw, chunkX << 4, chunkZ << 4); + // sect.doCalculations(); + try { + sect = BIOMESECTION_CACHE.getUnchecked(sect); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + sect.doCalculations(); + } + return sect; } - - public static @NotNull BiomeSection getBiomeSectionFromSectionCoords(TerraformWorld tw, int x, int z, boolean useSectionCoords) { - BiomeSection sect = new BiomeSection(tw,x,z,useSectionCoords); -// sect.doCalculations(); - try { - sect = BIOMESECTION_CACHE.getUnchecked(sect); - } - catch(Throwable e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - sect.doCalculations(); - } - return sect; + + public static @NotNull BiomeSection getBiomeSectionFromSectionCoords(TerraformWorld tw, + int x, + int z, + boolean useSectionCoords) + { + BiomeSection sect = new BiomeSection(tw, x, z, useSectionCoords); + // sect.doCalculations(); + try { + sect = BIOMESECTION_CACHE.getUnchecked(sect); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + sect.doCalculations(); + } + return sect; } /** - * WARNING: NOBODY SHOULD BE CALLING THIS METHOD. + * WARNING: NOBODY SHOULD BE CALLING THIS METHOD. * THIS METHOD WILL RUN ALL CALCULATIONS. *

    * Use terraformWorld.getCache(...).getBiomeBank(x,y,z) instead. + * * @return exact biome that will appear at these coordinates */ public static @NotNull BiomeBank calculateBiome(@NotNull TerraformWorld tw, int rawX, int height, int rawZ) { - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome called with args: " + tw.getName() + "," + rawX + "," + height + "," + rawZ); - - BiomeBank bank = calculateHeightIndependentBiome(tw, rawX, rawZ); - - // Bitshift rawX and rawZ. Biome storage is done every 4 blocks, - // so there's no need to recalculate for every block. - - FastNoise beachNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BEACH_HEIGHT, (world)->{ - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.PerlinFractal); - n.SetFrequency(0.01f); - n.SetFractalOctaves(4); - - return n; - }); - // If calculated height is less than sea level, but more than sea level after - // adding back river height, it means that the river height - // carved dry land into the sea level. - // That's a river. - if(height < TerraformGenerator.seaLevel - && height + HeightMap.getRawRiverDepth(tw, rawX, rawZ) >= TerraformGenerator.seaLevel) { - bank = bank.getHandler().getRiverType(); - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> River Detected"); - // If the height is at, or slightly higher than, sea level, - // it is a beach. - }else if(height >= TerraformGenerator.seaLevel - && height <= TerraformGenerator.seaLevel + 4*2*Math.abs(beachNoise.GetNoise(rawX, rawZ))) { - bank = bank.getHandler().getBeachType(); - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> Beach calculated"); - } - + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome called with args: " + + tw.getName() + + "," + + rawX + + "," + + height + + "," + + rawZ); + } + + BiomeBank bank = calculateHeightIndependentBiome(tw, rawX, rawZ); + + // Bitshift rawX and rawZ. Biome storage is done every 4 blocks, + // so there's no need to recalculate for every block. + + FastNoise beachNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BEACH_HEIGHT, (world) -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.PerlinFractal); + n.SetFrequency(0.01f); + n.SetFractalOctaves(4); + + return n; + }); + // If calculated height is less than sea level, but more than sea level after + // adding back river height, it means that the river height + // carved dry land into the sea level. + // That's a river. + if (height < TerraformGenerator.seaLevel + && height + HeightMap.getRawRiverDepth(tw, rawX, rawZ) >= TerraformGenerator.seaLevel) + { + bank = bank.getHandler().getRiverType(); + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> River Detected"); + } + // If the height is at, or slightly higher than, sea level, + // it is a beach. + } + else if (height >= TerraformGenerator.seaLevel && height <= TerraformGenerator.seaLevel + 4 * 2 * Math.abs( + beachNoise.GetNoise(rawX, rawZ))) + { + bank = bank.getHandler().getBeachType(); + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> Beach calculated"); + } + } + // Correct submerged biomes. They'll be rivers. // Exclude swamps from this check, as swamps are submerged. - if(bank != BiomeBank.SWAMP - && bank != BiomeBank.MANGROVE - && height < TerraformGenerator.seaLevel - && bank.isDry()){ - bank = bank.getHandler().getRiverType(); - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> Biome is submerged, defaulting to river"); - } - + if (bank != BiomeBank.SWAMP + && bank != BiomeBank.MANGROVE + && height < TerraformGenerator.seaLevel + && bank.isDry()) + { + bank = bank.getHandler().getRiverType(); + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> Biome is submerged, defaulting to river"); + } + } + // Oceanic biomes that are above water level // should be handled as the closest, most dominant dry biome, or be a beach - - if(!bank.isDry() && height >= TerraformGenerator.seaLevel) { - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> Submerged biome above ground detected"); - BiomeBank replacement = null; - - // If the ocean handler wants to force a beach default, it will be a beach default. - if(!bank.getHandler().forceDefaultToBeach()) - { - int highestDom = Integer.MIN_VALUE; - for(BiomeSection sect:BiomeSection.getSurroundingSections(tw, rawX, rawZ)) { - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> -> Comparison Section: " + sect.toString()); - if(sect.getBiomeBank().isDry()) { - int compDist = (int) sect.getDominanceBasedOnRadius(rawX, rawZ); - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> -> -> Dominance: " + compDist); - if(compDist > highestDom) { - replacement = sect.getBiomeBank(); - highestDom = compDist; - } - } - } - } - - // Fallback to beach if surrounding biomes are not dry - if(replacement == null) { - bank = bank.getHandler().getBeachType(); - } - else - bank = replacement; - - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> -> Submerged biome defaulted to: " + replacement); - - } - if(debugPrint) - TerraformGeneratorPlugin.logger.info("calculateBiome -> Evaluated: " + bank); - - return bank; + + if (!bank.isDry() && height >= TerraformGenerator.seaLevel) { + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> Submerged biome above ground detected"); + } + BiomeBank replacement = null; + + // If the ocean handler wants to force a beach default, it will be a beach default. + if (!bank.getHandler().forceDefaultToBeach()) { + int highestDom = Integer.MIN_VALUE; + for (BiomeSection sect : BiomeSection.getSurroundingSections(tw, rawX, rawZ)) { + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> -> Comparison Section: " + + sect.toString()); + } + if (sect.getBiomeBank().isDry()) { + int compDist = (int) sect.getDominanceBasedOnRadius(rawX, rawZ); + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> -> -> Dominance: " + compDist); + } + if (compDist > highestDom) { + replacement = sect.getBiomeBank(); + highestDom = compDist; + } + } + } + } + + // Fallback to beach if surrounding biomes are not dry + if (replacement == null) { + bank = bank.getHandler().getBeachType(); + } + else { + bank = replacement; + } + + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> -> Submerged biome defaulted to: " + + replacement); + } + + } + if (debugPrint) { + TerraformGeneratorPlugin.logger.info("calculateBiome -> Evaluated: " + bank); + } + + return bank; } - + /** * NOBODY SHOULD BE CALLING THIS METHOD. THIS IS AN INTERNAL CALCULATION, * AND IT WILL NOT RETURN THE FINAL BIOME. @@ -334,59 +588,70 @@ public enum BiomeBank { *

    * If for whatever reason, the biome must be calculated intead of * fetched from the cache, use calculateBiome(tw,x,y,z); + * * @return a biome type */ public static @NotNull BiomeBank calculateHeightIndependentBiome(TerraformWorld tw, int x, int z) { - TWSimpleLocation loc = new TWSimpleLocation(tw,x,0,z); - BiomeBank bank; - try { - bank = HEIGHTINDEPENDENTBIOME_CACHE.getUnchecked(loc); - } - catch(Throwable e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - bank = BiomeBank.PLAINS; - } - return bank; + TWSimpleLocation loc = new TWSimpleLocation(tw, x, 0, z); + BiomeBank bank; + try { + bank = HEIGHTINDEPENDENTBIOME_CACHE.getUnchecked(loc); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + bank = BiomeBank.PLAINS; + } + return bank; } - - public static @Nullable BiomeBank singleLand = null; - public static @Nullable BiomeBank singleOcean = null; - public static @Nullable BiomeBank singleDeepOcean = null; - public static @Nullable BiomeBank singleMountain = null; - public static @Nullable BiomeBank singleHighMountain = null; - public static void initSinglesConfig() { - try - { singleLand = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_TERRESTRIAL_TYPE.getString().toUpperCase(Locale.ENGLISH)); } - catch(IllegalArgumentException e) - {singleLand = null;} - try - { singleOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_OCEAN_TYPE.getString().toUpperCase(Locale.ENGLISH)); } - catch(IllegalArgumentException e) - {singleOcean = null;} - try - { singleDeepOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_DEEPOCEAN_TYPE.getString().toUpperCase(Locale.ENGLISH)); } - catch(IllegalArgumentException e) - {singleDeepOcean = null;} - try - { singleMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_MOUNTAIN_TYPE.getString().toUpperCase(Locale.ENGLISH)); } - catch(IllegalArgumentException e) - {singleMountain = null;} - try - { singleHighMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_HIGHMOUNTAIN_TYPE.getString().toUpperCase(Locale.ENGLISH)); } - catch(IllegalArgumentException e) - {singleHighMountain = null;} + + public static void initSinglesConfig() { + try { + singleLand = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_TERRESTRIAL_TYPE.getString() + .toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException e) { + singleLand = null; + } + try { + singleOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_OCEAN_TYPE.getString() + .toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException e) { + singleOcean = null; + } + try { + singleDeepOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_DEEPOCEAN_TYPE.getString() + .toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException e) { + singleDeepOcean = null; + } + try { + singleMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_MOUNTAIN_TYPE.getString() + .toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException e) { + singleMountain = null; + } + try { + singleHighMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_HIGHMOUNTAIN_TYPE.getString() + .toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException e) { + singleHighMountain = null; + } } - + /** * Does not currently work for beach and river. */ public static boolean isBiomeEnabled(@NotNull BiomeBank bank) { - - if(bank.getBiomeWeight() <= 0) - return false; - return switch(bank.getType()) { + if (bank.getBiomeWeight() <= 0) { + return false; + } + + return switch (bank.getType()) { case BEACH, RIVER -> true; // L case DEEP_OCEANIC -> singleDeepOcean == null || singleDeepOcean == bank; case FLAT -> singleLand == null || singleLand == bank; @@ -396,110 +661,171 @@ public static boolean isBiomeEnabled(@NotNull BiomeBank bank) { // L }; } - + /** * Used to get a biomebank from temperature and moisture values. */ public static @Nullable BiomeBank selectBiome(@NotNull BiomeSection section, double temperature, double moisture) { - Random sectionRand = section.getSectionRandom(); - - BiomeType targetType = null; - BiomeClimate climate = BiomeClimate.selectClimate(temperature, moisture); - - double oceanicNoise = section.getOceanLevel(); - if(oceanicNoise < 0 || TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat() < 0) - { - oceanicNoise = Math.abs(oceanicNoise); - if(oceanicNoise >= TConfigOption.BIOME_DEEP_OCEANIC_THRESHOLD.getFloat()){ - targetType = BiomeType.DEEP_OCEANIC; - }else if(oceanicNoise >= TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat()){ - targetType = BiomeType.OCEANIC; - } - } - else - { - // If it isn't an ocean, mountains may be plausible. - double mountainousNoise = section.getMountainLevel(); - if(mountainousNoise > 0) { - if(mountainousNoise >= TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat()){ - targetType = BiomeType.HIGH_MOUNTAINOUS; - }else if(mountainousNoise >= TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat()){ - targetType = BiomeType.MOUNTAINOUS; - } - } - } - - - // Force types if they're set. - if(targetType == BiomeType.OCEANIC && singleOcean != null) { - return singleOcean; - }else if(targetType == BiomeType.DEEP_OCEANIC && singleDeepOcean != null) { - return singleDeepOcean; - }else if(targetType == null && singleLand != null) { - return singleLand; - }else if(targetType == BiomeType.MOUNTAINOUS && singleMountain != null) { - return singleMountain; - }else if(targetType == BiomeType.HIGH_MOUNTAINOUS && singleHighMountain != null) { - return singleHighMountain; - } - - ArrayList contenders = new ArrayList<>(); - for(BiomeBank biome:BiomeBank.values()) { - if(biome.biomeWeight <= 0) continue; - if(targetType != null) { - if(targetType != biome.getType()) - continue; - - // Oceans and mountains only spawn with biome noise. - }else if(biome.getType() == BiomeType.DEEP_OCEANIC - || biome.getType() == BiomeType.OCEANIC - || biome.getType() == BiomeType.MOUNTAINOUS - || biome.getType() == BiomeType.HIGH_MOUNTAINOUS) { - continue; - } - - if(biome.climate == climate) { - for(int i = 0; i < biome.biomeWeight; i++) - contenders.add(biome); - } - } - - - Collections.shuffle(contenders, sectionRand); - - if(contenders.isEmpty()) { - return switch(targetType) { + Random sectionRand = section.getSectionRandom(); + + BiomeType targetType = null; + BiomeClimate climate = BiomeClimate.selectClimate(temperature, moisture); + + double oceanicNoise = section.getOceanLevel(); + if (oceanicNoise < 0 || TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat() < 0) { + oceanicNoise = Math.abs(oceanicNoise); + if (oceanicNoise >= TConfigOption.BIOME_DEEP_OCEANIC_THRESHOLD.getFloat()) { + targetType = BiomeType.DEEP_OCEANIC; + } + else if (oceanicNoise >= TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat()) { + targetType = BiomeType.OCEANIC; + } + } + else { + // If it isn't an ocean, mountains may be plausible. + double mountainousNoise = section.getMountainLevel(); + if (mountainousNoise > 0) { + if (mountainousNoise >= TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat()) { + targetType = BiomeType.HIGH_MOUNTAINOUS; + } + else if (mountainousNoise >= TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat()) { + targetType = BiomeType.MOUNTAINOUS; + } + } + } + + + // Force types if they're set. + if (targetType == BiomeType.OCEANIC && singleOcean != null) { + return singleOcean; + } + else if (targetType == BiomeType.DEEP_OCEANIC && singleDeepOcean != null) { + return singleDeepOcean; + } + else if (targetType == null && singleLand != null) { + return singleLand; + } + else if (targetType == BiomeType.MOUNTAINOUS && singleMountain != null) { + return singleMountain; + } + else if (targetType == BiomeType.HIGH_MOUNTAINOUS && singleHighMountain != null) { + return singleHighMountain; + } + + ArrayList contenders = new ArrayList<>(); + for (BiomeBank biome : BiomeBank.values()) { + if (biome.biomeWeight <= 0) { + continue; + } + if (targetType != null) { + if (targetType != biome.getType()) { + continue; + } + + // Oceans and mountains only spawn with biome noise. + } + else if (biome.getType() == BiomeType.DEEP_OCEANIC + || biome.getType() == BiomeType.OCEANIC + || biome.getType() == BiomeType.MOUNTAINOUS + || biome.getType() == BiomeType.HIGH_MOUNTAINOUS) + { + continue; + } + + if (biome.climate == climate) { + for (int i = 0; i < biome.biomeWeight; i++) { + contenders.add(biome); + } + } + } + + + Collections.shuffle(contenders, sectionRand); + + if (contenders.isEmpty()) { + return switch (targetType) { case BEACH -> { - TerraformGeneratorPlugin.logger.info("Defaulted for beach: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for beach: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_BEACH.getString()); } case DEEP_OCEANIC -> { - TerraformGeneratorPlugin.logger.info("Defaulted for deep oceanic: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for deep oceanic: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_DEEPOCEANIC.getString()); } case FLAT -> { - TerraformGeneratorPlugin.logger.info("Defaulted for flat: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for flat: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_FLAT.getString()); } case MOUNTAINOUS -> { - TerraformGeneratorPlugin.logger.info("Defaulted for mountainous: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for mountainous: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_MOUNTAINOUS.getString()); } case OCEANIC -> { - TerraformGeneratorPlugin.logger.info("Defaulted for ocean: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for ocean: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_OCEANIC.getString()); } case RIVER -> { - TerraformGeneratorPlugin.logger.info("Defaulted for river: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for river: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_RIVER.getString()); } case HIGH_MOUNTAINOUS -> { - TerraformGeneratorPlugin.logger.info("Defaulted for high mountainous: " + temperature + " : " + moisture + "," + climate + ":" + targetType); + TerraformGeneratorPlugin.logger.info("Defaulted for high mountainous: " + + temperature + + " : " + + moisture + + "," + + climate + + ":" + + targetType); yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_HIGHMOUNTAINOUS.getString()); } }; - }else - return contenders.get(0); + } + else { + return contenders.get(0); + } } /** @@ -520,14 +846,14 @@ public BiomeHandler getHandler() { return handler; } - public BiomeClimate getClimate() { - // TODO Auto-generated method stub - return climate; - } + public BiomeClimate getClimate() { + // TODO Auto-generated method stub + return climate; + } - public int getBiomeWeight() { - return biomeWeight; - } + public int getBiomeWeight() { + return biomeWeight; + } public boolean isDry() { return getType().isDry(); diff --git a/common/src/main/java/org/terraform/biome/BiomeBlender.java b/common/src/main/java/org/terraform/biome/BiomeBlender.java index b4323732..2fe6e921 100644 --- a/common/src/main/java/org/terraform/biome/BiomeBlender.java +++ b/common/src/main/java/org/terraform/biome/BiomeBlender.java @@ -17,11 +17,11 @@ * other biomes. */ public class BiomeBlender { + final boolean blendBiomeGrid; + final boolean blendWater; private final TerraformWorld tw; double gridBlendingFactor = 1; - final boolean blendBiomeGrid; int riverThreshold = 5; - final boolean blendWater; boolean blendBeachesToo = true; int smoothBlendTowardsRivers = -1; @@ -56,36 +56,46 @@ public double getEdgeFactor(BiomeBank currentBiome, int x, int z, double riverDe if (blendWater) { // Linear blending when closer to water - double riverFactor; - if(smoothBlendTowardsRivers == -1) { - riverFactor = blendBeachesToo ? riverDepth / (-riverThreshold) : - (HeightMap.getPreciseHeight(tw, x, z) - TerraformGenerator.seaLevel) / riverThreshold; - } - else - { - double height = HeightMap.getPreciseHeight(tw, x, z); - if(height > TerraformGenerator.seaLevel + smoothBlendTowardsRivers) - riverFactor = 1; - else if(height <= TerraformGenerator.seaLevel) - riverFactor = 0; - else - { - // if(height > TerraformGenerator.seaLevel) - // height = TerraformGenerator.seaLevel; - // Linearly blend - riverFactor = ((height - TerraformGenerator.seaLevel)/((double)smoothBlendTowardsRivers)); - // TerraformGeneratorPlugin.logger.info("RF" + riverFactor); - } - } - if (riverFactor < factor) factor = Math.max(0, riverFactor); + double riverFactor; + if (smoothBlendTowardsRivers == -1) { + riverFactor = blendBeachesToo + ? riverDepth / (-riverThreshold) + : (HeightMap.getPreciseHeight(tw, x, z) - TerraformGenerator.seaLevel) / riverThreshold; + } + else { + double height = HeightMap.getPreciseHeight(tw, x, z); + if (height > TerraformGenerator.seaLevel + smoothBlendTowardsRivers) { + riverFactor = 1; + } + else if (height <= TerraformGenerator.seaLevel) { + riverFactor = 0; + } + else { + // if(height > TerraformGenerator.seaLevel) + // height = TerraformGenerator.seaLevel; + // Linearly blend + riverFactor = ((height - TerraformGenerator.seaLevel) / ((double) smoothBlendTowardsRivers)); + // TerraformGeneratorPlugin.logger.info("RF" + riverFactor); + } + } + if (riverFactor < factor) { + factor = Math.max(0, riverFactor); + } } if (blendBiomeGrid) { // Same here when closer to biome edge - double gridFactor = getGridEdgeFactor(currentBiome, tw,x,z);// getGridEdgeFactor(BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z), - // currentBiome, - // BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getTemperature(), BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getMoisture()); - if (gridFactor < factor) factor = gridFactor; + double gridFactor = getGridEdgeFactor( + currentBiome, + tw, + x, + z + );// getGridEdgeFactor(BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z), + // currentBiome, + // BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getTemperature(), BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getMoisture()); + if (gridFactor < factor) { + factor = gridFactor; + } } return factor; @@ -96,34 +106,38 @@ else if(height <= TerraformGenerator.seaLevel) Updated to reflect new changes to heightmap and biomes */ public double getGridEdgeFactor(BiomeBank currentBiome, TerraformWorld tw, int x, int z) { - SimpleLocation target = new SimpleLocation(x,0,z); - Collection sections = BiomeSection.getSurroundingSections(tw, 3, x, z); - - BiomeSection mostDominantTarget = null; - double dominance = -100; - for (BiomeSection section : sections) { - if (section.getBiomeBank() == currentBiome) { - double dom = section.getDominance(target); - if (dom > dominance) { - mostDominantTarget = section; - dominance = dom; + SimpleLocation target = new SimpleLocation(x, 0, z); + Collection sections = BiomeSection.getSurroundingSections(tw, 3, x, z); + + BiomeSection mostDominantTarget = null; + double dominance = -100; + for (BiomeSection section : sections) { + if (section.getBiomeBank() == currentBiome) { + double dom = section.getDominance(target); + if (dom > dominance) { + mostDominantTarget = section; + dominance = dom; } } } - if (mostDominantTarget == null) return 0; + if (mostDominantTarget == null) { + return 0; + } double factor = 1; - for (BiomeSection section : sections) { - if (section.getBiomeBank() == currentBiome) continue; + for (BiomeSection section : sections) { + if (section.getBiomeBank() == currentBiome) { + continue; + } - float dom = section.getDominance(target); - double diff = Math.max(0, dominance - dom); + float dom = section.getDominance(target); + double diff = Math.max(0, dominance - dom); - factor = Math.min(factor, diff * gridBlendingFactor); + factor = Math.min(factor, diff * gridBlendingFactor); } - return Math.min(factor, 1); + return Math.min(factor, 1); } /** @@ -145,7 +159,7 @@ public double getGridEdgeFactor(BiomeBank currentBiome, TerraformWorld tw, int x this.riverThreshold = riverThreshold; return this; } - + /** * Use a slower algorithm to smooth towards rivers based on heightmap's getPreciseHeight *

    @@ -153,8 +167,8 @@ public double getGridEdgeFactor(BiomeBank currentBiome, TerraformWorld tw, int x */ public @NotNull BiomeBlender setSmoothBlendTowardsRivers(int smoothBlendTowardsRivers) { - this.smoothBlendTowardsRivers = smoothBlendTowardsRivers; - return this; + this.smoothBlendTowardsRivers = smoothBlendTowardsRivers; + return this; } /** diff --git a/common/src/main/java/org/terraform/biome/BiomeClimate.java b/common/src/main/java/org/terraform/biome/BiomeClimate.java index 2fe7e4fb..f39faa43 100644 --- a/common/src/main/java/org/terraform/biome/BiomeClimate.java +++ b/common/src/main/java/org/terraform/biome/BiomeClimate.java @@ -1,91 +1,95 @@ package org.terraform.biome; import org.jetbrains.annotations.NotNull; -import org.terraform.utils.Range; import org.terraform.main.config.TConfigOption; +import org.terraform.utils.Range; public enum BiomeClimate { - // Tree-Dense areas - HUMID_VEGETATION(Range.between( - TConfigOption.CLIMATE_HUMIDVEGETATION_MINTEMP.getDouble(), - TConfigOption.CLIMATE_HUMIDVEGETATION_MAXTEMP.getDouble()), - Range.between( - TConfigOption.CLIMATE_HUMIDVEGETATION_MINMOIST.getDouble(), - TConfigOption.CLIMATE_HUMIDVEGETATION_MAXMOIST.getDouble()),2), - - // Savannas - DRY_VEGETATION(Range.between( - TConfigOption.CLIMATE_DRYVEGETATION_MINTEMP.getDouble(), - TConfigOption.CLIMATE_DRYVEGETATION_MAXTEMP.getDouble()), - Range.between( - TConfigOption.CLIMATE_DRYVEGETATION_MINMOIST.getDouble(), - TConfigOption.CLIMATE_DRYVEGETATION_MAXMOIST.getDouble()),1), - - // Deserts - HOT_BARREN(Range.between( - TConfigOption.CLIMATE_HOTBARREN_MINTEMP.getDouble(), - TConfigOption.CLIMATE_HOTBARREN_MAXTEMP.getDouble()), - Range.between( - TConfigOption.CLIMATE_HOTBARREN_MINMOIST.getDouble(), - TConfigOption.CLIMATE_HOTBARREN_MAXMOIST.getDouble()),2), - - // Cold biomes - taigas, maybe eroded plains - COLD(Range.between( - TConfigOption.CLIMATE_COLD_MINTEMP.getDouble(), - TConfigOption.CLIMATE_COLD_MAXTEMP.getDouble()), - Range.between( - TConfigOption.CLIMATE_COLD_MINMOIST.getDouble(), - TConfigOption.CLIMATE_COLD_MAXMOIST.getDouble()),1), - - // Any snowy biomes. - SNOWY(Range.between( - TConfigOption.CLIMATE_SNOWY_MINTEMP.getDouble(), - TConfigOption.CLIMATE_SNOWY_MAXTEMP.getDouble()), - Range.between( - TConfigOption.CLIMATE_SNOWY_MINMOIST.getDouble(), - TConfigOption.CLIMATE_SNOWY_MAXMOIST.getDouble()),2), - - // Default climate. - TRANSITION(Range.between(-4.0,4.0),Range.between(-4.0,4.0),0), - ; - - final Range temperatureRange; - final Range moistureRange; - final int priority; // Higher priority means override. - BiomeClimate(Range temperatureRange, Range moistureRange, int priority){ - this.temperatureRange = temperatureRange; - this.moistureRange = moistureRange; - this.priority = priority; - } - - public Range getTemperatureRange() { - return temperatureRange; - } - - public Range getMoistureRange() { - return moistureRange; - } - - private static boolean isInRange(double val, @NotNull Range r) { - return r.getMaximum() >= val && r.getMinimum() <= val; - } - - public static @NotNull BiomeClimate selectClimate(double temp, double moist) { - - BiomeClimate candidate = BiomeClimate.TRANSITION; - - for(BiomeClimate climate:BiomeClimate.values()) - if(isInRange(temp,climate.getTemperatureRange()) - && isInRange(moist,climate.getMoistureRange())) { - - // If there are multiple climate ranges that apply to this, then - // the climate with the highest priority will win. - if(candidate.priority < climate.priority) + // Tree-Dense areas + HUMID_VEGETATION(Range.between(TConfigOption.CLIMATE_HUMIDVEGETATION_MINTEMP.getDouble(), + TConfigOption.CLIMATE_HUMIDVEGETATION_MAXTEMP.getDouble() + ), Range.between(TConfigOption.CLIMATE_HUMIDVEGETATION_MINMOIST.getDouble(), + TConfigOption.CLIMATE_HUMIDVEGETATION_MAXMOIST.getDouble() + ), 2), + + // Savannas + DRY_VEGETATION(Range.between(TConfigOption.CLIMATE_DRYVEGETATION_MINTEMP.getDouble(), + TConfigOption.CLIMATE_DRYVEGETATION_MAXTEMP.getDouble() + ), Range.between(TConfigOption.CLIMATE_DRYVEGETATION_MINMOIST.getDouble(), + TConfigOption.CLIMATE_DRYVEGETATION_MAXMOIST.getDouble() + ), 1), + + // Deserts + HOT_BARREN(Range.between(TConfigOption.CLIMATE_HOTBARREN_MINTEMP.getDouble(), + TConfigOption.CLIMATE_HOTBARREN_MAXTEMP.getDouble() + ), + Range.between(TConfigOption.CLIMATE_HOTBARREN_MINMOIST.getDouble(), + TConfigOption.CLIMATE_HOTBARREN_MAXMOIST.getDouble() + ), + 2 + ), + + // Cold biomes - taigas, maybe eroded plains + COLD(Range.between(TConfigOption.CLIMATE_COLD_MINTEMP.getDouble(), TConfigOption.CLIMATE_COLD_MAXTEMP.getDouble()), + Range.between(TConfigOption.CLIMATE_COLD_MINMOIST.getDouble(), + TConfigOption.CLIMATE_COLD_MAXMOIST.getDouble() + ), + 1 + ), + + // Any snowy biomes. + SNOWY(Range.between(TConfigOption.CLIMATE_SNOWY_MINTEMP.getDouble(), + TConfigOption.CLIMATE_SNOWY_MAXTEMP.getDouble() + ), + Range.between(TConfigOption.CLIMATE_SNOWY_MINMOIST.getDouble(), + TConfigOption.CLIMATE_SNOWY_MAXMOIST.getDouble() + ), + 2 + ), + + // Default climate. + TRANSITION(Range.between(-4.0, 4.0), Range.between(-4.0, 4.0), 0), + ; + + final Range temperatureRange; + final Range moistureRange; + final int priority; // Higher priority means override. + + BiomeClimate(Range temperatureRange, Range moistureRange, int priority) { + this.temperatureRange = temperatureRange; + this.moistureRange = moistureRange; + this.priority = priority; + } + + private static boolean isInRange(double val, @NotNull Range r) { + return r.getMaximum() >= val && r.getMinimum() <= val; + } + + public static @NotNull BiomeClimate selectClimate(double temp, double moist) { + + BiomeClimate candidate = BiomeClimate.TRANSITION; + + for (BiomeClimate climate : BiomeClimate.values()) { + if (isInRange(temp, climate.getTemperatureRange()) && isInRange(moist, climate.getMoistureRange())) { + + // If there are multiple climate ranges that apply to this, then + // the climate with the highest priority will win. + if (candidate.priority < climate.priority) { candidate = climate; - } - - return candidate; - } - + } + } + } + + return candidate; + } + + public Range getTemperatureRange() { + return temperatureRange; + } + + public Range getMoistureRange() { + return moistureRange; + } + } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/biome/BiomeHandler.java b/common/src/main/java/org/terraform/biome/BiomeHandler.java index 5060ea30..e509446f 100644 --- a/common/src/main/java/org/terraform/biome/BiomeHandler.java +++ b/common/src/main/java/org/terraform/biome/BiomeHandler.java @@ -17,8 +17,9 @@ public abstract class BiomeHandler { public abstract boolean isOcean(); public @NotNull CustomBiomeType getCustomBiome() { - return CustomBiomeType.NONE; + return CustomBiomeType.NONE; } + public abstract Biome getBiome(); // public abstract int getHeight(int x, int z, Random rand); @@ -42,16 +43,22 @@ public abstract class BiomeHandler { *
    * Structure exclusion zones does not stop this method, so structures * will have to get rid of the stuff placed by this method + * * @param surfaceY cached height from TerraformGenerator */ - public abstract void populateSmallItems(TerraformWorld tw, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data); - + public abstract void populateSmallItems(TerraformWorld tw, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data); + public abstract void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data); public int getMaxHeightForCaves(@NotNull TerraformWorld tw, int x, int z) { - return tw.maxY; + return tw.maxY; } - + /** * @return The used handler for transforming * the terrain. If handler uses another @@ -72,30 +79,39 @@ public int getMaxHeightForCaves(@NotNull TerraformWorld tw, int x, int z) { *
    * Purify into just X,Z queries, as TerraformGenerator is ALREADY iterating * through x,z. There's no need for a nested one here. + * * @param x [0-15] internal chunk coords * @param z [0-15] internal chunk coords */ - public void transformTerrain(ChunkCache cache, TerraformWorld tw, Random random, ChunkGenerator.ChunkData chunk, int x, int z, int chunkX, int chunkZ) { + public void transformTerrain(ChunkCache cache, + TerraformWorld tw, + Random random, + ChunkGenerator.ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { // Do nothing by default. } // Beach type. This will be used instead if the height is too close to sea level. public @NotNull BiomeBank getBeachType() { - return BiomeBank.SANDY_BEACH; + return BiomeBank.SANDY_BEACH; } - + // River type. This will be used instead if the heightmap got carved into a river. public @NotNull BiomeBank getRiverType() { - return BiomeBank.RIVER; + return BiomeBank.RIVER; } - + // By default, use the normal height map. // Omit mountain and sea calculations - they're not necessary. public double calculateHeight(TerraformWorld tw, int x, int z) { return HeightMap.CORE.getHeight(tw, x, z); } - + public boolean forceDefaultToBeach() { - return false; + return false; } } diff --git a/common/src/main/java/org/terraform/biome/BiomeSection.java b/common/src/main/java/org/terraform/biome/BiomeSection.java index 8bb49736..de0f97da 100644 --- a/common/src/main/java/org/terraform/biome/BiomeSection.java +++ b/common/src/main/java/org/terraform/biome/BiomeSection.java @@ -1,10 +1,5 @@ package org.terraform.biome; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; -import java.util.Random; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.data.SimpleLocation; @@ -15,217 +10,229 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Objects; +import java.util.Random; + public class BiomeSection { - private final int x; + // A BiomeSection is 128 blocks wide (Default of bitshift 7). + public static final int bitshifts = TConfigOption.BIOME_SECTION_BITSHIFTS.getInt(); + public static final int sectionWidth = (int) (1 << bitshifts); + public static final int minSize = sectionWidth; + public static final int dominanceThreshold = (int) (0.35 * sectionWidth); + private final int x; private final int z; - // A BiomeSection is 128 blocks wide (Default of bitshift 7). - public static final int bitshifts = TConfigOption.BIOME_SECTION_BITSHIFTS.getInt(); - private final TerraformWorld tw; - public static final int sectionWidth = (int) (1 << bitshifts); - public static final int minSize = sectionWidth; - public static final int dominanceThreshold = (int)(0.35 * sectionWidth); - private float temperature; - private float moisture; - private int radius; - private @Nullable BiomeBank biome; - private FastNoise shapeNoise; - - /** - * Block x and z - * + private final TerraformWorld tw; + private float temperature; + private float moisture; + private int radius; + private @Nullable BiomeBank biome; + private FastNoise shapeNoise; + + /** + * Block x and z */ - protected BiomeSection(TerraformWorld tw, int x, int z) { - this.x = x >> bitshifts; - this.z = z >> bitshifts; - this.tw = tw; - } - - protected BiomeSection(TerraformWorld tw, int x, int z, boolean useSectionCoords) { - this.x = x; - this.z = z; - this.tw = tw; - } - - protected void doCalculations() { - this.radius = GenUtils.randInt(getSectionRandom(), minSize / 2, 5 * minSize / 4); - this.shapeNoise = new FastNoise(Objects.hash(tw.getSeed(), x, z)); - shapeNoise.SetNoiseType(NoiseType.SimplexFractal); - shapeNoise.SetFractalOctaves(3); - shapeNoise.SetFrequency(0.01f); - this.biome = this.parseBiomeBank(); - } - - /** - * @return the width * width closest biome sections to this block point. - */ - public static @NotNull Collection getSurroundingSections(TerraformWorld tw, int width, int blockX, int blockZ) { - BiomeSection homeSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, blockX, blockZ); - Collection sections = new ArrayList<>(); - - SimpleLocation center = homeSection.getCenter(); - int startX, startZ; - if (width % 2 == 1) { - startX = startZ = -width / 2; - } else { - startX = blockX >= center.getX() ? -width / 2 - 1 : -width / 2 ; - startZ = blockZ >= center.getZ() ? -width / 2 - 1 : -width / 2 ; + protected BiomeSection(TerraformWorld tw, int x, int z) { + this.x = x >> bitshifts; + this.z = z >> bitshifts; + this.tw = tw; + } + + protected BiomeSection(TerraformWorld tw, int x, int z, boolean useSectionCoords) { + this.x = x; + this.z = z; + this.tw = tw; + } + + /** + * @return the width * width closest biome sections to this block point. + */ + public static @NotNull Collection getSurroundingSections(TerraformWorld tw, + int width, + int blockX, + int blockZ) + { + BiomeSection homeSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, blockX, blockZ); + Collection sections = new ArrayList<>(); + + SimpleLocation center = homeSection.getCenter(); + int startX, startZ; + if (width % 2 == 1) { + startX = startZ = -width / 2; + } + else { + startX = blockX >= center.getX() ? -width / 2 - 1 : -width / 2; + startZ = blockZ >= center.getZ() ? -width / 2 - 1 : -width / 2; } - for (int rx = startX; rx < startX + width; rx++) { - for (int rz = startZ; rz < startZ + width; rz++) { + for (int rx = startX; rx < startX + width; rx++) { + for (int rz = startZ; rz < startZ + width; rz++) { sections.add(homeSection.getRelative(rx, rz)); - } + } } - if (sections.size() != width * width) + if (sections.size() != width * width) { TerraformGeneratorPlugin.logger.error("Section size was not " + (width * width) + "."); + } - return sections; + return sections; } - /** - * - * @return the four closest biome sections to this block point - */ - public static @NotNull Collection getSurroundingSections(TerraformWorld tw, int blockX, int blockZ) { - Collection sections = new ArrayList<>(); - - BiomeSection homeBiome = BiomeBank.getBiomeSectionFromBlockCoords(tw, blockX, blockZ); - sections.add(homeBiome); - - SimpleLocation center = homeBiome.getCenter(); - if (blockX >= center.getX()) { - if (blockZ >= center.getZ()) { - sections.add(homeBiome.getRelative(1, 0)); - sections.add(homeBiome.getRelative(1, 1)); - sections.add(homeBiome.getRelative(0, 1)); - } else { - sections.add(homeBiome.getRelative(1, 0)); - sections.add(homeBiome.getRelative(1, -1)); - sections.add(homeBiome.getRelative(0, -1)); - } - } else { - if (blockZ >= center.getZ()) { - sections.add(homeBiome.getRelative(-1, 0)); - sections.add(homeBiome.getRelative(-1, 1)); - sections.add(homeBiome.getRelative(0, 1)); - } else { - sections.add(homeBiome.getRelative(-1, 0)); - sections.add(homeBiome.getRelative(-1, -1)); - sections.add(homeBiome.getRelative(0, -1)); - } - - } + /** + * @return the four closest biome sections to this block point + */ + public static @NotNull Collection getSurroundingSections(TerraformWorld tw, int blockX, int blockZ) { + Collection sections = new ArrayList<>(); + + BiomeSection homeBiome = BiomeBank.getBiomeSectionFromBlockCoords(tw, blockX, blockZ); + sections.add(homeBiome); + + SimpleLocation center = homeBiome.getCenter(); + if (blockX >= center.getX()) { + if (blockZ >= center.getZ()) { + sections.add(homeBiome.getRelative(1, 0)); + sections.add(homeBiome.getRelative(1, 1)); + sections.add(homeBiome.getRelative(0, 1)); + } + else { + sections.add(homeBiome.getRelative(1, 0)); + sections.add(homeBiome.getRelative(1, -1)); + sections.add(homeBiome.getRelative(0, -1)); + } + } + else { + if (blockZ >= center.getZ()) { + sections.add(homeBiome.getRelative(-1, 0)); + sections.add(homeBiome.getRelative(-1, 1)); + sections.add(homeBiome.getRelative(0, 1)); + } + else { + sections.add(homeBiome.getRelative(-1, 0)); + sections.add(homeBiome.getRelative(-1, -1)); + sections.add(homeBiome.getRelative(0, -1)); + } + + } return sections; - } - - public @NotNull Random getSectionRandom() { - return new Random(Objects.hash(tw.getSeed(), x, z)); - } + } + + public static @NotNull BiomeSection getMostDominantSection(@NotNull TerraformWorld tw, int x, int z) { + + double dither = TConfigOption.BIOME_DITHER.getDouble(); + Random locationBasedRandom = new Random(Objects.hash(tw.getSeed(), x, z)); + SimpleLocation target = new SimpleLocation(x, 0, z); + BiomeSection homeSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); + + // Don't calculate if distance is very close to center + if (target.distance(homeSection.getCenter()) <= dominanceThreshold) { + return homeSection; + } - public @NotNull Random getSectionRandom(int multiplier) { - return new Random((long) multiplier *Objects.hash(tw.getSeed(), x, z)); - } + Collection sections = BiomeSection.getSurroundingSections(tw, x, z); + BiomeSection mostDominant = homeSection; - public @NotNull BiomeSection getRelative(int x, int z) { + for (BiomeSection sect : sections) { + float dom = (float) (sect.getDominance(target) + GenUtils.randDouble(locationBasedRandom, -dither, dither)); + + if (dom > mostDominant.getDominance(target) + GenUtils.randDouble(locationBasedRandom, -dither, dither)) { + mostDominant = sect; + } + } + + return mostDominant; + } + + protected void doCalculations() { + this.radius = GenUtils.randInt(getSectionRandom(), minSize / 2, 5 * minSize / 4); + this.shapeNoise = new FastNoise(Objects.hash(tw.getSeed(), x, z)); + shapeNoise.SetNoiseType(NoiseType.SimplexFractal); + shapeNoise.SetFractalOctaves(3); + shapeNoise.SetFrequency(0.01f); + this.biome = this.parseBiomeBank(); + } + + public @NotNull Random getSectionRandom() { + return new Random(Objects.hash(tw.getSeed(), x, z)); + } + + public @NotNull Random getSectionRandom(int multiplier) { + return new Random((long) multiplier * Objects.hash(tw.getSeed(), x, z)); + } + + public @NotNull BiomeSection getRelative(int x, int z) { return BiomeBank.getBiomeSectionFromSectionCoords(this.tw, this.x + x, this.z + z, true); - } - - public @Nullable BiomeBank getBiomeBank() { - return biome; - } - - private @Nullable BiomeBank parseBiomeBank() { - temperature = 3.0f*2.5f*tw.getTemperatureOctave().GetNoise(this.x, this.z); - moisture = 3.0f*2.5f*tw.getMoistureOctave().GetNoise(this.x, this.z); - - return BiomeBank.selectBiome(this, temperature, moisture);// BiomeGrid.calculateBiome(BiomeType.FLAT, temperature, moisture); - } - - /** - * Will be used to calculate which biome section has dominance in a certain - * block - * + } + + public @Nullable BiomeBank getBiomeBank() { + return biome; + } + + private @Nullable BiomeBank parseBiomeBank() { + temperature = 3.0f * 2.5f * tw.getTemperatureOctave().GetNoise(this.x, this.z); + moisture = 3.0f * 2.5f * tw.getMoistureOctave().GetNoise(this.x, this.z); + + return BiomeBank.selectBiome( + this, + temperature, + moisture + );// BiomeGrid.calculateBiome(BiomeType.FLAT, temperature, moisture); + } + + /** + * Will be used to calculate which biome section has dominance in a certain + * block */ - public float getDominance(@NotNull SimpleLocation target) { - return getDominanceBasedOnRadius(target.getX(), target.getZ()); - } + public float getDominance(@NotNull SimpleLocation target) { + return getDominanceBasedOnRadius(target.getX(), target.getZ()); + } - public float getDominanceBasedOnRadius(int blockX, int blockZ) { - SimpleLocation center = this.getCenter(); + public float getDominanceBasedOnRadius(int blockX, int blockZ) { + SimpleLocation center = this.getCenter(); - int xOffset = center.getX() - blockX; - int zOffset = center.getZ() - blockZ; + int xOffset = center.getX() - blockX; + int zOffset = center.getZ() - blockZ; - double equationResult = Math.pow(xOffset, 2) / Math.pow(radius, 2) - + Math.pow(zOffset, 2) / Math.pow(radius, 2) - + 0.7 * shapeNoise.GetNoise(xOffset, zOffset); + double equationResult = Math.pow(xOffset, 2) / Math.pow(radius, 2) + + Math.pow(zOffset, 2) / Math.pow(radius, 2) + + 0.7 * shapeNoise.GetNoise(xOffset, zOffset); return (float) (1 - 1 * (equationResult)); - } + } - public @NotNull SimpleLocation getCenter() { - int x = ((this.x << bitshifts)) + sectionWidth / 2; - int z = ((this.z << bitshifts)) + sectionWidth / 2; + public @NotNull SimpleLocation getCenter() { + int x = ((this.x << bitshifts)) + sectionWidth / 2; + int z = ((this.z << bitshifts)) + sectionWidth / 2; return new SimpleLocation(x, 0, z); - } - - - /** - * - * @return Block coords of lowest coord pair in the section's square - */ - public @NotNull SimpleLocation getLowerBounds() { - int x = ((this.x << bitshifts)); - int z = ((this.z << bitshifts)); - return new SimpleLocation(x, 0, z); - } - - /** - * - * @return Block coords of highest coord pair in the section's square - */ - public @NotNull SimpleLocation getUpperBounds() { - int x = ((this.x << bitshifts)) + sectionWidth; - int z = ((this.z << bitshifts)) + sectionWidth; - return new SimpleLocation(x, 0, z); - } - - public static @NotNull BiomeSection getMostDominantSection(@NotNull TerraformWorld tw, int x, int z) { + } - double dither = TConfigOption.BIOME_DITHER.getDouble(); - Random locationBasedRandom = new Random(Objects.hash(tw.getSeed(),x,z)); - SimpleLocation target = new SimpleLocation(x,0,z); - BiomeSection homeSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, x,z); - - // Don't calculate if distance is very close to center - if(target.distance(homeSection.getCenter()) <= dominanceThreshold) { - return homeSection; - } - - Collection sections = BiomeSection.getSurroundingSections(tw, x, z); - BiomeSection mostDominant = homeSection; - - for(BiomeSection sect:sections) { - float dom = (float) (sect.getDominance(target)+GenUtils.randDouble(locationBasedRandom,-dither,dither)); - - if(dom > mostDominant.getDominance(target)+GenUtils.randDouble(locationBasedRandom,-dither,dither)) - mostDominant = sect; - } - - return mostDominant; - } - - /** - * - * @param radius in biomesection coords - * @return surrounding biome sections at radius distance away - */ + /** + * @return Block coords of lowest coord pair in the section's square + */ + public @NotNull SimpleLocation getLowerBounds() { + int x = ((this.x << bitshifts)); + int z = ((this.z << bitshifts)); + return new SimpleLocation(x, 0, z); + } + + /** + * @return Block coords of highest coord pair in the section's square + */ + public @NotNull SimpleLocation getUpperBounds() { + int x = ((this.x << bitshifts)) + sectionWidth; + int z = ((this.z << bitshifts)) + sectionWidth; + return new SimpleLocation(x, 0, z); + } + + /** + * @param radius in biomesection coords + * @return surrounding biome sections at radius distance away + */ public @NotNull Collection getRelativeSurroundingSections(int radius) { if (radius == 0) { - BiomeSection target = this; - return new ArrayList<>() {{ + BiomeSection target = this; + return new ArrayList<>() {{ add(target); }}; } @@ -235,117 +242,120 @@ public float getDominanceBasedOnRadius(int blockX, int blockZ) { // xxx x x // xxxxx ArrayList candidates = new ArrayList<>(); - + // Lock rX, iterate rZ - for(int rx:new int[] {-radius,radius}) { - for (int rz = -radius; rz <= radius; rz++) { - candidates.add(this.getRelative(rx, rz)); - } + for (int rx : new int[] {-radius, radius}) { + for (int rz = -radius; rz <= radius; rz++) { + candidates.add(this.getRelative(rx, rz)); + } } - + // Lock rZ, iterate rX - for(int rz:new int[] {-radius,radius}) { - for (int rx = 1-radius; rx <= radius-1; rx++) { - candidates.add(this.getRelative(rx, rz)); + for (int rz : new int[] {-radius, radius}) { + for (int rx = 1 - radius; rx <= radius - 1; rx++) { + candidates.add(this.getRelative(rx, rz)); } - } + } return candidates; } - + /** - * * @return the subsection within this biome section that the coordinates belong in. * Works even if the coords are outside the biome section. */ public @NotNull BiomeSubSection getSubSection(int rawX, int rawZ) { - // if(new BiomeSection(tw, rawX, rawZ).equals(this)) { - SimpleLocation sectionCenter = this.getCenter(); - int relXFromCenter = rawX - sectionCenter.getX(); - int relZFromCenter = rawZ - sectionCenter.getZ(); - - if(relXFromCenter > 0) { - if(relXFromCenter >= Math.abs(relZFromCenter)) - return BiomeSubSection.POSITIVE_X; - } - - if(relXFromCenter <= 0) { - if(Math.abs(relXFromCenter) >= Math.abs(relZFromCenter)) - return BiomeSubSection.NEGATIVE_X; - } - - if(relZFromCenter > 0) { - if(relZFromCenter >= Math.abs(relXFromCenter)) - return BiomeSubSection.POSITIVE_Z; - } - - if(relZFromCenter <= 0) { - if(Math.abs(relZFromCenter) >= Math.abs(relXFromCenter)) - return BiomeSubSection.NEGATIVE_Z; - } - - return BiomeSubSection.NONE; - - // } + // if(new BiomeSection(tw, rawX, rawZ).equals(this)) { + SimpleLocation sectionCenter = this.getCenter(); + int relXFromCenter = rawX - sectionCenter.getX(); + int relZFromCenter = rawZ - sectionCenter.getZ(); + + if (relXFromCenter > 0) { + if (relXFromCenter >= Math.abs(relZFromCenter)) { + return BiomeSubSection.POSITIVE_X; + } + } + if (relXFromCenter <= 0) { + if (Math.abs(relXFromCenter) >= Math.abs(relZFromCenter)) { + return BiomeSubSection.NEGATIVE_X; + } + } + + if (relZFromCenter > 0) { + if (relZFromCenter >= Math.abs(relXFromCenter)) { + return BiomeSubSection.POSITIVE_Z; + } + } + + if (relZFromCenter <= 0) { + if (Math.abs(relZFromCenter) >= Math.abs(relXFromCenter)) { + return BiomeSubSection.NEGATIVE_Z; + } + } + + return BiomeSubSection.NONE; + + // } + + } + + @Override + public int hashCode() { + int prime = 13; + int result = 5; + + result = prime * result + x; + result = prime * result + z; + result = prime * result + tw.getName().hashCode(); + + return result; } - @Override - public int hashCode() { - int prime = 13; - int result = 5; - - result = prime * result + x; - result = prime * result + z; - result = prime * result + tw.getName().hashCode(); - - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof BiomeSection BiomeSection) { + @Override + public boolean equals(Object obj) { + if (obj instanceof BiomeSection BiomeSection) { return this.tw.getName().equals(BiomeSection.tw.getName()) - && this.x == BiomeSection.x - && this.z == BiomeSection.z; - } - return false; - } - - public int getX() { - return x; - } - - public int getZ() { - return z; - } - - @Override - public @NotNull String toString() { - return "(" + x + "," + z + ")"; - } - - public @NotNull BiomeClimate getClimate() { - return BiomeClimate.selectClimate(temperature, moisture); - } - - public float getTemperature() { - return temperature; - } - - public float getMoisture() { - return moisture; - } - - public TerraformWorld getTw() { - return tw; - } - - public double getOceanLevel() { - return tw.getOceanicNoise().GetNoise(x,z)*50.0; - } - - public double getMountainLevel() { - return tw.getMountainousNoise().GetNoise(x,z)*50.0; - } + && this.x == BiomeSection.x + && this.z == BiomeSection.z; + } + return false; + } + + public int getX() { + return x; + } + + public int getZ() { + return z; + } + + @Override + public @NotNull String toString() { + return "(" + x + "," + z + ")"; + } + + public @NotNull BiomeClimate getClimate() { + return BiomeClimate.selectClimate(temperature, moisture); + } + + public float getTemperature() { + return temperature; + } + + public float getMoisture() { + return moisture; + } + + public TerraformWorld getTw() { + return tw; + } + + public double getOceanLevel() { + return tw.getOceanicNoise().GetNoise(x, z) * 50.0; + } + + public double getMountainLevel() { + return tw.getMountainousNoise().GetNoise(x, z) * 50.0; + } } diff --git a/common/src/main/java/org/terraform/biome/BiomeSectionCacheLoader.java b/common/src/main/java/org/terraform/biome/BiomeSectionCacheLoader.java index 7b516609..0cd2f4fe 100644 --- a/common/src/main/java/org/terraform/biome/BiomeSectionCacheLoader.java +++ b/common/src/main/java/org/terraform/biome/BiomeSectionCacheLoader.java @@ -6,10 +6,10 @@ public class BiomeSectionCacheLoader extends CacheLoader { - @Override - public @NotNull BiomeSection load(@NotNull BiomeSection key) { - key.doCalculations(); - return key; - } + @Override + public @NotNull BiomeSection load(@NotNull BiomeSection key) { + key.doCalculations(); + return key; + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/biome/BiomeSubSection.java b/common/src/main/java/org/terraform/biome/BiomeSubSection.java index d72877aa..e385a704 100644 --- a/common/src/main/java/org/terraform/biome/BiomeSubSection.java +++ b/common/src/main/java/org/terraform/biome/BiomeSubSection.java @@ -5,9 +5,5 @@ // Currently for mountains to detect their lowerbound heights. public enum BiomeSubSection { - POSITIVE_X, - NEGATIVE_X, - POSITIVE_Z, - NEGATIVE_Z, - NONE + POSITIVE_X, NEGATIVE_X, POSITIVE_Z, NEGATIVE_Z, NONE } diff --git a/common/src/main/java/org/terraform/biome/BiomeType.java b/common/src/main/java/org/terraform/biome/BiomeType.java index c8067940..54d657ae 100644 --- a/common/src/main/java/org/terraform/biome/BiomeType.java +++ b/common/src/main/java/org/terraform/biome/BiomeType.java @@ -12,9 +12,11 @@ public enum BiomeType { private final boolean isDry; - BiomeType(boolean isDry) { this.isDry = isDry; } - - public boolean isDry() { - return isDry; - } + BiomeType(boolean isDry) { + this.isDry = isDry; + } + + public boolean isDry() { + return isDry; + } } diff --git a/common/src/main/java/org/terraform/biome/HeightIndependentBiomeCacheLoader.java b/common/src/main/java/org/terraform/biome/HeightIndependentBiomeCacheLoader.java index e315ee61..5303c46a 100644 --- a/common/src/main/java/org/terraform/biome/HeightIndependentBiomeCacheLoader.java +++ b/common/src/main/java/org/terraform/biome/HeightIndependentBiomeCacheLoader.java @@ -1,26 +1,26 @@ package org.terraform.biome; +import com.google.common.cache.CacheLoader; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.data.TWSimpleLocation; import org.terraform.data.TerraformWorld; -import com.google.common.cache.CacheLoader; public class HeightIndependentBiomeCacheLoader extends CacheLoader { - @Override - public @Nullable BiomeBank load(@NotNull TWSimpleLocation loc) { - int x = loc.getX(); - int z = loc.getZ(); - - // This optimisation doesn't work here. Many aesthetic options rely on - // the fact that this is block-accurate. Calculating once per 4x4 blocks - // creates obvious ugly 4x4 artifacts - // x = (x >> 2) << 2; z = (z >> 2) << 2; - - TerraformWorld tw = loc.getTerraformWorld(); - BiomeSection mostDominant = BiomeSection.getMostDominantSection(tw,x,z); - return mostDominant.getBiomeBank(); - } + @Override + public @Nullable BiomeBank load(@NotNull TWSimpleLocation loc) { + int x = loc.getX(); + int z = loc.getZ(); + + // This optimisation doesn't work here. Many aesthetic options rely on + // the fact that this is block-accurate. Calculating once per 4x4 blocks + // creates obvious ugly 4x4 artifacts + // x = (x >> 2) << 2; z = (z >> 2) << 2; + + TerraformWorld tw = loc.getTerraformWorld(); + BiomeSection mostDominant = BiomeSection.getMostDominantSection(tw, x, z); + return mostDominant.getBiomeBank(); + } } diff --git a/common/src/main/java/org/terraform/biome/beach/BadlandsBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/BadlandsBeachHandler.java index fb819a34..e2627abc 100644 --- a/common/src/main/java/org/terraform/biome/beach/BadlandsBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/BadlandsBeachHandler.java @@ -24,16 +24,23 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ + return new Material[] { Material.RED_SAND, Material.RED_SAND, GenUtils.randChoice(rand, Material.RED_SAND, Material.RED_SANDSTONE), GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE), - GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { } @@ -42,9 +49,9 @@ public BiomeHandler getTransformHandler() { return BiomeBank.BADLANDS.getHandler(); } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/BlackOceanBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/BlackOceanBeachHandler.java index 3083ae4f..6378ad08 100644 --- a/common/src/main/java/org/terraform/biome/beach/BlackOceanBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/BlackOceanBeachHandler.java @@ -27,30 +27,42 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{Material.STONE}; + return new Material[] {Material.STONE}; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to gravel - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) - data.setType(rawX,surfaceY,rawZ, Material.GRAVEL); + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { + data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); + } } // No kelp above sea level. - if(surfaceY > TerraformGenerator.seaLevel) return; - if (!BlockUtils.isStoneLike(data.getType(rawX,surfaceY,rawZ))) return; + if (surfaceY > TerraformGenerator.seaLevel) { + return; + } + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 1, 80)) { // SEA GRASS/KELP - CoralGenerator.generateKelpGrowth(data, rawX,surfaceY+1,rawZ); + CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/BogBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/BogBeachHandler.java index 8136c411..8fef4ef2 100644 --- a/common/src/main/java/org/terraform/biome/beach/BogBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/BogBeachHandler.java @@ -13,6 +13,7 @@ import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.util.Random; public class BogBeachHandler extends BiomeHandler { @@ -34,29 +35,40 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - SimpleBlock block = new SimpleBlock(data,rawX,surfaceY,rawZ); - if(!BlockUtils.isWet(block.getUp())) { - if(GenUtils.chance(random, 1, 85)) + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + SimpleBlock block = new SimpleBlock(data, rawX, surfaceY, rawZ); + if (!BlockUtils.isWet(block.getUp())) { + if (GenUtils.chance(random, 1, 85)) { PlantBuilder.DEAD_BUSH.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) + } + else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.BROWN_MUSHROOM.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) + } + else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.GRASS.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) + } + else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.TALL_GRASS.build(block.getUp()); + } else { // Possible Sugarcane - for(BlockFace face:BlockUtils.directBlockFaces) { - if(GenUtils.chance(random, 1, 75) && BlockUtils.isWet(block.getRelative(face))) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (GenUtils.chance(random, 1, 75) && BlockUtils.isWet(block.getRelative(face))) { PlantBuilder.SUGAR_CANE.build(block.getUp(), random, 2, 5); } } @@ -65,8 +77,11 @@ else if(GenUtils.chance(random, 1, 85)) } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - new MuddyBogHandler().populateLargeItems(tw, random, data); - } + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + new MuddyBogHandler().populateLargeItems(tw, random, data); + } } diff --git a/common/src/main/java/org/terraform/biome/beach/CherryGroveBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/CherryGroveBeachHandler.java index 931a5bb1..b9166dca 100644 --- a/common/src/main/java/org/terraform/biome/beach/CherryGroveBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/CherryGroveBeachHandler.java @@ -28,48 +28,63 @@ public boolean isOcean() { public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.CHERRY_GROVE; } - + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean hasSugarcane = GenUtils.chance(random, 1, 100); - Material base = data.getType(rawX,surfaceY,rawZ); + Material base = data.getType(rawX, surfaceY, rawZ); // Remove submerged grass - if(base == Material.GRASS_BLOCK && data.getType(rawX, surfaceY+1, rawZ) == Material.WATER) - data.setType(rawX, surfaceY, rawZ,Material.DIRT); + if (base == Material.GRASS_BLOCK && data.getType(rawX, surfaceY + 1, rawZ) == Material.WATER) { + data.setType(rawX, surfaceY, rawZ, Material.DIRT); + } - if (base != Material.SAND && base != Material.GRASS_BLOCK) return; + if (base != Material.SAND && base != Material.GRASS_BLOCK) { + return; + } surfaceY++; // Spawn sugarcane if (hasSugarcane) { boolean hasWater = data.getType(rawX + 1, surfaceY - 1, rawZ) == Material.WATER; - if (data.getType(rawX - 1, surfaceY - 1, rawZ) == Material.WATER) + if (data.getType(rawX - 1, surfaceY - 1, rawZ) == Material.WATER) { hasWater = true; - if (data.getType(rawX, surfaceY - 1, rawZ + 1) == Material.WATER) + } + if (data.getType(rawX, surfaceY - 1, rawZ + 1) == Material.WATER) { hasWater = true; - if (data.getType(rawX, surfaceY - 1, rawZ - 1) == Material.WATER) + } + if (data.getType(rawX, surfaceY - 1, rawZ - 1) == Material.WATER) { hasWater = true; + } - if (hasWater) PlantBuilder.SUGAR_CANE.build(random, data, rawX, surfaceY, rawZ, 3, 7); + if (hasWater) { + PlantBuilder.SUGAR_CANE.build(random, data, rawX, surfaceY, rawZ, 3, 7); + } } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { } } diff --git a/common/src/main/java/org/terraform/biome/beach/DarkForestBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/DarkForestBeachHandler.java index b789a69d..ff712c90 100644 --- a/common/src/main/java/org/terraform/biome/beach/DarkForestBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/DarkForestBeachHandler.java @@ -24,21 +24,34 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.COARSE_DIRT, + return new Material[] { Material.COARSE_DIRT, - GenUtils.randChoice(rand, Material.STONE, Material.COARSE_DIRT, Material.COARSE_DIRT, Material.COARSE_DIRT, Material.COARSE_DIRT, Material.COARSE_DIRT), + Material.COARSE_DIRT, + GenUtils.randChoice(rand, + Material.STONE, + Material.COARSE_DIRT, + Material.COARSE_DIRT, + Material.COARSE_DIRT, + Material.COARSE_DIRT, + Material.COARSE_DIRT + ), Material.STONE, Material.STONE - }; + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/IcyBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/IcyBeachHandler.java index cc9a8459..7f3262ca 100644 --- a/common/src/main/java/org/terraform/biome/beach/IcyBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/IcyBeachHandler.java @@ -18,11 +18,11 @@ private static void makeIceSheet(int x, int y, int z, @NotNull PopulatorDataAbst int nz = z; while (length > 0) { length--; - if (data.getType(nx, y, nz).isSolid() && - data.getType(nx, y + 1, nz) == Material.AIR) + if (data.getType(nx, y, nz).isSolid() && data.getType(nx, y + 1, nz) == Material.AIR) { data.setType(nx, y, nz, Material.ICE); + } - switch(random.nextInt(5)) { // The direction chooser + switch (random.nextInt(5)) { // The direction chooser case 0 -> nx++; case 2 -> nz++; case 3 -> nx--; @@ -44,14 +44,22 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.STONE, 35, Material.GRAVEL, 5, Material.COBBLESTONE, 10), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.STONE, 35, Material.GRAVEL, 5, Material.COBBLESTONE, 10), GenUtils.weightedRandomMaterial(rand, Material.STONE, 35, Material.GRAVEL, 5, Material.COBBLESTONE, 10), GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL), - GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL)}; + GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { if (GenUtils.chance(random, 7, 100)) { makeIceSheet(rawX, surfaceY, rawZ, data, random); @@ -59,9 +67,9 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/MudflatsHandler.java b/common/src/main/java/org/terraform/biome/beach/MudflatsHandler.java index 7b623ffa..c3472d9b 100644 --- a/common/src/main/java/org/terraform/biome/beach/MudflatsHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/MudflatsHandler.java @@ -24,29 +24,41 @@ public boolean isOcean() { return OneOneNineBlockHandler.MANGROVE_SWAMP; } - @Override + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, OneOneNineBlockHandler.MUD, 35, Material.GRASS_BLOCK, 10), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, OneOneNineBlockHandler.MUD, 35, Material.GRASS_BLOCK, 10), GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { surfaceY++; - if (data.getType(rawX, surfaceY, rawZ) != Material.AIR) return; + if (data.getType(rawX, surfaceY, rawZ) != Material.AIR) { + return; + } if (GenUtils.chance(5, 100)) { - if (random.nextBoolean()) + if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY, rawZ); - else + } + else { PlantBuilder.GRASS.build(data, rawX, surfaceY, rawZ); + } } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { // does nothing - } + } } diff --git a/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java index 0be02756..77676cf4 100644 --- a/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java @@ -16,6 +16,7 @@ import org.terraform.tree.MushroomBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.util.Random; public class MushroomBeachHandler extends BiomeHandler { @@ -32,48 +33,75 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.MYCELIUM, + return new Material[] { + Material.MYCELIUM, Material.DIRT, GenUtils.randChoice(rand, Material.STONE, Material.DIRT, Material.DIRT), GenUtils.randChoice(rand, Material.STONE, Material.DIRT) - }; + }; } @Override - public void populateSmallItems(TerraformWorld tw, Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(surfaceY < TerraformGenerator.seaLevel) return; - + public void populateSmallItems(TerraformWorld tw, + Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (surfaceY < TerraformGenerator.seaLevel) { + return; + } + // Generate small shrooms if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { - if (BlockUtils.isAir(data.getType(rawX, surfaceY + 1, rawZ)) - && GenUtils.chance(1, 60)) { - PlantBuilder.build(data, rawX, surfaceY + 1, rawZ, PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); + if (BlockUtils.isAir(data.getType(rawX, surfaceY + 1, rawZ)) && GenUtils.chance(1, 60)) { + PlantBuilder.build( + data, + rawX, + surfaceY + 1, + rawZ, + PlantBuilder.RED_MUSHROOM, + PlantBuilder.BROWN_MUSHROOM + ); } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 33, 0.15f); - SimpleLocation[] smallDecorations = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 15, 0.30f); - - // Giant mushrooms + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 33, 0.15f); + SimpleLocation[] smallDecorations = GenUtils.randomObjectPositions( + tw, + data.getChunkX(), + data.getChunkZ(), + 15, + 0.30f + ); + + // Giant mushrooms for (SimpleLocation sLoc : bigTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - int choice = random.nextInt(3); - FractalTypes.Mushroom type = switch(choice) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + int choice = random.nextInt(3); + FractalTypes.Mushroom type = switch (choice) { case 0 -> FractalTypes.Mushroom.GIANT_RED_MUSHROOM; case 1 -> FractalTypes.Mushroom.GIANT_BROWN_MUSHROOM; default -> FractalTypes.Mushroom.GIANT_BROWN_FUNNEL_MUSHROOM; }; - if(HeightMap.getTrueHeightGradient(data, sLoc.getX(), sLoc.getZ(), 3) <= - TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) - new MushroomBuilder(type).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + if (HeightMap.getTrueHeightGradient(data, sLoc.getX(), sLoc.getZ(), 3) + <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + { + new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + } } } @@ -81,39 +109,70 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando for (SimpleLocation sLoc : smallDecorations) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { int choice = random.nextInt(4); - switch(choice) { - case 0: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_POINTY_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - case 1: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - case 2: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - default: - new MushroomBuilder(FractalTypes.Mushroom.TINY_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; + switch (choice) { + case 0: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_POINTY_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + case 1: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + case 2: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + default: + new MushroomBuilder(FractalTypes.Mushroom.TINY_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; } } } - + // Bracket fungus - for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x+=2) { - for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z+=2) { - int y = GenUtils.getHighestGround(data, x, z); - if(data.getBiome(x, z) != getBiome()) continue; - if(y < TerraformGenerator.seaLevel+4) continue; - if(HeightMap.getTrueHeightGradient(data, x, z, 3) > 2 - && GenUtils.chance(random, 1, 20)) { - BlockUtils.replaceCircle(random.nextInt(919292), - 3, new SimpleBlock(data,x,y-2,z), - GenUtils.randChoice(random, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK)); + for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x += 2) { + for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z += 2) { + int y = GenUtils.getHighestGround(data, x, z); + if (data.getBiome(x, z) != getBiome()) { + continue; + } + if (y < TerraformGenerator.seaLevel + 4) { + continue; + } + if (HeightMap.getTrueHeightGradient(data, x, z, 3) > 2 && GenUtils.chance(random, 1, 20)) { + BlockUtils.replaceCircle(random.nextInt(919292), + 3, + new SimpleBlock(data, x, y - 2, z), + GenUtils.randChoice(random, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK) + ); } } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/beach/OasisBeach.java b/common/src/main/java/org/terraform/biome/beach/OasisBeach.java index 54f7102f..548e3404 100644 --- a/common/src/main/java/org/terraform/biome/beach/OasisBeach.java +++ b/common/src/main/java/org/terraform/biome/beach/OasisBeach.java @@ -13,6 +13,7 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.NoiseCacheHandler; + import java.util.Random; /** @@ -23,8 +24,7 @@ public class OasisBeach { private static final float oasisFrequency = TConfigOption.BIOME_OASIS_FREQUENCY.getFloat(); public static float getOasisNoise(TerraformWorld world, int x, int z) { - FastNoise lushRiversNoise = NoiseCacheHandler.getNoise( - world, + FastNoise lushRiversNoise = NoiseCacheHandler.getNoise(world, NoiseCacheHandler.NoiseCacheEntry.BIOME_DESERT_LUSH_RIVER, w -> { FastNoise n = new FastNoise((int) (w.getSeed() * 0.4)); @@ -32,7 +32,8 @@ public static float getOasisNoise(TerraformWorld world, int x, int z) { n.SetFrequency(oasisFrequency); return n; - }); + } + ); return lushRiversNoise.GetNoise(x, z); } @@ -41,23 +42,30 @@ public static float getOasisNoise(TerraformWorld world, int x, int z) { * @return true if (x, z) is inside oasis */ private static boolean isOasisBeach(TerraformWorld tw, int x, int z, BiomeBank targetBiome) { - double lushRiverNoiseValue = getOasisNoise(tw, x, z); + double lushRiverNoiseValue = getOasisNoise(tw, x, z); double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); BiomeBank biome = BiomeBank.calculateHeightIndependentBiome(tw, x, z); - return lushRiverNoiseValue > oasisThreshold && - riverDepth > 0 && - biome == targetBiome; + return lushRiverNoiseValue > oasisThreshold && riverDepth > 0 && biome == targetBiome; } /** * Generate lush beach for coordinate. * Should be ran for every coordinate in BiomeHandler#populateSmallItems + * * @param targetBiome the biome this function is called from. * Prevents code from running twice when biome overlap */ - public static void generateOasisBeach(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int z, BiomeBank targetBiome) { - if (!isOasisBeach(tw, x, z, targetBiome)) return; + public static void generateOasisBeach(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int z, + BiomeBank targetBiome) + { + if (!isOasisBeach(tw, x, z, targetBiome)) { + return; + } int y = GenUtils.getHighestGround(data, x, z); int aboveSea = y - TerraformGenerator.seaLevel; @@ -71,34 +79,67 @@ public static void generateOasisBeach(@NotNull TerraformWorld tw, @NotNull Rando if (y == TerraformGenerator.seaLevel && random.nextInt(3) == 0) { PlantBuilder.SUGAR_CANE.build(random, data, x, y + 1, z, 1, 4); - } else if (y >= TerraformGenerator.seaLevel) { + } + else if (y >= TerraformGenerator.seaLevel) { if (random.nextInt(8) == 0) { TreeDB.spawnCoconutTree(tw, data, x, y, z); - } else if (random.nextInt(5) == 0) { - createBush(random, data, x, y, z, + } + else if (random.nextInt(5) == 0) { + createBush(random, + data, + x, + y, + z, GenUtils.randDouble(random, 1.7, 3), GenUtils.randDouble(random, 2, 2.8), GenUtils.randDouble(random, 1.7, 3), Material.JUNGLE_LEAVES, - Material.JUNGLE_LOG, 0.7); - } else if (isGrass) { - PlantBuilder.build(random, data, x, y + 1, z, PlantBuilder.GRASS, PlantBuilder.GRASS, PlantBuilder.GRASS, PlantBuilder.FERN); + Material.JUNGLE_LOG, + 0.7 + ); + } + else if (isGrass) { + PlantBuilder.build( + random, + data, + x, + y + 1, + z, + PlantBuilder.GRASS, + PlantBuilder.GRASS, + PlantBuilder.GRASS, + PlantBuilder.FERN + ); } } } // TODO: I feel like this is the 10th time I implement this in some form, should all game "objects" like rocks etc. be stored in one class as static functions? - public static void createBush(@NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, double xRadius, double yRadius, double zRadius, Material leaves, Material stem, double density) { - if (!TConfigOption.arePlantsEnabled()) return; + public static void createBush(@NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + double xRadius, + double yRadius, + double zRadius, + Material leaves, + Material stem, + double density) + { + if (!TConfigOption.arePlantsEnabled()) { + return; + } - for (int ny = y; ny < y + yRadius / 2; ny++) + for (int ny = y; ny < y + yRadius / 2; ny++) { data.setType(x, ny, z, stem); + } for (int xr = (int) -Math.ceil(xRadius); xr < Math.ceil(xRadius); xr++) { for (int yr = (int) -Math.ceil(yRadius); yr < Math.ceil(yRadius); yr++) { for (int zr = (int) -Math.ceil(zRadius); zr < Math.ceil(zRadius); zr++) { double distToCenter = Math.sqrt((xr * xr) / (xRadius * xRadius) - + (yr * yr) / (yRadius * yRadius) - + (zr * zr) / (zRadius * zRadius)); + + (yr * yr) / (yRadius * yRadius) + + (zr * zr) / (zRadius * zRadius)); if (distToCenter < 1 && random.nextDouble() < 1 - distToCenter + density) { data.lsetType(x + xr, y + yr, z + zr, leaves); diff --git a/common/src/main/java/org/terraform/biome/beach/RockBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/RockBeachHandler.java index 45467d52..eda8de64 100644 --- a/common/src/main/java/org/terraform/biome/beach/RockBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/RockBeachHandler.java @@ -24,20 +24,28 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.STONE, 5, Material.GRAVEL, 35, Material.COBBLESTONE, 10), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.STONE, 5, Material.GRAVEL, 35, Material.COBBLESTONE, 10), GenUtils.weightedRandomMaterial(rand, Material.STONE, 5, Material.GRAVEL, 35, Material.COBBLESTONE, 10), GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL), - GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL)}; + GenUtils.randChoice(rand, Material.STONE, Material.COBBLESTONE, Material.GRAVEL) + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/SandyBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/SandyBeachHandler.java index bd9339d2..19f0d7d8 100644 --- a/common/src/main/java/org/terraform/biome/beach/SandyBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/SandyBeachHandler.java @@ -28,54 +28,76 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.SAND, + return new Material[] { Material.SAND, - GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND, Material.SAND, Material.SAND, Material.SAND, Material.SAND), + Material.SAND, + GenUtils.randChoice(rand, + Material.SANDSTONE, + Material.SAND, + Material.SAND, + Material.SAND, + Material.SAND, + Material.SAND + ), GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE), - GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean hasSugarcane = GenUtils.chance(random, 1, 100); Material base = data.getType(rawX, surfaceY, rawZ); - if (base != Material.SAND && base != Material.GRASS_BLOCK) return; + if (base != Material.SAND && base != Material.GRASS_BLOCK) { + return; + } surfaceY++; // Spawn sugarcane if (hasSugarcane) { boolean hasWater = data.getType(rawX + 1, surfaceY - 1, rawZ) == Material.WATER; - if (data.getType(rawX - 1, surfaceY - 1, rawZ) == Material.WATER) + if (data.getType(rawX - 1, surfaceY - 1, rawZ) == Material.WATER) { hasWater = true; - if (data.getType(rawX, surfaceY - 1, rawZ + 1) == Material.WATER) + } + if (data.getType(rawX, surfaceY - 1, rawZ + 1) == Material.WATER) { hasWater = true; - if (data.getType(rawX, surfaceY - 1, rawZ - 1) == Material.WATER) + } + if (data.getType(rawX, surfaceY - 1, rawZ - 1) == Material.WATER) { hasWater = true; + } - if (hasWater) PlantBuilder.SUGAR_CANE.build(random, data, rawX, surfaceY, rawZ, 3, 7); + if (hasWater) { + PlantBuilder.SUGAR_CANE.build(random, data, rawX, surfaceY, rawZ, 3, 7); + } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { - - SimpleLocation[] coconutTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { + + SimpleLocation[] coconutTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - // Big trees and giant mushrooms + // Big trees and giant mushrooms for (SimpleLocation sLoc : coconutTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && - (BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ())) - || data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) == Material.SAND)) { - TreeDB.spawnCoconutTree(tw, data, sLoc.getX(), sLoc.getY()+1 ,sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && (BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) + || data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.SAND)) + { + TreeDB.spawnCoconutTree(tw, data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); } } - - } + + } } diff --git a/common/src/main/java/org/terraform/biome/beach/ScarletForestBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/ScarletForestBeachHandler.java index 63569d73..02a00a4c 100644 --- a/common/src/main/java/org/terraform/biome/beach/ScarletForestBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/ScarletForestBeachHandler.java @@ -27,25 +27,32 @@ public boolean isOcean() { public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.SCARLET_FOREST; } - + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.WHITE_CONCRETE, + return new Material[] { + Material.WHITE_CONCRETE, Material.WHITE_CONCRETE, Material.WHITE_CONCRETE, GenUtils.randChoice(rand, Material.WHITE_CONCRETE, Material.STONE), - GenUtils.randChoice(rand, Material.WHITE_CONCRETE, Material.STONE)}; + GenUtils.randChoice(rand, Material.WHITE_CONCRETE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { // WHAT THE FUCK DO YOU MEAN REMOVE SUBMERGED GRASS??? WHY WAS IT BEING SET??? - } + } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - } + } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/AbstractCaveClusterPopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/AbstractCaveClusterPopulator.java index f01d8434..d655b60f 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/AbstractCaveClusterPopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/AbstractCaveClusterPopulator.java @@ -1,11 +1,5 @@ package org.terraform.biome.cavepopulators; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Queue; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.NotNull; @@ -17,35 +11,42 @@ import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; +import java.util.*; + public abstract class AbstractCaveClusterPopulator extends AbstractCavePopulator { - private final float radius; + private final float radius; // Starts null, but will be populated by the time oneUnit is called. protected SimpleBlock center; protected SimpleBlock lowestYCenter; - public AbstractCaveClusterPopulator(float radius) { - this.radius = radius; - } - - protected abstract void oneUnit(TerraformWorld tw, Random random, SimpleBlock ceil, SimpleBlock floor, boolean isBoundary); - @Override + + public AbstractCaveClusterPopulator(float radius) { + this.radius = radius; + } + + protected abstract void oneUnit(TerraformWorld tw, + Random random, + SimpleBlock ceil, + SimpleBlock floor, + boolean isBoundary); + + @Override public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor) { - if(this.radius <= 0) return; - ArrayList ceilFloorPairs = new ArrayList<>(); + if (this.radius <= 0) { + return; + } + ArrayList ceilFloorPairs = new ArrayList<>(); ArrayList boundaries = new ArrayList<>(); - - FastNoise circleNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 11)); - n.SetNoiseType(FastNoise.NoiseType.Simplex); - n.SetFrequency(0.09f); - - return n; - }); - - center = new SimpleBlock(ceil.getPopData(), ceil.getX(), (ceil.getY() + floor.getY())/2, ceil.getZ()); + + FastNoise circleNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 11)); + n.SetNoiseType(FastNoise.NoiseType.Simplex); + n.SetFrequency(0.09f); + + return n; + }); + + center = new SimpleBlock(ceil.getPopData(), ceil.getX(), (ceil.getY() + floor.getY()) / 2, ceil.getZ()); int lowest = center.getY(); // Perform a breadth-first search from the center. @@ -53,11 +54,10 @@ public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil HashMap seen = new HashMap<>(); Queue queue = new LinkedList<>(); queue.add(center); // Add the root element - seen.put(center, new Wall[]{new Wall(ceil), new Wall(floor)}); + seen.put(center, new Wall[] {new Wall(ceil), new Wall(floor)}); // TerraformGeneratorPlugin.logger.info("Entering BFS for " + center); - while(!queue.isEmpty()) - { + while (!queue.isEmpty()) { SimpleBlock v = queue.remove(); // Process the node @@ -65,28 +65,25 @@ public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil Wall vFloor = seen.get(v)[1]; lowest = Math.min(vFloor.getY(), lowest); ceilFloorPairs.add(new SimpleBlock[] { - vCeil.get(), - vFloor.get() + vCeil.get(), vFloor.get() }); // TerraformGeneratorPlugin.logger.info("NLOOP: " + v); boolean sawFailCondition = false; - for(BlockFace face:BlockUtils.directBlockFaces) - { + for (BlockFace face : BlockUtils.directBlockFaces) { // Simulate the criteria as edge connections. // Continue if the neighbour doesn't meet the criteria SimpleBlock neighbour = v.getRelative(face); - if(seen.containsKey(neighbour)){ + if (seen.containsKey(neighbour)) { // TerraformGeneratorPlugin.logger.info("Seen " + neighbour); continue; } // Check if neighbour is within radius - double equationResult = Math.pow(neighbour.getX()-center.getX(), 2) / Math.pow(radius, 2) - + Math.pow(neighbour.getZ()-center.getZ(), 2) / Math.pow(radius, 2); - if(equationResult > 1 + 0.7*circleNoise.GetNoise(neighbour.getX(), neighbour.getZ())) - { + double equationResult = Math.pow(neighbour.getX() - center.getX(), 2) / Math.pow(radius, 2) + + Math.pow(neighbour.getZ() - center.getZ(), 2) / Math.pow(radius, 2); + if (equationResult > 1 + 0.7 * circleNoise.GetNoise(neighbour.getX(), neighbour.getZ())) { sawFailCondition = true; // TerraformGeneratorPlugin.logger.info("OOB " + neighbour + ": " + equationResult); continue; @@ -96,21 +93,22 @@ public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil Wall candidateCeilWall = new Wall(neighbour).findStonelikeCeiling(60); // Misc checks that don't affect boundary condition - if(candidateFloorWall == null - || candidateCeilWall == null - ||BlockUtils.amethysts.contains(floor.getType()) - || BlockUtils.fluids.contains(floor.getUp().getType()) - || BlockUtils.amethysts.contains(ceil.getDown().getType()) - || candidateFloorWall.getType() == Material.MOSS_BLOCK - || candidateFloorWall.getType() == Material.DRIPSTONE_BLOCK - || candidateFloorWall.getUp().isSolid() - || candidateCeilWall.getDown().isSolid()) { + if (candidateFloorWall == null + || candidateCeilWall == null + || BlockUtils.amethysts.contains(floor.getType()) + || BlockUtils.fluids.contains(floor.getUp().getType()) + || BlockUtils.amethysts.contains(ceil.getDown().getType()) + || candidateFloorWall.getType() == Material.MOSS_BLOCK + || candidateFloorWall.getType() == Material.DRIPSTONE_BLOCK + || candidateFloorWall.getUp().isSolid() + || candidateCeilWall.getDown().isSolid()) + { // TerraformGeneratorPlugin.logger.info("Misc Skip " + neighbour); continue; } // Process under BFS - seen.put(neighbour, new Wall[]{candidateCeilWall,candidateFloorWall}); + seen.put(neighbour, new Wall[] {candidateCeilWall, candidateFloorWall}); queue.add(neighbour); // TerraformGeneratorPlugin.logger.info("Enqueued " + neighbour); } @@ -123,13 +121,14 @@ public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil // TerraformGeneratorPlugin.logger.info("Finished for " + center); lowestYCenter = center.getAtY(lowest); - for(int i = 0; i < ceilFloorPairs.size(); i++) { + for (int i = 0; i < ceilFloorPairs.size(); i++) { SimpleBlock[] candidates = ceilFloorPairs.get(i); // Late fluid checks - if(BlockUtils.fluids.contains(candidates[1].getAtY(lowest+1).getType())) + if (BlockUtils.fluids.contains(candidates[1].getAtY(lowest + 1).getType())) { continue; - oneUnit(tw, random, candidates[0], candidates[1], boundaries.get(i)); + } + oneUnit(tw, random, candidates[0], candidates[1], boundaries.get(i)); } } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java b/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java index 1a647765..52012053 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java @@ -1,75 +1,65 @@ package org.terraform.biome.cavepopulators; -import java.util.Random; - import org.jetbrains.annotations.NotNull; import org.terraform.main.config.TConfigOption; import org.terraform.utils.GenUtils; +import java.util.Random; + public enum CaveClusterRegistry { - LUSH( - 9527213, - TConfigOption.BIOME_CAVE_LUSHCLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXPERTUB.getFloat() - ), - DRIPSTONE( - 5902907, - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB.getFloat() - ), - CRYSTALLINE( - 4427781, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB.getFloat() - ), - FLUID( - 79183628, - 40, - 0.2f - ), - ; - - final int hashSeed; - final int separation; - final float pertub; - CaveClusterRegistry(int hashSeed, int separation, float pertub){ - this.hashSeed = hashSeed; - this.separation = separation; - this.pertub = pertub; - } - - public @NotNull AbstractCaveClusterPopulator getPopulator(@NotNull Random random) { - return switch(this) { - case LUSH -> new LushClusterCavePopulator( - GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXSIZE.getInt()), - false); - case DRIPSTONE -> new DripstoneClusterCavePopulator( - GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE.getInt())); - case CRYSTALLINE -> new CrystallineClusterCavePopulator( - GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt())); - case FLUID -> new CaveFluidClusterPopulator( - GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt())); + LUSH(9527213, + TConfigOption.BIOME_CAVE_LUSHCLUSTER_SEPARATION.getInt(), + TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXPERTUB.getFloat() + ), DRIPSTONE(5902907, + TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION.getInt(), + TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB.getFloat() + ), CRYSTALLINE(4427781, + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION.getInt(), + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB.getFloat() + ), FLUID(79183628, 40, 0.2f), + ; + + final int hashSeed; + final int separation; + final float pertub; + + CaveClusterRegistry(int hashSeed, int separation, float pertub) { + this.hashSeed = hashSeed; + this.separation = separation; + this.pertub = pertub; + } + + public @NotNull AbstractCaveClusterPopulator getPopulator(@NotNull Random random) { + return switch (this) { + case LUSH -> new LushClusterCavePopulator(GenUtils.randInt(random, + TConfigOption.BIOME_CAVE_LUSHCLUSTER_MINSIZE.getInt(), + TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXSIZE.getInt() + ), false); + case DRIPSTONE -> new DripstoneClusterCavePopulator(GenUtils.randInt(random, + TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE.getInt(), + TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE.getInt() + )); + case CRYSTALLINE -> new CrystallineClusterCavePopulator(GenUtils.randInt(random, + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt() + )); + case FLUID -> new CaveFluidClusterPopulator(GenUtils.randInt(random, + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), + TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt() + )); }; } - public int getHashSeed() { - return hashSeed; - } + public int getHashSeed() { + return hashSeed; + } - public int getSeparation() { - return separation; - } + public int getSeparation() { + return separation; + } - public float getPertub() { - return pertub; - } + public float getPertub() { + return pertub; + } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/CaveFluidClusterPopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/CaveFluidClusterPopulator.java index 61c55ffa..7f9dbe79 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/CaveFluidClusterPopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/CaveFluidClusterPopulator.java @@ -18,45 +18,57 @@ public class CaveFluidClusterPopulator extends AbstractCaveClusterPopulator { Material fluid; int rY; - public CaveFluidClusterPopulator(float radius) { - super(radius); - } + public CaveFluidClusterPopulator(float radius) { + super(radius); + } + @Override - public void oneUnit(@NotNull TerraformWorld tw, Random doNotUse, @Nullable SimpleBlock ceil, @Nullable SimpleBlock floor, boolean boundary) { - if(ceil == null || floor == null) return; - if(rand == null) - { - rand = tw.getHashedRand(center.getX(),center.getY(),center.getZ()); - - fluid = GenUtils.choice(rand, new Material[]{Material.WATER, Material.LAVA}); - if(center.getY() < TerraformGeneratorPlugin.injector.getMinY() + 32) fluid = Material.LAVA; + public void oneUnit(@NotNull TerraformWorld tw, + Random doNotUse, + @Nullable SimpleBlock ceil, + @Nullable SimpleBlock floor, + boolean boundary) + { + if (ceil == null || floor == null) { + return; + } + if (rand == null) { + rand = tw.getHashedRand(center.getX(), center.getY(), center.getZ()); + + fluid = GenUtils.choice(rand, new Material[] {Material.WATER, Material.LAVA}); + if (center.getY() < TerraformGeneratorPlugin.injector.getMinY() + 32) { + fluid = Material.LAVA; + } rY = 3 + rand.nextInt(3); } Material original = floor.getType(); - for(int i = 0; i < rY; i++) - { + for (int i = 0; i < rY; i++) { // If the floor is above the pinned water level, set it to cave air // If not, set it to the solid boundary block, or the fluid // The exposedToMaterial check is REQUIRED as adjacent fluid sources // may spawn, and cave air may forcefully remove boundaries. - if(boundary) + if (boundary) { floor.setType(original); - else if(floor.getY() <= lowestYCenter.getY()) + } + else if (floor.getY() <= lowestYCenter.getY()) { floor.setType(fluid); - else if(!BlockUtils.isExposedToMaterial(floor, BlockUtils.fluids) - && !BlockUtils.fluids.contains(floor.getUp().getType())) // isExposed only checks NSEW + } + else if (!BlockUtils.isExposedToMaterial(floor, BlockUtils.fluids) + && !BlockUtils.fluids.contains(floor.getUp().getType())) // isExposed only checks NSEW + { floor.setType(Material.CAVE_AIR); + } floor = floor.getDown(); // Fix floating fluids - if(!floor.isSolid()){ + if (!floor.isSolid()) { floor.setType(original); break; } } } - - + + } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/CrystallineClusterCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/CrystallineClusterCavePopulator.java index ba1206c6..377573cc 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/CrystallineClusterCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/CrystallineClusterCavePopulator.java @@ -20,38 +20,40 @@ public class CrystallineClusterCavePopulator extends AbstractCaveClusterPopulator { // private static boolean genned = false; - + public CrystallineClusterCavePopulator(float radius) { - super(radius); - } + super(radius); + } - @Override - protected void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, boolean boundary) { - // if (!genned) { + @Override + protected void oneUnit(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor, + boolean boundary) + { + // if (!genned) { // genned = true; // } - - // ========================= + + // ========================= // Upper decorations // ========================= int caveHeight = ceil.getY() - floor.getY(); // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; - + } + // Amethyst crust. Don't cover ores. Don't mess with moss. - if(Material.MOSS_BLOCK != ceil.getType() - && !BlockUtils.isOre(ceil.getType())) { - ceil.setType(Material.AMETHYST_BLOCK); - + if (Material.MOSS_BLOCK != ceil.getType() && !BlockUtils.isOre(ceil.getType())) { + ceil.setType(Material.AMETHYST_BLOCK); + // Amethysts if (GenUtils.chance(random, 1, 5)) { - new DirectionalBuilder(Material.AMETHYST_CLUSTER) - .setFacing(BlockFace.DOWN) - .apply(ceil.getDown()); + new DirectionalBuilder(Material.AMETHYST_CLUSTER).setFacing(BlockFace.DOWN).apply(ceil.getDown()); } } @@ -60,54 +62,57 @@ protected void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull Simpl // ========================= // Amethyst crust. Don't cover ores. Don't mess with moss. - if(Material.MOSS_BLOCK != floor.getType() - && !BlockUtils.isOre(floor.getType())) { - floor.setType(Material.AMETHYST_BLOCK); - + if (Material.MOSS_BLOCK != floor.getType() && !BlockUtils.isOre(floor.getType())) { + floor.setType(Material.AMETHYST_BLOCK); + // Amethysts if (GenUtils.chance(random, 1, 5)) { - new DirectionalBuilder(Material.AMETHYST_CLUSTER) - .setFacing(BlockFace.UP) - .apply(floor.getUp()); - }else if(GenUtils.chance(random, 1, 20)) { // Calcite Pillars - floor.setType(Material.CALCITE); - floor.getUp().LPillar(2*caveHeight, new Random(), Material.CALCITE); + new DirectionalBuilder(Material.AMETHYST_CLUSTER).setFacing(BlockFace.UP).apply(floor.getUp()); + } + else if (GenUtils.chance(random, 1, 20)) { // Calcite Pillars + floor.setType(Material.CALCITE); + floor.getUp().LPillar(2 * caveHeight, new Random(), Material.CALCITE); } } - + // ========================= // Attempt to replace close-by walls with Amethyst. Also apply lichen. // ========================= - + SimpleBlock target = floor; - while(target.getY() != ceil.getY()) { - for(BlockFace face:BlockUtils.directBlockFaces) { - SimpleBlock rel = target.getRelative(face); - if(rel.getType() != Material.CALCITE - && !BlockUtils.isOre(ceil.getType()) - && BlockUtils.isStoneLike(rel.getType())) { - rel.setType(Material.AMETHYST_BLOCK); - if(BlockUtils.isAir(target.getType()) && GenUtils.chance(random, 1, 3)) { - new MultipleFacingBuilder(Material.GLOW_LICHEN) - .setFace(face, true) - .apply(target); - } - } - } - target = target.getUp(); + while (target.getY() != ceil.getY()) { + for (BlockFace face : BlockUtils.directBlockFaces) { + SimpleBlock rel = target.getRelative(face); + if (rel.getType() != Material.CALCITE + && !BlockUtils.isOre(ceil.getType()) + && BlockUtils.isStoneLike(rel.getType())) + { + rel.setType(Material.AMETHYST_BLOCK); + if (BlockUtils.isAir(target.getType()) && GenUtils.chance(random, 1, 3)) { + new MultipleFacingBuilder(Material.GLOW_LICHEN).setFace(face, true).apply(target); + } + } + } + target = target.getUp(); } // ========================= // Biome Setter // ========================= PopulatorDataAbstract d = TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()); - if(d instanceof PopulatorDataICABiomeWriterAbstract data) { - while(floor.getY() < ceil.getY()) { - data.setBiome(floor.getX(), floor.getY(), floor.getZ(), CustomBiomeType.CRYSTALLINE_CLUSTER, Biome.DRIPSTONE_CAVES); - floor = floor.getUp(); - } + if (d instanceof PopulatorDataICABiomeWriterAbstract data) { + while (floor.getY() < ceil.getY()) { + data.setBiome( + floor.getX(), + floor.getY(), + floor.getZ(), + CustomBiomeType.CRYSTALLINE_CLUSTER, + Biome.DRIPSTONE_CAVES + ); + floor = floor.getUp(); + } } } - - + + } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/DeepCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/DeepCavePopulator.java index 0f688c43..8ad2f360 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/DeepCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/DeepCavePopulator.java @@ -15,38 +15,40 @@ import java.util.Random; public class DeepCavePopulator extends AbstractCavePopulator { - + @Override - public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor) { - + public void populate(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor) + { + int caveHeight = ceil.getY() - floor.getY(); - + // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; + } // ========================= // Upper decorations // ========================= // Stalactites - if (GenUtils.chance(random, 1, 10*Math.max(3, caveHeight/4))) { + if (GenUtils.chance(random, 1, 10 * Math.max(3, caveHeight / 4))) { Wall w = new Wall(ceil, BlockFace.NORTH); - if(w.getUp().getType() == Material.DEEPSLATE) { - new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL) - .setSolidBlockType(Material.DEEPSLATE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, OneOneSevenBlockHandler.COBBLED_DEEPSLATE_WALL); + if (w.getUp().getType() == Material.DEEPSLATE) { + new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL).setSolidBlockType(Material.DEEPSLATE) + .setFacingUp(false) + .setVerticalSpace(caveHeight) + .build(random, w); + // w.downLPillar(random, h, OneOneSevenBlockHandler.COBBLED_DEEPSLATE_WALL); } else { - new StalactiteBuilder(Material.COBBLESTONE_WALL) - .setSolidBlockType(Material.COBBLESTONE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); + new StalactiteBuilder(Material.COBBLESTONE_WALL).setSolidBlockType(Material.COBBLESTONE) + .setFacingUp(false) + .setVerticalSpace(caveHeight) + .build(random, w); // w.downLPillar(random, h, Material.COBBLESTONE_WALL); } @@ -57,45 +59,56 @@ public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleB // ========================= // Stalagmites - if (GenUtils.chance(random, 1, 10*Math.max(3, caveHeight/4))) { + if (GenUtils.chance(random, 1, 10 * Math.max(3, caveHeight / 4))) { int h = caveHeight / 4; - if (h < 1) h = 1; + if (h < 1) { + h = 1; + } Wall w = new Wall(floor.getUp()); - if (BlockUtils.isAir(w.getType())) - if(w.getDown().getType() == Material.DEEPSLATE) - // w.LPillar(h, random, OneOneSevenBlockHandler.COBBLED_DEEPSLATE_WALL); + if (BlockUtils.isAir(w.getType())) { + if (w.getDown().getType() == Material.DEEPSLATE) + // w.LPillar(h, random, OneOneSevenBlockHandler.COBBLED_DEEPSLATE_WALL); - new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL) - .setSolidBlockType(Material.DEEPSLATE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); - else - // w.LPillar(h, random, Material.COBBLESTONE_WALL); + { + new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL).setSolidBlockType(Material.DEEPSLATE) + .setFacingUp(true) + .setVerticalSpace(caveHeight) + .build(random, w); + } + else + // w.LPillar(h, random, Material.COBBLESTONE_WALL); - new StalactiteBuilder(Material.COBBLESTONE_WALL) - .setSolidBlockType(Material.COBBLESTONE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); + { + new StalactiteBuilder(Material.COBBLESTONE_WALL).setSolidBlockType(Material.COBBLESTONE) + .setFacingUp(true) + .setVerticalSpace(caveHeight) + .build(random, w); + } + } - } else if (GenUtils.chance(random, 1, 25)) { // Slabbing + } + else if (GenUtils.chance(random, 1, 25)) { // Slabbing SimpleBlock base = floor.getUp(); // Only next to spots where there's some kind of solid block. - if (BlockUtils.isAir(base.getType())) + if (BlockUtils.isAir(base.getType())) { for (BlockFace face : BlockUtils.directBlockFaces) { if (base.getRelative(face).isSolid()) { - if(base.getDown().getType() == Material.DEEPSLATE) - base.setType(Material.COBBLED_DEEPSLATE_SLAB); - else - base.setType(Material.STONE_SLAB); + if (base.getDown().getType() == Material.DEEPSLATE) { + base.setType(Material.COBBLED_DEEPSLATE_SLAB); + } + else { + base.setType(Material.STONE_SLAB); + } break; } } - } else if (GenUtils.chance(random, 1, 35)) { // Shrooms :3 - if (BlockUtils.isAir(floor.getUp().getType())) + } + } + else if (GenUtils.chance(random, 1, 35)) { // Shrooms :3 + if (BlockUtils.isAir(floor.getUp().getType())) { PlantBuilder.build(floor.getUp(), PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); + } } - + } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/DeepDarkClusterCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/DeepDarkClusterCavePopulator.java index 19d84b62..1a8fa168 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/DeepDarkClusterCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/DeepDarkClusterCavePopulator.java @@ -15,120 +15,131 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.MultipleFacingBuilder; import org.terraform.utils.version.OneOneNineBlockHandler; + import java.util.Random; public class DeepDarkClusterCavePopulator extends AbstractCaveClusterPopulator { - // private boolean isForLargeCave; - public DeepDarkClusterCavePopulator(float radius) { - super(radius); - // this.isForLargeCave = isForLargeCave; - } - - public static void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock origin) { - if(origin.isSolid()) return; - new DeepDarkClusterCavePopulator(0f).oneUnit(tw, random, origin.findStonelikeCeiling(50), origin.findStonelikeFloor(50), false); - origin.setType(Material.GLASS); - } - + // private boolean isForLargeCave; + public DeepDarkClusterCavePopulator(float radius) { + super(radius); + // this.isForLargeCave = isForLargeCave; + } + + public static void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock origin) { + if (origin.isSolid()) { + return; + } + new DeepDarkClusterCavePopulator(0f).oneUnit( + tw, + random, + origin.findStonelikeCeiling(50), + origin.findStonelikeFloor(50), + false + ); + origin.setType(Material.GLASS); + } + @Override - public void oneUnit(TerraformWorld tw, @NotNull Random random, @Nullable SimpleBlock ceil, @Nullable SimpleBlock floor, boolean boundary) { - if(ceil == null || floor == null) return; - - // Already processed - if(ceil.getType() == OneOneNineBlockHandler.SCULK - || floor.getType() == OneOneNineBlockHandler.SCULK) return; - // ========================= + public void oneUnit(TerraformWorld tw, + @NotNull Random random, + @Nullable SimpleBlock ceil, + @Nullable SimpleBlock floor, + boolean boundary) + { + if (ceil == null || floor == null) { + return; + } + + // Already processed + if (ceil.getType() == OneOneNineBlockHandler.SCULK || floor.getType() == OneOneNineBlockHandler.SCULK) { + return; + } + // ========================= // Upper decorations // ========================= // int caveHeight = ceil.getY() - floor.getY(); // Don't decorate wet areas - if(!BlockUtils.isWet(ceil.getDown())) { - // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (!BlockUtils.isWet(ceil.getDown())) { + // Don't touch slabbed floors or stalagmites + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; - + } + // Ceiling is ALWAYS sculk/veins - if(BlockUtils.isStoneLike(ceil.getType())) { - ceil.setType(OneOneNineBlockHandler.SCULK); + if (BlockUtils.isStoneLike(ceil.getType())) { + ceil.setType(OneOneNineBlockHandler.SCULK); } - else - { - MultipleFacing sculkVein = (MultipleFacing) Bukkit.createBlockData(OneOneNineBlockHandler.SCULK_VEIN); - sculkVein.setFace(BlockFace.UP, true); - ceil.getDown().setBlockData(sculkVein); + else { + MultipleFacing sculkVein = (MultipleFacing) Bukkit.createBlockData(OneOneNineBlockHandler.SCULK_VEIN); + sculkVein.setFace(BlockFace.UP, true); + ceil.getDown().setBlockData(sculkVein); } } // ========================= // Lower decorations // ========================= - + // If floor is submerged, then don't touch it. - if(BlockUtils.isWet(floor.getUp())) { - return; + if (BlockUtils.isWet(floor.getUp())) { + return; } - + // Ground is sculk // Ceiling is ALWAYS sculk/veins - if(BlockUtils.isStoneLike(ceil.getType())) { - floor.setType(OneOneNineBlockHandler.SCULK); + if (BlockUtils.isStoneLike(ceil.getType())) { + floor.setType(OneOneNineBlockHandler.SCULK); } - else - { - MultipleFacing sculkVein = (MultipleFacing) Bukkit.createBlockData(OneOneNineBlockHandler.SCULK_VEIN); - sculkVein.setFace(BlockFace.DOWN, true); - floor.getUp().setBlockData(sculkVein); + else { + MultipleFacing sculkVein = (MultipleFacing) Bukkit.createBlockData(OneOneNineBlockHandler.SCULK_VEIN); + sculkVein.setFace(BlockFace.DOWN, true); + floor.getUp().setBlockData(sculkVein); + } + + + if (GenUtils.chance(random, 1, 20)) { // Sculk Catalysts + floor.getUp().setType(OneOneNineBlockHandler.SCULK_CATALYST); } - - - if (GenUtils.chance(random, 1, 20)) - { // Sculk Catalysts - floor.getUp().setType(OneOneNineBlockHandler.SCULK_CATALYST); + else if (GenUtils.chance(random, 1, 17)) { // Sculk Sensors + floor.getUp().setType(OneOneNineBlockHandler.SCULK_SENSOR); } - else if (GenUtils.chance(random, 1, 17)) - { // Sculk Sensors - floor.getUp().setType(OneOneNineBlockHandler.SCULK_SENSOR); + else if (GenUtils.chance(random, 1, 25)) + // Sculk Shrieker + { + floor.getUp().setType(OneOneNineBlockHandler.SCULK_SHRIEKER); } - else if(GenUtils.chance(random, 1, 25)) - // Sculk Shrieker - floor.getUp().setType(OneOneNineBlockHandler.SCULK_SHRIEKER); - // ========================= // Attempt to replace close-by walls with sculk. // ========================= - + SimpleBlock target = floor; - while(target.getY() != ceil.getY()) { - for(BlockFace face:BlockUtils.directBlockFaces) { - SimpleBlock rel = target.getRelative(face); - if(BlockUtils.isStoneLike(rel.getType())) { - rel.setType(OneOneNineBlockHandler.SCULK); - if(BlockUtils.isAir(target.getType()) && GenUtils.chance(random, 1, 5)) - { - new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN) - .setFace(face, true) - .apply(target); - } - } - } - target = target.getUp(); + while (target.getY() != ceil.getY()) { + for (BlockFace face : BlockUtils.directBlockFaces) { + SimpleBlock rel = target.getRelative(face); + if (BlockUtils.isStoneLike(rel.getType())) { + rel.setType(OneOneNineBlockHandler.SCULK); + if (BlockUtils.isAir(target.getType()) && GenUtils.chance(random, 1, 5)) { + new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN).setFace(face, true).apply(target); + } + } + } + target = target.getUp(); } - + // ========================= // Biome Setter // ========================= - if(TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) instanceof PopulatorDataICABiomeWriterAbstract data) { - while(floor.getY() < ceil.getY()) { - data.setBiome(floor.getX(), floor.getY(), floor.getZ(), OneOneNineBlockHandler.DEEP_DARK); - floor = floor.getUp(); - } + if (TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) instanceof PopulatorDataICABiomeWriterAbstract data) { + while (floor.getY() < ceil.getY()) { + data.setBiome(floor.getX(), floor.getY(), floor.getZ(), OneOneNineBlockHandler.DEEP_DARK); + floor = floor.getUp(); + } } } - - + + } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/DripstoneClusterCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/DripstoneClusterCavePopulator.java index a4196c53..cb411b72 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/DripstoneClusterCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/DripstoneClusterCavePopulator.java @@ -14,33 +14,42 @@ import java.util.Random; public class DripstoneClusterCavePopulator extends AbstractCaveClusterPopulator { - + public DripstoneClusterCavePopulator(float radius) { - super(radius); - } + super(radius); + } + + @Override + protected void oneUnit(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor, + boolean boundary) + { - @Override - protected void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, boolean boundary) { - - // ========================= + // ========================= // Upper decorations // ========================= int caveHeight = ceil.getY() - floor.getY(); // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; - + } + // All ceiling is dripstone ceil.setType(Material.DRIPSTONE_BLOCK); - + // Stalactites if (GenUtils.chance(random, 1, 4)) { int h = caveHeight / 4; - if (h < 1) h = 1; - if (h > 4) h = 4; + if (h < 1) { + h = 1; + } + if (h > 4) { + h = 4; + } BlockUtils.downLPointedDripstone(GenUtils.randInt(1, h), ceil.getDown()); } @@ -50,25 +59,29 @@ protected void oneUnit(TerraformWorld tw, @NotNull Random random, @NotNull Simpl // Floor is dripstone floor.setType(Material.DRIPSTONE_BLOCK); - + // Stalagmites if (GenUtils.chance(random, 1, 4)) { int h = caveHeight / 4; - if (h < 1) h = 1; - if (h > 4) h = 4; - BlockUtils.upLPointedDripstone(GenUtils.randInt(1,h), floor.getUp()); + if (h < 1) { + h = 1; + } + if (h > 4) { + h = 4; + } + BlockUtils.upLPointedDripstone(GenUtils.randInt(1, h), floor.getUp()); } // ========================= // Biome Setter // ========================= - if(TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) instanceof PopulatorDataICABiomeWriterAbstract data) { - while(floor.getY() < ceil.getY()) { - data.setBiome(floor.getX(), floor.getY(), floor.getZ(), Biome.DRIPSTONE_CAVES); - floor = floor.getUp(); - } + if (TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) instanceof PopulatorDataICABiomeWriterAbstract data) { + while (floor.getY() < ceil.getY()) { + data.setBiome(floor.getX(), floor.getY(), floor.getZ(), Biome.DRIPSTONE_CAVES); + floor = floor.getUp(); + } } } - - + + } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/ForestedMountainsCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/ForestedMountainsCavePopulator.java index 578971cf..9bf04582 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/ForestedMountainsCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/ForestedMountainsCavePopulator.java @@ -16,54 +16,59 @@ public class ForestedMountainsCavePopulator extends AbstractCavePopulator { private final @NotNull MossyCavePopulator mossyCavePop; - + public ForestedMountainsCavePopulator() { - mossyCavePop = new MossyCavePopulator(); + mossyCavePop = new MossyCavePopulator(); } - + @Override - public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor) { + public void populate(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor) + { // Likely to be a river cave - if(ceil.getY() > TerraformGenerator.seaLevel && floor.getY() < TerraformGenerator.seaLevel) - { - // Definitely a river cave - if(ceil.getAtY(TerraformGenerator.seaLevel).getType() == Material.WATER) { + if (ceil.getY() > TerraformGenerator.seaLevel && floor.getY() < TerraformGenerator.seaLevel) { + // Definitely a river cave + if (ceil.getAtY(TerraformGenerator.seaLevel).getType() == Material.WATER) { int caveHeight = ceil.getY() - TerraformGenerator.seaLevel - 1; - - if(caveHeight <= 2) return; - + if (caveHeight <= 2) { + return; + } + + // Pillars - if(GenUtils.chance(random, 1, 100)) { - new CylinderBuilder(random, floor.getRelative( - 0,(ceil.getY() - floor.getY())/2,0), - Material.STONE) - .setRadius(1.5f) - .setRY((ceil.getY() - floor.getY())/2f + 3) - .setHardReplace(false) - .build(); - return; + if (GenUtils.chance(random, 1, 100)) { + new CylinderBuilder(random, + floor.getRelative(0, (ceil.getY() - floor.getY()) / 2, 0), + Material.STONE + ).setRadius(1.5f).setRY((ceil.getY() - floor.getY()) / 2f + 3).setHardReplace(false).build(); + return; } - + // CEILING DECORATIONS - - // Glow berries + + // Glow berries int glowBerryChance = 15; if (GenUtils.chance(random, 1, glowBerryChance)) { int h = caveHeight / 2; - if (h > 6) h = 6; + if (h > 6) { + h = 6; + } BlockUtils.downLCaveVines(h, ceil); } - + // Spore blossom - if(GenUtils.chance(random, 1, 30)) + if (GenUtils.chance(random, 1, 30)) { PlantBuilder.SPORE_BLOSSOM.build(ceil); + } // WATER DECORATIONS // Lily pads - if(GenUtils.chance(random, 1, 50)) { + if (GenUtils.chance(random, 1, 50)) { var at = ceil.getAtY(TerraformGenerator.seaLevel + 1); if (!at.isSolid()) { PlantBuilder.LILY_PAD.build(at); @@ -71,23 +76,22 @@ public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleB } // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; - + } + // BOTTOM DECORATIONS (underwater) - + // sea pickles - if(GenUtils.chance(random, 1, 20)) - CoralGenerator.generateSeaPickles( - floor.getPopData(), - floor.getX(), floor.getY()+1, floor.getZ()); - - return; - } + if (GenUtils.chance(random, 1, 20)) { + CoralGenerator.generateSeaPickles(floor.getPopData(), floor.getX(), floor.getY() + 1, floor.getZ()); + } + + return; + } } - - mossyCavePop.populate(tw, random, ceil, floor); - + + mossyCavePop.populate(tw, random, ceil, floor); + } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/FrozenCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/FrozenCavePopulator.java index faaf77fb..a59b6d31 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/FrozenCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/FrozenCavePopulator.java @@ -15,14 +15,18 @@ public class FrozenCavePopulator extends AbstractCavePopulator { @Override - public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor) { + public void populate(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor) + { int caveHeight = ceil.getY() - floor.getY(); // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; + } // ========================= // Upper decorations @@ -36,11 +40,10 @@ public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleB Wall w = new Wall(ceil.getDown(), BlockFace.NORTH); // w.downLPillar(random, h, Material.ICE); - new StalactiteBuilder(Material.ICE) - .setSolidBlockType(Material.ICE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); + new StalactiteBuilder(Material.ICE).setSolidBlockType(Material.ICE) + .setFacingUp(false) + .setVerticalSpace(caveHeight) + .build(random, w); } // ========================= @@ -54,12 +57,13 @@ public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleB if (GenUtils.chance(random, 1, 25)) { Wall w = new Wall(floor.getUp(2)); if (w.getType() == Material.CAVE_AIR) - // w.LPillar(h, random, Material.ICE); - new StalactiteBuilder(Material.ICE) - .setSolidBlockType(Material.ICE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); + // w.LPillar(h, random, Material.ICE); + { + new StalactiteBuilder(Material.ICE).setSolidBlockType(Material.ICE) + .setFacingUp(true) + .setVerticalSpace(caveHeight) + .build(random, w); + } } } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java index 492dd225..fa275536 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java @@ -24,64 +24,81 @@ public class LushClusterCavePopulator extends AbstractCaveClusterPopulator { - private final boolean isForLargeCave; - public LushClusterCavePopulator(float radius, boolean isForLargeCave) { - super(radius); - this.isForLargeCave = isForLargeCave; - } - + private final boolean isForLargeCave; + + public LushClusterCavePopulator(float radius, boolean isForLargeCave) { + super(radius); + this.isForLargeCave = isForLargeCave; + } + @Override - public void oneUnit(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, boolean boundary) { - - // ========================= + public void oneUnit(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor, + boolean boundary) + { + + // ========================= // Upper decorations // ========================= int caveHeight = ceil.getY() - floor.getY(); // Don't decorate wet areas - if(!BlockUtils.isWet(ceil.getDown())) { - // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) + if (!BlockUtils.isWet(ceil.getDown())) { + // Don't touch slabbed floors or stalagmites + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { return; - + } + // Ceiling is sometimes roots - if(GenUtils.chance(random, 1, 8)) { - // This part doesn't spawn Azaleas - ceil.setType(Material.ROOTED_DIRT); - if(random.nextBoolean()) + if (GenUtils.chance(random, 1, 8)) { + // This part doesn't spawn Azaleas + ceil.setType(Material.ROOTED_DIRT); + if (random.nextBoolean()) { PlantBuilder.HANGING_ROOTS.build(ceil.getDown()); + } } else // If not, it's moss { - ceil.setType(Material.MOSS_BLOCK); - for(BlockFace face:BlockUtils.sixBlockFaces) - if(ceil.getRelative(face).getType() == Material.LAVA) - ceil.getRelative(face).setType(Material.AIR); - - // Spore blossom - if(GenUtils.chance(random, 1, 15)) + ceil.setType(Material.MOSS_BLOCK); + for (BlockFace face : BlockUtils.sixBlockFaces) { + if (ceil.getRelative(face).getType() == Material.LAVA) { + ceil.getRelative(face).setType(Material.AIR); + } + } + + // Spore blossom + if (GenUtils.chance(random, 1, 15)) { PlantBuilder.SPORE_BLOSSOM.build(ceil.getDown()); + } } - + // Spawn these on the surface, and let the roots go downwards. // Hopefully, there won't be random small caves in between the tree // and this cave hole. - if(isForLargeCave && GenUtils.chance(random, 1, 300)) { - SimpleBlock base = ceil.getGround(); - if(BlockUtils.isDirtLike(base.getType()) && !BlockUtils.isWet(base.getUp())) - TreeDB.spawnAzalea(random, tw, base.getPopData(), base.getX(), base.getY()+1, base.getZ()); + if (isForLargeCave && GenUtils.chance(random, 1, 300)) { + SimpleBlock base = ceil.getGround(); + if (BlockUtils.isDirtLike(base.getType()) && !BlockUtils.isWet(base.getUp())) { + TreeDB.spawnAzalea(random, tw, base.getPopData(), base.getX(), base.getY() + 1, base.getZ()); + } } - + // Glow Berries int glowBerryChance = 5; - if(isForLargeCave) glowBerryChance = 7; + if (isForLargeCave) { + glowBerryChance = 7; + } if (GenUtils.chance(random, 1, glowBerryChance)) { int h = caveHeight / 4; - if (h < 1) h = 1; - if (h > 6) h = 6; + if (h < 1) { + h = 1; + } + if (h > 6) { + h = 6; + } BlockUtils.downLCaveVines(h, ceil.getDown()); } } @@ -89,96 +106,102 @@ public void oneUnit(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull // ========================= // Lower decorations // ========================= - + // If floor is submerged, set it to clay, then don't touch it. - if(BlockUtils.isWet(floor.getUp())) { - if(!isForLargeCave) - floor.setType(Material.CLAY); - return; + if (BlockUtils.isWet(floor.getUp())) { + if (!isForLargeCave) { + floor.setType(Material.CLAY); + } + return; } - + // Ground is moss. floor.setType(Material.MOSS_BLOCK); - - - if (GenUtils.chance(random, 1, 15)) - { // Azaleas - if(random.nextBoolean()) + + + if (GenUtils.chance(random, 1, 15)) { // Azaleas + if (random.nextBoolean()) { PlantBuilder.AZALEA.build(floor.getUp()); - else + } + else { PlantBuilder.FLOWERING_AZALEA.build(floor.getUp()); + } } - else if (Version.isAtLeast(17) && GenUtils.chance(random, 1, 7)) - { // Dripleaves + else if (Version.isAtLeast(17) && GenUtils.chance(random, 1, 7)) { // Dripleaves if (TConfigOption.arePlantsEnabled()) { - if(random.nextBoolean()) - new DirectionalBuilder(Material.BIG_DRIPLEAF) - .setFacing(BlockUtils.getDirectBlockFace(random)) - .apply(floor.getUp()); - else - new BisectedBuilder(Material.SMALL_DRIPLEAF) - .placeBoth(floor.getUp()); + if (random.nextBoolean()) { + new DirectionalBuilder(Material.BIG_DRIPLEAF).setFacing(BlockUtils.getDirectBlockFace(random)) + .apply(floor.getUp()); + } + else { + new BisectedBuilder(Material.SMALL_DRIPLEAF).placeBoth(floor.getUp()); + } } } - else if(GenUtils.chance(random, 1, 6)) - // Grass + else if (GenUtils.chance(random, 1, 6)) + // Grass + { PlantBuilder.GRASS.build(floor.getUp()); - else if(GenUtils.chance(random, 1, 7)) - // Moss carpets + } + else if (GenUtils.chance(random, 1, 7)) + // Moss carpets + { PlantBuilder.MOSS_CARPET.build(floor.getUp()); - + } // ========================= // Wall decorations // ========================= - if(!isForLargeCave) - { + if (!isForLargeCave) { SimpleBlock target = floor; - while(target.getY() != ceil.getY()) { + while (target.getY() != ceil.getY()) { // Place small pools of water for axolotls - if(target.getY()-floor.getY() < 3 - && GenUtils.chance(1,700)) - { - new SphereBuilder(random, target, Material.WATER) - .setSphereType(SphereBuilder.SphereType.LOWER_SEMISPHERE) - .setCointainmentMaterials(Material.CLAY) - .setRX(3) - .setRY(2) - .setRZ(3) - .setDoLiquidContainment(true) - .setHardReplace(true) - .build(); + if (target.getY() - floor.getY() < 3 && GenUtils.chance(1, 700)) { + new SphereBuilder( + random, + target, + Material.WATER + ).setSphereType(SphereBuilder.SphereType.LOWER_SEMISPHERE) + .setCointainmentMaterials(Material.CLAY) + .setRX(3) + .setRY(2) + .setRZ(3) + .setDoLiquidContainment(true) + .setHardReplace(true) + .build(); } // Replace the walls with moss, and line with lichen - for(BlockFace face:BlockUtils.directBlockFaces) { + for (BlockFace face : BlockUtils.directBlockFaces) { SimpleBlock rel = target.getRelative(face); - if(BlockUtils.isStoneLike(rel.getType())) { + if (BlockUtils.isStoneLike(rel.getType())) { rel.setType(Material.MOSS_BLOCK); - if(TConfigOption.arePlantsEnabled() && BlockUtils.isAir(target.getType()) && GenUtils.chance(random, 1, 5)) { - new MultipleFacingBuilder(Material.GLOW_LICHEN) - .setFace(face, true) - .apply(target); + if (TConfigOption.arePlantsEnabled() && BlockUtils.isAir(target.getType()) && GenUtils.chance( + random, + 1, + 5 + )) + { + new MultipleFacingBuilder(Material.GLOW_LICHEN).setFace(face, true).apply(target); } } } target = target.getUp(); } } - + // ========================= // Biome Setter // ========================= - if(TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) - instanceof PopulatorDataICABiomeWriterAbstract data) { - while(floor.getY() < ceil.getY()) { - data.setBiome(floor.getX(), floor.getY(), floor.getZ(), Biome.LUSH_CAVES); - floor = floor.getUp(); - } + if (TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()) instanceof PopulatorDataICABiomeWriterAbstract data) { + while (floor.getY() < ceil.getY()) { + data.setBiome(floor.getX(), floor.getY(), floor.getZ(), Biome.LUSH_CAVES); + floor = floor.getUp(); + } } } - - + + } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/MasterCavePopulatorDistributor.java b/common/src/main/java/org/terraform/biome/cavepopulators/MasterCavePopulatorDistributor.java index aacb1192..01012c9b 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/MasterCavePopulatorDistributor.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/MasterCavePopulatorDistributor.java @@ -1,10 +1,5 @@ package org.terraform.biome.cavepopulators; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Random; - import org.jetbrains.annotations.NotNull; import org.terraform.biome.BiomeBank; import org.terraform.coregen.populatordata.PopulatorDataAbstract; @@ -15,26 +10,36 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Random; + /** * This class will distribute ALL cave post-population to the right populators, * as well as handle placements for special small clusters like dripzone, lush and * deep zones. - * */ -public class MasterCavePopulatorDistributor{ +public class MasterCavePopulatorDistributor { + + private static final ArrayList> populatedBefore = new ArrayList<>(); + + public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + HashMap clusters = calculateClusterLocations( + random, + tw, + data.getChunkX(), + data.getChunkZ() + ); - private static final ArrayList> populatedBefore = new ArrayList<>(); - public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - HashMap clusters = calculateClusterLocations(random, tw, data.getChunkX(), data.getChunkZ()); - for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) { for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z++) { - - BiomeBank bank = tw.getBiomeBank(x, z); - int maxHeightForCaves = bank.getHandler().getMaxHeightForCaves(tw, x, z); + + BiomeBank bank = tw.getBiomeBank(x, z); + int maxHeightForCaves = bank.getHandler().getMaxHeightForCaves(tw, x, z); // Remove clusters when they're spawned. - CaveClusterRegistry reg = clusters.remove(new SimpleLocation(x,0,z)); + CaveClusterRegistry reg = clusters.remove(new SimpleLocation(x, 0, z)); Collection pairs = GenUtils.getCaveCeilFloors(data, x, z, 4); @@ -42,18 +47,22 @@ public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNul int clusterPair = !pairs.isEmpty() ? random.nextInt(pairs.size()) : 0; for (int[] pair : pairs) { - - // Biome disallows caves above this height - if(pair[0] > maxHeightForCaves) continue; - SimpleBlock ceil = new SimpleBlock(data,x,pair[0],z); // non-solid - SimpleBlock floor = new SimpleBlock(data,x,pair[1],z); // solid + // Biome disallows caves above this height + if (pair[0] > maxHeightForCaves) { + continue; + } + + SimpleBlock ceil = new SimpleBlock(data, x, pair[0], z); // non-solid + SimpleBlock floor = new SimpleBlock(data, x, pair[1], z); // solid // If this is wet, don't touch it. // Don't populate inside amethysts - if(BlockUtils.amethysts.contains(floor.getType()) - || BlockUtils.fluids.contains(floor.getUp().getType()) - || BlockUtils.amethysts.contains(ceil.getDown().getType())) { + if (BlockUtils.amethysts.contains(floor.getType()) + || BlockUtils.fluids.contains(floor.getUp() + .getType()) + || BlockUtils.amethysts.contains(ceil.getDown().getType())) + { continue; } @@ -64,10 +73,10 @@ public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNul * This has to happen, as most surfaces * too low down will be lava. Hard to decorate. */ - if(floor.getY() < TerraformGeneratorPlugin.injector.getMinY() + 32) - pop = new DeepCavePopulator(); - else - { + if (floor.getY() < TerraformGeneratorPlugin.injector.getMinY() + 32) { + pop = new DeepCavePopulator(); + } + else { /* * Cluster Populators won't just decorate one block, they * will populate the surrounding surfaces in a fuzzy @@ -82,35 +91,50 @@ public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNul pop.populate(tw, random, ceil, floor); // Locating and debug print - if(!populatedBefore.contains(pop.getClass())) { + if (!populatedBefore.contains(pop.getClass())) { populatedBefore.add(pop.getClass()); - TerraformGeneratorPlugin.logger.info("Spawning " + pop.getClass().getSimpleName() + " at " + floor); + TerraformGeneratorPlugin.logger.info("Spawning " + + pop.getClass().getSimpleName() + + " at " + + floor); + } + } + } + } + } + + private @NotNull HashMap calculateClusterLocations(@NotNull Random rand, + @NotNull TerraformWorld tw, + int chunkX, + int chunkZ) + { + HashMap locs = new HashMap<>(); + + for (CaveClusterRegistry type : CaveClusterRegistry.values()) { + SimpleLocation[] positions = GenUtils.randomObjectPositions(tw.getHashedRand( + chunkX, + type.getHashSeed(), + chunkZ + ).nextInt(9999999), + chunkX, + chunkZ, + type.getSeparation(), + type.getPertub() + ); + for (SimpleLocation pos : positions) { + if (locs.containsKey(pos)) + // give a chance to replace the old one + { + if (rand.nextBoolean()) { + continue; } } + + locs.put(pos, type); } + } - } - - private @NotNull HashMap calculateClusterLocations(@NotNull Random rand, @NotNull TerraformWorld tw, int chunkX, int chunkZ){ - HashMap locs = new HashMap<>(); - - for(CaveClusterRegistry type:CaveClusterRegistry.values()) { - SimpleLocation[] positions = GenUtils.randomObjectPositions( - tw.getHashedRand(chunkX, type.getHashSeed(), chunkZ).nextInt(9999999), - chunkX, - chunkZ, - type.getSeparation(), - type.getPertub()); - for(SimpleLocation pos:positions) { - if(locs.containsKey(pos)) - // give a chance to replace the old one - if(rand.nextBoolean()) continue; - - locs.put(pos, type); - } - - } - - return locs; - } + + return locs; + } } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/MossyCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/MossyCavePopulator.java index 5b01dde6..f60f4da6 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/MossyCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/MossyCavePopulator.java @@ -17,14 +17,18 @@ public class MossyCavePopulator extends AbstractCavePopulator { @Override - public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock ceil, @NotNull SimpleBlock floor) { + public void populate(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock ceil, + @NotNull SimpleBlock floor) + { int caveHeight = ceil.getY() - floor.getY(); // Don't touch slabbed floors or stalagmites - if (Tag.SLABS.isTagged(floor.getType()) || - Tag.WALLS.isTagged(floor.getType())) - return; + if (Tag.SLABS.isTagged(floor.getType()) || Tag.WALLS.isTagged(floor.getType())) { + return; + } // ========================= // Upper decorations @@ -33,30 +37,26 @@ public void populate(TerraformWorld tw, @NotNull Random random, @NotNull SimpleB // Stalactites if (GenUtils.chance(random, 1, 35)) { Wall w = new Wall(ceil); - if (w.getUp().getType() == Material.SAND || w.getUp().getType() == Material.SANDSTONE) - new StalactiteBuilder(Material.SANDSTONE_WALL) - .setSolidBlockType(Material.SANDSTONE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.SANDSTONE_WALL); - else - if(w.getUp().getType() == Material.DEEPSLATE) { - new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL) - .setSolidBlockType(Material.DEEPSLATE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.COBBLED_DEEPSLATE_WALL); - } - else if(BlockUtils.isStoneLike(w.getUp().getType())){ - new StalactiteBuilder(Material.COBBLESTONE_WALL,Material.MOSSY_COBBLESTONE_WALL) - .setSolidBlockType(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .setFacingUp(false) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.COBBLESTONE_WALL); - } + if (w.getUp().getType() == Material.SAND || w.getUp().getType() == Material.SANDSTONE) { + new StalactiteBuilder(Material.SANDSTONE_WALL).setSolidBlockType(Material.SANDSTONE) + .setFacingUp(false) + .setVerticalSpace(caveHeight) + .build(random, w); + } + // w.downLPillar(random, h, Material.SANDSTONE_WALL); + else if (w.getUp().getType() == Material.DEEPSLATE) { + new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL).setSolidBlockType(Material.DEEPSLATE) + .setFacingUp(false) + .setVerticalSpace(caveHeight) + .build(random, w); + // w.downLPillar(random, h, Material.COBBLED_DEEPSLATE_WALL); + } + else if (BlockUtils.isStoneLike(w.getUp().getType())) { + new StalactiteBuilder(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL).setSolidBlockType(Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).setFacingUp(false).setVerticalSpace(caveHeight).build(random, w); + // w.downLPillar(random, h, Material.COBBLESTONE_WALL); + } } // ========================= @@ -66,57 +66,56 @@ else if(BlockUtils.isStoneLike(w.getUp().getType())){ // Stalagmites if (GenUtils.chance(random, 1, 35)) { int h = caveHeight / 4; - if (h < 1) h = 1; + if (h < 1) { + h = 1; + } Wall w = new Wall(floor.getUp(), BlockFace.NORTH); if (BlockUtils.isAir(w.getType())) { - if (w.getDown().getType() == Material.SAND || w.getUp().getType() == Material.SANDSTONE) - new StalactiteBuilder(Material.SANDSTONE_WALL) - .setSolidBlockType(Material.SANDSTONE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.SANDSTONE_WALL); - else - if(w.getDown().getType() == Material.DEEPSLATE) { - new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL) - .setSolidBlockType(Material.DEEPSLATE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.COBBLED_DEEPSLATE_WALL); - } - else if(BlockUtils.isStoneLike(w.getDown().getType())){ - new StalactiteBuilder(Material.COBBLESTONE_WALL,Material.MOSSY_COBBLESTONE_WALL) - .setSolidBlockType(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .setFacingUp(true) - .setVerticalSpace(caveHeight) - .build(random, w); - // w.downLPillar(random, h, Material.COBBLESTONE_WALL); - } + if (w.getDown().getType() == Material.SAND || w.getUp().getType() == Material.SANDSTONE) { + new StalactiteBuilder(Material.SANDSTONE_WALL).setSolidBlockType(Material.SANDSTONE) + .setFacingUp(true) + .setVerticalSpace(caveHeight) + .build(random, w); + } + // w.downLPillar(random, h, Material.SANDSTONE_WALL); + else if (w.getDown().getType() == Material.DEEPSLATE) { + new StalactiteBuilder(Material.COBBLED_DEEPSLATE_WALL).setSolidBlockType(Material.DEEPSLATE) + .setFacingUp(true) + .setVerticalSpace(caveHeight) + .build(random, w); + // w.downLPillar(random, h, Material.COBBLED_DEEPSLATE_WALL); + } + else if (BlockUtils.isStoneLike(w.getDown().getType())) { + new StalactiteBuilder(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL).setSolidBlockType(Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).setFacingUp(true).setVerticalSpace(caveHeight).build(random, w); + // w.downLPillar(random, h, Material.COBBLESTONE_WALL); + } } - } - else if (GenUtils.chance(random, 1, 25) - && BlockUtils.isStoneLike(floor.getUp().getType())) - { // Slabbing + } + else if (GenUtils.chance(random, 1, 25) && BlockUtils.isStoneLike(floor.getUp().getType())) { // Slabbing SimpleBlock base = floor.getUp(); // Only next to spots where there's some kind of solid block. - if (BlockUtils.isAir(base.getType())) + if (BlockUtils.isAir(base.getType())) { for (BlockFace face : BlockUtils.directBlockFaces) { if (base.getRelative(face).isSolid()) { - if(base.getDown().getType() == Material.DEEPSLATE) - base.setType(Material.COBBLED_DEEPSLATE_SLAB); - else - base.setType(Material.STONE_SLAB); + if (base.getDown().getType() == Material.DEEPSLATE) { + base.setType(Material.COBBLED_DEEPSLATE_SLAB); + } + else { + base.setType(Material.STONE_SLAB); + } break; } } - } - else if (GenUtils.chance(random, 1, 35) && BlockUtils.isStoneLike(floor.getUp().getType())) - { // Shrooms - if (BlockUtils.isAir(floor.getUp().getType())) + } + } + else if (GenUtils.chance(random, 1, 35) && BlockUtils.isStoneLike(floor.getUp().getType())) { // Shrooms + if (BlockUtils.isAir(floor.getUp().getType())) { PlantBuilder.build(floor.getUp(), PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); + } } - + } } diff --git a/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeSupportedBiomeGrid.java b/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeSupportedBiomeGrid.java index 2d0889d5..80f6c15c 100644 --- a/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeSupportedBiomeGrid.java +++ b/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeSupportedBiomeGrid.java @@ -5,12 +5,12 @@ import org.terraform.data.TerraformWorld; public abstract class CustomBiomeSupportedBiomeGrid { - - public void setBiome(@NotNull TerraformWorld tw, int x, int z, CustomBiomeType bio, Biome fallback) { - for (int y = tw.minY; y < tw.maxY; y+=4) { + + public void setBiome(@NotNull TerraformWorld tw, int x, int z, CustomBiomeType bio, Biome fallback) { + for (int y = tw.minY; y < tw.maxY; y += 4) { setBiome(x, y, z, bio, fallback); } - } - - public abstract void setBiome(int x, int y, int z, CustomBiomeType bio, Biome fallback); + } + + public abstract void setBiome(int x, int y, int z, CustomBiomeType bio, Biome fallback); } diff --git a/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeType.java b/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeType.java index 13d588df..cee0d9ac 100644 --- a/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeType.java +++ b/common/src/main/java/org/terraform/biome/custombiomes/CustomBiomeType.java @@ -7,10 +7,10 @@ public enum CustomBiomeType { NONE, - MUDDY_BOG("b8ad49","9c8046","b8ad49","d9cd62","ad8445","ad8445"), - CHERRY_GROVE("","69faff","","87fffb","ffa1fc","acff96"), - SCARLET_FOREST("","","","","fc3103","ff7700"), - CRYSTALLINE_CLUSTER("e54fff","c599ff","e54fff","","",""), + MUDDY_BOG("b8ad49", "9c8046", "b8ad49", "d9cd62", "ad8445", "ad8445"), + CHERRY_GROVE("", "69faff", "", "87fffb", "ffa1fc", "acff96"), + SCARLET_FOREST("", "", "", "", "fc3103", "ff7700"), + CRYSTALLINE_CLUSTER("e54fff", "c599ff", "e54fff", "", "", ""), ; private final @NotNull String key; @@ -18,8 +18,8 @@ public enum CustomBiomeType { private final String waterColor; private final String waterFogColor; private final String skyColor; - private String foliageColor; private final String grassColor; + private String foliageColor; private float rainFall = 0.8f; private boolean isCold = false; @@ -33,8 +33,13 @@ public enum CustomBiomeType { this.grassColor = ""; } - CustomBiomeType(String fogColor, String waterColor, String waterFogColor, - String skyColor, String foliageColor, String grassColor) { + CustomBiomeType(String fogColor, + String waterColor, + String waterFogColor, + String skyColor, + String foliageColor, + String grassColor) + { this.key = "terraformgenerator:" + this.toString().toLowerCase(Locale.ENGLISH); this.fogColor = fogColor; this.waterColor = waterColor; @@ -45,8 +50,9 @@ public enum CustomBiomeType { this.rainFall = 0.8f; this.isCold = false; // In 1.20, cherry trees no longer need the pink. - if(Version.isAtLeast(20) && this.foliageColor.equals("ffa1fc")) + if (Version.isAtLeast(20) && this.foliageColor.equals("ffa1fc")) { this.foliageColor = "acff96"; + } } diff --git a/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java b/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java index d7b57015..a51ec890 100644 --- a/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java @@ -32,6 +32,16 @@ public class ArchedCliffsHandler extends BiomeHandler { static BiomeBlender biomeBlender; + /** + * Might want to phase this out + */ + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setGridBlendingFactor(4).setSmoothBlendTowardsRivers(4); + } + return biomeBlender; + } + @Override public boolean isOcean() { return false; @@ -41,30 +51,39 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.PLAINS; } - + // Remove rivers from arched cliffs. // Arched cliffs are slightly higher than other biomes to lower beach sizes @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - double height = super.calculateHeight(tw, x, z); - double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); - if(riverDepth > 0) - height += riverDepth; - return height + 3; + double height = super.calculateHeight(tw, x, z); + double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); + if (riverDepth > 0) { + height += riverDepth; + } + return height + 3; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - SimpleBlock target = new SimpleBlock(data,rawX,surfaceY,rawZ); + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + SimpleBlock target = new SimpleBlock(data, rawX, surfaceY, rawZ); // Highest Ground decorations: grass and flowers if (GenUtils.chance(random, 1, 10)) { // Grass @@ -73,21 +92,24 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(target.getUp()); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { BlockUtils.pickFlower().build(target.getUp()); - else + } + else { BlockUtils.pickTallFlower().build(target.getUp()); + } } } // Underside decorations: Mushrooms SimpleBlock underside = target.findAirPocket(30); - if(underside != null && underside.getY() > TerraformGenerator.seaLevel) { + if (underside != null && underside.getY() > TerraformGenerator.seaLevel) { // TODO: Consider optimization: calculateHeight() instead of this shit SimpleBlock grassBottom = underside.findStonelikeFloor(50); - if(grassBottom != null && grassBottom.getY() > TerraformGenerator.seaLevel) { - if(grassBottom.getType() == Material.GRASS_BLOCK) { + if (grassBottom != null && grassBottom.getY() > TerraformGenerator.seaLevel) { + if (grassBottom.getType() == Material.GRASS_BLOCK) { // Indicates that this area is valid for population if (GenUtils.chance(random, 1, 10)) { @@ -96,11 +118,13 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int // If an underside was valid, you can check the upper area for // decorating overhangs - for(BlockFace face:BlockUtils.directBlockFaces) { - if(TConfigOption.arePlantsEnabled() && target.getRelative(face).getType() == Material.AIR) { - if(GenUtils.chance(random, 1, 5)) - // TODO:PlantBuilder + for (BlockFace face : BlockUtils.directBlockFaces) { + if (TConfigOption.arePlantsEnabled() && target.getRelative(face).getType() == Material.AIR) { + if (GenUtils.chance(random, 1, 5)) + // TODO:PlantBuilder + { target.getRelative(face).downLPillar(random, random.nextInt(8), Material.OAK_LEAVES); + } } } } @@ -108,40 +132,52 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { // Highest Ground decorations // Small trees generate in the presence of light SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 6); - + for (SimpleLocation sLoc : trees) { - int highestY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - if(BlockUtils.isWet(new SimpleBlock(data, sLoc.getX(), highestY+1, sLoc.getZ()))) - continue; - + int highestY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + if (BlockUtils.isWet(new SimpleBlock(data, sLoc.getX(), highestY + 1, sLoc.getZ()))) { + continue; + } + sLoc.setY(highestY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); } - + } - + // Mushrooms generate underneath the overhangs SimpleLocation[] shrooms = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 10); - + for (SimpleLocation sLoc : shrooms) { - SimpleBlock target = new SimpleBlock(data, sLoc.getX(),0,sLoc.getZ()).getGround(); - SimpleBlock underside = target.findAirPocket(30); - if(underside != null && underside.getY() > TerraformGenerator.seaLevel) { - SimpleBlock grassBottom = underside.findStonelikeFloor(50); - if(grassBottom != null && grassBottom.getY() > TerraformGenerator.seaLevel) { - if(grassBottom.getType() == Material.GRASS_BLOCK) { - // Indicates that this area is valid for population - sLoc.setY(grassBottom.getY()); - - FractalTypes.Mushroom type = switch(random.nextInt(6)) { + SimpleBlock target = new SimpleBlock(data, sLoc.getX(), 0, sLoc.getZ()).getGround(); + SimpleBlock underside = target.findAirPocket(30); + if (underside != null && underside.getY() > TerraformGenerator.seaLevel) { + SimpleBlock grassBottom = underside.findStonelikeFloor(50); + if (grassBottom != null && grassBottom.getY() > TerraformGenerator.seaLevel) { + if (grassBottom.getType() == Material.GRASS_BLOCK) { + // Indicates that this area is valid for population + sLoc.setY(grassBottom.getY()); + + FractalTypes.Mushroom type = switch (random.nextInt(6)) { case 0 -> FractalTypes.Mushroom.MEDIUM_RED_MUSHROOM; case 1 -> FractalTypes.Mushroom.MEDIUM_BROWN_MUSHROOM; case 2 -> FractalTypes.Mushroom.MEDIUM_BROWN_FUNNEL_MUSHROOM; @@ -150,12 +186,12 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando default -> FractalTypes.Mushroom.SMALL_RED_MUSHROOM; }; - new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY()+1, sLoc.getZ()); - } - } - } + new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); + } + } + } } - } + } @Override public BiomeHandler getTransformHandler() { @@ -163,29 +199,37 @@ public BiomeHandler getTransformHandler() { } @Override - public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld tw, @NotNull Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - - FastNoise platformNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_ARCHEDCLIFFS_PLATFORMNOISE, - world -> { - FastNoise n = new FastNoise(tw.getRand(12115222).nextInt()); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.01f); - return n; - }); - - FastNoise pillarNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_ARCHEDCLIFFS_PILLARNOISE, - world -> { - FastNoise n = new FastNoise(tw.getRand(12544422).nextInt()); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFractalOctaves(4); - n.SetFrequency(0.01f); - return n; - }); + public void transformTerrain(@NotNull ChunkCache cache, + @NotNull TerraformWorld tw, + @NotNull Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + + FastNoise platformNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.BIOME_ARCHEDCLIFFS_PLATFORMNOISE, + world -> { + FastNoise n = new FastNoise(tw.getRand(12115222).nextInt()); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.01f); + return n; + } + ); + + FastNoise pillarNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.BIOME_ARCHEDCLIFFS_PILLARNOISE, + world -> { + FastNoise n = new FastNoise(tw.getRand(12544422).nextInt()); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFractalOctaves(4); + n.SetFrequency(0.01f); + return n; + } + ); int rawX = chunkX * 16 + x; int rawZ = chunkZ * 16 + z; @@ -194,69 +238,65 @@ public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld int height = (int) preciseHeight; // Round to force a 0 if the value is too low. Makes blending better. - double platformNoiseVal = - Math.round( - Math.max( - platformNoise.GetNoise(rawX, rawZ) - *70 - *getBiomeBlender(tw).getEdgeFactor(BiomeBank.ARCHED_CLIFFS, rawX, rawZ) - , 0) - ); - - if(platformNoiseVal >= 1) { - int platformHeight = (int) ( - HeightMap.CORE.getHeight(tw, rawX, rawZ) - - HeightMap.ATTRITION.getHeight(tw, rawX, rawZ) - + 55); + double platformNoiseVal = Math.round(Math.max(platformNoise.GetNoise(rawX, rawZ) + * 70 + * getBiomeBlender(tw).getEdgeFactor( + BiomeBank.ARCHED_CLIFFS, + rawX, + rawZ + ), 0)); + + if (platformNoiseVal >= 1) { + int platformHeight = (int) (HeightMap.CORE.getHeight(tw, rawX, rawZ) - HeightMap.ATTRITION.getHeight( + tw, + rawX, + rawZ + ) + 55); // for higher platform noise vals, make a thicker platform - cache.writeTransformedHeight (x,z,(short) platformHeight); + cache.writeTransformedHeight(x, z, (short) platformHeight); chunk.setBlock(x, platformHeight, z, Material.GRASS_BLOCK); Material[] crust = getSurfaceCrust(random); - for(int i = 0; i < platformNoiseVal; i++) { - if(i < crust.length) - chunk.setBlock(x, platformHeight-i, z, crust[i]); - else - chunk.setBlock(x, platformHeight-i, z, Material.STONE); + for (int i = 0; i < platformNoiseVal; i++) { + if (i < crust.length) { + chunk.setBlock(x, platformHeight - i, z, crust[i]); + } + else { + chunk.setBlock(x, platformHeight - i, z, Material.STONE); + } } // This is for the bottom platform // DOES NOT change height, so can be ignored in pure height calculation // This is bad practice - if(!(chunk instanceof DudChunkData) - && platformNoiseVal > 6) { - int pillarNoiseVal = (int) ((platformNoiseVal/10.0)*((0.1+Math.abs(pillarNoise.GetNoise(rawX, rawZ)))*20.0)); - if(pillarNoiseVal + height > platformHeight) + if (!(chunk instanceof DudChunkData) && platformNoiseVal > 6) { + int pillarNoiseVal = (int) ((platformNoiseVal / 10.0) * ((0.1 + Math.abs(pillarNoise.GetNoise( + rawX, + rawZ + ))) * 20.0)); + if (pillarNoiseVal + height > platformHeight) { pillarNoiseVal = platformHeight - height; + } // Crust cannot be under solids. // Guarded from DudChunkData, so safe to read - boolean applyCrust = !chunk.getType(x, height+pillarNoiseVal+1, z).isSolid(); + boolean applyCrust = !chunk.getType(x, height + pillarNoiseVal + 1, z).isSolid(); - for(int i = pillarNoiseVal; i >= 1; i--) { - if((pillarNoiseVal-i) < crust.length && applyCrust) - chunk.setBlock(x, height+i, z, crust[pillarNoiseVal-i]); - else - chunk.setBlock(x, height+i, z, Material.STONE); + for (int i = pillarNoiseVal; i >= 1; i--) { + if ((pillarNoiseVal - i) < crust.length && applyCrust) { + chunk.setBlock(x, height + i, z, crust[pillarNoiseVal - i]); + } + else { + chunk.setBlock(x, height + i, z, Material.STONE); + } } } } } - /** - * Might want to phase this out - */ - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setGridBlendingFactor(4) - .setSmoothBlendTowardsRivers(4); - return biomeBlender; - } - - @Override public int getMaxHeightForCaves(@NotNull TerraformWorld tw, int x, int z) { - return (int) HeightMap.CORE.getHeight(tw, x, z); + return (int) HeightMap.CORE.getHeight(tw, x, z); } diff --git a/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java b/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java index f2741f7c..1b364d9d 100644 --- a/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java @@ -27,38 +27,53 @@ import java.util.Random; public class BadlandsHandler extends BiomeHandler { - static private BiomeBlender riversBlender; - static private BiomeBlender plateauBlender; - static final int sandRadius = TConfigOption.BIOME_BADLANDS_PLATEAU_SAND_RADIUS.getInt(); static final int plateauHeight = TConfigOption.BIOME_BADLANDS_PLATEAU_HEIGHT.getInt(); static final float plateauFrequency = TConfigOption.BIOME_BADLANDS_PLATEAU_FREQUENCY.getFloat(); static final double plateauThreshold = TConfigOption.BIOME_BADLANDS_PLATEAU_THRESHOLD.getDouble(); static final double plateauCommonness = TConfigOption.BIOME_BADLANDS_PLATEAU_COMMONNESS.getDouble(); + static private BiomeBlender riversBlender; + static private BiomeBlender plateauBlender; private static @NotNull BiomeBlender getRiversBlender(TerraformWorld tw) { // Only one blender needed! - if (riversBlender == null) riversBlender = new BiomeBlender(tw, true, false) - .setGridBlendingFactor(0.45); + if (riversBlender == null) { + riversBlender = new BiomeBlender(tw, true, false).setGridBlendingFactor(0.45); + } return riversBlender; } private static @NotNull BiomeBlender getPlateauBlender(TerraformWorld tw) { - if (plateauBlender == null) plateauBlender = new BiomeBlender(tw, true, true).setRiverThreshold(10); + if (plateauBlender == null) { + plateauBlender = new BiomeBlender(tw, true, true).setRiverThreshold(10); + } return plateauBlender; } public static @NotNull FastNoise getPlateauNoise(TerraformWorld tw) { - return NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_BADLANDS_PLATEAUNOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 7509)); - n.SetNoiseType(FastNoise.NoiseType.CubicFractal); - n.SetFractalOctaves(2); - n.SetFrequency(plateauFrequency); - return n; - }); + return NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BADLANDS_PLATEAUNOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 7509)); + n.SetNoiseType(FastNoise.NoiseType.CubicFractal); + n.SetFractalOctaves(2); + n.SetFrequency(plateauFrequency); + return n; + }); + } + + // This is for optimizing sand, ew + static int getPlateauHeight(TerraformWorld tw, int x, int z) { + double rawValue = Math.max(0, getPlateauNoise(tw).GetNoise(x, z) + plateauCommonness); + double noiseValue = rawValue * getPlateauBlender(tw).getEdgeFactor(BiomeBank.BADLANDS, x, z) * (1 - ((int) ( + rawValue + / plateauThreshold) * 0.1)); + + double graduated = noiseValue / plateauThreshold; + double platformHeight = (int) graduated * plateauHeight + (10 * Math.pow(graduated + - (int) graduated + - 0.5 + - 0.1, 7) * plateauHeight); + + return (int) Math.round(platformHeight); } @Override @@ -78,23 +93,30 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ + return new Material[] { Material.RED_SAND, Material.RED_SAND, GenUtils.randChoice(rand, Material.RED_SAND, Material.RED_SANDSTONE), GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE), - GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - - // While not a small item, generatePlateaus is left in, as it - // transforms the terrain itself. Structures placed must account for - // these terrain changes. + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + + // While not a small item, generatePlateaus is left in, as it + // transforms the terrain itself. Structures placed must account for + // these terrain changes. // TODO: Past me wrote this to kick the bucket to future me. I am future me. Fuck you. - generatePlateaus(world, rawX, surfaceY, rawZ,data); + generatePlateaus(world, rawX, surfaceY, rawZ, data); OasisBeach.generateOasisBeach(world, random, data, rawX, rawZ, BiomeBank.BADLANDS); @@ -104,22 +126,27 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } Material base = data.getType(rawX, surfaceY, rawZ); - if (base == Material.SAND || - base == Material.RED_SAND) { + if (base == Material.SAND || base == Material.RED_SAND) { if (GenUtils.chance(random, 1, 200)) { boolean canSpawn = true; for (BlockFace face : BlockUtils.directBlockFaces) { - if (data.getType(rawX + face.getModX(), surfaceY + 1, rawZ + face.getModZ()) != Material.AIR) + if (data.getType(rawX + face.getModX(), surfaceY + 1, rawZ + face.getModZ()) != Material.AIR) { canSpawn = false; + } } // Prevent cactus from spawning on plateaus: - if (HeightMap.getBlockHeight(world, rawX, rawZ) + 5 < surfaceY) canSpawn = false; - if (canSpawn && GenUtils.chance(1, 50)) + if (HeightMap.getBlockHeight(world, rawX, rawZ) + 5 < surfaceY) { + canSpawn = false; + } + if (canSpawn && GenUtils.chance(1, 50)) { spawnDeadTree(data, rawX, surfaceY, rawZ); - else if (canSpawn) + } + else if (canSpawn) { PlantBuilder.CACTUS.build(random, data, rawX, surfaceY + 1, rawZ, 2, 5); - } else if (GenUtils.chance(random, 1, 80) && surfaceY > TerraformGenerator.seaLevel) { + } + } + else if (GenUtils.chance(random, 1, 80) && surfaceY > TerraformGenerator.seaLevel) { PlantBuilder.DEAD_BUSH.build(data, rawX, surfaceY + 1, rawZ); } } @@ -130,8 +157,16 @@ public BiomeHandler getTransformHandler() { return this; } - @Override - public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { + @Override + public void transformTerrain(ChunkCache cache, + @NotNull TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { // Badlands doesn't actually mutate height in here (WHY??). // Because of that, don't edit heightChanges // This is perpetuating the cycle of abuse and falsehood @@ -139,16 +174,13 @@ public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Rando BiomeBlender blender = getRiversBlender(tw); - FastNoise wallNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_BADLANDS_WALLNOISE, - world -> { - FastNoise n = new FastNoise((int) (tw.getWorld().getSeed() * 2)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.07f); - n.SetFractalOctaves(2); - return n; - }); + FastNoise wallNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BADLANDS_WALLNOISE, world -> { + FastNoise n = new FastNoise((int) (tw.getWorld().getSeed() * 2)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.07f); + n.SetFractalOctaves(2); + return n; + }); int rawX = chunkX * 16 + x; int rawZ = chunkZ * 16 + z; @@ -169,8 +201,9 @@ public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Rando double riverFactor = heightAboveSea / maxDiff; // 0 at river level, 1 at riverlessHeight if (riverFactor > 0 && heightAboveSea > 0) { - int buildHeight = (int) Math.round(bottomEdgeFactor * - (Math.min(1, 4 * Math.pow(riverFactor, 4)) * maxDiff + wallNoise.GetNoise(rawX, rawZ) * 1.5)); + int buildHeight = (int) Math.round(bottomEdgeFactor * (Math.min(1, 4 * Math.pow(riverFactor, 4)) + * maxDiff + + wallNoise.GetNoise(rawX, rawZ) * 1.5)); for (int i = buildHeight; i >= 0; i--) { int lowerHeight = Math.min(TerraformGenerator.seaLevel + i, (int) Math.round(riverlessHeight)); @@ -182,11 +215,13 @@ public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Rando // Curved top edges if (riverFactor > threshold) { - int upperBuildHeight = (int) Math.round( - 1 *// topEdgeFactor * - (Math.min(1, 50 * Math.pow(riverFactor - threshold, 2.5)) * maxDiff + wallNoise.GetNoise(rawX, rawZ) * 1.5)); + int upperBuildHeight = (int) Math.round(1 *// topEdgeFactor * + (Math.min(1, 50 * Math.pow(riverFactor - threshold, 2.5)) + * maxDiff + wallNoise.GetNoise(rawX, rawZ) * 1.5)); - if (topEdgeFactor == 0) return; + if (topEdgeFactor == 0) { + return; + } for (int i = 0; i <= upperBuildHeight; i++) { int upperHeight = (int) riverlessHeight - i; @@ -196,8 +231,9 @@ public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Rando } // Coat with red sand - if (riverFactor > threshold + 0.12) + if (riverFactor > threshold + 0.12) { chunk.setBlock(x, (int) riverlessHeight + 1, z, Material.RED_SAND); + } } } } @@ -206,83 +242,98 @@ public void transformTerrain(ChunkCache cache, @NotNull TerraformWorld tw, Rando * how the surrounding base sand is placed. transformTerrain is only supposed to access * one pair of x and z coordinates at a time. */ - void generatePlateaus(@NotNull TerraformWorld tw, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - FastNoise detailsNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_BADLANDS_WALLNOISE, - world -> { - FastNoise n = new FastNoise((int) (tw.getSeed() * 7509)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.08f); - return n; - }); - - // Calculate plateau height - double rawValue = Math.max(0, getPlateauNoise(tw).GetNoise(rawX, rawZ) + plateauCommonness); - double noiseValue = rawValue * getPlateauBlender(tw).getEdgeFactor(BiomeBank.BADLANDS, rawX, rawZ) * (1 - ((int) (rawValue / plateauThreshold) * 0.05)); - - double graduated = noiseValue / plateauThreshold; - double platformHeight = (int) graduated * plateauHeight - + (10 * Math.pow(graduated - (int) graduated - 0.5 - 0.1, 7) * plateauHeight); - - boolean placeSand = false; - for (int y = 1; y <= (int) Math.round(platformHeight); y++) { - placeSand = true; - Material material; // Coat plateaus with sand - if ((int) graduated * plateauHeight == y) - material = Material.RED_SAND; - else if ((int) graduated * plateauHeight == y + 1) - material = GenUtils.randChoice(Material.RED_SAND, Material.RED_SAND, BlockUtils.getTerracotta(surfaceY + y)); - else if ((int) graduated * plateauHeight == y + 2) - material = GenUtils.randChoice(Material.RED_SAND, BlockUtils.getTerracotta(surfaceY + y), - BlockUtils.getTerracotta(surfaceY + y)); - else - material = BlockUtils.getTerracotta(surfaceY + y); - - data.setType(rawX, surfaceY + y, rawZ, material); - } + void generatePlateaus(@NotNull TerraformWorld tw, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + FastNoise detailsNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BADLANDS_WALLNOISE, world -> { + FastNoise n = new FastNoise((int) (tw.getSeed() * 7509)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.08f); + return n; + }); + + // Calculate plateau height + double rawValue = Math.max(0, getPlateauNoise(tw).GetNoise(rawX, rawZ) + plateauCommonness); + double noiseValue = rawValue * getPlateauBlender(tw).getEdgeFactor(BiomeBank.BADLANDS, rawX, rawZ) * (1 + - ((int) ( + rawValue + / plateauThreshold) * 0.05)); - // Prevent inner parts of plateau from generating sand in vain - if (!placeSand || graduated - (int) graduated > 0.2) return; + double graduated = noiseValue / plateauThreshold; + double platformHeight = (int) graduated * plateauHeight + (10 * Math.pow(graduated + - (int) graduated + - 0.5 + - 0.1, 7) * plateauHeight); + + boolean placeSand = false; + for (int y = 1; y <= (int) Math.round(platformHeight); y++) { + placeSand = true; + Material material; // Coat plateaus with sand + if ((int) graduated * plateauHeight == y) { + material = Material.RED_SAND; + } + else if ((int) graduated * plateauHeight == y + 1) { + material = GenUtils.randChoice(Material.RED_SAND, + Material.RED_SAND, + BlockUtils.getTerracotta(surfaceY + y) + ); + } + else if ((int) graduated * plateauHeight == y + 2) { + material = GenUtils.randChoice(Material.RED_SAND, + BlockUtils.getTerracotta(surfaceY + y), + BlockUtils.getTerracotta(surfaceY + y) + ); + } + else { + material = BlockUtils.getTerracotta(surfaceY + y); + } - // Surround plateaus with sand - int level = (((int) graduated) - 1) * plateauHeight; // handle second and third levels of plateau - for (int sx = rawX - sandRadius; sx <= rawX + sandRadius; sx++) { - for (int sz = rawZ - sandRadius; sz <= rawZ + sandRadius; sz++) { - double distance = Math.sqrt(Math.pow(sx - rawX, 2) + Math.pow(sz - rawZ, 2)); + data.setType(rawX, surfaceY + y, rawZ, material); + } - if (distance < sandRadius) { - // Skip if sand would levitate - if ((int) graduated != 1 && getPlateauHeight(tw, sx, sz) != plateauHeight) continue; + // Prevent inner parts of plateau from generating sand in vain + if (!placeSand || graduated - (int) graduated > 0.2) { + return; + } + + // Surround plateaus with sand + int level = (((int) graduated) - 1) * plateauHeight; // handle second and third levels of plateau + for (int sx = rawX - sandRadius; sx <= rawX + sandRadius; sx++) { + for (int sz = rawZ - sandRadius; sz <= rawZ + sandRadius; sz++) { + double distance = Math.sqrt(Math.pow(sx - rawX, 2) + Math.pow(sz - rawZ, 2)); + + if (distance < sandRadius) { + // Skip if sand would levitate + if ((int) graduated != 1 && getPlateauHeight(tw, sx, sz) != plateauHeight) { + continue; + } - int sandHeight = (int) Math.round(plateauHeight * 0.55 * Math.pow(1 - distance / sandRadius, 1.7) + detailsNoise.GetNoise(sx, sz)); - for (int y = 1 + level; y <= sandHeight + level; y++) - if (data.getType(sx, HeightMap.getBlockHeight(tw, sx, sz) + y, sz) == Material.AIR) - data.setType(sx, HeightMap.getBlockHeight(tw, sx, sz) + y, sz, Material.RED_SAND); + int sandHeight = (int) Math.round(plateauHeight * 0.55 * Math.pow(1 - distance / sandRadius, 1.7) + + detailsNoise.GetNoise(sx, sz)); + for (int y = 1 + level; y <= sandHeight + level; y++) { + if (data.getType(sx, HeightMap.getBlockHeight(tw, sx, sz) + y, sz) == Material.AIR) { + data.setType(sx, HeightMap.getBlockHeight(tw, sx, sz) + y, sz, Material.RED_SAND); } } } - } - - // This is for optimizing sand, ew - static int getPlateauHeight(TerraformWorld tw, int x, int z) { - double rawValue = Math.max(0, getPlateauNoise(tw).GetNoise(x, z) + plateauCommonness); - double noiseValue = rawValue * getPlateauBlender(tw).getEdgeFactor(BiomeBank.BADLANDS, x, z) * (1 - ((int) (rawValue / plateauThreshold) * 0.1)); - - double graduated = noiseValue / plateauThreshold; - double platformHeight = (int) graduated * plateauHeight - + (10 * Math.pow(graduated - (int) graduated - 0.5 - 0.1, 7) * plateauHeight); - - return (int) Math.round(platformHeight); + } + } } void spawnDeadTree(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if ( !TConfigOption.areTreesEnabled()) return; + if (!TConfigOption.areTreesEnabled()) { + return; + } int height = GenUtils.randInt(5, 7); int branches = GenUtils.randInt(1, height == 5 ? 2 : 3); - for (int i = 1; i <= height; i++) data.setType(x, y + i, z, Material.DARK_OAK_WOOD); + for (int i = 1; i <= height; i++) { + data.setType(x, y + i, z, Material.DARK_OAK_WOOD); + } ArrayList usedBranchHorizontals = new ArrayList<>(); ArrayList usedBranchVerticals = new ArrayList<>(); @@ -299,10 +350,18 @@ void spawnDeadTree(@NotNull PopulatorDataAbstract data, int x, int y, int z) { int bz = z; switch (bDirection) { - case 1: bz++; break; - case 2: bx++; break; - case 3: bz--; break; - default: bx--; break; + case 1: + bz++; + break; + case 2: + bx++; + break; + case 3: + bz--; + break; + default: + bx--; + break; } data.setType(bx, y + bHeight, bz, Material.DARK_OAK_WOOD); @@ -314,17 +373,23 @@ void spawnDeadTree(@NotNull PopulatorDataAbstract data, int x, int y, int z) { // TODO: Seems like a mass of excessive calculation just to spawn dead trees // Look into optimisation here in future. - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) { for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z++) { int highest = GenUtils.getTrueHighestBlock(data, x, z); BiomeBank currentBiome = tw.getBiomeBank(x, z); - if (currentBiome != BiomeBank.BADLANDS && - currentBiome != BiomeBank.BADLANDS_BEACH && - currentBiome != BiomeBank.BADLANDS_CANYON) continue; + if (currentBiome != BiomeBank.BADLANDS + && currentBiome != BiomeBank.BADLANDS_BEACH + && currentBiome != BiomeBank.BADLANDS_CANYON) + { + continue; + } if (HeightMap.getNoiseGradient(tw, x, z, 3) >= 1.5 && GenUtils.chance(random, 49, 50)) { BadlandsCanyonHandler.oneUnit(random, data, x, z, true); @@ -332,29 +397,32 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } Material base = data.getType(x, highest, z); - if (base == Material.SAND || - base == Material.RED_SAND) { + if (base == Material.SAND || base == Material.RED_SAND) { if (GenUtils.chance(random, 1, 200)) { boolean canSpawn = true; for (BlockFace face : BlockUtils.directBlockFaces) { - if (data.getType(x + face.getModX(), highest + 1, z + face.getModZ()) != Material.AIR) + if (data.getType(x + face.getModX(), highest + 1, z + face.getModZ()) != Material.AIR) { canSpawn = false; + } } - - if (GenUtils.getHighestGround(data, x, z) + 5 < highest) canSpawn = false; - if (canSpawn && GenUtils.chance(1, 50)) + + if (GenUtils.getHighestGround(data, x, z) + 5 < highest) { + canSpawn = false; + } + if (canSpawn && GenUtils.chance(1, 50)) { spawnDeadTree(data, x, highest, z); - + } + } } } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.BADLANDS_BEACH; - } + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.BADLANDS_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java b/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java index 264de4c9..210e2f0f 100644 --- a/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java @@ -15,8 +15,8 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; @@ -35,36 +35,43 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - FastNoise pathNoise = NoiseCacheHandler.getNoise( - world, - NoiseCacheEntry.BIOME_BAMBOOFOREST_PATHNOISE, - tw -> { - FastNoise n = new FastNoise((int) (tw.getSeed() * 13)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.07f); - return n; + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + FastNoise pathNoise = NoiseCacheHandler.getNoise(world, NoiseCacheEntry.BIOME_BAMBOOFOREST_PATHNOISE, tw -> { + FastNoise n = new FastNoise((int) (tw.getSeed() * 13)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.07f); + return n; }); // Podzol Paths if (pathNoise.GetNoise(rawX, rawZ) > 0.27) { - if (GenUtils.chance(random, 99, 100) && - data.getBiome(rawX, rawZ) == getBiome() && - BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) + if (GenUtils.chance(random, 99, 100) && data.getBiome(rawX, rawZ) == getBiome() && BlockUtils.isDirtLike( + data.getType(rawX, surfaceY, rawZ))) + { data.setType(rawX, surfaceY, rawZ, Material.PODZOL); + } } - if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK || - data.getType(rawX, surfaceY, rawZ) == Material.PODZOL) { + if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK + || data.getType(rawX, surfaceY, rawZ) == Material.PODZOL) + { // Grass and shrubbery if (GenUtils.chance(random, 1, 3)) { @@ -73,36 +80,47 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { PlantBuilder.FERN.build(data, rawX, surfaceY + 1, rawZ); - else + } + else { PlantBuilder.LARGE_FERN.build(data, rawX, surfaceY + 1, rawZ); + } } } } } - @Override - public void populateLargeItems(TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) { for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z++) { int y = GenUtils.getTrueHighestBlock(data, x, z); - if (data.getBiome(x, z) != getBiome()) continue; + if (data.getBiome(x, z) != getBiome()) { + continue; + } + + if (data.getType(x, y, z) == Material.GRASS_BLOCK || data.getType(x, y, z) == Material.PODZOL) { - if (data.getType(x, y, z) == Material.GRASS_BLOCK || - data.getType(x, y, z) == Material.PODZOL) { - // Small grass poffs if (TConfigOption.arePlantsEnabled() && GenUtils.chance(random, 1, 50)) { - BlockUtils.replaceSphere( - random.nextInt(424444), - 2, 3, 2, - new SimpleBlock(data, x, y + 1, z), false, Material.JUNGLE_LEAVES); + BlockUtils.replaceSphere(random.nextInt(424444), + 2, + 3, + 2, + new SimpleBlock(data, x, y + 1, z), + false, + Material.JUNGLE_LEAVES + ); } // Bamboo - if (TConfigOption.arePlantsEnabled() && GenUtils.chance(random, 1, 3) && BlockUtils.isDirtLike(data.getType(x, y, z))) { + if (TConfigOption.arePlantsEnabled() + && GenUtils.chance(random, 1, 3) + && BlockUtils.isDirtLike(data.getType(x, y, z))) + { int h = BlockUtils.spawnPillar(random, data, x, y + 1, z, Material.BAMBOO, 12, 16); Bamboo bambooHead = (Bamboo) Bukkit.createBlockData(Material.BAMBOO); bambooHead.setLeaves(Leaves.LARGE); @@ -119,5 +137,5 @@ public void populateLargeItems(TerraformWorld tw, @NotNull Random random, @NotNu } } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java b/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java index 9461dd9f..141fd129 100644 --- a/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java @@ -34,7 +34,7 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.PLAINS; } - + @Override public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.CHERRY_GROVE; @@ -42,15 +42,23 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { @@ -58,51 +66,82 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (GenUtils.chance(random, 8, 10)) { // Pink petals. No longer generate tall grass. if (Version.isAtLeast(20) && TConfigOption.arePlantsEnabled() && GenUtils.chance(random, 6, 10)) { - data.setBlockData(rawX,surfaceY+1,rawZ, OneTwentyBlockHandler.getPinkPetalData(GenUtils.randInt(1,4))); - }else + data.setBlockData( + rawX, + surfaceY + 1, + rawZ, + OneTwentyBlockHandler.getPinkPetalData(GenUtils.randInt(1, 4)) + ); + } + else { PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); - } else { - if (GenUtils.chance(random, 7, 10)) + } + } + else { + if (GenUtils.chance(random, 7, 10)) { PlantBuilder.ALLIUM.build(data, rawX, surfaceY + 1, rawZ); - else + } + else { PlantBuilder.PEONY.build(data, rawX, surfaceY + 1, rawZ); + } } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Small trees or grass poffs + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Small trees or grass poffs SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - + for (SimpleLocation sLoc : trees) { - - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - - if(tw.getBiomeBank(sLoc.getX(),sLoc.getZ()) == BiomeBank.CHERRY_GROVE && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) - switch(random.nextInt(20)) // 0 to 19 inclusive + + if (tw.getBiomeBank(sLoc.getX(), sLoc.getZ()) == BiomeBank.CHERRY_GROVE + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + switch (random.nextInt(20)) // 0 to 19 inclusive { case 19, 18, 17, 16, 15 -> // Rock (5/20) - new SphereBuilder(random, new SimpleBlock(data, sLoc), Material.COBBLESTONE, Material.STONE, Material.STONE, Material.STONE, Material.MOSSY_COBBLESTONE) - .setRadius(GenUtils.randInt(random, 3, 5)) - .setRY(GenUtils.randInt(random, 6, 10)) - .build(); + new SphereBuilder(random, + new SimpleBlock(data, sLoc), + Material.COBBLESTONE, + Material.STONE, + Material.STONE, + Material.STONE, + Material.MOSSY_COBBLESTONE + ).setRadius(GenUtils.randInt(random, 3, 5)).setRY(GenUtils.randInt(random, 6, 10)).build(); default -> { // Tree (15/20) - if(random.nextBoolean()) // small trees - new FractalTreeBuilder(FractalTypes.Tree.CHERRY_SMALL).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - else - new FractalTreeBuilder(FractalTypes.Tree.CHERRY_THICK).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + if (random.nextBoolean()) // small trees + { + new FractalTreeBuilder(FractalTypes.Tree.CHERRY_SMALL).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } + else { + new FractalTreeBuilder(FractalTypes.Tree.CHERRY_THICK).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } // No spore blossoms on 1.20 as the new cherry trees already drop petals - if(!Version.isAtLeast(20)) { - for(int rX = sLoc.getX() - 6; rX <= sLoc.getX() + 6; rX++) { - for(int rZ = sLoc.getZ() - 6; rZ <= sLoc.getZ() + 6; rZ++) { + if (!Version.isAtLeast(20)) { + for (int rX = sLoc.getX() - 6; rX <= sLoc.getX() + 6; rX++) { + for (int rZ = sLoc.getZ() - 6; rZ <= sLoc.getZ() + 6; rZ++) { Wall ceil = new Wall(new SimpleBlock(data, rX, sLoc.getY(), rZ)).findCeiling(15); - if(ceil != null && GenUtils.chance(random, 1, 30)) { - if(ceil.getType() == Material.DARK_OAK_LEAVES) { + if (ceil != null && GenUtils.chance(random, 1, 30)) { + if (ceil.getType() == Material.DARK_OAK_LEAVES) { PlantBuilder.SPORE_BLOSSOM.build(ceil.getDown()); } } @@ -111,15 +150,16 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } } } + } } - } - + } + public @NotNull BiomeBank getBeachType() { - return BiomeBank.CHERRY_GROVE_BEACH; + return BiomeBank.CHERRY_GROVE_BEACH; } - + public @NotNull BiomeBank getRiverType() { - return BiomeBank.CHERRY_GROVE_RIVER; + return BiomeBank.CHERRY_GROVE_RIVER; } } diff --git a/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java b/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java index 01f94326..4da9c7f0 100644 --- a/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java @@ -23,6 +23,47 @@ public class DarkForestHandler extends BiomeHandler { + private static void spawnRock(Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + ArrayList locations = new ArrayList<>(); + locations.add(new int[] {x, y, z}); + locations.add(new int[] {x, y + 2, z}); + + locations.add(new int[] {x, y + 1, z}); + locations.add(new int[] {x + 1, y + 1, z}); + locations.add(new int[] {x - 1, y + 1, z}); + locations.add(new int[] {x, y + 1, z + 1}); + locations.add(new int[] {x, y + 1, z - 1}); + + locations.add(new int[] {x + 1, y, z}); + locations.add(new int[] {x - 1, y, z}); + locations.add(new int[] {x, y, z + 1}); + locations.add(new int[] {x, y, z - 1}); + locations.add(new int[] {x + 1, y, z}); + locations.add(new int[] {x - 1, y, z + 1}); + locations.add(new int[] {x + 1, y, z + 1}); + locations.add(new int[] {x - 1, y, z - 1}); + + for (int[] coords : locations) { + int Tx = coords[0]; + int Ty = coords[1]; + int Tz = coords[2]; + if (!data.getType(Tx, Ty, Tz).isSolid() || data.getType(Tx, Ty, Tz).toString().contains("LEAVES")) { + BlockUtils.setDownUntilSolid(Tx, + Ty, + Tz, + data, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE, + Material.STONE, + Material.CHISELED_STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS, + Material.MOSSY_STONE_BRICKS + ); + } + } + } + @Override public boolean isOcean() { return false; @@ -35,27 +76,40 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - boolean spawnHeads = TConfigOption.BIOME_DARK_FOREST_SPAWN_HEADS.getBoolean() - && GenUtils.chance(random, 1, 100); + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + boolean spawnHeads = TConfigOption.BIOME_DARK_FOREST_SPAWN_HEADS.getBoolean() && GenUtils.chance( + random, + 1, + 100 + ); if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { if (GenUtils.chance(random, 1, 10)) { - if (data.getType(rawX, surfaceY + 1, rawZ) != Material.AIR) return; + if (data.getType(rawX, surfaceY + 1, rawZ) != Material.AIR) { + return; + } // Only grass and mushrooms PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); if (random.nextInt(3) != 0) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); - } else { + } + else { if (random.nextBoolean()) { PlantBuilder.BROWN_MUSHROOM.build(data, rawX, surfaceY + 1, rawZ); } @@ -77,28 +131,34 @@ public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int ra } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 10); - SimpleLocation[] smallDecorations = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7); - - // Big trees and giant mushrooms + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 10); + SimpleLocation[] smallDecorations = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7); + + // Big trees and giant mushrooms for (SimpleLocation sLoc : bigTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { if (GenUtils.chance(random, 2, 10)) { - int choice = random.nextInt(3); - FractalTypes.Mushroom type = switch(choice) { + int choice = random.nextInt(3); + FractalTypes.Mushroom type = switch (choice) { case 0 -> FractalTypes.Mushroom.GIANT_RED_MUSHROOM; case 1 -> FractalTypes.Mushroom.GIANT_BROWN_MUSHROOM; default -> FractalTypes.Mushroom.GIANT_BROWN_FUNNEL_MUSHROOM; }; - new MushroomBuilder(type).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - } else if (TConfigOption.TREES_DARK_FOREST_BIG_ENABLED.getBoolean()) { - FractalTypes.Tree.DARK_OAK_BIG_TOP.build(tw, new SimpleBlock(data,sLoc)); + new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + } + else if (TConfigOption.TREES_DARK_FOREST_BIG_ENABLED.getBoolean()) { + FractalTypes.Tree.DARK_OAK_BIG_TOP.build(tw, new SimpleBlock(data, sLoc)); } } } @@ -107,10 +167,12 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando for (SimpleLocation sLoc : trees) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - // new FractalTreeBuilder(FractalTypes.Tree.DARK_OAK_SMALL) - FractalTypes.Tree.DARK_OAK_SMALL.build(tw, new SimpleBlock(data,sLoc)); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + // new FractalTreeBuilder(FractalTypes.Tree.DARK_OAK_SMALL) + FractalTypes.Tree.DARK_OAK_SMALL.build(tw, new SimpleBlock(data, sLoc)); } } @@ -118,74 +180,65 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando for (SimpleLocation sLoc : smallDecorations) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { int choice = random.nextInt(5); - switch(choice) { - case 0: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_POINTY_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - case 1: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - case 2: - new MushroomBuilder(FractalTypes.Mushroom.SMALL_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; - case 3: - for (int i = 0; i < GenUtils.randInt(3, 6); i++) { - spawnRock(random, data, sLoc.getX(), sLoc.getY() + i + 1, sLoc.getZ()); - } - break; - default: - new MushroomBuilder(FractalTypes.Mushroom.TINY_RED_MUSHROOM).build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - break; + switch (choice) { + case 0: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_POINTY_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + case 1: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + case 2: + new MushroomBuilder(FractalTypes.Mushroom.SMALL_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; + case 3: + for (int i = 0; i < GenUtils.randInt(3, 6); i++) { + spawnRock(random, data, sLoc.getX(), sLoc.getY() + i + 1, sLoc.getZ()); + } + break; + default: + new MushroomBuilder(FractalTypes.Mushroom.TINY_RED_MUSHROOM).build( + tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + break; } } } - } - - private static void spawnRock(Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - ArrayList locations = new ArrayList<>(); - locations.add(new int[]{x, y, z}); - locations.add(new int[]{x, y + 2, z}); - - locations.add(new int[]{x, y + 1, z}); - locations.add(new int[]{x + 1, y + 1, z}); - locations.add(new int[]{x - 1, y + 1, z}); - locations.add(new int[]{x, y + 1, z + 1}); - locations.add(new int[]{x, y + 1, z - 1}); - - locations.add(new int[]{x + 1, y, z}); - locations.add(new int[]{x - 1, y, z}); - locations.add(new int[]{x, y, z + 1}); - locations.add(new int[]{x, y, z - 1}); - locations.add(new int[]{x + 1, y, z}); - locations.add(new int[]{x - 1, y, z + 1}); - locations.add(new int[]{x + 1, y, z + 1}); - locations.add(new int[]{x - 1, y, z - 1}); - - for (int[] coords : locations) { - int Tx = coords[0]; - int Ty = coords[1]; - int Tz = coords[2]; - if (!data.getType(Tx, Ty, Tz).isSolid() || - data.getType(Tx, Ty, Tz).toString().contains("LEAVES")) { - BlockUtils.setDownUntilSolid(Tx, Ty, Tz, data, - Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, - Material.STONE, Material.CHISELED_STONE_BRICKS, - Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, - Material.MOSSY_STONE_BRICKS); - } - } } public @NotNull BiomeBank getBeachType() { - return BiomeBank.DARK_FOREST_BEACH; + return BiomeBank.DARK_FOREST_BEACH; } - + // River type. This will be used instead if the heightmap got carved into a river. public @NotNull BiomeBank getRiverType() { - return BiomeBank.DARK_FOREST_RIVER; + return BiomeBank.DARK_FOREST_RIVER; } - + } diff --git a/common/src/main/java/org/terraform/biome/flat/DesertHandler.java b/common/src/main/java/org/terraform/biome/flat/DesertHandler.java index b3a1d36c..072c849e 100644 --- a/common/src/main/java/org/terraform/biome/flat/DesertHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/DesertHandler.java @@ -46,7 +46,8 @@ public BiomeHandler getTransformHandler() { // Pad more sandstone so that mountains don't get stone exposed vertically @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.SAND, + return new Material[] { + Material.SAND, Material.SAND, GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND), Material.SANDSTONE, @@ -54,109 +55,129 @@ public BiomeHandler getTransformHandler() { Material.SANDSTONE, Material.SANDSTONE, GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE), - GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean cactusGathering = GenUtils.chance(random, 1, 100); OasisBeach.generateOasisBeach(world, random, data, rawX, rawZ, BiomeBank.DESERT); Material base = data.getType(rawX, surfaceY, rawZ); if (cactusGathering) { - if (GenUtils.chance(random, 5, 100)) + if (GenUtils.chance(random, 5, 100)) { data.setType(rawX, surfaceY, rawZ, Material.DIRT_PATH); + } } if (base == Material.SAND) { - if (GenUtils.chance(random, 1, 100) || - (GenUtils.chance(random, 1, 20) && cactusGathering)) { + if (GenUtils.chance(random, 1, 100) || (GenUtils.chance(random, 1, 20) && cactusGathering)) { boolean canSpawn = true; for (BlockFace face : BlockUtils.directBlockFaces) { - if (data.getType(rawX + face.getModX(), surfaceY + 1, rawZ + face.getModZ()) != Material.AIR) + if (data.getType(rawX + face.getModX(), surfaceY + 1, rawZ + face.getModZ()) != Material.AIR) { canSpawn = false; + } } - if (canSpawn) + if (canSpawn) { PlantBuilder.CACTUS.build(random, data, rawX, surfaceY + 1, rawZ, 3, 5); - } else if (GenUtils.chance(random, 1, 80)) { + } + } + else if (GenUtils.chance(random, 1, 80)) { PlantBuilder.DEAD_BUSH.build(data, rawX, surfaceY + 1, rawZ); } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Rib cages - SimpleLocation[] ribCages = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), - 256, 0.6f); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Rib cages + SimpleLocation[] ribCages = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 256, 0.6f); for (SimpleLocation sLoc : ribCages) { - int ribY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int ribY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(ribY - GenUtils.randInt(random, 0, 6)); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - data.getType(sLoc.getX(),ribY,sLoc.getZ()) == Material.SAND) { - spawnRibCage(random, new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ())); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && data.getType(sLoc.getX(), ribY, sLoc.getZ()) == Material.SAND) + { + spawnRibCage(random, new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ())); } } - } - - public void spawnRibCage(@NotNull Random random, @NotNull SimpleBlock target) { - if (!TConfigOption.areStructuresEnabled()) return; - - BlockFace direction = BlockUtils.getDirectBlockFace(random); - int spineLength = GenUtils.randInt(random, 10, 14); - float ribWidthRadius = GenUtils.randInt(random, 1, 2) + (float) spineLength /2; - float ribHeightRadius = 0.7f*ribWidthRadius; // GenUtils.randInt(random, 6, 8); - // eqn -> ((y-ribHeight)/(ribHeight))^2 + ((x)/(ribWidth))^2 = 1 - int interval = 2; - if(random.nextBoolean()) - interval += 1; - - float ribSizeMultiplier = 1.0f; - - for(int segmentIndex = 0; segmentIndex < spineLength; segmentIndex++) { - Wall seg = new Wall(target.getRelative(direction, segmentIndex),direction); - new OrientableBuilder(Material.BONE_BLOCK) - .setAxis(BlockUtils.getAxisFromBlockFace(direction)) - .apply(seg); - - if(segmentIndex < (int) (spineLength/2f)) { - ribSizeMultiplier += 0.05f; - }else if(segmentIndex > (int) (spineLength/2f)) - ribSizeMultiplier -= 0.05f; - - if(segmentIndex % interval == 0 && segmentIndex > spineLength/6) { - for(float nHor = 1; nHor <= ribWidthRadius*ribSizeMultiplier; nHor+= 0.01F) { - - int[] multipliers = {-1}; - if(nHor > ribWidthRadius*ribSizeMultiplier/3) - multipliers = new int[]{-1,1}; - - for(int multiplier:multipliers) { - int ny = (int) Math.round(ribHeightRadius*ribSizeMultiplier + (multiplier*ribHeightRadius*ribSizeMultiplier - *Math.sqrt(1-Math.pow( - (nHor) - /(ribWidthRadius*ribSizeMultiplier), - 2) - ))); - - int horRel = Math.round(nHor); - Axis axis = BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(direction)); - if(ny > ribSizeMultiplier*ribHeightRadius/3 && ny < 5*ribSizeMultiplier*ribHeightRadius/3) { - axis = Axis.Y; - } - - new OrientableBuilder(Material.BONE_BLOCK) - .setAxis(axis) - .apply(seg.getRelative(0,ny,0).getRight(horRel)) - .apply(seg.getRelative(0,ny,0).getLeft(horRel)); - } - } - - } - } - - } + } + + public void spawnRibCage(@NotNull Random random, @NotNull SimpleBlock target) { + if (!TConfigOption.areStructuresEnabled()) { + return; + } + + BlockFace direction = BlockUtils.getDirectBlockFace(random); + int spineLength = GenUtils.randInt(random, 10, 14); + float ribWidthRadius = GenUtils.randInt(random, 1, 2) + (float) spineLength / 2; + float ribHeightRadius = 0.7f * ribWidthRadius; // GenUtils.randInt(random, 6, 8); + // eqn -> ((y-ribHeight)/(ribHeight))^2 + ((x)/(ribWidth))^2 = 1 + int interval = 2; + if (random.nextBoolean()) { + interval += 1; + } + + float ribSizeMultiplier = 1.0f; + + for (int segmentIndex = 0; segmentIndex < spineLength; segmentIndex++) { + Wall seg = new Wall(target.getRelative(direction, segmentIndex), direction); + new OrientableBuilder(Material.BONE_BLOCK).setAxis(BlockUtils.getAxisFromBlockFace(direction)).apply(seg); + + if (segmentIndex < (int) (spineLength / 2f)) { + ribSizeMultiplier += 0.05f; + } + else if (segmentIndex > (int) (spineLength / 2f)) { + ribSizeMultiplier -= 0.05f; + } + + if (segmentIndex % interval == 0 && segmentIndex > spineLength / 6) { + for (float nHor = 1; nHor <= ribWidthRadius * ribSizeMultiplier; nHor += 0.01F) { + + int[] multipliers = {-1}; + if (nHor > ribWidthRadius * ribSizeMultiplier / 3) { + multipliers = new int[] {-1, 1}; + } + + for (int multiplier : multipliers) { + int ny = (int) Math.round(ribHeightRadius * ribSizeMultiplier + (multiplier + * ribHeightRadius + * ribSizeMultiplier + * Math.sqrt(1 - Math.pow((nHor) + / (ribWidthRadius + * ribSizeMultiplier), + 2 + )))); + + int horRel = Math.round(nHor); + Axis axis = BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(direction)); + if (ny > ribSizeMultiplier * ribHeightRadius / 3 + && ny < 5 * ribSizeMultiplier * ribHeightRadius / 3) + { + axis = Axis.Y; + } + + new OrientableBuilder(Material.BONE_BLOCK).setAxis(axis) + .apply(seg.getRelative(0, ny, 0).getRight(horRel)) + .apply(seg.getRelative(0, ny, 0).getLeft(horRel)); + } + } + + } + } + + } } diff --git a/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java index 5f805c3a..237fc18c 100644 --- a/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java @@ -20,11 +20,36 @@ import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.util.Random; public class ElevatedPlainsHandler extends BiomeHandler { + private static final Material[] rocks = new Material[] { + Material.GRANITE, + Material.GRANITE, + Material.GRANITE, + Material.GRANITE, + Material.GRANITE, + Material.GRANITE, + Material.DIORITE, + Material.DIORITE, + Material.DIORITE, + Material.ANDESITE, + Material.ANDESITE, + Material.ANDESITE, + Material.DIORITE, + Material.DIORITE, + Material.DIORITE + }; static BiomeBlender biomeBlender; + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setRiverThreshold(4).setBlendBeaches(false); + } + return biomeBlender; + } + @Override public boolean isOcean() { return false; @@ -37,21 +62,31 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[] {Material.STONE}; + return new Material[] {Material.STONE}; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean gradient = HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble(); - if(gradient) { + <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble(); + if (gradient) { data.setType(rawX, surfaceY, rawZ, Material.GRASS_BLOCK); - if(random.nextBoolean()) - data.setType(rawX, surfaceY-1, rawZ, Material.DIRT); + if (random.nextBoolean()) { + data.setType(rawX, surfaceY - 1, rawZ, Material.DIRT); + } } - if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && - !BlockUtils.isWet(new SimpleBlock(data,rawX,surfaceY,rawZ))) { + if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && !BlockUtils.isWet(new SimpleBlock(data, + rawX, + surfaceY, + rawZ))) + { if (GenUtils.chance(random, 1, 10)) { // Grass if (GenUtils.chance(random, 6, 10)) { @@ -59,11 +94,14 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); - else + } + else { BlockUtils.pickTallFlower().build(data, rawX, surfaceY + 1, rawZ); + } } } } @@ -75,7 +113,15 @@ public BiomeHandler getTransformHandler() { } @Override - public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, @NotNull Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { + public void transformTerrain(@NotNull ChunkCache cache, + TerraformWorld tw, + @NotNull Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { int heightFactor = 15; int rawX = chunkX * 16 + x; @@ -84,57 +130,59 @@ public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, @NotN double preciseHeight = HeightMap.getPreciseHeight(tw, rawX, rawZ); int height = (int) preciseHeight; - int noiseValue = (int) Math.round(heightFactor * getBiomeBlender(tw).getEdgeFactor(BiomeBank.ELEVATED_PLAINS, rawX, rawZ)); - if(noiseValue < 1) return; // If no changes are made, DO NOT TOUCH CACHE + int noiseValue = (int) Math.round(heightFactor * getBiomeBlender(tw).getEdgeFactor( + BiomeBank.ELEVATED_PLAINS, + rawX, + rawZ + )); + if (noiseValue < 1) { + return; // If no changes are made, DO NOT TOUCH CACHE + } for (int y = 1; y <= noiseValue; y++) { - chunk.setBlock(x, height + y, z, getRockAt(random, x,y,z)); + chunk.setBlock(x, height + y, z, getRockAt(random, x, y, z)); } - cache.writeTransformedHeight(x,z, (short) (height+noiseValue)); + cache.writeTransformedHeight(x, z, (short) (height + noiseValue)); } - - private static final Material[] rocks = new Material[] { - Material.GRANITE, Material.GRANITE, Material.GRANITE, - Material.GRANITE, Material.GRANITE, Material.GRANITE, - Material.DIORITE, Material.DIORITE, Material.DIORITE, - Material.ANDESITE, Material.ANDESITE, Material.ANDESITE, - Material.DIORITE, Material.DIORITE, Material.DIORITE - }; - private @NotNull Material getRockAt(@NotNull Random rand, int rawX, int y, int rawZ) { - return rocks[((int)Math.round(0.7*rawX + 0.7*(GenUtils.randInt(rand, -1, 1)+y) + 0.7*rawZ)) % rocks.length]; - } - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setRiverThreshold(4).setBlendBeaches(false); - return biomeBlender; + private @NotNull Material getRockAt(@NotNull Random rand, int rawX, int y, int rawZ) { + return rocks[((int) Math.round(0.7 * rawX + 0.7 * (GenUtils.randInt(rand, -1, 1) + y) + 0.7 * rawZ)) + % rocks.length]; } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 18); for (SimpleLocation sLoc : trees) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRASS_BLOCK) - continue; - + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRASS_BLOCK) { + continue; + } + FractalTreeBuilder builder = new FractalTreeBuilder(FractalTypes.Tree.TAIGA_SMALL); builder.setTrunkType(Material.OAK_LOG); - builder.setFractalLeaves( - new FractalLeaves() - .setLeafNoiseFrequency(0.65f) - .setLeafNoiseMultiplier(0.8f) - .setRadius(2).setMaterial(Material.OAK_LEAVES) - .setConeLeaves(true)); - - if(builder.build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ())) - BlockUtils.replaceCircularPatch(random.nextInt(99999), 2.5f, new SimpleBlock(data, sLoc), Material.PODZOL); + builder.setFractalLeaves(new FractalLeaves().setLeafNoiseFrequency(0.65f) + .setLeafNoiseMultiplier(0.8f) + .setRadius(2) + .setMaterial(Material.OAK_LEAVES) + .setConeLeaves(true)); + + if (builder.build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ())) { + BlockUtils.replaceCircularPatch(random.nextInt(99999), + 2.5f, + new SimpleBlock(data, sLoc), + Material.PODZOL + ); + } } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java index 6c8ba5e6..e0037d2c 100644 --- a/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java @@ -20,9 +20,16 @@ import java.util.Random; public class ErodedPlainsHandler extends BiomeHandler { - static BiomeBlender biomeBlender; static final BiomeHandler plainsHandler = BiomeBank.PLAINS.getHandler(); static final boolean slabs = TConfigOption.MISC_USE_SLABS_TO_SMOOTH.getBoolean(); + static BiomeBlender biomeBlender; + + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setRiverThreshold(4).setBlendBeaches(false); + } + return biomeBlender; + } @Override public boolean isOcean() { @@ -35,10 +42,18 @@ public Biome getBiome() { } @Override - public Material[] getSurfaceCrust(Random rand) { return plainsHandler.getSurfaceCrust(rand); } + public Material[] getSurfaceCrust(Random rand) { + return plainsHandler.getSurfaceCrust(rand); + } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { plainsHandler.populateSmallItems(world, random, rawX, surfaceY, rawZ, data); } @@ -48,28 +63,30 @@ public BiomeHandler getTransformHandler() { } @Override - public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - - FastNoise noise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_ERODEDPLAINS_CLIFFNOISE, - world -> { - FastNoise n = new FastNoise(); - n.SetNoiseType(FastNoise.NoiseType.CubicFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.02f); - return n; - }); - - FastNoise details = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_ERODEDPLAINS_DETAILS, - world -> { - FastNoise n = new FastNoise(); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.03f); - return n; - }); + public void transformTerrain(@NotNull ChunkCache cache, + TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + + FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_ERODEDPLAINS_CLIFFNOISE, world -> { + FastNoise n = new FastNoise(); + n.SetNoiseType(FastNoise.NoiseType.CubicFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.02f); + return n; + }); + + FastNoise details = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_ERODEDPLAINS_DETAILS, world -> { + FastNoise n = new FastNoise(); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.03f); + return n; + }); double threshold = 0.1; @@ -81,38 +98,48 @@ public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, Rando double preciseHeight = HeightMap.getPreciseHeight(tw, rawX, rawZ); int height = (int) preciseHeight; - double noiseValue = Math.max(0, noise.GetNoise(rawX, rawZ)) * getBiomeBlender(tw).getEdgeFactor(BiomeBank.ERODED_PLAINS, rawX, rawZ); + double noiseValue = Math.max(0, noise.GetNoise(rawX, rawZ)) + * getBiomeBlender(tw).getEdgeFactor(BiomeBank.ERODED_PLAINS, rawX, rawZ); double detailsValue = details.GetNoise(rawX, rawZ); double d = (noiseValue / threshold) - (int) (noiseValue / threshold) - 0.5; double platformHeight = (int) (noiseValue / threshold) * heightFactor - + (64 * Math.pow(d, 7) * heightFactor) - + detailsValue * heightFactor * 0.5; + + (64 * Math.pow(d, 7) * heightFactor) + + detailsValue * heightFactor * 0.5; short newHeight = (short) (height + (int) Math.round(platformHeight)); - if(newHeight < height) return; // Does not make changes if the platform is lower. - - cache.writeTransformedHeight (x,z,(short) ((int)Math.round(platformHeight)+height)); - for (int y = height+1; y <= newHeight; y++) { - Material material = GenUtils.randChoice(Material.STONE, Material.STONE, Material.STONE, Material.STONE, - Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, Material.ANDESITE); - if (slabs && material != Material.GRASS_BLOCK && y == newHeight && - platformHeight - (int) platformHeight >= 0.5) + if (newHeight < height) { + return; // Does not make changes if the platform is lower. + } + + cache.writeTransformedHeight(x, z, (short) ((int) Math.round(platformHeight) + height)); + for (int y = height + 1; y <= newHeight; y++) { + Material material = GenUtils.randChoice(Material.STONE, + Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE, + Material.ANDESITE + ); + if (slabs + && material != Material.GRASS_BLOCK + && y == newHeight + && platformHeight - (int) platformHeight >= 0.5) + { material = Material.getMaterial(material.name() + "_SLAB"); + } assert material != null; chunk.setBlock(x, y, z, material); } - if (detailsValue < 0.2 && GenUtils.chance(3, 4)) chunk.setBlock(x, newHeight, z, Material.GRASS_BLOCK); + if (detailsValue < 0.2 && GenUtils.chance(3, 4)) { + chunk.setBlock(x, newHeight, z, Material.GRASS_BLOCK); + } } - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setRiverThreshold(4).setBlendBeaches(false); - return biomeBlender; + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + plainsHandler.populateLargeItems(tw, random, data); } - - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - plainsHandler.populateLargeItems(tw, random, data); - } } diff --git a/common/src/main/java/org/terraform/biome/flat/ForestHandler.java b/common/src/main/java/org/terraform/biome/flat/ForestHandler.java index 12771c7a..78f91b9b 100644 --- a/common/src/main/java/org/terraform/biome/flat/ForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ForestHandler.java @@ -14,8 +14,8 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.ArrayList; @@ -25,37 +25,40 @@ public class ForestHandler extends BiomeHandler { private static void spawnRock(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z) { ArrayList locations = new ArrayList<>(20); - locations.add(new int[]{x, y, z}); - - locations.add(new int[]{x, y + 1, z}); - locations.add(new int[]{x + 1, y + 1, z}); - locations.add(new int[]{x - 1, y + 1, z}); - locations.add(new int[]{x, y + 1, z + 1}); - locations.add(new int[]{x, y + 1, z - 1}); - - locations.add(new int[]{x + 1, y, z}); - locations.add(new int[]{x - 1, y, z}); - locations.add(new int[]{x, y, z + 1}); - locations.add(new int[]{x, y, z - 1}); - locations.add(new int[]{x + 1, y, z}); - locations.add(new int[]{x - 1, y, z + 1}); - locations.add(new int[]{x + 1, y, z + 1}); - locations.add(new int[]{x - 1, y, z - 1}); - - locations.add(new int[]{x, y - 1, z}); - locations.add(new int[]{x + 1, y - 1, z}); - locations.add(new int[]{x - 1, y - 1, z}); - locations.add(new int[]{x, y - 1, z + 1}); - locations.add(new int[]{x, y - 1, z - 1}); + locations.add(new int[] {x, y, z}); + + locations.add(new int[] {x, y + 1, z}); + locations.add(new int[] {x + 1, y + 1, z}); + locations.add(new int[] {x - 1, y + 1, z}); + locations.add(new int[] {x, y + 1, z + 1}); + locations.add(new int[] {x, y + 1, z - 1}); + + locations.add(new int[] {x + 1, y, z}); + locations.add(new int[] {x - 1, y, z}); + locations.add(new int[] {x, y, z + 1}); + locations.add(new int[] {x, y, z - 1}); + locations.add(new int[] {x + 1, y, z}); + locations.add(new int[] {x - 1, y, z + 1}); + locations.add(new int[] {x + 1, y, z + 1}); + locations.add(new int[] {x - 1, y, z - 1}); + + locations.add(new int[] {x, y - 1, z}); + locations.add(new int[] {x + 1, y - 1, z}); + locations.add(new int[] {x - 1, y - 1, z}); + locations.add(new int[] {x, y - 1, z + 1}); + locations.add(new int[] {x, y - 1, z - 1}); for (int[] coords : locations) { int Tx = coords[0]; int Ty = coords[1]; int Tz = coords[2]; - if (!data.getType(Tx, Ty, Tz).isSolid() || - data.getType(Tx, Ty, Tz).toString().contains("LEAVES")) { - data.setType(Tx, Ty, Tz, GenUtils.randChoice(rand, - Material.COBBLESTONE, Material.STONE, Material.MOSSY_COBBLESTONE)); + if (!data.getType(Tx, Ty, Tz).isSolid() || data.getType(Tx, Ty, Tz).toString().contains("LEAVES")) { + data.setType( + Tx, + Ty, + Tz, + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.MOSSY_COBBLESTONE) + ); } } } @@ -72,48 +75,60 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.PODZOL, 3), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.PODZOL, 3), Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - FastNoise pathNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_FOREST_PATHNOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 12)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.07f); - return n; + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + FastNoise pathNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_FOREST_PATHNOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 12)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.07f); + return n; }); if (pathNoise.GetNoise(rawX, rawZ) > 0.3) { - if (GenUtils.chance(random, 99, 100) && - data.getBiome(rawX, rawZ) == getBiome() && - BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) + if (GenUtils.chance(random, 99, 100) && data.getBiome(rawX, rawZ) == getBiome() && BlockUtils.isDirtLike( + data.getType(rawX, surfaceY, rawZ))) + { data.setType(rawX, surfaceY, rawZ, Material.DIRT_PATH); + } } if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { if (GenUtils.chance(random, 1, 10)) { - if (data.getType(rawX, surfaceY + 1, rawZ) != Material.AIR) return; + if (data.getType(rawX, surfaceY + 1, rawZ) != Material.AIR) { + return; + } // Grass & Flowers PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); - } else { + } + else { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { // Most forest chunks have a big tree if (TConfigOption.TREES_FOREST_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 6, 10)) { int treeX = GenUtils.randInt(random, 2, 12) + data.getChunkX() * 16; @@ -121,8 +136,9 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando if (data.getBiome(treeX, treeZ) == getBiome()) { int treeY = GenUtils.getHighestGround(data, treeX, treeZ); - if (BlockUtils.isDirtLike(data.getType(treeX, treeY, treeZ))) + if (BlockUtils.isDirtLike(data.getType(treeX, treeY, treeZ))) { FractalTypes.Tree.FOREST.build(tw, new SimpleBlock(data, treeX, treeY, treeZ)); + } } } @@ -130,11 +146,13 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 8); for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - FractalTypes.Tree.NORMAL_SMALL.build(tw, new SimpleBlock(data, sLoc.getX(),sLoc.getY(),sLoc.getZ())); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + FractalTypes.Tree.NORMAL_SMALL.build(tw, new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ())); } } @@ -142,18 +160,26 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 10); for (SimpleLocation sLoc : rocks) { - sLoc.setY(GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ())); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - if (BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ())) || - data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) == Material.COBBLESTONE || - data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) == Material.MOSSY_COBBLESTONE || - data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) == Material.STONE) { + sLoc.setY(GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ())); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + if (BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) + || data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.COBBLESTONE + || data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.MOSSY_COBBLESTONE + || data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.STONE) + { int ny = GenUtils.randInt(random, -1, 1); - spawnRock(random, data, sLoc.getX(),sLoc.getY()+ny,sLoc.getZ()); - if (GenUtils.chance(random, 1, 3)) - spawnRock(random, data, GenUtils.randInt(random, -1, 1) + sLoc.getX(), sLoc.getY() + ny + 1, sLoc.getZ() + GenUtils.randInt(random, -1, 1)); + spawnRock(random, data, sLoc.getX(), sLoc.getY() + ny, sLoc.getZ()); + if (GenUtils.chance(random, 1, 3)) { + spawnRock( + random, + data, + GenUtils.randInt(random, -1, 1) + sLoc.getX(), + sLoc.getY() + ny + 1, + sLoc.getZ() + GenUtils.randInt(random, -1, 1) + ); + } } } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java b/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java index 89e7c6bb..0477c418 100644 --- a/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java @@ -25,9 +25,16 @@ import java.util.Random; public class GorgeHandler extends BiomeHandler { - static BiomeBlender biomeBlender; static final BiomeHandler plainsHandler = BiomeBank.PLAINS.getHandler(); static final boolean slabs = TConfigOption.MISC_USE_SLABS_TO_SMOOTH.getBoolean(); + static BiomeBlender biomeBlender; + + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setGridBlendingFactor(2).setSmoothBlendTowardsRivers(4); + } + return biomeBlender; + } @Override public boolean isOcean() { @@ -38,56 +45,70 @@ public boolean isOcean() { public Biome getBiome() { return plainsHandler.getBiome(); } - + // Remove rivers from gorges. @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - double height = super.calculateHeight(tw, x, z); - double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); - if(riverDepth > 0) - height += riverDepth; - return height; + double height = super.calculateHeight(tw, x, z); + double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); + if (riverDepth > 0) { + height += riverDepth; + } + return height; } @Override - public Material[] getSurfaceCrust(Random rand) { return plainsHandler.getSurfaceCrust(rand); } + public Material[] getSurfaceCrust(Random rand) { + return plainsHandler.getSurfaceCrust(rand); + } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - - SimpleBlock target = new SimpleBlock(data,rawX,surfaceY+1,rawZ); + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + + SimpleBlock target = new SimpleBlock(data, rawX, surfaceY + 1, rawZ); boolean wasBelowSea = false; // the repair work is here because it needs the 3x3 boundary // for cave air that is BESIDE the water // DOES NOT change height truth because another block MUST be above the // one being changed due to the way this works - while(target.getY() <= TerraformGenerator.seaLevel-20) { + while (target.getY() <= TerraformGenerator.seaLevel - 20) { wasBelowSea = true; - if(target.getType() == Material.WATER) - for(BlockFace face:BlockUtils.directBlockFaces) { - if(BlockUtils.isAir(target.getRelative(face).getType())) + if (target.getType() == Material.WATER) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (BlockUtils.isAir(target.getRelative(face).getType())) { target.getRelative(face).setType(Material.STONE); + } } + } target = target.getUp(); } // Do not do dry decorations if this was water - if(wasBelowSea) return; + if (wasBelowSea) { + return; + } target = target.getGround(); - if(!BlockUtils.isWet(target.getUp()) && target.getType() == Material.STONE) { + if (!BlockUtils.isWet(target.getUp()) && target.getType() == Material.STONE) { // Make the ground more dynamic target.setType(Material.GRASS_BLOCK); target.getDown().setType(Material.DIRT); - if(random.nextBoolean()) { + if (random.nextBoolean()) { target.getDown(2).setType(Material.DIRT); - if(random.nextBoolean()) + if (random.nextBoolean()) { target.getDown(3).setType(Material.DIRT); + } } } - plainsHandler.populateSmallItems(world, random, rawX, surfaceY, rawZ, data); + plainsHandler.populateSmallItems(world, random, rawX, surfaceY, rawZ, data); } @Override @@ -96,28 +117,30 @@ public BiomeHandler getTransformHandler() { } @Override - public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - - FastNoise cliffNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_GORGE_CLIFFNOISE, - world -> { - FastNoise n = new FastNoise(); - n.SetNoiseType(FastNoise.NoiseType.CubicFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.04f); - return n; - }); - - FastNoise detailsNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_GORGE_DETAILS, - world -> { - FastNoise n = new FastNoise(); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.03f); - return n; - }); + public void transformTerrain(@NotNull ChunkCache cache, + TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + + FastNoise cliffNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_GORGE_CLIFFNOISE, world -> { + FastNoise n = new FastNoise(); + n.SetNoiseType(FastNoise.NoiseType.CubicFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.04f); + return n; + }); + + FastNoise detailsNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_GORGE_DETAILS, world -> { + FastNoise n = new FastNoise(); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.03f); + return n; + }); double threshold = 0.1; @@ -134,96 +157,106 @@ public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, Rando double detailsValue = detailsNoise.GetNoise(rawX, rawZ); // Raise up a tall area - if(noiseValue >= 0) { + if (noiseValue >= 0) { double d = (noiseValue / threshold) - (int) (noiseValue / threshold) - 0.5; double platformHeight = (int) (noiseValue / threshold) * heightFactor - + (64 * Math.pow(d, 7) * heightFactor) - + detailsValue * heightFactor * 0.5; + + (64 * Math.pow(d, 7) * heightFactor) + + detailsValue * heightFactor * 0.5; - if(Math.round(platformHeight) >= 1) + if (Math.round(platformHeight) >= 1) { cache.writeTransformedHeight(x, z, (short) (Math.round(platformHeight) + height)); - for(int y = 1; y <= (int) Math.round(platformHeight); y++) { - Material material = GenUtils.randChoice(Material.STONE, Material.STONE, Material.STONE, Material.STONE, - Material.COBBLESTONE, Material.COBBLESTONE, Material.ANDESITE, Material.ANDESITE); - - if(slabs - && material != Material.GRASS_BLOCK - && y == (int) Math.round(platformHeight) - && platformHeight - (int) platformHeight >= 0.5) + } + for (int y = 1; y <= (int) Math.round(platformHeight); y++) { + Material material = GenUtils.randChoice(Material.STONE, + Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.ANDESITE, + Material.ANDESITE + ); + + if (slabs + && material != Material.GRASS_BLOCK + && y == (int) Math.round(platformHeight) + && platformHeight - (int) platformHeight >= 0.5) + { material = Material.getMaterial(material.name() + "_SLAB"); + } chunk.setBlock(x, height + y, z, material); } - if(detailsValue < 0.2 && GenUtils.chance(3, 4)) { + if (detailsValue < 0.2 && GenUtils.chance(3, 4)) { chunk.setBlock(x, height + (int) Math.round(platformHeight), z, Material.GRASS_BLOCK); } } else // Burrow a gorge deep down like a ravine { - int depth = (int) Math.sqrt(Math.abs(rawCliffNoiseVal * getBiomeBlender(tw).getEdgeFactor(BiomeBank.GORGE, rawX, rawZ)) * 200 * 50); + int depth = (int) Math.sqrt(Math.abs(rawCliffNoiseVal * getBiomeBlender(tw).getEdgeFactor( + BiomeBank.GORGE, + rawX, + rawZ + )) * 200 * 50); // Smooth out anything that crosses the water threshold - if(height - depth < TerraformGenerator.seaLevel - 20) { + if (height - depth < TerraformGenerator.seaLevel - 20) { int depthToPreserve = height - (TerraformGenerator.seaLevel - 20); depth = (int) (depthToPreserve + Math.round(Math.sqrt(depth - depthToPreserve))); } // Prevent going beneath y = 10 - if(depth > height - 10) depth = height-10; + if (depth > height - 10) { + depth = height - 10; + } // No guard here, depth is an integer, so if its 0, this cache write is safe - cache.writeTransformedHeight (x,z, (short) (height - depth)); + cache.writeTransformedHeight(x, z, (short) (height - depth)); for (int y = 0; y < depth; y++) { - if(TerraformGenerator.seaLevel - 20 >= height-y) + if (TerraformGenerator.seaLevel - 20 >= height - y) { chunk.setBlock(x, height - y, z, Material.WATER); - else - { + } + else { chunk.setBlock(x, height - y, z, Material.AIR); } } // Stop water from escaping. Also makes the highest-ground assertion true // MYSTERIO IS THE TRUTH - if(height-depth <= TerraformGenerator.seaLevel - 20) - chunk.setBlock(x, height-depth, z, Material.STONE); + if (height - depth <= TerraformGenerator.seaLevel - 20) { + chunk.setBlock(x, height - depth, z, Material.STONE); + } } } - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setGridBlendingFactor(2) - .setSmoothBlendTowardsRivers(4); - return biomeBlender; - } + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + plainsHandler.populateLargeItems(tw, random, data); + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 17, 0.4f); - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - plainsHandler.populateLargeItems(tw, random, data); - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 17, 0.4f); - for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(rockY > TerraformGenerator.seaLevel - 18) - continue; - - BlockUtils.replaceSphere( - random.nextInt(91822), - (float) GenUtils.randDouble(random, 3, 6), - (float) GenUtils.randDouble(random, 4, 7), - (float) GenUtils.randDouble(random, 3, 6), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (rockY > TerraformGenerator.seaLevel - 18) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(91822), + (float) GenUtils.randDouble(random, 3, 6), + (float) GenUtils.randDouble(random, 4, 7), + (float) GenUtils.randDouble(random, 3, 6), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/IceSpikesHandler.java b/common/src/main/java/org/terraform/biome/flat/IceSpikesHandler.java index acb8059f..b12a75d4 100644 --- a/common/src/main/java/org/terraform/biome/flat/IceSpikesHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/IceSpikesHandler.java @@ -18,16 +18,24 @@ import java.util.Random; public class IceSpikesHandler extends BiomeHandler { - - public static void genSpike(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, int baseRadius, int height) { + + public static void genSpike(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int baseRadius, + int height) + { y -= height / 5; // Vector one to two; Vector base = new Vector(x, y, z); - Vector base2 = new Vector( - x + GenUtils.randInt(random, (int) (-1.5 * baseRadius), (int) (1.5 * baseRadius)), - y + height, - z + GenUtils.randInt(random, (int) (-1.5 * baseRadius), (int) (1.5 * baseRadius))); - + Vector base2 = new Vector(x + GenUtils.randInt(random, (int) (-1.5 * baseRadius), (int) (1.5 * baseRadius)), + y + height, + z + GenUtils.randInt(random, (int) (-1.5 * baseRadius), (int) (1.5 * baseRadius)) + ); + Vector v = base2.subtract(base); SimpleBlock one = new SimpleBlock(data, x, y, z); @@ -36,7 +44,16 @@ public static void genSpike(@NotNull TerraformWorld tw, @NotNull Random random, Vector seg = v.clone().multiply((float) i / ((float) height)); SimpleBlock segment = one.getRelative(seg); - BlockUtils.replaceSphere((int) (tw.getSeed() * 12), (float) radius, 2, (float) radius, segment, false, false, Material.PACKED_ICE); + BlockUtils.replaceSphere( + (int) (tw.getSeed() * 12), + (float) radius, + 2, + (float) radius, + segment, + false, + false, + Material.PACKED_ICE + ); radius = ((double) baseRadius) * (1 - ((double) i) / ((double) height)); } @@ -54,18 +71,30 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.SNOW_BLOCK, 5, Material.SNOW_BLOCK, 25), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.SNOW_BLOCK, 5, Material.SNOW_BLOCK, 25), Material.SNOW_BLOCK, GenUtils.randChoice(rand, Material.SNOW_BLOCK, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { - if (data.getType(rawX, surfaceY + 1, rawZ) == Material.AIR - && !Tag.ICE.isTagged(data.getType(rawX, surfaceY, rawZ))) { + if (data.getType(rawX, surfaceY + 1, rawZ) == Material.AIR && !Tag.ICE.isTagged(data.getType( + rawX, + surfaceY, + rawZ + ))) + { data.setType(rawX, surfaceY + 1, rawZ, Material.SNOW); if (data.getBlockData(rawX, surfaceY, rawZ) instanceof Snowable snowable) { snowable.setSnowy(true); @@ -74,39 +103,46 @@ public void populateSmallItems(TerraformWorld world, Random random, int rawX, in } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { - // Ice Spikes + // Ice Spikes SimpleLocation[] spikes = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 16, 0.5f); - + for (SimpleLocation sLoc : spikes) { - int spikeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int spikeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(spikeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) == Material.SNOW_BLOCK) { - - if (GenUtils.chance(random, 1, 10)) { // big spike - genSpike(tw, random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), - GenUtils.randInt(3, 7), // radius - GenUtils.randInt(40, 55)); // height - } else // Small spike - genSpike(tw, random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), - GenUtils.randInt(3, 5), // radius - GenUtils.randInt(13, 24)); // height - + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.SNOW_BLOCK) + { + + if (GenUtils.chance(random, 1, 10)) { // big spike + genSpike(tw, random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), GenUtils.randInt(3, 7), // radius + GenUtils.randInt(40, 55) + ); // height + } + else // Small spike + { + genSpike(tw, random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), GenUtils.randInt(3, 5), // radius + GenUtils.randInt(13, 24) + ); // height + } + } } - } - - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } - - @Override - public @NotNull BiomeBank getRiverType() { - return BiomeBank.FROZEN_RIVER; - } + } + + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } + + @Override + public @NotNull BiomeBank getRiverType() { + return BiomeBank.FROZEN_RIVER; + } } diff --git a/common/src/main/java/org/terraform/biome/flat/JungleHandler.java b/common/src/main/java/org/terraform/biome/flat/JungleHandler.java index 723ab25b..030050d4 100644 --- a/common/src/main/java/org/terraform/biome/flat/JungleHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/JungleHandler.java @@ -23,8 +23,8 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Locale; @@ -32,6 +32,51 @@ public class JungleHandler extends BiomeHandler { + public static void createBush(@NotNull PopulatorDataAbstract data, + float noiseIncrement, + int oriX, + int oriY, + int oriZ) + { + if (!TConfigOption.arePlantsEnabled()) { + return; + } + + // noiseIncrement is always < 0.5 and > 0 + float rX = 2.5f + (float) (noiseIncrement * Math.random()); + float rY = 1.3f + (float) (noiseIncrement * Math.random()); + float rZ = 2.5f + (float) (noiseIncrement * Math.random()); + + SimpleBlock base = new SimpleBlock(data, oriX, oriY, oriZ); + + for (int x = -Math.round(rX); x <= rX; x++) { + for (int y = -Math.round(rY); y <= rY; y++) { + for (int z = -Math.round(rZ); z <= rZ; z++) { + double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); + + if (equationResult <= 1) { + SimpleBlock block = base.getRelative(x, y + 1, z); + + // Skip random leaves, less leaves when close to center. + if (Math.random() < equationResult - 0.5) { + continue; + } + + if (!block.isSolid() && !BlockUtils.isWet(block)) { + block.setType(Material.JUNGLE_LEAVES); + } + } + } + } + } + + if (Math.random() > 0.3) { + base.setType(Material.JUNGLE_LOG); + } + } + @Override public boolean isOcean() { return false; @@ -49,118 +94,103 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.PODZOL, 5), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.PODZOL, 5), Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - // Almost everything about jungle population is highly disruptive. - // Only grass spawning remains here. Mushrooms and everything else go to - // populateLargeItems - // Generate grass - if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { - if (BlockUtils.isAir(data.getType(rawX, surfaceY + 1, rawZ)) && GenUtils.chance(2, 3)) { - if (random.nextBoolean()) { - GenUtils.weightedRandomSmallItem(random, PlantBuilder.GRASS, 5, BlockUtils.pickFlower(), 1).build(data, rawX, surfaceY + 1, rawZ); - } else { - if (BlockUtils.isAir(data.getType(rawX, surfaceY + 2, rawZ))) - PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); - } - } - } + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + // Almost everything about jungle population is highly disruptive. + // Only grass spawning remains here. Mushrooms and everything else go to + // populateLargeItems + // Generate grass + if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { + if (BlockUtils.isAir(data.getType(rawX, surfaceY + 1, rawZ)) && GenUtils.chance(2, 3)) { + if (random.nextBoolean()) { + GenUtils.weightedRandomSmallItem(random, PlantBuilder.GRASS, 5, BlockUtils.pickFlower(), 1) + .build(data, rawX, surfaceY + 1, rawZ); + } + else { + if (BlockUtils.isAir(data.getType(rawX, surfaceY + 2, rawZ))) { + PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); + } + } + } + } } - public static void createBush(@NotNull PopulatorDataAbstract data, float noiseIncrement, int oriX, int oriY, int oriZ) { - if ( !TConfigOption.arePlantsEnabled()) return; - - // noiseIncrement is always < 0.5 and > 0 - float rX = 2.5f + (float) (noiseIncrement * Math.random()); - float rY = 1.3f + (float) (noiseIncrement * Math.random()); - float rZ = 2.5f + (float) (noiseIncrement * Math.random()); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { - SimpleBlock base = new SimpleBlock(data, oriX, oriY, oriZ); + FastNoise groundWoodNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_JUNGLE_GROUNDWOOD, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 12)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.07f); + return n; + }); - for (int x = -Math.round(rX); x <= rX; x++) { - for (int y = -Math.round(rY); y <= rY; y++) { - for (int z = -Math.round(rZ); z <= rZ; z++) { - double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) + - Math.pow(y, 2) / Math.pow(rY, 2) + - Math.pow(z, 2) / Math.pow(rZ, 2); - - if (equationResult <= 1) { - SimpleBlock block = base.getRelative(x, y + 1, z); + FastNoise groundLeavesNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.BIOME_JUNGLE_GROUNDLEAVES, + world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 2)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFrequency(0.07f); + return n; + } + ); - // Skip random leaves, less leaves when close to center. - if (Math.random() < equationResult - 0.5) - continue; + SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - if (!block.isSolid() && !BlockUtils.isWet(block)) { - block.setType(Material.JUNGLE_LEAVES); - } - } + if (TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) { + for (SimpleLocation sLoc : bigTrees) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); } } } - if (Math.random() > 0.3) - base.setType(Material.JUNGLE_LOG); - } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - FastNoise groundWoodNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JUNGLE_GROUNDWOOD, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 12)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.07f); - return n; - }); - - FastNoise groundLeavesNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JUNGLE_GROUNDLEAVES, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 2)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFrequency(0.07f); - return n; - }); - - SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - - if(TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) - for (SimpleLocation sLoc : bigTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - } - } - - // Small jungle trees, OR jungle statues SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 9); for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - if(GenUtils.chance(random, 1000-TConfigOption.BIOME_JUNGLE_STATUE_CHANCE.getInt(), 1000)) { - TreeDB.spawnSmallJungleTree(false, tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - }else { - spawnStatue(random, data, sLoc); - } + + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + if (GenUtils.chance(random, 1000 - TConfigOption.BIOME_JUNGLE_STATUE_CHANCE.getInt(), 1000)) { + TreeDB.spawnSmallJungleTree(false, tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + } + else { + spawnStatue(random, data, sLoc); + } } } @@ -182,76 +212,82 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } // Generate some ground leaves - if (data.getBiome(x, z) == getBiome() - && leavesNoiseValue > -0.12 - && Math.random() > 0.85) + if (data.getBiome(x, z) == getBiome() && leavesNoiseValue > -0.12 && Math.random() > 0.85) { createBush(data, leavesNoiseValue, x, y, z); + } else if (GenUtils.chance(1, 95)) // Some random ones where there is no noise. + { createBush(data, 0, x, y, z); + } // Generate random wood, or "roots" on the ground - if (groundWoodNoiseValue > 0.3) + if (groundWoodNoiseValue > 0.3) { data.lsetType(x, y + 1, z, Material.JUNGLE_WOOD); + } } // Generate mushrooms - if (data.getBiome(x, z) == getBiome() && - BlockUtils.isDirtLike(data.getType(x, y, z))) { + if (data.getBiome(x, z) == getBiome() && BlockUtils.isDirtLike(data.getType(x, y, z))) { if (data.getType(x, y + 1, z) == Material.JUNGLE_WOOD - && BlockUtils.isAir(data.getType(x, y + 2, z)) - && GenUtils.chance(2, 9)) { - PlantBuilder.build(data, x, y+2, z, PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); + && BlockUtils.isAir(data.getType(x, y + 2, z)) + && GenUtils.chance(2, 9)) + { + PlantBuilder.build(data, x, y + 2, z, PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); } } } } } - - private void spawnStatue(@NotNull Random random, @NotNull PopulatorDataAbstract data, @NotNull SimpleLocation sLoc) { - if ( !TConfigOption.areStructuresEnabled()) return; - try { - TerraSchematic schema = TerraSchematic.load("jungle-statue1", - new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ())); + private void spawnStatue(@NotNull Random random, + @NotNull PopulatorDataAbstract data, + @NotNull SimpleLocation sLoc) + { + if (!TConfigOption.areStructuresEnabled()) { + return; + } + + try { + TerraSchematic schema = TerraSchematic.load("jungle-statue1", + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()) + ); schema.parser = new JungleStatueSchematicParser(); schema.setFace(BlockUtils.getDirectBlockFace(random)); schema.apply(); - } catch (Throwable e) { + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - - } - - private static class JungleStatueSchematicParser extends SchematicParser{ - - public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(new Random(), - Material.COBBLESTONE, Material.ANDESITE, Material.STONE, Material.MOSSY_COBBLESTONE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); - super.applyData(block, data); - }else if (data.getMaterial() == Material.STONE_BRICK_STAIRS) { - if(new Random().nextBoolean()) - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "stone_brick", - "mossy_stone_brick" - ) - ); - super.applyData(block, data); - }else { - block.setBlockData(data); - super.applyData(block, data); - } - - if(data.getMaterial().isBlock() && GenUtils.chance(1, 10)) { - BlockUtils.vineUp(block, 3); - } - } - } + + } + + private static class JungleStatueSchematicParser extends SchematicParser { + + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { + if (data.getMaterial().toString().contains("COBBLESTONE")) { + data = Bukkit.createBlockData(data.getAsString() + .replaceAll("cobblestone", GenUtils.randChoice(new Random(), + Material.COBBLESTONE, + Material.ANDESITE, + Material.STONE, + Material.MOSSY_COBBLESTONE + ).toString().toLowerCase(Locale.ENGLISH))); + super.applyData(block, data); + } + else if (data.getMaterial() == Material.STONE_BRICK_STAIRS) { + if (new Random().nextBoolean()) { + data = Bukkit.createBlockData(data.getAsString().replaceAll("stone_brick", "mossy_stone_brick")); + } + super.applyData(block, data); + } + else { + block.setBlockData(data); + super.applyData(block, data); + } + + if (data.getMaterial().isBlock() && GenUtils.chance(1, 10)) { + BlockUtils.vineUp(block, 3); + } + } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java b/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java index a53be7e3..bbfddda0 100644 --- a/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java @@ -30,7 +30,9 @@ public class MangroveHandler extends BiomeHandler { @Override - public @NotNull BiomeBank getRiverType(){ return BiomeBank.MANGROVE; } + public @NotNull BiomeBank getRiverType() { + return BiomeBank.MANGROVE; + } @Override public boolean isOcean() { @@ -41,85 +43,114 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return OneOneNineBlockHandler.MANGROVE_SWAMP; } + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.randChoice(rand, Material.GRASS_BLOCK, Material.PODZOL, Material.PODZOL), + return new Material[] { + GenUtils.randChoice(rand, Material.GRASS_BLOCK, Material.PODZOL, Material.PODZOL), GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.DIRT, Material.STONE), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public @NotNull BiomeHandler getTransformHandler(){ + public @NotNull BiomeHandler getTransformHandler() { return this; } + @Override - public void transformTerrain(@NotNull ChunkCache cache, TerraformWorld tw, @NotNull Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - int surfaceY = cache.getTransformedHeight(x,z); - if(surfaceY < TerraformGenerator.seaLevel) - { - int rawX = chunkX*16+x; - int rawZ = chunkZ*16+z; - FastNoise mudNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_SWAMP_MUDNOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 4)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFrequency(0.05f); - n.SetFractalOctaves(4); - - return n; - }); - - double noise = mudNoise.GetNoise(rawX,rawZ); - - if (noise < 0) noise = 0; + public void transformTerrain(@NotNull ChunkCache cache, + TerraformWorld tw, + @NotNull Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + int surfaceY = cache.getTransformedHeight(x, z); + if (surfaceY < TerraformGenerator.seaLevel) { + int rawX = chunkX * 16 + x; + int rawZ = chunkZ * 16 + z; + FastNoise mudNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_SWAMP_MUDNOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 4)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFrequency(0.05f); + n.SetFractalOctaves(4); + + return n; + }); + + double noise = mudNoise.GetNoise(rawX, rawZ); + + if (noise < 0) { + noise = 0; + } int att = (int) Math.round(noise * 10); - if (att + surfaceY > TerraformGenerator.seaLevel) + if (att + surfaceY > TerraformGenerator.seaLevel) { att = TerraformGenerator.seaLevel - surfaceY; + } for (int i = 1; i <= att; i++) { - if (i < att) + if (i < att) { chunk.setBlock(x, surfaceY + i, z, getSurfaceCrust(random)[1]); - else + } + else { chunk.setBlock(x, surfaceY + i, z, getSurfaceCrust(random)[0]); + } } // No guard needed, att < 1 will write surfaceY - cache.writeTransformedHeight(x,z, (short) (surfaceY + att)); + cache.writeTransformedHeight(x, z, (short) (surfaceY + att)); } } + @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { int seaLevel = TerraformGenerator.seaLevel; - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (surfaceY < seaLevel) { - if (data.getType(rawX,TerraformGenerator.seaLevel,rawZ) == Material.WATER) { - if (GenUtils.chance(random, 1, 30)) + if (data.getType(rawX, TerraformGenerator.seaLevel, rawZ) == Material.WATER) { + if (GenUtils.chance(random, 1, 30)) { PlantBuilder.LILY_PAD.build(data, rawX, TerraformGenerator.seaLevel + 1, rawZ); + } } } - if (BlockUtils.isWet(new SimpleBlock(data,rawX,surfaceY+1,rawZ)) - && GenUtils.chance(random, 10, 100) && surfaceY < TerraformGenerator.seaLevel - 3) { // SEA GRASS/KELP + if (BlockUtils.isWet(new SimpleBlock(data, rawX, surfaceY + 1, rawZ)) + && GenUtils.chance(random, 10, 100) + && surfaceY < TerraformGenerator.seaLevel - 3) + { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } - if(GenUtils.chance(random, 5, 1000)) { - BlockUtils.replaceCircularPatch( - random.nextInt(9999), + if (GenUtils.chance(random, 5, 1000)) { + BlockUtils.replaceCircularPatch(random.nextInt(9999), 3.5f, - new SimpleBlock(data,rawX,surfaceY,rawZ), OneOneNineBlockHandler.MUD); + new SimpleBlock(data, rawX, surfaceY, rawZ), + OneOneNineBlockHandler.MUD + ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { int treeX, treeY, treeZ; if (GenUtils.chance(random, 8, 10)) { @@ -128,31 +159,41 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando if (data.getBiome(treeX, treeZ) == getBiome()) { treeY = GenUtils.getHighestGround(data, treeX, treeZ); - - if(treeY > TerraformGenerator.seaLevel-6) { - // Don't do gradient checks for swamp trees, the mud is uneven. - // just make sure it's submerged - TreeDB.spawnBreathingRoots(tw, new SimpleBlock(data,treeX,treeY,treeZ), OneOneNineBlockHandler.MANGROVE_ROOTS); - FractalTypes.Tree.SWAMP_TOP.build(tw, new SimpleBlock(data,treeX,treeY,treeZ), (t)->t.setCheckGradient(false)); + + if (treeY > TerraformGenerator.seaLevel - 6) { + // Don't do gradient checks for swamp trees, the mud is uneven. + // just make sure it's submerged + TreeDB.spawnBreathingRoots( + tw, + new SimpleBlock(data, treeX, treeY, treeZ), + OneOneNineBlockHandler.MANGROVE_ROOTS + ); + FractalTypes.Tree.SWAMP_TOP.build( + tw, + new SimpleBlock(data, treeX, treeY, treeZ), + (t) -> t.setCheckGradient(false) + ); } } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.MUDFLATS; - } - - @Override + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.MUDFLATS; + } + + @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - + double height = HeightMap.CORE.getHeight(tw, x, z) - 10; // If the height is too low, force it back to 3. // 30/11/2023: what the fuck is this guard clause for - if (height <= 0) height = 3; - + if (height <= 0) { + height = 3; + } + return height; } diff --git a/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java b/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java index 68526d48..03e41dcd 100644 --- a/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java @@ -19,9 +19,10 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; + import java.util.Random; public class MuddyBogHandler extends BiomeHandler { @@ -40,97 +41,128 @@ public boolean isOcean() { public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.MUDDY_BOG; } - + // Beach type. This will be used instead if the height is too close to sea level. public @NotNull BiomeBank getBeachType() { - return BiomeBank.BOG_BEACH; + return BiomeBank.BOG_BEACH; } - + // River type. This will be used instead if the heightmap got carved into a river. public @NotNull BiomeBank getRiverType() { - return BiomeBank.BOG_RIVER; + return BiomeBank.BOG_RIVER; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - SimpleBlock block = new SimpleBlock(data,rawX,surfaceY,rawZ); - if(block.getUp().getType() == Material.AIR && - block.getType() == Material.GRASS_BLOCK) { - if(GenUtils.chance(random, 1, 85)) + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + SimpleBlock block = new SimpleBlock(data, rawX, surfaceY, rawZ); + if (block.getUp().getType() == Material.AIR && block.getType() == Material.GRASS_BLOCK) { + if (GenUtils.chance(random, 1, 85)) { PlantBuilder.DEAD_BUSH.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) + } + else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.BROWN_MUSHROOM.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) + } + else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.GRASS.build(block.getUp()); - else if(GenUtils.chance(random, 1, 85)) - PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY+1, rawZ); - else if(TConfigOption.areDecorationsEnabled() && GenUtils.chance(random, 1, 300)) - {// Dripstone Cluster + } + else if (GenUtils.chance(random, 1, 85)) { + PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); + } + else if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(random, 1, 300)) {// Dripstone Cluster BlockUtils.replaceCircularPatch(random.nextInt(9999), 2.5f, block, Material.DRIPSTONE_BLOCK); - if(GenUtils.chance(random, 1, 7)) + if (GenUtils.chance(random, 1, 7)) { BlockUtils.upLPointedDripstone(GenUtils.randInt(random, 2, 4), block.getUp()); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) - if(GenUtils.chance(random, 1, 7)) - BlockUtils.upLPointedDripstone(GenUtils.randInt(random, 2, 4), block.getRelative(face).getGround().getUp()); + } + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + if (GenUtils.chance(random, 1, 7)) { + BlockUtils.upLPointedDripstone(GenUtils.randInt(random, 2, 4), + block.getRelative(face).getGround().getUp() + ); + } + } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - // Small brown mushrooms on dry areas + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + // Small brown mushrooms on dry areas SimpleLocation[] shrooms = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 16); for (SimpleLocation sLoc : shrooms) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(isRightBiome(tw.getBiomeBank(sLoc.getX(),sLoc.getZ())) && - !BlockUtils.isWet(new SimpleBlock(data,sLoc.getX(),sLoc.getY()+1,sLoc.getZ()))&& - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - if(data.getType(sLoc.getX(),sLoc.getY()+1,sLoc.getZ()) == Material.AIR) - if(random.nextBoolean()) - new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM) - .build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); - else - new MushroomBuilder(FractalTypes.Mushroom.TINY_BROWN_MUSHROOM) - .build(tw, data, sLoc.getX(),sLoc.getY()+1,sLoc.getZ()); + if (isRightBiome(tw.getBiomeBank(sLoc.getX(), sLoc.getZ())) && !BlockUtils.isWet(new SimpleBlock(data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ())) && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + if (data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()) == Material.AIR) { + if (random.nextBoolean()) { + new MushroomBuilder(FractalTypes.Mushroom.SMALL_BROWN_MUSHROOM).build(tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + } + else { + new MushroomBuilder(FractalTypes.Mushroom.TINY_BROWN_MUSHROOM).build(tw, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + } + } } } - } + } - private boolean isRightBiome(BiomeBank bank){ - return bank == BiomeBank.MUDDY_BOG || - bank == BiomeBank.BOG_BEACH; + private boolean isRightBiome(BiomeBank bank) { + return bank == BiomeBank.MUDDY_BOG || bank == BiomeBank.BOG_BEACH; } @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - - double height = super.calculateHeight(tw, x, z) - 5; - - FastNoise sinkin = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_MUDDYBOG_HEIGHTMAP, world -> { + + double height = super.calculateHeight(tw, x, z) - 5; + + FastNoise sinkin = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_MUDDYBOG_HEIGHTMAP, world -> { FastNoise n = new FastNoise((int) world.getSeed()); n.SetNoiseType(NoiseType.SimplexFractal); n.SetFractalOctaves(4); n.SetFrequency(0.08f); return n; }); - - if(sinkin.GetNoise(x, z) < -0.15) { - if(height > TerraformGenerator.seaLevel) - height -= (height - TerraformGenerator.seaLevel) + 2; - } - + + if (sinkin.GetNoise(x, z) < -0.15) { + if (height > TerraformGenerator.seaLevel) { + height -= (height - TerraformGenerator.seaLevel) + 2; + } + } + return height; } } diff --git a/common/src/main/java/org/terraform/biome/flat/PetrifiedCliffsHandler.java b/common/src/main/java/org/terraform/biome/flat/PetrifiedCliffsHandler.java index f68a6fdc..6e89814d 100644 --- a/common/src/main/java/org/terraform/biome/flat/PetrifiedCliffsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/PetrifiedCliffsHandler.java @@ -27,7 +27,20 @@ import java.util.Random; public class PetrifiedCliffsHandler extends BiomeHandler { + public static final HashSet endWithStones = new HashSet<>() {{ + add(Material.STONE); + add(Material.MOSSY_COBBLESTONE); + add(Material.COBBLESTONE); + }}; static BiomeBlender biomeBlender; + + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setRiverThreshold(4).setBlendBeaches(false); + } + return biomeBlender; + } + @Override public boolean isOcean() { return false; @@ -40,47 +53,52 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } - public static final HashSet endWithStones = new HashSet<>(){{ - add(Material.STONE); - add(Material.MOSSY_COBBLESTONE); - add(Material.COBBLESTONE); - }}; - @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - for(int i = 0; i < 30; i++) - if(data.getType(rawX, surfaceY, rawZ) == Material.DIORITE - || data.getType(rawX, surfaceY, rawZ) == Material.ANDESITE - || data.getType(rawX, surfaceY, rawZ) == Material.GRANITE - || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_DIORITE - || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_ANDESITE - || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_GRANITE) + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + for (int i = 0; i < 30; i++) { + if (data.getType(rawX, surfaceY, rawZ) == Material.DIORITE + || data.getType(rawX, surfaceY, rawZ) == Material.ANDESITE + || data.getType(rawX, surfaceY, rawZ) == Material.GRANITE + || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_DIORITE + || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_ANDESITE + || data.getType(rawX, surfaceY, rawZ) == Material.POLISHED_GRANITE) { surfaceY--; } - else + else { break; + } + } if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { - SimpleBlock core = new SimpleBlock(data,rawX,surfaceY+1,rawZ); + SimpleBlock core = new SimpleBlock(data, rawX, surfaceY + 1, rawZ); boolean continueOut = false; - for(BlockFace face:BlockUtils.directBlockFaces) { + for (BlockFace face : BlockUtils.directBlockFaces) { Material relType = core.getRelative(face).getType(); - if(endWithStones.contains(relType)) - { + if (endWithStones.contains(relType)) { core.setType(Material.DIORITE_SLAB); continueOut = true; break; } } - if(continueOut) return; + if (continueOut) { + return; + } if (GenUtils.chance(random, 1, 10)) { // Grass if (GenUtils.chance(random, 6, 10)) { @@ -88,11 +106,14 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); - else + } + else { BlockUtils.pickTallFlower().build(data, rawX, surfaceY + 1, rawZ); + } } } } @@ -102,37 +123,38 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int public BiomeHandler getTransformHandler() { return this; } - + @Override public int getMaxHeightForCaves(@NotNull TerraformWorld tw, int x, int z) { - return (int) HeightMap.CORE.getHeight(tw, x, z); + return (int) HeightMap.CORE.getHeight(tw, x, z); } - @Override - public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - - FastNoise noise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_PETRIFIEDCLIFFS_CLIFFNOISE, - world -> { - FastNoise n = new FastNoise(tw.getHashedRand(123, 2222, 1111).nextInt(99999)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.03f); - return n; - }); - - FastNoise details = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_PETRIFIEDCLIFFS_INNERNOISE, - world -> { - FastNoise n = new FastNoise(tw.getHashedRand(111, 102, 1).nextInt(99999)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.05f); - return n; - }); + public void transformTerrain(@NotNull ChunkCache cache, + @NotNull TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + + FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_PETRIFIEDCLIFFS_CLIFFNOISE, world -> { + FastNoise n = new FastNoise(tw.getHashedRand(123, 2222, 1111).nextInt(99999)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.03f); + return n; + }); + + FastNoise details = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_PETRIFIEDCLIFFS_INNERNOISE, world -> { + FastNoise n = new FastNoise(tw.getHashedRand(111, 102, 1).nextInt(99999)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.05f); + return n; + }); // Generates -0.8 to 0.8 int rawX = chunkX * 16 + x; int rawZ = chunkZ * 16 + z; @@ -140,61 +162,68 @@ public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld double preciseHeight = HeightMap.getPreciseHeight(tw, rawX, rawZ); int height = (int) preciseHeight; - double noiseValue = Math.max(0, noise.GetNoise(rawX, rawZ)) * getBiomeBlender(tw).getEdgeFactor(BiomeBank.PETRIFIED_CLIFFS, rawX, rawZ); - if(noiseValue == 0) return; + double noiseValue = Math.max(0, noise.GetNoise(rawX, rawZ)) + * getBiomeBlender(tw).getEdgeFactor(BiomeBank.PETRIFIED_CLIFFS, rawX, rawZ); + if (noiseValue == 0) { + return; + } double platformHeight = 7 + noiseValue * 50; - if(platformHeight > 15) platformHeight = 15 + Math.sqrt(0.5*(platformHeight - 15)); + if (platformHeight > 15) { + platformHeight = 15 + Math.sqrt(0.5 * (platformHeight - 15)); + } for (int y = 1; y <= (int) Math.round(platformHeight); y++) { - double detailsNoiseMultiplier = Math.pow(1.0-(1.0/(Math.pow(platformHeight/2.0, 2)))*Math.pow(y-platformHeight/2.0, 2), 2); - double detailsNoise = details.GetNoise(rawX, height+y, rawZ); - - if(0.85+detailsNoise > detailsNoiseMultiplier) { - chunk.setBlock(x, height + y, z, - GenUtils.randChoice( - Material.STONE, - Material.STONE, - Material.STONE, - Material.COBBLESTONE, - Material.MOSSY_COBBLESTONE - )); - cache.writeTransformedHeight (x,z, (short) Math.max(cache.getTransformedHeight(x,z), height+y)); + double detailsNoiseMultiplier = Math.pow(1.0 - (1.0 / (Math.pow(platformHeight / 2.0, 2))) * Math.pow( + y + - platformHeight + / 2.0, + 2 + ), 2); + double detailsNoise = details.GetNoise(rawX, height + y, rawZ); + + if (0.85 + detailsNoise > detailsNoiseMultiplier) { + chunk.setBlock(x, height + y, z, GenUtils.randChoice(Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + )); + cache.writeTransformedHeight(x, z, (short) Math.max(cache.getTransformedHeight(x, z), height + y)); } } } - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setRiverThreshold(4).setBlendBeaches(false); - return biomeBlender; - } - - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - // Rock trees + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + // Rock trees SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 13, 0.2f); - + for (SimpleLocation sLoc : trees) { - if(random.nextBoolean()) { - int treeY = GenUtils.getTrueHighestBlock(data, sLoc.getX(),sLoc.getZ()); + if (random.nextBoolean()) { + int treeY = GenUtils.getTrueHighestBlock(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()).toString().endsWith("STONE")) { - Tree treeType = switch(random.nextInt(3)) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()).toString().endsWith("STONE")) + { + Tree treeType = switch (random.nextInt(3)) { case 0 -> Tree.ANDESITE_PETRIFIED_SMALL; case 1 -> Tree.GRANITE_PETRIFIED_SMALL; default -> Tree.DIORITE_PETRIFIED_SMALL; }; - new FractalTreeBuilder(treeType).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + new FractalTreeBuilder(treeType).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); } - } + } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ROCKY_BEACH; - } + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ROCKY_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java index ce97daa4..a0ba205a 100644 --- a/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java @@ -31,17 +31,28 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && - !BlockUtils.isWet(new SimpleBlock(data,rawX,surfaceY,rawZ))) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && !BlockUtils.isWet(new SimpleBlock(data, + rawX, + surfaceY, + rawZ))) + { if (GenUtils.chance(random, 1, 10)) { // Grass if (GenUtils.chance(random, 6, 10)) { @@ -49,26 +60,40 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); - else + } + else { BlockUtils.pickTallFlower().build(data, rawX, surfaceY + 1, rawZ); + } } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { // Pumpkin Patch if (GenUtils.chance(1, 1000)) { for (int i = 0; i < GenUtils.randInt(5, 10); i++) { int[] loc = GenUtils.randomSurfaceCoordinates(random, data); - if (data.getBiome(loc[0], loc[2]) != getBiome()) continue; - SimpleBlock target = new SimpleBlock(data, loc[0], GenUtils.getHighestGround(data, loc[0], loc[2])+1, loc[2]); - if(!target.isSolid()) + if (data.getBiome(loc[0], loc[2]) != getBiome()) { + continue; + } + SimpleBlock target = new SimpleBlock( + data, + loc[0], + GenUtils.getHighestGround(data, loc[0], loc[2]) + 1, + loc[2] + ); + if (!target.isSolid()) { PlantBuilder.PUMPKIN.build(target); + } } } @@ -76,39 +101,62 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando if (GenUtils.chance(1, 1000)) { for (int i = 0; i < GenUtils.randInt(5, 10); i++) { int[] loc = GenUtils.randomSurfaceCoordinates(random, data); - if (data.getBiome(loc[0], loc[2]) != getBiome()) continue; - SimpleBlock target = new SimpleBlock(data, loc[0], GenUtils.getHighestGround(data, loc[0], loc[2])+1, loc[2]); - if(!target.isSolid()) + if (data.getBiome(loc[0], loc[2]) != getBiome()) { + continue; + } + SimpleBlock target = new SimpleBlock( + data, + loc[0], + GenUtils.getHighestGround(data, loc[0], loc[2]) + 1, + loc[2] + ); + if (!target.isSolid()) { PlantBuilder.MELON.build(target); + } } } - // Small trees or grass poffs + // Small trees or grass poffs SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 16); - + for (SimpleLocation sLoc : trees) { - int highestY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - if(BlockUtils.isWet(new SimpleBlock(data, sLoc.getX(), highestY+1, sLoc.getZ()))) - continue; - - if(random.nextBoolean()) { // trees + int highestY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + if (BlockUtils.isWet(new SimpleBlock(data, sLoc.getX(), highestY + 1, sLoc.getZ()))) { + continue; + } + + if (random.nextBoolean()) { // trees sLoc.setY(highestY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); } - }else { // Poffs + } + else { // Poffs sLoc.setY(highestY); - if(TConfigOption.arePlantsEnabled() && data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - BlockUtils.replaceSphere( - random.nextInt(424444), - 2, 2, 2, - new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()), false, Material.OAK_LEAVES); + if (TConfigOption.arePlantsEnabled() + && data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + BlockUtils.replaceSphere(random.nextInt(424444), + 2, + 2, + 2, + new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()), + false, + Material.OAK_LEAVES + ); } } - + } - - } + + } } diff --git a/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java b/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java index d434f677..abfd25c7 100644 --- a/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java @@ -19,16 +19,21 @@ public class SavannaHandler extends BiomeHandler { - private static void makeYellowPatch(int x, int y, int z, @NotNull PopulatorDataAbstract data, @NotNull Random random) { + private static void makeYellowPatch(int x, + int y, + int z, + @NotNull PopulatorDataAbstract data, + @NotNull Random random) + { int length = GenUtils.randInt(6, 16); int nx = x; int nz = z; while (length-- > 0) { - if (BlockUtils.isDirtLike(data.getType(nx, y, nz)) && - data.getType(nx, y + 1, nz) == Material.AIR) + if (BlockUtils.isDirtLike(data.getType(nx, y, nz)) && data.getType(nx, y + 1, nz) == Material.AIR) { data.setType(nx, y, nz, Material.DIRT_PATH); + } - switch(random.nextInt(5)) { // The direction chooser + switch (random.nextInt(5)) { // The direction chooser case 0 -> nx++; case 2 -> nz++; case 3 -> nx--; @@ -51,21 +56,43 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.randChoice(rand, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, - Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.GRASS_BLOCK, Material.COARSE_DIRT), + return new Material[] { + GenUtils.randChoice(rand, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.GRASS_BLOCK, + Material.COARSE_DIRT + ), Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(GenUtils.chance(random,1,128)) + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (GenUtils.chance(random, 1, 128)) { makeYellowPatch(rawX, surfaceY, rawZ, data, random); + } - if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK - && !data.getType(rawX, surfaceY + 1, rawZ).isSolid()) { + if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && !data.getType(rawX, surfaceY + 1, rawZ) + .isSolid()) + { // Dense grass if (GenUtils.chance(random, 5, 10)) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); @@ -73,47 +100,65 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + boolean spawnedLargeSavannaTree = false; - - // large trees + + // large trees SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 112, 0.6f); - - if(TConfigOption.TREES_SAVANNA_BIG_ENABLED.getBoolean()) - for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_BIG).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - spawnedLargeSavannaTree = true; - } - } - + + if (TConfigOption.TREES_SAVANNA_BIG_ENABLED.getBoolean()) { + for (SimpleLocation sLoc : trees) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_BIG).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + spawnedLargeSavannaTree = true; + } + } + } + // Small trees if (!spawnedLargeSavannaTree) { - trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 32); + trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 32); for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - } + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } } } - + // Grass Poffs - if ( TConfigOption.arePlantsEnabled()) { + if (TConfigOption.arePlantsEnabled()) { SimpleLocation[] poffs = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 31); - for(SimpleLocation sLoc : poffs) { + for (SimpleLocation sLoc : poffs) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) && - !data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()).isSolid()) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) + && !data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()).isSolid()) + { SimpleBlock base = new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); int rX = GenUtils.randInt(random, 2, 4); int rY = GenUtils.randInt(random, 2, 4); @@ -122,5 +167,5 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java b/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java index f0f6aa00..03c49352 100644 --- a/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java @@ -16,6 +16,7 @@ import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.util.Random; public class ScarletForestHandler extends BiomeHandler { @@ -29,7 +30,7 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.FOREST; } - + @Override public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.SCARLET_FOREST; @@ -37,15 +38,23 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { if (GenUtils.chance(random, 1, 10)) { // Grass @@ -54,62 +63,84 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - } else { - if (GenUtils.chance(random, 7, 10)) + } + else { + if (GenUtils.chance(random, 7, 10)) { PlantBuilder.POPPY.build(data, rawX, surfaceY + 1, rawZ); - else + } + else { PlantBuilder.ROSE_BUSH.build(data, rawX, surfaceY + 1, rawZ); + } } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 16); - + for (SimpleLocation sLoc : trees) { - - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - - if(tw.getBiomeBank(sLoc.getX(),sLoc.getZ()) == BiomeBank.SCARLET_FOREST && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) + + if (tw.getBiomeBank(sLoc.getX(), sLoc.getZ()) == BiomeBank.SCARLET_FOREST + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) { - if(TConfigOption.TREES_SCARLET_BIG_ENABLED.getBoolean()) - new FractalTreeBuilder(FractalTypes.Tree.SCARLET_BIG).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - else - new FractalTreeBuilder(FractalTypes.Tree.SCARLET_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - - TaigaHandler.replacePodzol( - tw.getHashedRand(sLoc.getX(),sLoc.getY(),sLoc.getZ()).nextInt(9999), - 7f, - new SimpleBlock(data,sLoc.getX(),sLoc.getY(),sLoc.getZ())); + if (TConfigOption.TREES_SCARLET_BIG_ENABLED.getBoolean()) { + new FractalTreeBuilder(FractalTypes.Tree.SCARLET_BIG).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } + else { + new FractalTreeBuilder(FractalTypes.Tree.SCARLET_SMALL).build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } + + TaigaHandler.replacePodzol(tw.getHashedRand(sLoc.getX(), sLoc.getY(), sLoc.getZ()).nextInt(9999), + 7f, + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()) + ); } } - + SimpleLocation[] smalltrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7); - + for (SimpleLocation sLoc : smalltrees) { - - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) + + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.SCARLET_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - } + new FractalTreeBuilder(FractalTypes.Tree.SCARLET_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } } - } - + } + public @NotNull BiomeBank getBeachType() { - return BiomeBank.SCARLET_FOREST_BEACH; + return BiomeBank.SCARLET_FOREST_BEACH; } - + public @NotNull BiomeBank getRiverType() { - return BiomeBank.SCARLET_FOREST_RIVER; + return BiomeBank.SCARLET_FOREST_RIVER; } } diff --git a/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java b/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java index 9fe342aa..18d8663a 100644 --- a/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java @@ -22,6 +22,50 @@ public class SnowyTaigaHandler extends BiomeHandler { + /** + * Replaces the highest dirt-like blocks with a noise-fuzzed + * circle of Podzol. Fuzzes the edges. + */ + public static void defrostAndReplacePodzol(int seed, float radius, @NotNull SimpleBlock base) { + if (radius <= 0) { + return; + } + if (radius <= 0.5) { + // block.setReplaceType(ReplaceType.ALL); + base.setType(GenUtils.randChoice(new Random(seed), Material.PODZOL)); + return; + } + + FastNoise noise = new FastNoise(seed); + noise.SetNoiseType(NoiseType.Simplex); + noise.SetFrequency(0.13f); + Random rand = new Random(seed); + for (float x = -radius; x <= radius; x++) { + for (float z = -radius; z <= radius; z++) { + SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); + rel = rel.getGround(); + if (!BlockUtils.isDirtLike(rel.getType())) { + continue; + } + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); + double noiseVal = Math.abs(noise.GetNoise(rel.getX(), rel.getZ())); + if (equationResult <= 1.0 + noiseVal) { + // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ + if (equationResult * 4 > 0.7 + noiseVal) { + if (rand.nextBoolean()) { + rel.setType(Material.PODZOL); + rel.getUp().lsetType(Material.AIR); + } + } + else { + rel.setType(Material.PODZOL); + rel.getUp().lsetType(Material.AIR); + } + } + } + } + } + @Override public boolean isOcean() { return false; @@ -34,15 +78,23 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.DIRT, 3, Material.PODZOL, 2), + return new Material[] { + GenUtils.weightedRandomMaterial(rand, Material.GRASS_BLOCK, 35, Material.DIRT, 3, Material.PODZOL, 2), Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { if (data.getType(rawX, surfaceY, rawZ) == Material.DIRT) { if (GenUtils.chance(random, 1, 20)) { PlantBuilder.DEAD_BUSH.build(data, rawX, surfaceY + 1, rawZ); @@ -51,8 +103,12 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } } - if (data.getType(rawX, surfaceY + 1, rawZ) == Material.AIR - && GenUtils.isGroundLike(data.getType(rawX, surfaceY, rawZ))) { + if (data.getType(rawX, surfaceY + 1, rawZ) == Material.AIR && GenUtils.isGroundLike(data.getType( + rawX, + surfaceY, + rawZ + ))) + { data.setType(rawX, surfaceY + 1, rawZ, Material.SNOW); if (data.getBlockData(rawX, surfaceY, rawZ) instanceof Snowable snowable) { snowable.setSnowy(true); @@ -61,79 +117,51 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 11); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 11); for (SimpleLocation sLoc : trees) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees if (TConfigOption.TREES_TAIGA_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { - FractalTypes.Tree.TAIGA_BIG.build(tw, new SimpleBlock(data, sLoc.getX(),sLoc.getY(),sLoc.getZ()), (b) -> b.getFractalLeaves().setSnowy(true)); - defrostAndReplacePodzol( - tw.getHashedRand(sLoc.getX(),sLoc.getY(),sLoc.getZ()).nextInt(9999), - 2.5f, - new SimpleBlock(data,sLoc.getX(),sLoc.getY()-1,sLoc.getZ())); - }else { // Normal trees - FractalTypes.Tree.TAIGA_SMALL.build(tw, new SimpleBlock(data, sLoc.getX(),sLoc.getY(),sLoc.getZ()), (b) -> b.getFractalLeaves().setSnowy(true)); - defrostAndReplacePodzol( - tw.getHashedRand(sLoc.getX(),sLoc.getY(),sLoc.getZ()).nextInt(9999), - 1.5f, - new SimpleBlock(data,sLoc.getX(),sLoc.getY()-1,sLoc.getZ())); + FractalTypes.Tree.TAIGA_BIG.build( + tw, + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()), + (b) -> b.getFractalLeaves().setSnowy(true) + ); + defrostAndReplacePodzol(tw.getHashedRand(sLoc.getX(), sLoc.getY(), sLoc.getZ()).nextInt(9999), + 2.5f, + new SimpleBlock(data, sLoc.getX(), sLoc.getY() - 1, sLoc.getZ()) + ); } - } - } - } - /** - * Replaces the highest dirt-like blocks with a noise-fuzzed - * circle of Podzol. Fuzzes the edges. - */ - public static void defrostAndReplacePodzol(int seed, float radius, @NotNull SimpleBlock base) { - if (radius <= 0) return; - if (radius <= 0.5) { - // block.setReplaceType(ReplaceType.ALL); - base.setType(GenUtils.randChoice(new Random(seed), Material.PODZOL)); - return; - } - - FastNoise noise = new FastNoise(seed); - noise.SetNoiseType(NoiseType.Simplex); - noise.SetFrequency(0.13f); - Random rand = new Random(seed); - for (float x = -radius; x <= radius; x++) { - for (float z = -radius; z <= radius; z++) { - SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); - rel = rel.getGround(); - if(!BlockUtils.isDirtLike(rel.getType())) - continue; - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - double noiseVal = Math.abs(noise.GetNoise(rel.getX(), rel.getZ())); - if (equationResult <= 1.0+noiseVal) { - // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if(equationResult * 4 > 0.7+noiseVal) { - if(rand.nextBoolean()) { - rel.setType(Material.PODZOL); - rel.getUp().lsetType(Material.AIR); - } - }else { - rel.setType(Material.PODZOL); - rel.getUp().lsetType(Material.AIR); - } + else { // Normal trees + FractalTypes.Tree.TAIGA_SMALL.build( + tw, + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()), + (b) -> b.getFractalLeaves().setSnowy(true) + ); + defrostAndReplacePodzol(tw.getHashedRand(sLoc.getX(), sLoc.getY(), sLoc.getZ()).nextInt(9999), + 1.5f, + new SimpleBlock(data, sLoc.getX(), sLoc.getY() - 1, sLoc.getZ()) + ); } } } } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } - - @Override + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } + + @Override public @NotNull BiomeBank getRiverType() { - return BiomeBank.FROZEN_RIVER; + return BiomeBank.FROZEN_RIVER; } } diff --git a/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java b/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java index 95370e59..3d4d00d4 100644 --- a/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java @@ -32,22 +32,36 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.SNOW_BLOCK, + return new Material[] { + Material.SNOW_BLOCK, Material.SNOW_BLOCK, GenUtils.randChoice(rand, Material.SNOW_BLOCK, Material.SNOW_BLOCK, Material.DIRT, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Snowier Snow - if(GenUtils.chance(random, 1, 500)) { - BlockUtils.replaceCircularPatch(random.nextInt(9999), 3, new SimpleBlock(data,rawX,0,rawZ), Material.POWDER_SNOW); + if (GenUtils.chance(random, 1, 500)) { + BlockUtils.replaceCircularPatch( + random.nextInt(9999), + 3, + new SimpleBlock(data, rawX, 0, rawZ), + Material.POWDER_SNOW + ); } if (data.getType(rawX, surfaceY + 1, rawZ) == Material.AIR - && data.getType(rawX, surfaceY, rawZ) != Material.POWDER_SNOW - && GenUtils.isGroundLike(data.getType(rawX, surfaceY, rawZ))) { + && data.getType(rawX, surfaceY, rawZ) != Material.POWDER_SNOW + && GenUtils.isGroundLike(data.getType(rawX, surfaceY, rawZ))) + { data.setType(rawX, surfaceY + 1, rawZ, Material.SNOW); if (data.getBlockData(rawX, surfaceY, rawZ) instanceof Snowable snowable) { snowable.setSnowy(true); @@ -56,34 +70,55 @@ public void populateSmallItems(TerraformWorld world, @NotNull Random random, int } } - @Override - public void populateLargeItems(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld world, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { SimpleLocation[] items = GenUtils.randomObjectPositions(world, data.getChunkX(), data.getChunkZ(), 44); - for(SimpleLocation sLoc:items) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) != getBiome()) continue; - sLoc.setY(GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ())); - if (data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.SNOW_BLOCK) continue; + for (SimpleLocation sLoc : items) { + if (data.getBiome(sLoc.getX(), sLoc.getZ()) != getBiome()) { + continue; + } + sLoc.setY(GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ())); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.SNOW_BLOCK) { + continue; + } - if (!TConfigOption.areTreesEnabled()) - BlockUtils.spawnPillar(random, data, sLoc.getX(),sLoc.getY(),sLoc.getZ(), Material.SPRUCE_LOG, 6, 8); + if (!TConfigOption.areTreesEnabled()) { + BlockUtils.spawnPillar(random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), Material.SPRUCE_LOG, 6, 8); + } - if (GenUtils.chance(1, 3)) - new FractalTreeBuilder(FractalTypes.Tree.FROZEN_TREE_SMALL) - .setSnowyLeaves(true).build(world, data, sLoc.getX(), sLoc.getY()+1, sLoc.getZ()); + if (GenUtils.chance(1, 3)) { + new FractalTreeBuilder(FractalTypes.Tree.FROZEN_TREE_SMALL).setSnowyLeaves(true) + .build(world, + data, + sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ() + ); + } - if (GenUtils.chance(1, 30)) - new FractalTreeBuilder(FractalTypes.Tree.FROZEN_TREE_BIG) - .build(world, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + if (GenUtils.chance(1, 30)) { + new FractalTreeBuilder(FractalTypes.Tree.FROZEN_TREE_BIG).build(world, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } } - } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } - @Override - public @NotNull BiomeBank getRiverType() { - return BiomeBank.FROZEN_RIVER; - } + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } + + @Override + public @NotNull BiomeBank getRiverType() { + return BiomeBank.FROZEN_RIVER; + } } diff --git a/common/src/main/java/org/terraform/biome/flat/SwampHandler.java b/common/src/main/java/org/terraform/biome/flat/SwampHandler.java index 09e64c40..b0264900 100644 --- a/common/src/main/java/org/terraform/biome/flat/SwampHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SwampHandler.java @@ -19,7 +19,9 @@ public class SwampHandler extends BiomeHandler { @Override - public @NotNull BiomeBank getRiverType(){ return BiomeBank.SWAMP; } + public @NotNull BiomeBank getRiverType() { + return BiomeBank.SWAMP; + } @Override public boolean isOcean() { @@ -30,26 +32,39 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.SWAMP; } + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.randChoice(rand, Material.GRASS_BLOCK, Material.PODZOL, Material.PODZOL), + return new Material[] { + GenUtils.randChoice(rand, Material.GRASS_BLOCK, Material.PODZOL, Material.PODZOL), GenUtils.randChoice(rand, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.DIRT, Material.STONE), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public BiomeHandler getTransformHandler(){ + public BiomeHandler getTransformHandler() { return BiomeBank.MANGROVE.getHandler(); } + @Override - public void populateSmallItems(TerraformWorld tw, Random random, int rawX, int surfaceY, int rawZ, PopulatorDataAbstract data) { - BiomeBank.MANGROVE.getHandler().populateSmallItems(tw,random,rawX,surfaceY,rawZ,data); + public void populateSmallItems(TerraformWorld tw, + Random random, + int rawX, + int surfaceY, + int rawZ, + PopulatorDataAbstract data) + { + BiomeBank.MANGROVE.getHandler().populateSmallItems(tw, random, rawX, surfaceY, rawZ, data); } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { int treeX, treeY, treeZ; if (GenUtils.chance(random, 8, 10)) { @@ -58,12 +73,12 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando if (data.getBiome(treeX, treeZ) == getBiome()) { treeY = GenUtils.getHighestGround(data, treeX, treeZ); - - if(treeY > TerraformGenerator.seaLevel-6) { - // Don't do gradient checks for swamp trees, the mud is uneven. - // just make sure it's submerged - TreeDB.spawnBreathingRoots(tw, new SimpleBlock(data,treeX,treeY,treeZ), Material.OAK_LOG); - FractalTypes.Tree.SWAMP_TOP.build(tw, new SimpleBlock(data,treeX,treeY,treeZ), (t)->{ + + if (treeY > TerraformGenerator.seaLevel - 6) { + // Don't do gradient checks for swamp trees, the mud is uneven. + // just make sure it's submerged + TreeDB.spawnBreathingRoots(tw, new SimpleBlock(data, treeX, treeY, treeZ), Material.OAK_LOG); + FractalTypes.Tree.SWAMP_TOP.build(tw, new SimpleBlock(data, treeX, treeY, treeZ), (t) -> { t.setCheckGradient(false); t.setRootMaterial(Material.OAK_WOOD); t.setBranchMaterial(Material.OAK_LOG); @@ -74,21 +89,23 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.MUDFLATS; - } - - @Override + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.MUDFLATS; + } + + @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - + double height = HeightMap.CORE.getHeight(tw, x, z) - 10; // If the height is too low, force it back to 3. - if (height <= 0) height = 3; - + if (height <= 0) { + height = 3; + } + return height; } diff --git a/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java b/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java index c0d4a14c..85e1b837 100644 --- a/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java @@ -22,6 +22,49 @@ import java.util.Random; public class TaigaHandler extends BiomeHandler { + /** + * Replaces the highest dirt-like blocks with a noise-fuzzed + * circle of Podzol. Fuzzes the edges. + */ + public static void replacePodzol(int seed, float radius, @NotNull SimpleBlock base) { + if (radius <= 0) { + return; + } + if (radius <= 0.5) { + // block.setReplaceType(ReplaceType.ALL); + base.setType(GenUtils.randChoice(new Random(seed), Material.PODZOL)); + return; + } + + FastNoise noise = new FastNoise(seed); + noise.SetNoiseType(NoiseType.Simplex); + noise.SetFrequency(0.13f); + Random rand = new Random(seed); + for (float x = -radius; x <= radius; x++) { + for (float z = -radius; z <= radius; z++) { + SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); + rel = rel.getGround(); + if (!BlockUtils.isDirtLike(rel.getType())) { + continue; + } + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); + double noiseVal = Math.abs(noise.GetNoise(rel.getX(), rel.getZ())); + if (equationResult <= 1.0 + noiseVal) { + // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ + if (equationResult * 4 > 0.7 + noiseVal) { + if (rand.nextBoolean()) { + rel.setType(Material.PODZOL); + } + } + else { + rel.setType(Material.PODZOL); + } + } + } + } + } + @Override public boolean isOcean() { return false; @@ -34,35 +77,44 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Use noise to group sweet berry bushes - FastNoise sweetBerriesNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheHandler.NoiseCacheEntry.BIOME_TAIGA_BERRY_BUSHNOISE, - w -> { - FastNoise n = new FastNoise((int) (w.getSeed() * 2)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFrequency(0.04f); + FastNoise sweetBerriesNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheHandler.NoiseCacheEntry.BIOME_TAIGA_BERRY_BUSHNOISE, + w -> { + FastNoise n = new FastNoise((int) (w.getSeed() * 2)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFrequency(0.04f); - return n; - }); + return n; + } + ); if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { // Generate sweet berry bushes - if (TConfigOption.arePlantsEnabled() && sweetBerriesNoise.GetNoise(rawX, rawZ) > 0.3 && - sweetBerriesNoise.GetNoise(rawX, rawZ) * random.nextFloat() > 0.35) { + if (TConfigOption.arePlantsEnabled() + && sweetBerriesNoise.GetNoise(rawX, rawZ) > 0.3 + && sweetBerriesNoise.GetNoise(rawX, rawZ) * random.nextFloat() > 0.35) + { Ageable bush = (Ageable) Material.SWEET_BERRY_BUSH.createBlockData(); // TODO: SmallItemsBuilder - bush.setAge(GenUtils.randInt(random, 1, 3)); + bush.setAge(GenUtils.randInt(random, 1, 3)); data.setBlockData(rawX, surfaceY + 1, rawZ, bush); return; } @@ -72,91 +124,71 @@ public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int ra int i = random.nextInt(4); if (i >= 2) { - if (random.nextBoolean()) - PlantBuilder.TALL_GRASS.build(data,rawX, surfaceY + 1, rawZ); - else - PlantBuilder.LARGE_FERN.build(data,rawX, surfaceY + 1, rawZ); - } else if (i == 1) { - if (random.nextBoolean()) - PlantBuilder.GRASS.build(data,rawX, surfaceY + 1, rawZ); - else - PlantBuilder.FERN.build(data,rawX, surfaceY + 1, rawZ); - } else { + if (random.nextBoolean()) { + PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); + } + else { + PlantBuilder.LARGE_FERN.build(data, rawX, surfaceY + 1, rawZ); + } + } + else if (i == 1) { + if (random.nextBoolean()) { + PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); + } + else { + PlantBuilder.FERN.build(data, rawX, surfaceY + 1, rawZ); + } + } + else { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); } } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 11); for (SimpleLocation sLoc : trees) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees if (TConfigOption.TREES_TAIGA_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { - if(FractalTypes.Tree.TAIGA_BIG.build(tw, new SimpleBlock(data, sLoc.getX(),sLoc.getY(),sLoc.getZ()))) - replacePodzol( - tw.getHashedRand(sLoc.getX(),sLoc.getY(),sLoc.getZ()).nextInt(9999), - 5f, - new SimpleBlock(data,sLoc.getX(),sLoc.getY()-1,sLoc.getZ())); - }else { // Normal trees - if(FractalTypes.Tree.TAIGA_SMALL - .build(tw, new SimpleBlock(data, sLoc.getX(),sLoc.getY(),sLoc.getZ()))) - replacePodzol( - tw.getHashedRand(sLoc.getX(),sLoc.getY(),sLoc.getZ()).nextInt(9999), - 3.5f, - new SimpleBlock(data,sLoc.getX(),sLoc.getY()-1,sLoc.getZ())); + if (FractalTypes.Tree.TAIGA_BIG.build(tw, + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()) + )) + { + replacePodzol( + tw.getHashedRand(sLoc.getX(), sLoc.getY(), sLoc.getZ()).nextInt(9999), + 5f, + new SimpleBlock(data, sLoc.getX(), sLoc.getY() - 1, sLoc.getZ()) + ); + } } - } - } - - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ROCKY_BEACH; - } - - /** - * Replaces the highest dirt-like blocks with a noise-fuzzed - * circle of Podzol. Fuzzes the edges. - */ - public static void replacePodzol(int seed, float radius, @NotNull SimpleBlock base) { - if (radius <= 0) return; - if (radius <= 0.5) { - // block.setReplaceType(ReplaceType.ALL); - base.setType(GenUtils.randChoice(new Random(seed), Material.PODZOL)); - return; - } - - FastNoise noise = new FastNoise(seed); - noise.SetNoiseType(NoiseType.Simplex); - noise.SetFrequency(0.13f); - Random rand = new Random(seed); - for (float x = -radius; x <= radius; x++) { - for (float z = -radius; z <= radius; z++) { - SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); - rel = rel.getGround(); - if(!BlockUtils.isDirtLike(rel.getType())) - continue; - // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - double noiseVal = Math.abs(noise.GetNoise(rel.getX(), rel.getZ())); - if (equationResult <= 1.0+noiseVal) { - // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if(equationResult * 4 > 0.7+noiseVal) { - if(rand.nextBoolean()) - rel.setType(Material.PODZOL); - }else { - rel.setType(Material.PODZOL); + else { // Normal trees + if (FractalTypes.Tree.TAIGA_SMALL.build(tw, + new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()) + )) + { + replacePodzol( + tw.getHashedRand(sLoc.getX(), sLoc.getY(), sLoc.getZ()).nextInt(9999), + 3.5f, + new SimpleBlock(data, sLoc.getX(), sLoc.getY() - 1, sLoc.getZ()) + ); } } } } + + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ROCKY_BEACH; } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java b/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java index 21c03848..8a63096f 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java @@ -1,13 +1,7 @@ package org.terraform.biome.mountainous; -import java.util.Random; - import org.jetbrains.annotations.NotNull; -import org.terraform.biome.BiomeBank; -import org.terraform.biome.BiomeHandler; -import org.terraform.biome.BiomeSection; -import org.terraform.biome.BiomeSubSection; -import org.terraform.biome.BiomeType; +import org.terraform.biome.*; import org.terraform.coregen.HeightMap; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; @@ -15,104 +9,126 @@ import org.terraform.main.config.TConfigOption; import org.terraform.utils.GenUtils; +import java.util.Random; + public abstract class AbstractMountainHandler extends BiomeHandler { - protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) - { - // this is positive as this is a mountain. - // double elevation = section.getElevation(); - double lowerBound = 1.4; - double upperBound = 1.7; - - // boolean surroundedByMountains = true; - - float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); - // float hmt = TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat(); - - // Check direct faces, not diagonals - for(int[] rel:new int[][] {{1,0},{-1,0},{0,1},{0,-1}}) { - int nx = rel[0]; - int nz = rel[1]; - if(section.getRelative(nx, nz).getOceanLevel() >= mt) { - // surroundedByMountains = false; - lowerBound = 1.2; - upperBound = 1.4; - break; - } - } - - return GenUtils.randDouble(sectionRandom, lowerBound, upperBound); - } - - /** - * Mountain height calculation works by taking the BiomeSection - * center, then multiplying current height to peak at that location. - */ - @Override + protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) + { + // this is positive as this is a mountain. + // double elevation = section.getElevation(); + double lowerBound = 1.4; + double upperBound = 1.7; + + // boolean surroundedByMountains = true; + + float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); + // float hmt = TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat(); + + // Check direct faces, not diagonals + for (int[] rel : new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) { + int nx = rel[0]; + int nz = rel[1]; + if (section.getRelative(nx, nz).getOceanLevel() >= mt) { + // surroundedByMountains = false; + lowerBound = 1.2; + upperBound = 1.4; + break; + } + } + + return GenUtils.randDouble(sectionRandom, lowerBound, upperBound); + } + + /** + * Mountain height calculation works by taking the BiomeSection + * center, then multiplying current height to peak at that location. + */ + @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { - + double height = HeightMap.CORE.getHeight(tw, x, z);// HeightMap.MOUNTAINOUS.getHeight(tw, x, z); // Added here - + // Let mountains cut into adjacent sections. double maxMountainRadius = ((double) BiomeSection.sectionWidth); // Double attrition height height += HeightMap.ATTRITION.getHeight(tw, x, z); - + BiomeSection sect = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); - if(sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { - sect = BiomeSection.getMostDominantSection(tw, x, z); + if (sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { + sect = BiomeSection.getMostDominantSection(tw, x, z); } - + Random sectionRand = sect.getSectionRandom(); double maxPeak = getPeakMultiplier(sect, sectionRand); - + // Let's just not offset the peak. This seems to give a better result. SimpleLocation mountainPeak = sect.getCenter(); - - double distFromPeak = (1.42*maxMountainRadius)-Math.sqrt( - Math.pow(x-mountainPeak.getX(), 2)+Math.pow(z-mountainPeak.getZ(), 2) - ); - double heightMultiplier = maxPeak*(distFromPeak/maxMountainRadius); + double distFromPeak = (1.42 * maxMountainRadius) - Math.sqrt(Math.pow(x - mountainPeak.getX(), 2) + Math.pow( + z + - mountainPeak.getZ(), + 2 + )); + + double heightMultiplier = maxPeak * (distFromPeak / maxMountainRadius); double minMultiplier = 1; BiomeSubSection subSect = sect.getSubSection(x, z); - float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); - switch(subSect) { - case NEGATIVE_X: - if(sect.getRelative(-1, 0).getOceanLevel() >= mt) - minMultiplier = 1.25; - break; - case NEGATIVE_Z: - if(sect.getRelative(0, -1).getOceanLevel() >= mt) - minMultiplier = 1.25; - break; - case POSITIVE_X: - if(sect.getRelative(1, 0).getOceanLevel() >= mt) - minMultiplier = 1.25; - break; - case POSITIVE_Z: - if(sect.getRelative(1, 0).getOceanLevel() >= mt) - minMultiplier = 1.25; - break; - case NONE: - minMultiplier = 1.7; - break; - + float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); + switch (subSect) { + case NEGATIVE_X: + if (sect.getRelative(-1, 0).getOceanLevel() >= mt) { + minMultiplier = 1.25; + } + break; + case NEGATIVE_Z: + if (sect.getRelative(0, -1).getOceanLevel() >= mt) { + minMultiplier = 1.25; + } + break; + case POSITIVE_X: + if (sect.getRelative(1, 0).getOceanLevel() >= mt) { + minMultiplier = 1.25; + } + break; + case POSITIVE_Z: + if (sect.getRelative(1, 0).getOceanLevel() >= mt) { + minMultiplier = 1.25; + } + break; + case NONE: + minMultiplier = 1.7; + break; + } - - if(heightMultiplier < minMultiplier) heightMultiplier = minMultiplier; - - height = height*heightMultiplier; - + + if (heightMultiplier < minMultiplier) { + heightMultiplier = minMultiplier; + } + + height = height * heightMultiplier; + // If the height is too high, just force it to smooth out - if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 56)) height = (TerraformGeneratorPlugin.injector.getMaxY() - 56) + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 56)) * 0.5; - if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 25)) height = (TerraformGeneratorPlugin.injector.getMaxY() - 25) + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 25)) * 0.3; - if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 15)) height = (TerraformGeneratorPlugin.injector.getMaxY() - 15) + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 15)) * 0.1; - if (height > TerraformGeneratorPlugin.injector.getMaxY() - 5) height = TerraformGeneratorPlugin.injector.getMaxY() - 5 + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 5)) * 0.05; - + if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 56)) { + height = (TerraformGeneratorPlugin.injector.getMaxY() - 56) + + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 56)) * 0.5; + } + if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 25)) { + height = (TerraformGeneratorPlugin.injector.getMaxY() - 25) + + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 25)) * 0.3; + } + if (height > (TerraformGeneratorPlugin.injector.getMaxY() - 15)) { + height = (TerraformGeneratorPlugin.injector.getMaxY() - 15) + + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 15)) * 0.1; + } + if (height > TerraformGeneratorPlugin.injector.getMaxY() - 5) { + height = TerraformGeneratorPlugin.injector.getMaxY() - 5 + + (height - (TerraformGeneratorPlugin.injector.getMaxY() - 5)) * 0.05; + } + return height; } - - + + } diff --git a/common/src/main/java/org/terraform/biome/mountainous/BadlandsCanyonHandler.java b/common/src/main/java/org/terraform/biome/mountainous/BadlandsCanyonHandler.java index 81f0e630..5aa465c2 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/BadlandsCanyonHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/BadlandsCanyonHandler.java @@ -12,8 +12,8 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; @@ -22,24 +22,32 @@ public class BadlandsCanyonHandler extends AbstractMountainHandler { /** * Performs badlands plateau generation for one x/z coord. */ - public static void oneUnit(@NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int z, boolean force) { + public static void oneUnit(@NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int z, + boolean force) + { int highest = GenUtils.getHighestGround(data, x, z); int threshold = 65; - if (force) + if (force) { threshold = highest - GenUtils.randInt(random, 3, 6); + } for (int y = highest; y > threshold; y--) { if (data.getBiome(x, z) != Biome.ERODED_BADLANDS && !force) { - if(data.getBiome(x, z) == Biome.DESERT) { - continue; - } + if (data.getBiome(x, z) == Biome.DESERT) { + continue; + } } if (data.getType(x, y, z) != Material.RED_SANDSTONE - && data.getType(x, y, z) != Material.SANDSTONE - && data.getType(x, y, z) != Material.RED_SAND - && data.getType(x, y, z) != Material.SAND - && data.getType(x, y, z) != Material.STONE) + && data.getType(x, y, z) != Material.SANDSTONE + && data.getType(x, y, z) != Material.RED_SAND + && data.getType(x, y, z) != Material.SAND + && data.getType(x, y, z) != Material.STONE) + { continue; - + } + data.setType(x, y, z, BlockUtils.getTerracotta(y)); } } @@ -57,13 +65,13 @@ public boolean isOcean() { // Extra red sandstone padding required: Prevents exposed vertical surfaces. @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.RED_SAND, - Material.RED_SAND, - Material.RED_SAND, - Material.RED_SAND, - Material.RED_SAND, - Material.RED_SAND, + return new Material[] { + Material.RED_SAND, + Material.RED_SAND, + Material.RED_SAND, + Material.RED_SAND, + Material.RED_SAND, + Material.RED_SAND, GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.RED_SAND), GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.RED_SAND), Material.RED_SANDSTONE, @@ -78,109 +86,123 @@ public boolean isOcean() { Material.RED_SANDSTONE, Material.RED_SANDSTONE, GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE), - GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.RED_SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { - if(surfaceY > - 10+HeightMap.CORE.getHeight(world, rawX, rawZ)) { + if (surfaceY > 10 + HeightMap.CORE.getHeight(world, rawX, rawZ)) { oneUnit(random, data, rawX, rawZ, false); } - if(HeightMap.getTrueHeightGradient(data, rawX, rawZ, 2) < 2) { + if (HeightMap.getTrueHeightGradient(data, rawX, rawZ, 2) < 2) { data.setType(rawX, surfaceY, rawZ, Material.RED_SAND); } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.BADLANDS_BEACH; - } - - /** - * Badlands Canyons will use the mountain algorithm, then forcefully - * smooth out at a set Y level - */ - @Override + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.BADLANDS_BEACH; + } + + /** + * Badlands Canyons will use the mountain algorithm, then forcefully + * smooth out at a set Y level + */ + @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { - double baseHeight = HeightMap.CORE.getHeight(tw, x, z); - FastNoise duneNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_BADLANDS_CANYON_NOISE, - world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.Simplex); - n.SetFractalOctaves(3); - n.SetFrequency(0.02f); - return n; - }); - double noise = duneNoise.GetNoise(x, z); - if(noise < 0) noise = 0; - - + double baseHeight = HeightMap.CORE.getHeight(tw, x, z); + FastNoise duneNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_BADLANDS_CANYON_NOISE, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.Simplex); + n.SetFractalOctaves(3); + n.SetFrequency(0.02f); + return n; + }); + double noise = duneNoise.GetNoise(x, z); + if (noise < 0) { + noise = 0; + } + + double height = HeightMap.CORE.getHeight(tw, x, z);// HeightMap.MOUNTAINOUS.getHeight(tw, x, z); // Added here - + // Let mountains cut into adjacent sections. double maxMountainRadius = ((double) BiomeSection.sectionWidth); // Add dune height - height += noise*20; - + height += noise * 20; + BiomeSection sect = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); - if(sect.getBiomeBank() != BiomeBank.BADLANDS_CANYON - || sect.getBiomeBank() != BiomeBank.BADLANDS_CANYON_PEAK) { - sect = BiomeSection.getMostDominantSection(tw, x, z); + if (sect.getBiomeBank() != BiomeBank.BADLANDS_CANYON || sect.getBiomeBank() != BiomeBank.BADLANDS_CANYON_PEAK) { + sect = BiomeSection.getMostDominantSection(tw, x, z); } - + Random sectionRand = sect.getSectionRandom(); double maxPeak = getPeakMultiplier(sect, sectionRand); - + // Let's just not offset the peak. This seems to give a better result. SimpleLocation mountainPeak = sect.getCenter(); - + double angleFromPeak = new SimpleLocation(x, 0, z).twoDAngleTo(mountainPeak); - double circleFuzz = 1.32 + Math.abs(duneNoise.GetValue((float) (10*angleFromPeak), 40519*mountainPeak.getX() + 75721*mountainPeak.getZ()));// Math.min(0.5, 0.5*duneNoise.GetValue((float) angleFromPeak, 40519*mountainPeak.getX() + 75721*mountainPeak.getZ())); - - - double distFromPeak = (circleFuzz*maxMountainRadius)-Math.sqrt( - Math.pow(x-mountainPeak.getX(), 2)+Math.pow(z-mountainPeak.getZ(), 2) - ); - - - - double heightMultiplier = maxPeak*(distFromPeak/maxMountainRadius); + double circleFuzz = 1.32 + Math.abs(duneNoise.GetValue( + (float) (10 * angleFromPeak), + 40519 * mountainPeak.getX() + 75721 * mountainPeak.getZ() + ));// Math.min(0.5, 0.5*duneNoise.GetValue((float) angleFromPeak, 40519*mountainPeak.getX() + 75721*mountainPeak.getZ())); + + + double distFromPeak = (circleFuzz * maxMountainRadius) - Math.sqrt(Math.pow(x - mountainPeak.getX(), 2) + + Math.pow(z - mountainPeak.getZ(), 2)); + + + double heightMultiplier = maxPeak * (distFromPeak / maxMountainRadius); double minMultiplier = 1; - if(heightMultiplier < minMultiplier) heightMultiplier = minMultiplier; - - height = height*heightMultiplier; - - // Thresholds to make separate plateau-looking bits - if(height > 75) { - if(height < 80) - height = 80; - if(height < 90) - height = 90; - else if(height < 105) - height = 105; - else if(height < 120) - height = 120; - else - height = 135; - } - else height = baseHeight; - + if (heightMultiplier < minMultiplier) { + heightMultiplier = minMultiplier; + } + + height = height * heightMultiplier; + + // Thresholds to make separate plateau-looking bits + if (height > 75) { + if (height < 80) { + height = 80; + } + if (height < 90) { + height = 90; + } + else if (height < 105) { + height = 105; + } + else if (height < 120) { + height = 120; + } + else { + height = 135; + } + } + else { + height = baseHeight; + } + return height; } - - @Override - protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) - { - return super.getPeakMultiplier(section, sectionRandom)*0.9; - } + + @Override + protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) + { + return super.getPeakMultiplier(section, sectionRandom) * 0.9; + } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java index d0fdfe78..f0dfe46f 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java @@ -22,13 +22,13 @@ import java.util.Random; public class BirchMountainsHandler extends AbstractMountainHandler { - - // Birch Mountains must be shorter to allow trees to populate. - @Override - protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { - return GenUtils.randDouble(sectionRandom, 1.1, 1.3); - } - + + // Birch Mountains must be shorter to allow trees to populate. + @Override + protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { + return GenUtils.randDouble(sectionRandom, 1.1, 1.3); + } + @Override public boolean isOcean() { return false; @@ -41,17 +41,24 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, + return new Material[] { + Material.GRASS_BLOCK, Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - setRock(new SimpleBlock(data,rawX,0,rawZ).getGround()); + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + setRock(new SimpleBlock(data, rawX, 0, rawZ).getGround()); if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK) { @@ -59,107 +66,140 @@ public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int ra PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); - } else { + } + else { BlockUtils.pickFlower().build(data, rawX, surfaceY + 1, rawZ); } } } } - + /** * Replace steep areas with various rocks. */ private void setRock(@NotNull SimpleBlock target) { - if(HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) - > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) { - Material rock = Material.ANDESITE; - if(HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) - > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()*2) - rock = Material.DIORITE; - while(BlockUtils.isExposedToNonSolid(target)) { - target.setType(rock); - target = target.getDown(); - } - } + if (HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) + > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + { + Material rock = Material.ANDESITE; + if (HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) + > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble() * 2) + { + rock = Material.DIORITE; + } + while (BlockUtils.isExposedToNonSolid(target)) { + target.setType(rock); + target = target.getDown(); + } + } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7); for (SimpleLocation sLoc : trees) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees if (TConfigOption.TREES_BIRCH_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { - new FractalTreeBuilder(FractalTypes.Tree.BIRCH_BIG).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - - }else { // Normal trees - new FractalTreeBuilder(FractalTypes.Tree.BIRCH_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - + new FractalTreeBuilder(FractalTypes.Tree.BIRCH_BIG).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + + } + else { // Normal trees + new FractalTreeBuilder(FractalTypes.Tree.BIRCH_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } } } - } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ROCKY_BEACH; - } - - /** - * Birch Mountains will allow rivers to carve through them. - */ - @Override + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ROCKY_BEACH; + } + + /** + * Birch Mountains will allow rivers to carve through them. + */ + @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { - double coreRawHeight; + double coreRawHeight; double height = HeightMap.CORE.getHeight(tw, x, z);// HeightMap.MOUNTAINOUS.getHeight(tw, x, z); // Added here - + // Let mountains cut into adjacent sections. double maxMountainRadius = ((double) BiomeSection.sectionWidth); // Double attrition height height += HeightMap.ATTRITION.getHeight(tw, x, z); coreRawHeight = height; - + BiomeSection sect = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); - if(sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { - sect = BiomeSection.getMostDominantSection(tw, x, z); + if (sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { + sect = BiomeSection.getMostDominantSection(tw, x, z); } - + Random sectionRand = sect.getSectionRandom(); double maxPeak = getPeakMultiplier(sect, sectionRand); - + // Let's just not offset the peak. This seems to give a better result. SimpleLocation mountainPeak = sect.getCenter(); - - double distFromPeak = (1.42*maxMountainRadius)-Math.sqrt( - Math.pow(x-mountainPeak.getX(), 2)+Math.pow(z-mountainPeak.getZ(), 2) - ); - - double heightMultiplier = maxPeak*(distFromPeak/maxMountainRadius); - - if(heightMultiplier < 1) heightMultiplier = 1; - - height = height*heightMultiplier; - + + double distFromPeak = (1.42 * maxMountainRadius) - Math.sqrt(Math.pow(x - mountainPeak.getX(), 2) + Math.pow( + z + - mountainPeak.getZ(), + 2 + )); + + double heightMultiplier = maxPeak * (distFromPeak / maxMountainRadius); + + if (heightMultiplier < 1) { + heightMultiplier = 1; + } + + height = height * heightMultiplier; + // If the height is too high, just force it to smooth out - if (height > 200) height = 200 + (height - 200) * 0.5; - if (height > 230) height = 230 + (height - 230) * 0.3; - if (height > 240) height = 240 + (height - 240) * 0.1; - if (height > 250) height = 250 + (height - 250) * 0.05; - + if (height > 200) { + height = 200 + (height - 200) * 0.5; + } + if (height > 230) { + height = 230 + (height - 230) * 0.3; + } + if (height > 240) { + height = 240 + (height - 240) * 0.1; + } + if (height > 250) { + height = 250 + (height - 250) * 0.05; + } + // Let rivers forcefully carve through birch mountains if they're deep enough. double riverDepth = HeightMap.getRawRiverDepth(tw, x, z); // HeightMap.RIVER.getHeight(tw, x, z); - - if(coreRawHeight - riverDepth <= TerraformGenerator.seaLevel - 4) { - double makeup = 0; - // Ensure depth - if(coreRawHeight - riverDepth > TerraformGenerator.seaLevel - 10) { - makeup = (coreRawHeight - riverDepth) - (TerraformGenerator.seaLevel - 10); - } - height = coreRawHeight - makeup;// - riverDepth; + + if (coreRawHeight - riverDepth <= TerraformGenerator.seaLevel - 4) { + double makeup = 0; + // Ensure depth + if (coreRawHeight - riverDepth > TerraformGenerator.seaLevel - 10) { + makeup = (coreRawHeight - riverDepth) - (TerraformGenerator.seaLevel - 10); + } + height = coreRawHeight - makeup;// - riverDepth; } - + return height; } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java index a8e127d4..713c87e3 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java @@ -10,8 +10,8 @@ import org.terraform.main.config.TConfigOption; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; @@ -22,11 +22,11 @@ public boolean isOcean() { return false; } - // Make these resemble dunes more, not massive mountains. - @Override - protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { - return GenUtils.randDouble(sectionRandom, 1.1, 1.3); - } + // Make these resemble dunes more, not massive mountains. + @Override + protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { + return GenUtils.randDouble(sectionRandom, 1.1, 1.3); + } @Override public @NotNull Biome getBiome() { @@ -35,7 +35,8 @@ protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Rando @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.SAND, + return new Material[] { + Material.SAND, Material.SAND, GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND), GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND), @@ -47,38 +48,48 @@ protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Rando Material.SANDSTONE, Material.SANDSTONE, GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND, Material.STONE), - GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE)}; + GenUtils.randChoice(rand, Material.SANDSTONE, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - - FastNoise duneNoise = NoiseCacheHandler.getNoise( - world, - NoiseCacheEntry.BIOME_DESERT_DUNENOISE, - tw -> { - FastNoise n = new FastNoise((int) tw.getSeed()); - n.SetNoiseType(NoiseType.CubicFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.03f); - return n; + public void populateSmallItems(TerraformWorld world, + Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + + FastNoise duneNoise = NoiseCacheHandler.getNoise(world, NoiseCacheEntry.BIOME_DESERT_DUNENOISE, tw -> { + FastNoise n = new FastNoise((int) tw.getSeed()); + n.SetNoiseType(NoiseType.CubicFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.03f); + return n; }); for (int y = surfaceY; y > HeightMap.CORE.getHeight(world, rawX, rawZ); y--) { - if (duneNoise.GetNoise(rawX, y, rawZ) > 0) - if (data.getType(rawX, y, rawZ) == Material.SAND || data.getType(rawX,y,rawZ) == Material.RED_SAND) { - if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER.getBoolean()) + if (duneNoise.GetNoise(rawX, y, rawZ) > 0) { + if (data.getType(rawX, y, rawZ) == Material.SAND || data.getType(rawX, y, rawZ) == Material.RED_SAND) { + if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER.getBoolean()) { data.setType(rawX, y, rawZ, Material.YELLOW_CONCRETE_POWDER); - } else if (data.getType(rawX, y, rawZ) == Material.SANDSTONE || data.getType(rawX, y, rawZ) == Material.RED_SANDSTONE) { - if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE.getBoolean()) + } + } + else if (data.getType(rawX, y, rawZ) == Material.SANDSTONE + || data.getType(rawX, y, rawZ) == Material.RED_SANDSTONE) + { + if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE.getBoolean()) { data.setType(rawX, y, rawZ, Material.YELLOW_CONCRETE); + } } + } } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java index f2917387..70f6ba8c 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java @@ -20,8 +20,8 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.SphereBuilder; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; @@ -31,16 +31,18 @@ public class ForestedMountainsHandler extends AbstractMountainHandler { private static void dirtStack(@NotNull PopulatorDataAbstract data, @NotNull Random rand, int x, int y, int z) { data.setType(x, y, z, Material.GRASS_BLOCK); - if (GenUtils.chance(rand, 1, 10)) + if (GenUtils.chance(rand, 1, 10)) { PlantBuilder.GRASS.build(data, x, y + 1, z); - + } + int depth = GenUtils.randInt(rand, 3, 7); for (int i = 1; i < depth; i++) { - if(!BlockUtils.isStoneLike(data.getType(x, y-i, z))) - break; + if (!BlockUtils.isStoneLike(data.getType(x, y - i, z))) { + break; + } data.setType(x, y - i, z, Material.DIRT); - if(BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y-i, z))) { - depth++; + if (BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y - i, z))) { + depth++; } } } @@ -57,106 +59,136 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.randChoice(rand, Material.STONE, Material.STONE, Material.STONE, Material.STONE, Material.COBBLESTONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE),}; + return new Material[] { + GenUtils.randChoice( + rand, + Material.STONE, + Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE + ), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Carve under-mountain river holes - if(rawX % 3 == 0 && rawZ % 3 == 0) - if(HeightMap.CORE.getHeight(tw, rawX, rawZ) - - HeightMap.getRawRiverDepth(tw, rawX, rawZ) - < TerraformGenerator.seaLevel - 4) { - new SphereBuilder(random, new SimpleBlock(data,rawX,TerraformGenerator.seaLevel,rawZ), Material.AIR) - .setRadius(5) - .setStaticWaterLevel(TerraformGenerator.seaLevel) - .setHardReplace(true) - .build(); - - if(GenUtils.chance(random, 1, 30)) { - int cylY = TerraformGenerator.seaLevel + (surfaceY-TerraformGenerator.seaLevel)/2 + 4; - new CylinderBuilder(random, new SimpleBlock(data,rawX,cylY,rawZ), Material.AIR) - .setRadius(5) - .setRY((surfaceY-TerraformGenerator.seaLevel)/2f + 2) - .setHardReplace(true) - .build(); + if (rawX % 3 == 0 && rawZ % 3 == 0) { + if (HeightMap.CORE.getHeight(tw, rawX, rawZ) - HeightMap.getRawRiverDepth(tw, rawX, rawZ) + < TerraformGenerator.seaLevel - 4) + { + new SphereBuilder(random, + new SimpleBlock(data, rawX, TerraformGenerator.seaLevel, rawZ), + Material.AIR + ).setRadius(5).setStaticWaterLevel(TerraformGenerator.seaLevel).setHardReplace(true).build(); + + if (GenUtils.chance(random, 1, 30)) { + int cylY = TerraformGenerator.seaLevel + (surfaceY - TerraformGenerator.seaLevel) / 2 + 4; + new CylinderBuilder(random, new SimpleBlock(data, rawX, cylY, rawZ), Material.AIR).setRadius(5) + .setRY((surfaceY + - TerraformGenerator.seaLevel) + / 2f + 2) + .setHardReplace( + true) + .build(); } } + } // Don't touch submerged blocks for the other decorations - if(surfaceY < TerraformGenerator.seaLevel) + if (surfaceY < TerraformGenerator.seaLevel) { return; + } // Make patches of dirt that extend on the mountain sides if (GenUtils.chance(random, 1, 25)) { dirtStack(data, random, rawX, surfaceY, rawZ); - for (int nx = -2; nx <= 2; nx++) + for (int nx = -2; nx <= 2; nx++) { for (int nz = -2; nz <= 2; nz++) { - if (GenUtils.chance(random, 1, 5)) continue; + if (GenUtils.chance(random, 1, 5)) { + continue; + } surfaceY = GenUtils.getHighestGround(data, rawX + nx, rawZ + nz); // Another check, make sure relative position isn't underwater. - if(surfaceY < TerraformGenerator.seaLevel) + if (surfaceY < TerraformGenerator.seaLevel) { continue; + } dirtStack(data, random, rawX + nx, surfaceY, rawZ + nz); } + } } - } - - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - FastNoise groundWoodNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JUNGLE_GROUNDWOOD, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 12)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.07f); - return n; - }); - - FastNoise groundLeavesNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JUNGLE_GROUNDLEAVES, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 2)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFrequency(0.07f); - return n; - }); + } + + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + FastNoise groundWoodNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_JUNGLE_GROUNDWOOD, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 12)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.07f); + return n; + }); + + FastNoise groundLeavesNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.BIOME_JUNGLE_GROUNDLEAVES, + world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 2)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFrequency(0.07f); + return n; + } + ); SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - - if(TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) - for (SimpleLocation sLoc : bigTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG) - .skipGradientCheck() - .build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); - } - } - - + + if (TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) { + for (SimpleLocation sLoc : bigTrees) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG).skipGradientCheck() + .build(tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } + } + } + + // Small jungle trees SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 9); for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - TreeDB.spawnSmallJungleTree(true, tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + TreeDB.spawnSmallJungleTree(true, tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); } } @@ -179,24 +211,29 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random rando } // Generate some ground leaves - if (leavesNoiseValue > -0.12 - && Math.random() > 0.85) + if (leavesNoiseValue > -0.12 && Math.random() > 0.85) { JungleHandler.createBush(data, leavesNoiseValue, x, y, z); + } // Also generate it very commonly on steep areas. - else if (GenUtils.chance(random, 1, 10) && HeightMap.getTrueHeightGradient(data, x, z, 2) > 2) // Some random ones where there is no noise. - JungleHandler.createBush(data, 0, x, y, z); + else if (GenUtils.chance(random, 1, 10) + && HeightMap.getTrueHeightGradient(data, x, z, 2) + > 2) // Some random ones where there is no noise. + { + JungleHandler.createBush(data, 0, x, y, z); + } // Generate random wood, or "roots" on the ground - if (groundWoodNoiseValue > 0.3) + if (groundWoodNoiseValue > 0.3) { data.lsetType(x, y + 1, z, Material.JUNGLE_WOOD); + } } // Generate mushrooms - if (data.getBiome(x, z) == getBiome() && - BlockUtils.isDirtLike(data.getType(x, y, z))) { + if (data.getBiome(x, z) == getBiome() && BlockUtils.isDirtLike(data.getType(x, y, z))) { if (data.getType(x, y + 1, z) == Material.JUNGLE_WOOD - && BlockUtils.isAir(data.getType(x, y + 2, z)) - && GenUtils.chance(2, 9)) { + && BlockUtils.isAir(data.getType(x, y + 2, z)) + && GenUtils.chance(2, 9)) + { PlantBuilder.build(data, x, y + 2, z, PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/JaggedPeaksHandler.java b/common/src/main/java/org/terraform/biome/mountainous/JaggedPeaksHandler.java index 1c9f07d4..897860d9 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/JaggedPeaksHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/JaggedPeaksHandler.java @@ -13,14 +13,35 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; public class JaggedPeaksHandler extends AbstractMountainHandler { - + + private static void stoneStack(Material stoneType, + @NotNull PopulatorDataAbstract data, + @NotNull Random rand, + int x, + int y, + int z) + { + data.setType(x, y, z, stoneType); + + int depth = GenUtils.randInt(rand, 3, 7); + for (int i = 1; i < depth; i++) { + if (!BlockUtils.isStoneLike(data.getType(x, y - i, z))) { + break; + } + data.setType(x, y - i, z, stoneType); + if (BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y - i, z))) { + depth++; + } + } + } + @Override public boolean isOcean() { return false; @@ -33,109 +54,108 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{Material.STONE}; + return new Material[] {Material.STONE}; } @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { - double height = super.calculateHeight(tw, x, z); - FastNoise jaggedPeaksNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JAGGED_PEAKSNOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed()*2)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(6); - n.SetFrequency(0.03f); - return n; - }); - - double noise = jaggedPeaksNoise.GetNoise(x,z); - if(noise > 0) { - height += noise * 50; - } - return height * 1.03; + double height = super.calculateHeight(tw, x, z); + FastNoise jaggedPeaksNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_JAGGED_PEAKSNOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 2)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(6); + n.SetFrequency(0.03f); + return n; + }); + + double noise = jaggedPeaksNoise.GetNoise(x, z); + if (noise > 0) { + height += noise * 50; + } + return height * 1.03; } - + @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { - if(surfaceY < TerraformGenerator.seaLevel) return; + if (surfaceY < TerraformGenerator.seaLevel) { + return; + } // Dirt Fixer // Snowy wastelands and the like will spawn snow blocks, then dirt blocks. // Analyze 5 blocks down. Replace the block if anything next to it is stone. - correctDirt(new SimpleBlock(data,rawX,surfaceY,rawZ)); + correctDirt(new SimpleBlock(data, rawX, surfaceY, rawZ)); // Make patches of decorative rock on the mountain sides. if (GenUtils.chance(random, 1, 25)) { Material stoneType = GenUtils.randChoice(Material.ANDESITE, Material.DIORITE); stoneStack(stoneType, data, random, rawX, surfaceY, rawZ); - for (int nx = -2; nx <= 2; nx++) + for (int nx = -2; nx <= 2; nx++) { for (int nz = -2; nz <= 2; nz++) { - if (GenUtils.chance(random, 1, 5)) continue; + if (GenUtils.chance(random, 1, 5)) { + continue; + } int stoneY = GenUtils.getHighestGround(data, rawX + nx, rawZ + nz); // Another check, make sure relative position isn't underwater. - if(stoneY < TerraformGenerator.seaLevel) + if (stoneY < TerraformGenerator.seaLevel) { continue; + } stoneStack(stoneType, data, random, rawX + nx, stoneY, rawZ + nz); } + } } // Thick Snow on shallow areas // Snowy Snow on near flat areas double gradient = HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3); - if(gradient < 1.4) { - if(surfaceY < TerraformGenerator.seaLevel) + if (gradient < 1.4) { + if (surfaceY < TerraformGenerator.seaLevel) { return; - if(gradient < 1.2) { + } + if (gradient < 1.2) { data.setType(rawX, surfaceY, rawZ, Material.POWDER_SNOW); - data.setType(rawX, surfaceY+1, rawZ, Material.AIR); // remove snow - }else + data.setType(rawX, surfaceY + 1, rawZ, Material.AIR); // remove snow + } + else { data.setType(rawX, surfaceY, rawZ, Material.SNOW_BLOCK); + } } } - - private void correctDirt(@NotNull SimpleBlock start) { - for(int depth = 0; depth < 5; depth++) { - for(BlockFace face:BlockUtils.directBlockFaces) { - if(start.getRelative(face).getType() == Material.STONE) { - start.setType(Material.STONE); - break; - } - } - start = start.getDown(); - } - } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } - - @Override - public @NotNull BiomeBank getRiverType() { - return BiomeBank.FROZEN_RIVER; - } - - private static void stoneStack(Material stoneType, @NotNull PopulatorDataAbstract data, @NotNull Random rand, int x, int y, int z) { - data.setType(x, y, z, stoneType); - - int depth = GenUtils.randInt(rand, 3, 7); - for (int i = 1; i < depth; i++) { - if(!BlockUtils.isStoneLike(data.getType(x, y-i, z))) - break; - data.setType(x, y - i, z, stoneType); - if(BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y-i, z))) { - depth++; + private void correctDirt(@NotNull SimpleBlock start) { + for (int depth = 0; depth < 5; depth++) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (start.getRelative(face).getType() == Material.STONE) { + start.setType(Material.STONE); + break; + } } + start = start.getDown(); } } + + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } + + @Override + public @NotNull BiomeBank getRiverType() { + return BiomeBank.FROZEN_RIVER; + } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java index 39d41dea..4fdd4b8a 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java @@ -19,20 +19,20 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; public class PaintedHillsHandler extends AbstractMountainHandler { - - // Birch Mountains must be shorter to allow trees to populate. - @Override - protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { - return GenUtils.randDouble(sectionRandom, 1.05, 1.1); - } - + + // Birch Mountains must be shorter to allow trees to populate. + @Override + protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Random sectionRandom) { + return GenUtils.randDouble(sectionRandom, 1.05, 1.1); + } + @Override public boolean isOcean() { return false; @@ -45,158 +45,189 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.ORANGE_TERRACOTTA, + return new Material[] { + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, GenUtils.randChoice(rand, Material.ORANGE_TERRACOTTA, Material.STONE), - GenUtils.randChoice(rand, Material.ORANGE_TERRACOTTA, Material.STONE)}; + GenUtils.randChoice(rand, Material.ORANGE_TERRACOTTA, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - correctDirt(new SimpleBlock(data,rawX,surfaceY,rawZ)); - - FastNoise paintNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_PAINTEDHILLS_NOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed()*4)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.03f); - return n; - }); - - - if(HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) - < TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + correctDirt(new SimpleBlock(data, rawX, surfaceY, rawZ)); + + FastNoise paintNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_PAINTEDHILLS_NOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 4)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.03f); + return n; + }); + + + if (HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) + < TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + { data.setType(rawX, surfaceY, rawZ, Material.GRASS_BLOCK); - if (random.nextBoolean()) - data.setType(rawX, surfaceY-1, rawZ, Material.DIRT); + if (random.nextBoolean()) { + data.setType(rawX, surfaceY - 1, rawZ, Material.DIRT); + } if (GenUtils.chance(random, 1, 30)) { PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); if (random.nextBoolean()) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); - } else { + } + else { PlantBuilder.DEAD_BUSH.build(data, rawX, surfaceY + 1, rawZ); } } } int terracottaDepth = 9; - for(int i = 0; i < terracottaDepth; i++) { - if(data.getType(rawX, surfaceY-i, rawZ) != Material.ORANGE_TERRACOTTA) + for (int i = 0; i < terracottaDepth; i++) { + if (data.getType(rawX, surfaceY - i, rawZ) != Material.ORANGE_TERRACOTTA) { continue; + } - double noise = paintNoise.GetNoise(rawX, surfaceY-i, rawZ); + double noise = paintNoise.GetNoise(rawX, surfaceY - i, rawZ); Material mat; - if(noise > 0.3) + if (noise > 0.3) { mat = Material.RED_TERRACOTTA; - else if(noise > 0) + } + else if (noise > 0) { mat = Material.CYAN_TERRACOTTA; - else if(noise > -0.3) + } + else if (noise > -0.3) { mat = Material.LIGHT_BLUE_TERRACOTTA; - else + } + else { mat = Material.YELLOW_TERRACOTTA; + } - data.setType(rawX, surfaceY-i, rawZ, mat); + data.setType(rawX, surfaceY - i, rawZ, mat); } } - - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25); + + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25); for (SimpleLocation sLoc : trees) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRASS_BLOCK) - continue; + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRASS_BLOCK) { + continue; + } // Normal trees - new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); } } - } + } private void correctDirt(@NotNull SimpleBlock start) { - for(int depth = 0; depth < 5; depth++) { - for(BlockFace face:BlockUtils.directBlockFaces) { - if(start.getRelative(face).getType() == Material.ORANGE_TERRACOTTA) { - start.setType(Material.ORANGE_TERRACOTTA); - break; - } - } - start = start.getDown(); - } + for (int depth = 0; depth < 5; depth++) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (start.getRelative(face).getType() == Material.ORANGE_TERRACOTTA) { + start.setType(Material.ORANGE_TERRACOTTA); + break; + } + } + start = start.getDown(); + } } /** - * Savanna Mountains will not allow rivers to carve through them. - */ - @Override + * Savanna Mountains will not allow rivers to carve through them. + */ + @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { double height = HeightMap.CORE.getHeight(tw, x, z);// HeightMap.MOUNTAINOUS.getHeight(tw, x, z); // Added here - + // Let mountains cut into adjacent sections. double maxMountainRadius = ((double) BiomeSection.sectionWidth); // Double attrition height height += HeightMap.ATTRITION.getHeight(tw, x, z); - + BiomeSection sect = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); - if(sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { - sect = BiomeSection.getMostDominantSection(tw, x, z); + if (sect.getBiomeBank().getType() != BiomeType.MOUNTAINOUS) { + sect = BiomeSection.getMostDominantSection(tw, x, z); } - + Random sectionRand = sect.getSectionRandom(); double maxPeak = getPeakMultiplier(sect, sectionRand); - + SimpleLocation mountainPeak = sect.getCenter(); - - double distFromPeak = (1.42*maxMountainRadius)-Math.sqrt( - Math.pow(x-mountainPeak.getX(), 2)+Math.pow(z-mountainPeak.getZ(), 2) - ); - - double heightMultiplier = maxPeak*(distFromPeak/maxMountainRadius); - - if(heightMultiplier < 1) heightMultiplier = 1; - - height = height*heightMultiplier; - + + double distFromPeak = (1.42 * maxMountainRadius) - Math.sqrt(Math.pow(x - mountainPeak.getX(), 2) + Math.pow( + z + - mountainPeak.getZ(), + 2 + )); + + double heightMultiplier = maxPeak * (distFromPeak / maxMountainRadius); + + if (heightMultiplier < 1) { + heightMultiplier = 1; + } + + height = height * heightMultiplier; + // Add randomised peaks - FastNoise jaggedPeaksNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_PAINTEDHILLS_ROCKS_NOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed()*2)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(5); - n.SetFrequency(0.05f); - return n; - }); - - double noise = jaggedPeaksNoise.GetNoise(x,z); - if(noise > 0.3) { - height += Math.sqrt(noise)* 40; - } - - + FastNoise jaggedPeaksNoise = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.BIOME_PAINTEDHILLS_ROCKS_NOISE, + world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 2)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(5); + n.SetFrequency(0.05f); + return n; + } + ); + + double noise = jaggedPeaksNoise.GetNoise(x, z); + if (noise > 0.3) { + height += Math.sqrt(noise) * 40; + } + + // If the height is too high, just force it to smooth out - if (height > 200) height = 200 + (height - 200) * 0.5; - if (height > 230) height = 230 + (height - 230) * 0.3; - if (height > 240) height = 240 + (height - 240) * 0.1; - if (height > 250) height = 250 + (height - 250) * 0.05; - + if (height > 200) { + height = 200 + (height - 200) * 0.5; + } + if (height > 230) { + height = 230 + (height - 230) * 0.3; + } + if (height > 240) { + height = 240 + (height - 240) * 0.1; + } + if (height > 250) { + height = 250 + (height - 250) * 0.05; + } + return height; } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java index 3f389eda..39d2e01e 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java @@ -26,16 +26,53 @@ public class RockyMountainsHandler extends AbstractMountainHandler { private static void dirtStack(@NotNull PopulatorDataAbstract data, @NotNull Random rand, int x, int y, int z) { data.setType(x, y, z, Material.GRASS_BLOCK); - if (GenUtils.chance(rand, 1, 10)) + if (GenUtils.chance(rand, 1, 10)) { PlantBuilder.GRASS.build(data, x, y + 1, z); + } int depth = GenUtils.randInt(rand, 3, 7); for (int i = 1; i < depth; i++) { - if(!BlockUtils.isStoneLike(data.getType(x, y-i, z))) - break; + if (!BlockUtils.isStoneLike(data.getType(x, y - i, z))) { + break; + } data.setType(x, y - i, z, Material.DIRT); - if(BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y-i, z))) { - depth++; + if (BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y - i, z))) { + depth++; + } + } + } + + public static void placeWaterFall(@NotNull TerraformWorld tw, int seed, @NotNull SimpleBlock base) { + float radius = 4.0f; + + FastNoise noise = new FastNoise(seed); + noise.SetNoiseType(NoiseType.Simplex); + noise.SetFrequency(0.09f); + + for (float x = -radius; x <= radius; x++) { + for (float y = -radius / 2.0f; y <= radius / 2.0f; y++) { + for (float z = -radius; z <= radius; z++) { + + SimpleBlock rel = base.getRelative(Math.round(x), Math.round(y), Math.round(z)); + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + + Math.pow(y, 2) / Math.pow(radius, 2) + + Math.pow(z, 2) / Math.pow(radius, 2); + if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { + // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ + if (y > 0) { // Upper half of sphere is air + rel.setType(Material.AIR); + } + else if (rel.isSolid()) { + // Lower half is water, if replaced block was solid. + rel.setType(Material.WATER); + PhysicsUpdaterPopulator.pushChange( + tw.getName(), + new SimpleLocation(rel.getX(), rel.getY(), rel.getZ()) + ); + } + } + } } } } @@ -52,116 +89,120 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{GenUtils.randChoice(rand, Material.STONE, Material.STONE, Material.STONE, Material.STONE, Material.COBBLESTONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE),}; + return new Material[] { + GenUtils.randChoice( + rand, + Material.STONE, + Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE + ), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + GenUtils.randChoice(rand, Material.COBBLESTONE, Material.STONE, Material.STONE), + }; } @Override - public void populateSmallItems(TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Don't touch submerged blocks - if(surfaceY < TerraformGenerator.seaLevel) + if (surfaceY < TerraformGenerator.seaLevel) { return; + } // Make patches of dirt that extend on the mountain sides if (GenUtils.chance(random, 1, 25)) { dirtStack(data, random, rawX, surfaceY, rawZ); - for (int nx = -2; nx <= 2; nx++) + for (int nx = -2; nx <= 2; nx++) { for (int nz = -2; nz <= 2; nz++) { - if (GenUtils.chance(random, 1, 5)) continue; + if (GenUtils.chance(random, 1, 5)) { + continue; + } surfaceY = GenUtils.getHighestGround(data, rawX + nx, rawZ + nz); // Another check, make sure relative position isn't underwater. - if(surfaceY < TerraformGenerator.seaLevel) + if (surfaceY < TerraformGenerator.seaLevel) { continue; + } dirtStack(data, random, rawX + nx, surfaceY, rawZ + nz); } + } } } - - public static void placeWaterFall(@NotNull TerraformWorld tw, int seed, @NotNull SimpleBlock base) { - float radius = 4.0f; - - FastNoise noise = new FastNoise(seed); - noise.SetNoiseType(NoiseType.Simplex); - noise.SetFrequency(0.09f); - - for (float x = -radius; x <= radius; x++) { - for (float y = -radius/2.0f; y <= radius/2.0f; y++) { - for (float z = -radius; z <= radius; z++) { - SimpleBlock rel = base.getRelative(Math.round(x), Math.round(y), Math.round(z)); - // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(y, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { - // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if(y > 0) { // Upper half of sphere is air - rel.setType(Material.AIR); - }else if(rel.isSolid()) { - // Lower half is water, if replaced block was solid. - rel.setType(Material.WATER); - PhysicsUpdaterPopulator.pushChange(tw.getName(), new SimpleLocation(rel.getX(),rel.getY(),rel.getZ())); - } - } - } + public boolean checkWaterfallSpace(@NotNull SimpleBlock b) { + // Only bother if the waterfall is at least 15 blocks up + if (b.getY() < TerraformGenerator.seaLevel + 15) { + return false; + } + for (int i = 0; i < 5; i++) { + if (!b.getRelative(0, -i, 0).isSolid()) { + return false; } } - } - - public boolean checkWaterfallSpace(@NotNull SimpleBlock b) { - // Only bother if the waterfall is at least 15 blocks up - if(b.getY() < TerraformGenerator.seaLevel + 15) - return false; - for(int i = 0; i < 5; i++) { - if(!b.getRelative(0,-i,0).isSolid()) - return false; - } - return BlockUtils.isExposedToNonSolid(b.getDown(4)); + return BlockUtils.isExposedToNonSolid(b.getDown(4)); } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { // Waterfalls only spawn 1 in 30 times (rolled after checking position.). - for(int rawX = data.getChunkX()*16; rawX < data.getChunkX()*16+16; rawX++) - for(int rawZ = data.getChunkZ()*16; rawZ < data.getChunkZ()*16+16; rawZ++) - { + for (int rawX = data.getChunkX() * 16; rawX < data.getChunkX() * 16 + 16; rawX++) { + for (int rawZ = data.getChunkZ() * 16; rawZ < data.getChunkZ() * 16 + 16; rawZ++) { int surfaceY = GenUtils.getTransformedHeight(data.getTerraformWorld(), rawX, rawZ); - if(HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) > 1.5) - if(HeightMap.CORE.getHeight(tw, rawX, rawZ) - HeightMap.getRawRiverDepth(tw, rawX, rawZ) < TerraformGenerator.seaLevel) { + if (HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) > 1.5) { + if (HeightMap.CORE.getHeight(tw, rawX, rawZ) - HeightMap.getRawRiverDepth(tw, rawX, rawZ) + < TerraformGenerator.seaLevel) + { // If this face is at least 4 blocks wide, carve a waterfall opening - SimpleBlock block = new SimpleBlock(data,rawX,surfaceY,rawZ); - if(checkWaterfallSpace(block) - && GenUtils.chance(tw.getHashedRand(rawX, surfaceY, rawZ), 1, 30)) { + SimpleBlock block = new SimpleBlock(data, rawX, surfaceY, rawZ); + if (checkWaterfallSpace(block) && GenUtils.chance(tw.getHashedRand(rawX, surfaceY, rawZ), + 1, + 30 + )) + { block = block.getDown(4); - placeWaterFall(tw, rawX + 11*rawZ + 31*surfaceY, block); + placeWaterFall(tw, rawX + 11 * rawZ + 31 * surfaceY, block); break; } } + } } + } // Small trees SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 14); - + // Trees on shallow areas for (SimpleLocation sLoc : trees) { - if(HeightMap.getTrueHeightGradient(data, sLoc.getX(), sLoc.getZ(), 3) < 1.4) { // trees - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (HeightMap.getTrueHeightGradient(data, sLoc.getX(), sLoc.getZ(), 3) < 1.4) { // trees + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build(tw, data, sLoc.getX(),sLoc.getY(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.NORMAL_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); } - } + } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ROCKY_BEACH; - } + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ROCKY_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java b/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java index 23ebc02a..1ef6918b 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java @@ -38,7 +38,16 @@ * The real interest in the biome lies in its transformer */ public class ShatteredSavannaHandler extends AbstractMountainHandler { - + + static BiomeBlender biomeBlender; + + private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { + if (biomeBlender == null) { + biomeBlender = new BiomeBlender(tw, true, true).setGridBlendingFactor(4).setSmoothBlendTowardsRivers(2); + } + return biomeBlender; + } + @Override public boolean isOcean() { return false; @@ -51,130 +60,153 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{ - Material.GRASS_BLOCK, - Material.DIRT, - GenUtils.randChoice(Material.DIRT, Material.STONE), - GenUtils.randChoice(Material.DIRT, Material.STONE), - Material.STONE - }; + return new Material[] { + Material.GRASS_BLOCK, + Material.DIRT, + GenUtils.randChoice(Material.DIRT, Material.STONE), + GenUtils.randChoice(Material.DIRT, Material.STONE), + Material.STONE + }; } @Override - public @NotNull BiomeHandler getTransformHandler(){ return this; } + public @NotNull BiomeHandler getTransformHandler() { + return this; + } /** * One 2D noise value to handle whether or not to carve * One 1D noise value as a Y-multiplier */ @Override - public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - - FastNoise creviceNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_SHATTERED_SAVANNANOISE, - world -> { - FastNoise n = new FastNoise(tw.getHashedRand(181234,32189,16342134).nextInt()); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalType(FastNoise.FractalType.Billow); - n.SetFractalOctaves(1); - n.SetFrequency(0.02f); - return n; + public void transformTerrain(@NotNull ChunkCache cache, + @NotNull TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + + FastNoise creviceNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_SHATTERED_SAVANNANOISE, world -> { + FastNoise n = new FastNoise(tw.getHashedRand(181234, 32189, 16342134).nextInt()); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalType(FastNoise.FractalType.Billow); + n.SetFractalOctaves(1); + n.SetFrequency(0.02f); + return n; }); - FastNoise yScaleNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_SHATTERED_SAVANNANOISE, - world -> { - FastNoise n = new FastNoise(tw.getHashedRand(982374,18723,1983701).nextInt()); - n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(0.06f); - return n; - }); - int rawX = chunkX*16+x; - int rawZ = chunkZ*16+z; - double crevice = Math.abs(creviceNoise.GetNoise(rawX,rawZ)); + FastNoise yScaleNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_SHATTERED_SAVANNANOISE, world -> { + FastNoise n = new FastNoise(tw.getHashedRand(982374, 18723, 1983701).nextInt()); + n.SetNoiseType(NoiseType.Simplex); + n.SetFrequency(0.06f); + return n; + }); + int rawX = chunkX * 16 + x; + int rawZ = chunkZ * 16 + z; + double crevice = Math.abs(creviceNoise.GetNoise(rawX, rawZ)); // peakHeight *= getBiomeBlender(tw).getEdgeFactor(BiomeBank.SHATTERED_SAVANNA, rawX, rawZ); - if(crevice < 0.40f) return; + if (crevice < 0.40f) { + return; + } - short baseHeight = cache.getTransformedHeight(x,z); - int low = (int) HeightMap.CORE.getHeight(tw,rawX,rawZ); + short baseHeight = cache.getTransformedHeight(x, z); + int low = (int) HeightMap.CORE.getHeight(tw, rawX, rawZ); boolean updateHeight = true; - for(int y = baseHeight; y > low; y--) - { + for (int y = baseHeight; y > low; y--) { // Noise meant to scale with y while making terraces every 10 blocks // Additionally, add a small curve to make the land bend a bit // Make the pillars connect around baseHeight+0.5*(peakHeight-baseHeight) // by multiplying a factor that approaches lower values there - double scale = (1f - 0.4*Math.abs(yScaleNoise.GetNoise(y,0))); - if(crevice*scale < 0.40f){ + double scale = (1f - 0.4 * Math.abs(yScaleNoise.GetNoise(y, 0))); + if (crevice * scale < 0.40f) { updateHeight = false; continue; } - chunk.setBlock(x,y,z,Material.CAVE_AIR); - if(updateHeight) cache.writeTransformedHeight(x,z, (short) (y-1)); + chunk.setBlock(x, y, z, Material.CAVE_AIR); + if (updateHeight) { + cache.writeTransformedHeight(x, z, (short) (y - 1)); + } } // Make write changes - if(chunk instanceof DudChunkData) return; + if (chunk instanceof DudChunkData) { + return; + } Material[] crust = getSurfaceCrust(new Random()); - for(int i = 0; i < crust.length; i++) - { - if(BlockUtils.isAir(chunk.getType(x,cache.getTransformedHeight(x,z)-i,z))) + for (int i = 0; i < crust.length; i++) { + if (BlockUtils.isAir(chunk.getType(x, cache.getTransformedHeight(x, z) - i, z))) { return; - chunk.setBlock(x,cache.getTransformedHeight(x,z)-i,z,crust[i]); + } + chunk.setBlock(x, cache.getTransformedHeight(x, z) - i, z, crust[i]); } } - static BiomeBlender biomeBlender; - private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { - if (biomeBlender == null) biomeBlender = new BiomeBlender(tw, true, true) - .setGridBlendingFactor(4) - .setSmoothBlendTowardsRivers(2); - return biomeBlender; - } - @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(surfaceY < TerraformGenerator.seaLevel) return; + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (surfaceY < TerraformGenerator.seaLevel) { + return; + } - if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK - && !data.getType(rawX, surfaceY + 1, rawZ).isSolid()) { + if (data.getType(rawX, surfaceY, rawZ) == Material.GRASS_BLOCK && !data.getType(rawX, surfaceY + 1, rawZ) + .isSolid()) + { // Dense grass if (GenUtils.chance(random, 2, 10)) { - PlantBuilder.GRASS.build(data, rawX, surfaceY+1, rawZ); + PlantBuilder.GRASS.build(data, rawX, surfaceY + 1, rawZ); } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { // Small trees - SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 34); + SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 34); for (SimpleLocation sLoc : trees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - } + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).build( + tw, + data, + sLoc.getX(), + sLoc.getY(), + sLoc.getZ() + ); + } } // Grass Poffs SimpleLocation[] poffs = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 35); for (SimpleLocation sLoc : poffs) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if(TConfigOption.arePlantsEnabled() && data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ())) && - !data.getType(sLoc.getX(),sLoc.getY()+1,sLoc.getZ()).isSolid()) { - SimpleBlock base = new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); - int rX = GenUtils.randInt(random, 2, 4); - int rY = GenUtils.randInt(random, 2, 4); - int rZ = GenUtils.randInt(random, 2, 4); - BlockUtils.replaceSphere(random.nextInt(999), rX, rY, rZ, base, false, Material.ACACIA_LEAVES); - } + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (TConfigOption.arePlantsEnabled() + && data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) + && !data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()).isSolid()) + { + SimpleBlock base = new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); + int rX = GenUtils.randInt(random, 2, 4); + int rY = GenUtils.randInt(random, 2, 4); + int rZ = GenUtils.randInt(random, 2, 4); + BlockUtils.replaceSphere(random.nextInt(999), rX, rY, rZ, base, false, Material.ACACIA_LEAVES); + } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/SnowyMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/SnowyMountainsHandler.java index 5aa94324..23a41ee1 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/SnowyMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/SnowyMountainsHandler.java @@ -16,7 +16,28 @@ import java.util.Random; public class SnowyMountainsHandler extends AbstractMountainHandler { - + + private static void stoneStack(Material stoneType, + @NotNull PopulatorDataAbstract data, + @NotNull Random rand, + int x, + int y, + int z) + { + data.setType(x, y, z, stoneType); + + int depth = GenUtils.randInt(rand, 3, 7); + for (int i = 1; i < depth; i++) { + if (!BlockUtils.isStoneLike(data.getType(x, y - i, z))) { + break; + } + data.setType(x, y - i, z, stoneType); + if (BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y - i, z))) { + depth++; + } + } + } + @Override public boolean isOcean() { return false; @@ -29,91 +50,93 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{Material.STONE}; + return new Material[] {Material.STONE}; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - - if(surfaceY < TerraformGenerator.seaLevel) return; + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + + if (surfaceY < TerraformGenerator.seaLevel) { + return; + } // Dirt Fixer // Snowy wastelands and the like will spawn snow blocks, then dirt blocks. // Analyze 5 blocks down. Replace the block if anything next to it is stone. - correctDirt(new SimpleBlock(data,rawX,surfaceY,rawZ)); + correctDirt(new SimpleBlock(data, rawX, surfaceY, rawZ)); // Snow on top if the biome is the same - data.setType(rawX, surfaceY+1, rawZ, Material.SNOW); + data.setType(rawX, surfaceY + 1, rawZ, Material.SNOW); // Make patches of decorative rock on the mountain sides. if (GenUtils.chance(random, 1, 25)) { Material stoneType = GenUtils.randChoice(Material.ANDESITE, Material.DIORITE); stoneStack(stoneType, data, random, rawX, surfaceY, rawZ); - for (int nx = -2; nx <= 2; nx++) + for (int nx = -2; nx <= 2; nx++) { for (int nz = -2; nz <= 2; nz++) { - if (GenUtils.chance(random, 1, 5)) continue; + if (GenUtils.chance(random, 1, 5)) { + continue; + } int stoneY = GenUtils.getHighestGround(data, rawX + nx, rawZ + nz); // Another check, make sure relative position isn't underwater. - if(stoneY < TerraformGenerator.seaLevel) + if (stoneY < TerraformGenerator.seaLevel) { continue; + } stoneStack(stoneType, data, random, rawX + nx, stoneY, rawZ + nz); } + } } // Thick Snow on shallow areas // Snowy Snow on near flat areas double gradient = HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3); - if(gradient < 1.4) { + if (gradient < 1.4) { - if(surfaceY < TerraformGenerator.seaLevel) + if (surfaceY < TerraformGenerator.seaLevel) { return; - if(gradient < 1.2) { + } + if (gradient < 1.2) { data.setType(rawX, surfaceY, rawZ, Material.POWDER_SNOW); - data.setType(rawX, surfaceY+1, rawZ, Material.AIR); // remove snow - }else + data.setType(rawX, surfaceY + 1, rawZ, Material.AIR); // remove snow + } + else { data.setType(rawX, surfaceY, rawZ, Material.SNOW_BLOCK); + } } } - - private void correctDirt(@NotNull SimpleBlock start) { - for(int depth = 0; depth < 5; depth++) { - for(BlockFace face:BlockUtils.directBlockFaces) { - if(start.getRelative(face).getType() == Material.STONE) { - start.setType(Material.STONE); - break; - } - } - start = start.getDown(); - } - } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } - - @Override - public @NotNull BiomeBank getRiverType() { - return BiomeBank.FROZEN_RIVER; - } - - private static void stoneStack(Material stoneType, @NotNull PopulatorDataAbstract data, @NotNull Random rand, int x, int y, int z) { - data.setType(x, y, z, stoneType); - - int depth = GenUtils.randInt(rand, 3, 7); - for (int i = 1; i < depth; i++) { - if(!BlockUtils.isStoneLike(data.getType(x, y-i, z))) - break; - data.setType(x, y - i, z, stoneType); - if(BlockUtils.isExposedToNonSolid(new SimpleBlock(data, x, y-i, z))) { - depth++; + private void correctDirt(@NotNull SimpleBlock start) { + for (int depth = 0; depth < 5; depth++) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (start.getRelative(face).getType() == Material.STONE) { + start.setType(Material.STONE); + break; + } } + start = start.getDown(); } } + + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } + + @Override + public @NotNull BiomeBank getRiverType() { + return BiomeBank.FROZEN_RIVER; + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/AbstractOceanHandler.java b/common/src/main/java/org/terraform/biome/ocean/AbstractOceanHandler.java index d8cdafa2..a870ec3c 100644 --- a/common/src/main/java/org/terraform/biome/ocean/AbstractOceanHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/AbstractOceanHandler.java @@ -7,22 +7,26 @@ public abstract class AbstractOceanHandler extends BiomeHandler { - protected final BiomeType oceanType; - public AbstractOceanHandler(BiomeType oceanType) { - this.oceanType = oceanType; - } - - @Override + protected final BiomeType oceanType; + + public AbstractOceanHandler(BiomeType oceanType) { + this.oceanType = oceanType; + } + + @Override public double calculateHeight(TerraformWorld tw, int x, int z) { - + double height = HeightMap.CORE.getHeight(tw, x, z) - 25; - - if(oceanType == BiomeType.DEEP_OCEANIC) - height -= 20; - + + if (oceanType == BiomeType.DEEP_OCEANIC) { + height -= 20; + } + // If the height is too low, force it back to 3. - if (height <= 0) height = 3; - + if (height <= 0) { + height = 3; + } + return height; } } diff --git a/common/src/main/java/org/terraform/biome/ocean/BlackOceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/BlackOceansHandler.java index a8f75b54..2686dba6 100644 --- a/common/src/main/java/org/terraform/biome/ocean/BlackOceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/BlackOceansHandler.java @@ -20,15 +20,27 @@ public class BlackOceansHandler extends AbstractOceanHandler { public BlackOceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - public static void genSpike(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, int baseRadius, int height) { + public static void genSpike(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int baseRadius, + int height) + { y -= height / 5; // Vector one to two; Vector base = new Vector(x, y, z); - Vector base2 = new Vector(x + GenUtils.randInt(random, -2 * baseRadius, 2 * baseRadius), y + height, z + GenUtils.randInt(random, -2 * baseRadius, 2 * baseRadius)); + Vector base2 = new Vector( + x + GenUtils.randInt(random, -2 * baseRadius, 2 * baseRadius), + y + height, + z + GenUtils.randInt(random, -2 * baseRadius, 2 * baseRadius) + ); Vector v = base2.subtract(base); SimpleBlock one = new SimpleBlock(data, x, y, z); @@ -36,11 +48,15 @@ public static void genSpike(@NotNull TerraformWorld tw, @NotNull Random random, for (int i = 0; i <= height; i++) { Vector seg = v.clone().multiply((float) i / ((float) height)); SimpleBlock segment = one.getRelative(seg); - BlockUtils.replaceSphere( - (int) (tw.getSeed() * 12), - (float) radius, 2, (float) radius, - segment, false, false, - Material.STONE); + BlockUtils.replaceSphere((int) (tw.getSeed() * 12), + (float) radius, + 2, + (float) radius, + segment, + false, + false, + Material.STONE + ); radius = ((double) baseRadius) * (1 - ((double) i) / ((double) height)); } } @@ -52,60 +68,78 @@ public boolean isOcean() { @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_COLD_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_COLD_OCEAN; + } return Biome.COLD_OCEAN; } @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{Material.STONE}; + return new Material[] {Material.STONE}; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to gravel - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); + } } // No kelp above sea level. - if(surfaceY > TerraformGenerator.seaLevel) return; - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (surfaceY > TerraformGenerator.seaLevel) { + return; + } + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 1, 80)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { for (int x = data.getChunkX() * 16 + 3; x < data.getChunkX() * 16 + 16 - 3; x++) { for (int z = data.getChunkZ() * 16 + 3; z < data.getChunkZ() * 16 + 16 - 3; z++) { - - if (data.getBiome(x, z) != getBiome()) continue; + + if (data.getBiome(x, z) != getBiome()) { + continue; + } // black spike if (GenUtils.chance(random, 1, 200)) { - int y = HeightMap.getBlockHeight(tw, x, z); - genSpike(tw, random, data, x, y, z, - GenUtils.randInt(5, 15), // radius - GenUtils.randInt(50, 100)); + int y = HeightMap.getBlockHeight(tw, x, z); + genSpike(tw, random, data, x, y, z, GenUtils.randInt(5, 15), // radius + GenUtils.randInt(50, 100) + ); } } } - } - - @Override - public boolean forceDefaultToBeach() { - return true; - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.BLACK_OCEAN_BEACH; - } + } + + @Override + public boolean forceDefaultToBeach() { + return true; + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.BLACK_OCEAN_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/ColdOceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/ColdOceansHandler.java index 5780f344..0603f60c 100644 --- a/common/src/main/java/org/terraform/biome/ocean/ColdOceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/ColdOceansHandler.java @@ -19,81 +19,92 @@ public class ColdOceansHandler extends AbstractOceanHandler { public ColdOceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_COLD_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_COLD_OCEAN; + } return Biome.COLD_OCEAN; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRAVEL, - Material.GRAVEL, + return new Material[] { + Material.GRAVEL, + Material.GRAVEL, GenUtils.randChoice(rand, Material.STONE, Material.GRAVEL, Material.STONE), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to gravel - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 1, 150)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } + } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ROCKY_BEACH; - } + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ROCKY_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/CoralReefOceanHandler.java b/common/src/main/java/org/terraform/biome/ocean/CoralReefOceanHandler.java index c7c9b1bd..d1314fc9 100644 --- a/common/src/main/java/org/terraform/biome/ocean/CoralReefOceanHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/CoralReefOceanHandler.java @@ -19,104 +19,132 @@ public class CoralReefOceanHandler extends AbstractOceanHandler { public CoralReefOceanHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_LUKEWARM_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_LUKEWARM_OCEAN; + } return Biome.LUKEWARM_OCEAN; } + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.SAND, - Material.SAND, + return new Material[] { + Material.SAND, + Material.SAND, GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND, Material.SAND), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 10, 100)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - // Large Corals - SimpleLocation[] largeCorals = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + // Large Corals + SimpleLocation[] largeCorals = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : largeCorals) { - int coralY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - if(coralY >= TerraformGenerator.seaLevel) continue; + int coralY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + if (coralY >= TerraformGenerator.seaLevel) { + continue; + } sLoc.setY(coralY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - TreeDB.spawnRandomGiantCoral(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - if(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.GRAVEL) - BlockUtils.replaceCircularPatch(random.nextInt(9999), 4, new SimpleBlock(data, sLoc), Material.SAND); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + TreeDB.spawnRandomGiantCoral(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.GRAVEL) { + BlockUtils.replaceCircularPatch(random.nextInt(9999), + 4, + new SimpleBlock(data, sLoc), + Material.SAND + ); + } } } - - SimpleLocation[] smallCorals = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 4, 0.5f); - + + SimpleLocation[] smallCorals = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 4, 0.5f); + for (SimpleLocation sLoc : smallCorals) { - int coralY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - if(coralY >= TerraformGenerator.seaLevel) continue; + int coralY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + if (coralY >= TerraformGenerator.seaLevel) { + continue; + } sLoc.setY(coralY); - if(data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() - && !data.getType(sLoc.getX(),sLoc.getY()+1,sLoc.getZ()).isSolid()) { - CoralGenerator.generateCoral(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); - if(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.GRAVEL) - BlockUtils.replaceCircularPatch(random.nextInt(9999), 2, new SimpleBlock(data, sLoc), Material.SAND); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && !data.getType(sLoc.getX(), + sLoc.getY() + 1, + sLoc.getZ()).isSolid()) + { + CoralGenerator.generateCoral(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) == Material.GRAVEL) { + BlockUtils.replaceCircularPatch(random.nextInt(9999), + 2, + new SimpleBlock(data, sLoc), + Material.SAND + ); + } } } - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 30, 0.4f); - + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 30, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - - } + + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/FrozenOceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/FrozenOceansHandler.java index 6ca34208..21fb8048 100644 --- a/common/src/main/java/org/terraform/biome/ocean/FrozenOceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/FrozenOceansHandler.java @@ -18,82 +18,92 @@ public class FrozenOceansHandler extends AbstractOceanHandler { public FrozenOceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_FROZEN_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_FROZEN_OCEAN; + } return Biome.FROZEN_OCEAN; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRAVEL, - Material.GRAVEL, + return new Material[] { + Material.GRAVEL, + Material.GRAVEL, GenUtils.randChoice(rand, Material.STONE, Material.GRAVEL, Material.STONE), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to gravel - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); + } } // Full ice-sheets - if (!data.getType(rawX, TerraformGenerator.seaLevel, rawZ).isSolid()) + if (!data.getType(rawX, TerraformGenerator.seaLevel, rawZ).isSolid()) { data.setType(rawX, TerraformGenerator.seaLevel, rawZ, Material.ICE); + } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } + } - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.ICY_BEACH; - } + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.ICY_BEACH; + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/LukewarmOceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/LukewarmOceansHandler.java index 8358674f..7f2ce4a1 100644 --- a/common/src/main/java/org/terraform/biome/ocean/LukewarmOceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/LukewarmOceansHandler.java @@ -18,80 +18,91 @@ public class LukewarmOceansHandler extends AbstractOceanHandler { public LukewarmOceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_LUKEWARM_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_LUKEWARM_OCEAN; + } return Biome.LUKEWARM_OCEAN; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ + return new Material[] { Material.SAND, Material.SAND, GenUtils.randChoice(rand, Material.SANDSTONE, Material.SAND, Material.SAND), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 10, 100)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 30, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 30, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - - } + + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/MushroomIslandHandler.java b/common/src/main/java/org/terraform/biome/ocean/MushroomIslandHandler.java index 717f5ee6..2a17ee2b 100644 --- a/common/src/main/java/org/terraform/biome/ocean/MushroomIslandHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/MushroomIslandHandler.java @@ -16,91 +16,94 @@ import org.terraform.utils.CoralGenerator; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; /** * Mushroom Islands are only oceans that have a custom height generator. - * They will not actually generate mycelium, they will only build the + * They will not actually generate mycelium, they will only build the * island itself */ public class MushroomIslandHandler extends AbstractOceanHandler { public MushroomIslandHandler() { - super(BiomeType.DEEP_OCEANIC); - // TODO Auto-generated constructor stub - } - - @Override + super(BiomeType.DEEP_OCEANIC); + // TODO Auto-generated constructor stub + } + + @Override public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { - + double height = super.calculateHeight(tw, x, z); BiomeSection currentSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); - if(currentSection.getBiomeBank() != BiomeBank.MUSHROOM_ISLANDS) { - currentSection = BiomeSection.getMostDominantSection(tw, x, z); + if (currentSection.getBiomeBank() != BiomeBank.MUSHROOM_ISLANDS) { + currentSection = BiomeSection.getMostDominantSection(tw, x, z); } - + // CHECK 4 SURROUNDING BIOMES. // If ANY of them are dry, the mushroom island radius will be // aggressively shrunk to avoid land connections. // If they're still connected uh. Lol I guess. - float islandRadius = BiomeSection.sectionWidth/2.5f; - for(BlockFace face:BlockUtils.directBlockFaces) { - if(currentSection.getRelative(face.getModX(), face.getModZ()) - .getBiomeBank().isDry()) - { - islandRadius *= 0.65f; - break; - } + float islandRadius = BiomeSection.sectionWidth / 2.5f; + for (BlockFace face : BlockUtils.directBlockFaces) { + if (currentSection.getRelative(face.getModX(), face.getModZ()).getBiomeBank().isDry()) { + islandRadius *= 0.65f; + break; + } } - + // The island itself is a distorted circle. // Everything within the circle's radius is aggressively raised above // sea level. - - FastNoise circleNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_MUSHROOMISLAND_CIRCLE, - world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(3); - n.SetFrequency(0.04f); - return n; - }); - SimpleLocation center = currentSection.getCenter(); + + FastNoise circleNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_MUSHROOMISLAND_CIRCLE, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(3); + n.SetFrequency(0.04f); + return n; + }); + SimpleLocation center = currentSection.getCenter(); int relX = x - center.getX(); int relZ = z - center.getZ(); - + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(relX, 2) / Math.pow(islandRadius, 2) - + Math.pow(relZ, 2) / Math.pow(islandRadius, 2); + double equationResult = Math.pow(relX, 2) / Math.pow(islandRadius, 2) + Math.pow(relZ, 2) / Math.pow( + islandRadius, + 2 + ); double noise = 1 + 0.7 * circleNoise.GetNoise(relX, relZ); if (equationResult <= noise) { - - double supplement = TerraformGenerator.seaLevel - height; - - if (equationResult >= noise * 0.9) { + + double supplement = TerraformGenerator.seaLevel - height; + + if (equationResult >= noise * 0.9) { return height + supplement * 0.6; - }else if(equationResult >= noise * 0.7) { + } + else if (equationResult >= noise * 0.7) { return height + supplement + 10; - }else if(equationResult >= noise * 0.6) { + } + else if (equationResult >= noise * 0.6) { return height + supplement + 9; - }else if(equationResult >= noise * 0.5) { + } + else if (equationResult >= noise * 0.5) { return height + supplement + 8; - }else if(equationResult >= noise * 0.4) { + } + else if (equationResult >= noise * 0.4) { return height + supplement + 7.5; - }else - return height + supplement + 7; + } + else { + return height + supplement + 7; + } } return height; } - @Override + @Override public boolean isOcean() { return true; } @@ -112,65 +115,77 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRAVEL, - Material.GRAVEL, + return new Material[] { + Material.GRAVEL, + Material.GRAVEL, GenUtils.randChoice(rand, Material.STONE, Material.GRAVEL, Material.STONE), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(rawX >= TerraformGenerator.seaLevel) return; + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (rawX >= TerraformGenerator.seaLevel) { + return; + } - if (!BlockUtils.isStoneLike(data.getType(rawX, rawX, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, rawX, rawZ))) { + return; + } if (GenUtils.chance(random, 1, 150)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, rawX + 1, rawZ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - if(rockY >= TerraformGenerator.seaLevel) continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + if (rockY >= TerraformGenerator.seaLevel) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } - - @Override - public @NotNull BiomeBank getBeachType() { - return BiomeBank.MUSHROOM_BEACH; - } - - @Override - public boolean forceDefaultToBeach() { - return true; - } + } + + @Override + public @NotNull BiomeBank getBeachType() { + return BiomeBank.MUSHROOM_BEACH; + } + + @Override + public boolean forceDefaultToBeach() { + return true; + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/OceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/OceansHandler.java index 7c38e9be..926fb0bb 100644 --- a/common/src/main/java/org/terraform/biome/ocean/OceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/OceansHandler.java @@ -18,49 +18,60 @@ public class OceansHandler extends AbstractOceanHandler { public OceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @Override public @NotNull Biome getBiome() { - if(this.oceanType == BiomeType.DEEP_OCEANIC) - return Biome.DEEP_OCEAN; + if (this.oceanType == BiomeType.DEEP_OCEANIC) { + return Biome.DEEP_OCEAN; + } return Biome.OCEAN; } @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRAVEL, - Material.GRAVEL, + return new Material[] { + Material.GRAVEL, + Material.GRAVEL, GenUtils.randChoice(rand, Material.STONE, Material.GRAVEL, Material.STONE), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - boolean growsKelp = world.getHashedRand(rawX>>4,rawZ>>4,371412).nextBoolean(); + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + boolean growsKelp = world.getHashedRand(rawX >> 4, rawZ >> 4, 371412).nextBoolean(); // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 10, 100)) { // SEA GRASS/KELP CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); - } else if (GenUtils.chance(random, 3, 50) - && growsKelp - && surfaceY + 1 < TerraformGenerator.seaLevel - 10) { + } + else if (GenUtils.chance(random, 3, 50) && growsKelp && surfaceY + 1 < TerraformGenerator.seaLevel - 10) { generateKelp(rawX, surfaceY + 1, rawZ, data, random); } } @@ -71,35 +82,34 @@ private void generateKelp(int x, int y, int z, @NotNull PopulatorDataAbstract da } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/ocean/WarmOceansHandler.java b/common/src/main/java/org/terraform/biome/ocean/WarmOceansHandler.java index cc80c061..e66d2c93 100644 --- a/common/src/main/java/org/terraform/biome/ocean/WarmOceansHandler.java +++ b/common/src/main/java/org/terraform/biome/ocean/WarmOceansHandler.java @@ -17,11 +17,11 @@ public class WarmOceansHandler extends AbstractOceanHandler { public WarmOceansHandler(BiomeType oceanType) { - super(oceanType); - // TODO Auto-generated constructor stub - } + super(oceanType); + // TODO Auto-generated constructor stub + } - @Override + @Override public boolean isOcean() { return true; } @@ -33,61 +33,72 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.GRAVEL, - Material.GRAVEL, + return new Material[] { + Material.GRAVEL, + Material.GRAVEL, GenUtils.randChoice(rand, Material.STONE, Material.GRAVEL, Material.STONE), GenUtils.randChoice(rand, Material.STONE), - GenUtils.randChoice(rand, Material.STONE)}; + GenUtils.randChoice(rand, Material.STONE) + }; } @Override - public void populateSmallItems(TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } if (GenUtils.chance(random, 10, 100)) { // SEA GRASS/KELP data.setType(rawX, surfaceY + 1, rawZ, Material.SEAGRASS); - if (random.nextBoolean() && surfaceY < TerraformGenerator.seaLevel - 3) + if (random.nextBoolean() && surfaceY < TerraformGenerator.seaLevel - 3) { BlockUtils.setDoublePlant(data, rawX, surfaceY + 1, rawZ, Material.TALL_SEAGRASS); + } } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - - // Spawn rocks - SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); - + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + + // Spawn rocks + SimpleLocation[] rocks = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 25, 0.4f); + for (SimpleLocation sLoc : rocks) { - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome()) { - int rockY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome()) { + int rockY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(rockY); - if(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()) != Material.GRAVEL) - continue; - - BlockUtils.replaceSphere( - random.nextInt(9987), - (float) GenUtils.randDouble(random, 3, 7), - (float) GenUtils.randDouble(random, 2, 4), - (float) GenUtils.randDouble(random, 3, 7), - new SimpleBlock(data,sLoc), - true, - GenUtils.randChoice( - Material.STONE, - Material.GRANITE, - Material.ANDESITE, - Material.DIORITE - )); + if (data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()) != Material.GRAVEL) { + continue; + } + + BlockUtils.replaceSphere(random.nextInt(9987), + (float) GenUtils.randDouble(random, 3, 7), + (float) GenUtils.randDouble(random, 2, 4), + (float) GenUtils.randDouble(random, 3, 7), + new SimpleBlock(data, sLoc), + true, + GenUtils.randChoice(Material.STONE, Material.GRANITE, Material.ANDESITE, Material.DIORITE) + ); } } - } + } } diff --git a/common/src/main/java/org/terraform/biome/river/BadlandsRiverHandler.java b/common/src/main/java/org/terraform/biome/river/BadlandsRiverHandler.java index f3a77934..dfe1dd52 100644 --- a/common/src/main/java/org/terraform/biome/river/BadlandsRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/BadlandsRiverHandler.java @@ -9,8 +9,14 @@ public class BadlandsRiverHandler extends RiverHandler { @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - super.populateSmallItems(world, random,rawX, surfaceY, rawZ, data); + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + super.populateSmallItems(world, random, rawX, surfaceY, rawZ, data); OasisRiver.generateOasisRiver(world, random, data, rawX, rawZ, BiomeBank.BADLANDS); } } diff --git a/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java b/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java index fc8b3fb6..c8a5659a 100644 --- a/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java @@ -17,9 +17,10 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; + import java.util.Random; public class BogRiverHandler extends BiomeHandler { @@ -42,12 +43,13 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.DIRT, + return new Material[] { + Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override @@ -56,9 +58,17 @@ public BiomeHandler getTransformHandler() { } @Override - public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld tw, Random random, ChunkGenerator.@NotNull ChunkData chunk, int x, int z, int chunkX, int chunkZ) { - int rawX = chunkX*16+x; - int rawZ = chunkZ*16+z; + public void transformTerrain(@NotNull ChunkCache cache, + @NotNull TerraformWorld tw, + Random random, + ChunkGenerator.@NotNull ChunkData chunk, + int x, + int z, + int chunkX, + int chunkZ) + { + int rawX = chunkX * 16 + x; + int rawZ = chunkZ * 16 + z; FastNoise sinkin = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_MUDDYBOG_HEIGHTMAP, world -> { FastNoise n = new FastNoise((int) tw.getSeed()); @@ -69,40 +79,52 @@ public void transformTerrain(@NotNull ChunkCache cache, @NotNull TerraformWorld }); double noise = sinkin.GetNoise(rawX, rawZ); - if(noise > -0.2) { + if (noise > -0.2) { noise += 0.5; - if(noise > 1.05) noise = 1.05; - if(cache.getTransformedHeight(x,z) < TerraformGenerator.seaLevel){ - double maxHeight = (TerraformGenerator.seaLevel - cache.getTransformedHeight(x,z)) + 2.0; - int height = (int) Math.round((maxHeight*noise)); - - if (tw.getBiomeBank(rawX,rawZ) != BiomeBank.BOG_RIVER - && tw.getBiomeBank(rawX,rawZ) != BiomeBank.MUDDY_BOG - && tw.getBiomeBank(rawX,rawZ) != BiomeBank.BOG_BEACH) + if (noise > 1.05) { + noise = 1.05; + } + if (cache.getTransformedHeight(x, z) < TerraformGenerator.seaLevel) { + double maxHeight = (TerraformGenerator.seaLevel - cache.getTransformedHeight(x, z)) + 2.0; + int height = (int) Math.round((maxHeight * noise)); + + if (tw.getBiomeBank(rawX, rawZ) != BiomeBank.BOG_RIVER + && tw.getBiomeBank(rawX, rawZ) != BiomeBank.MUDDY_BOG + && tw.getBiomeBank(rawX, rawZ) != BiomeBank.BOG_BEACH) + { height = 0; - - for(int newHeight = 1; newHeight <= height; newHeight++) - chunk.setBlock(x,cache.getTransformedHeight(x,z)+newHeight,z,Material.DIRT); - - if(height >= 1) - cache.writeTransformedHeight(x,z, (short) (cache.getTransformedHeight(x,z)+height)); - if(cache.getTransformedHeight(x,z) >= TerraformGenerator.seaLevel) - chunk.setBlock(x,cache.getTransformedHeight(x,z),z,Material.GRASS_BLOCK); + } + + for (int newHeight = 1; newHeight <= height; newHeight++) { + chunk.setBlock(x, cache.getTransformedHeight(x, z) + newHeight, z, Material.DIRT); + } + + if (height >= 1) { + cache.writeTransformedHeight(x, z, (short) (cache.getTransformedHeight(x, z) + height)); + } + if (cache.getTransformedHeight(x, z) >= TerraformGenerator.seaLevel) { + chunk.setBlock(x, cache.getTransformedHeight(x, z), z, Material.GRASS_BLOCK); + } } } } @Override - public void populateSmallItems(@NotNull TerraformWorld tw, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(@NotNull TerraformWorld tw, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { // Dry decorations new MuddyBogHandler().populateSmallItems(tw, random, rawX, surfaceY, rawZ, data); - - // Water decorations - - SimpleBlock block = new SimpleBlock(data,rawX,surfaceY,rawZ); - if(BlockUtils.isWet(block.getUp())) - { + + // Water decorations + + SimpleBlock block = new SimpleBlock(data, rawX, surfaceY, rawZ); + if (BlockUtils.isWet(block.getUp())) { // SEA GRASS/KELP RiverHandler.riverVegetation(tw, random, data, rawX, surfaceY, rawZ); @@ -114,10 +136,13 @@ public void populateSmallItems(@NotNull TerraformWorld tw, @NotNull Random rando } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - new MuddyBogHandler().populateLargeItems(tw, random, data); - } + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data) + { + new MuddyBogHandler().populateLargeItems(tw, random, data); + } } diff --git a/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java b/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java index c23cad28..5b3e8dee 100644 --- a/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java @@ -25,6 +25,7 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.RIVER; } + @Override public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.CHERRY_GROVE; @@ -32,21 +33,32 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.DIRT, + return new Material[] { + Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } // SEA GRASS/KELP RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); @@ -57,11 +69,11 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java b/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java index 012be803..6e6d252e 100644 --- a/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java @@ -29,32 +29,43 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.RIVER; } - + @Override public Material @NotNull [] getSurfaceCrust(Random rand) { - return new Material[]{ - Material.DIRT, Material.PODZOL, - Material.STONE, - Material.STONE}; + return new Material[] { + Material.DIRT, Material.PODZOL, Material.STONE, Material.STONE + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } // Set ground near sea level to coarse dirt - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.COARSE_DIRT); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.COARSE_DIRT); + } } // Don't generate kelp on non-stonelike. - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } // SEA GRASS/KELP RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); @@ -64,31 +75,42 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } - if(GenUtils.chance(random, 1, 1000)) { - BlockUtils.replaceCircularPatch(random.nextInt(9999), 2.0f, new SimpleBlock(data,rawX,surfaceY,rawZ), Material.MAGMA_BLOCK); + if (GenUtils.chance(random, 1, 1000)) { + BlockUtils.replaceCircularPatch( + random.nextInt(9999), + 2.0f, + new SimpleBlock(data, rawX, surfaceY, rawZ), + Material.MAGMA_BLOCK + ); } } - @Override - public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { - SimpleLocation[] roots = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7, 0.6f); + @Override + public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data) { + SimpleLocation[] roots = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 7, 0.6f); SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 24); for (SimpleLocation sLoc : bigTrees) { - int treeY = GenUtils.getHighestGround(data, sLoc.getX(),sLoc.getZ()); - sLoc.setY(treeY); - if (data.getBiome(sLoc.getX(),sLoc.getZ()) == getBiome() && - BlockUtils.isDirtLike(data.getType(sLoc.getX(),sLoc.getY(),sLoc.getZ()))) { - treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); - - if(treeY < TerraformGenerator.seaLevel) { - // Don't do gradient checks for swamp trees, the mud is uneven. - // just make sure it's submerged - TreeDB.spawnBreathingRoots(tw, new SimpleBlock(data,sLoc), OneOneNineBlockHandler.MANGROVE_ROOTS); - FractalTypes.Tree.SWAMP_TOP.build(tw, new SimpleBlock(data,sLoc), (t)->t.setCheckGradient(false)); - } - } - } - } + int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + sLoc.setY(treeY); + if (data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), + sLoc.getY(), + sLoc.getZ()))) + { + treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); + + if (treeY < TerraformGenerator.seaLevel) { + // Don't do gradient checks for swamp trees, the mud is uneven. + // just make sure it's submerged + TreeDB.spawnBreathingRoots(tw, new SimpleBlock(data, sLoc), OneOneNineBlockHandler.MANGROVE_ROOTS); + FractalTypes.Tree.SWAMP_TOP.build( + tw, + new SimpleBlock(data, sLoc), + (t) -> t.setCheckGradient(false) + ); + } + } + } + } } diff --git a/common/src/main/java/org/terraform/biome/river/DesertRiverHandler.java b/common/src/main/java/org/terraform/biome/river/DesertRiverHandler.java index 9a3ef1c0..ade73d4e 100644 --- a/common/src/main/java/org/terraform/biome/river/DesertRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/DesertRiverHandler.java @@ -9,7 +9,13 @@ public class DesertRiverHandler extends RiverHandler { @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { super.populateSmallItems(world, random, rawX, surfaceY, rawZ, data); OasisRiver.generateOasisRiver(world, random, data, rawX, rawZ, BiomeBank.DESERT); } diff --git a/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java b/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java index ce76c40a..44754bda 100644 --- a/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java @@ -25,36 +25,51 @@ public boolean isOcean() { return Biome.FROZEN_RIVER; } - @Override + @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{Material.DIRT, + return new Material[] { + Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - boolean growsKelp = world.getHashedRand(rawX>>4,rawZ>>4,14979813).nextBoolean(); - - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + boolean growsKelp = world.getHashedRand(rawX >> 4, rawZ >> 4, 14979813).nextBoolean(); + + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } // Ice - if (!data.getType(rawX, TerraformGenerator.seaLevel, rawZ).isSolid()) + if (!data.getType(rawX, TerraformGenerator.seaLevel, rawZ).isSolid()) { data.setType(rawX, TerraformGenerator.seaLevel, rawZ, Material.ICE); + } // Set ground near sea level to gravel - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.GRAVEL); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); @@ -63,11 +78,11 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub + + } } diff --git a/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java b/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java index 47ca263e..9aaca11b 100644 --- a/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java @@ -19,6 +19,45 @@ public class JungleRiverHandler extends BiomeHandler { + /** + * Generate random lily pads in jungle rivers + * Deeper waters -> less pads. Noise makes sure they are in groups + */ + public static void generateLilyPad(TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int z, + int highestGround) + { + if (GenUtils.chance( + random, + 1, + (int) (getLilyPadNoise(tw, x, z) * 7 + Math.pow(TerraformGenerator.seaLevel - highestGround, 3) + 18) + )) + { + PlantBuilder.LILY_PAD.build(data, x, TerraformGenerator.seaLevel + 1, z); + } + } + + public static void generateKelp(int x, int y, int z, @NotNull PopulatorDataAbstract data, @NotNull Random random) { + for (int ny = y; ny < TerraformGenerator.seaLevel - GenUtils.randInt(random, 0, 2); ny++) { + PlantBuilder.KELP_PLANT.build(data, x, ny, z); + } + } + + public static double getLilyPadNoise(TerraformWorld tw, int x, int z) { + FastNoise lilyPadNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_JUNGLE_LILYPADS, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 2)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.05f); + + return n; + }); + + return lilyPadNoise.GetNoise(x, z); + } + @Override public boolean isOcean() { return true; @@ -31,30 +70,42 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ + return new Material[] { Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } - @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean growsKelp = random.nextBoolean(); - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } generateLilyPad(world, random, data, rawX, rawZ, surfaceY); @@ -66,41 +117,10 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } } - /** - * Generate random lily pads in jungle rivers - * Deeper waters -> less pads. Noise makes sure they are in groups - */ - public static void generateLilyPad(TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int z, int highestGround) { - if (GenUtils.chance(random, 1, (int) (getLilyPadNoise(tw, x, z) * 7 + Math.pow(TerraformGenerator.seaLevel - highestGround, 3) + 18))) { - PlantBuilder.LILY_PAD.build(data, x, TerraformGenerator.seaLevel + 1, z); - } - } - - public static void generateKelp(int x, int y, int z, @NotNull PopulatorDataAbstract data, @NotNull Random random) { - for (int ny = y; ny < TerraformGenerator.seaLevel - GenUtils.randInt(random, 0, 2); ny++) { - PlantBuilder.KELP_PLANT.build(data, x, ny, z); - } - } - - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } - - public static double getLilyPadNoise(TerraformWorld tw, int x, int z) { - FastNoise lilyPadNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_JUNGLE_LILYPADS, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 2)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.05f); - - return n; - }); + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub - return lilyPadNoise.GetNoise(x, z); } } diff --git a/common/src/main/java/org/terraform/biome/river/OasisRiver.java b/common/src/main/java/org/terraform/biome/river/OasisRiver.java index f7dc28bd..99c80c87 100644 --- a/common/src/main/java/org/terraform/biome/river/OasisRiver.java +++ b/common/src/main/java/org/terraform/biome/river/OasisRiver.java @@ -25,13 +25,21 @@ private static boolean isOasisRiver(TerraformWorld tw, int x, int z, BiomeBank t int height = HeightMap.getBlockHeight(tw, x, z); BiomeBank biome = BiomeBank.calculateHeightIndependentBiome(tw, x, z); - return lushRiverNoiseValue > OasisBeach.oasisThreshold && - height < TerraformGenerator.seaLevel && - targetBiome == biome; + return lushRiverNoiseValue > OasisBeach.oasisThreshold + && height < TerraformGenerator.seaLevel + && targetBiome == biome; } - public static void generateOasisRiver(TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int z, BiomeBank targetBiome) { - if (!isOasisRiver(tw, x, z, targetBiome)) return; + public static void generateOasisRiver(TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int z, + BiomeBank targetBiome) + { + if (!isOasisRiver(tw, x, z, targetBiome)) { + return; + } int riverBottom = GenUtils.getHighestGround(data, x, z); @@ -41,13 +49,16 @@ public static void generateOasisRiver(TerraformWorld tw, @NotNull Random random, // Kelp and sea grass if (random.nextInt(4) == 0) { JungleRiverHandler.generateKelp(x, riverBottom + 1, z, data, random); - } else if (random.nextInt(5) == 0) { + } + else if (random.nextInt(5) == 0) { if (random.nextBoolean()) { data.setType(x, riverBottom + 1, z, Material.SEAGRASS); - } else if (riverBottom + 1 < TerraformGenerator.seaLevel){ + } + else if (riverBottom + 1 < TerraformGenerator.seaLevel) { BlockUtils.setDoublePlant(data, x, riverBottom + 1, z, Material.TALL_SEAGRASS); } - } else if (random.nextInt(13) == 0) { + } + else if (random.nextInt(13) == 0) { data.setType(x, riverBottom + 1, z, Material.SEA_PICKLE); } } diff --git a/common/src/main/java/org/terraform/biome/river/RiverHandler.java b/common/src/main/java/org/terraform/biome/river/RiverHandler.java index a734b18e..2e042aef 100644 --- a/common/src/main/java/org/terraform/biome/river/RiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/RiverHandler.java @@ -16,6 +16,49 @@ public class RiverHandler extends BiomeHandler { + public static void riverVegetation(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int rawX, + int surfaceY, + int rawZ) + { + boolean growsKelp = tw.getHashedRand(rawX >> 4, rawZ >> 4, 97418).nextBoolean(); + if (GenUtils.chance(random, 10, 100)) { + generateSeagrass(rawX, surfaceY + 1, rawZ, data); + if (random.nextBoolean()) { + generateTallSeagrass(rawX, surfaceY + 1, rawZ, data); + } + } + else if (GenUtils.chance(random, 3, 50) && growsKelp && surfaceY + 1 < TerraformGenerator.seaLevel - 10) { + generateKelp(rawX, surfaceY + 1, rawZ, data, random); + } + } + + public static void generateSeagrass(int x, int y, int z, @NotNull PopulatorDataAbstract data) { + if (data.getType(x, y, z) != Material.WATER) { + return; + } + PlantBuilder.SEAGRASS.build(data, x, y, z); + + } + + public static void generateTallSeagrass(int x, int y, int z, @NotNull PopulatorDataAbstract data) { + if (data.getType(x, y, z) != Material.WATER || data.getType(x, y, z) != Material.WATER) { + return; + } + PlantBuilder.TALL_SEAGRASS.build(data, x, y, z); + } + + private static void generateKelp(int x, int y, int z, @NotNull PopulatorDataAbstract data, Random random) { + for (int ny = y; ny < TerraformGenerator.seaLevel - GenUtils.randInt(5, 15); ny++) { + if (data.getType(x, ny, z) != Material.WATER) { + break; + } + PlantBuilder.KELP_PLANT.build(data, x, ny, z); + } + } + @Override public boolean isOcean() { return true; @@ -28,29 +71,41 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.DIRT, + return new Material[] { + Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } - @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } // Set ground near sea level to sand - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.SAND); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.SAND); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } // SEA GRASS/KELP riverVegetation(world, random, data, rawX, surfaceY, rawZ); @@ -61,37 +116,11 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } } - public static void riverVegetation(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int rawX, int surfaceY, int rawZ){ - boolean growsKelp = tw.getHashedRand(rawX>>4, rawZ>>4, 97418).nextBoolean(); - if (GenUtils.chance(random, 10, 100)) { - generateSeagrass(rawX, surfaceY + 1, rawZ, data); - if (random.nextBoolean()) - generateTallSeagrass(rawX, surfaceY + 1, rawZ, data); - } else if (GenUtils.chance(random, 3, 50) && growsKelp && surfaceY + 1 < TerraformGenerator.seaLevel - 10) { - generateKelp(rawX, surfaceY + 1, rawZ, data, random); - } - } - public static void generateSeagrass(int x, int y, int z, @NotNull PopulatorDataAbstract data) { - if(data.getType(x,y,z) != Material.WATER) return; - PlantBuilder.SEAGRASS.build(data, x,y,z); + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + // TODO Auto-generated method stub } - public static void generateTallSeagrass(int x, int y, int z, @NotNull PopulatorDataAbstract data) { - if(data.getType(x,y,z) != Material.WATER || data.getType(x,y,z) != Material.WATER) return; - PlantBuilder.TALL_SEAGRASS.build(data, x,y,z); - } - private static void generateKelp(int x, int y, int z, @NotNull PopulatorDataAbstract data, Random random) { - for (int ny = y; ny < TerraformGenerator.seaLevel - GenUtils.randInt(5, 15); ny++) { - if(data.getType(x,ny,z) != Material.WATER) break; - PlantBuilder.KELP_PLANT.build(data, x,ny,z); - } - } - - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - // TODO Auto-generated method stub - - } } diff --git a/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java b/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java index 5d8784a3..ffb74e2d 100644 --- a/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java @@ -25,6 +25,7 @@ public boolean isOcean() { public @NotNull Biome getBiome() { return Biome.RIVER; } + @Override public @NotNull CustomBiomeType getCustomBiome() { return CustomBiomeType.SCARLET_FOREST; @@ -32,31 +33,44 @@ public boolean isOcean() { @Override public Material @NotNull [] getSurfaceCrust(@NotNull Random rand) { - return new Material[]{ - Material.DIRT, + return new Material[] { + Material.DIRT, Material.DIRT, GenUtils.randChoice(rand, Material.DIRT, Material.STONE, Material.DIRT), GenUtils.randChoice(rand, Material.DIRT, Material.STONE), - GenUtils.randChoice(rand, Material.DIRT, Material.STONE)}; + GenUtils.randChoice(rand, Material.DIRT, Material.STONE) + }; } @Override - public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random random, int rawX, int surfaceY, int rawZ, @NotNull PopulatorDataAbstract data) { + public void populateSmallItems(@NotNull TerraformWorld world, + @NotNull Random random, + int rawX, + int surfaceY, + int rawZ, + @NotNull PopulatorDataAbstract data) + { boolean growsKelp = random.nextBoolean(); - if(surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + if (surfaceY >= TerraformGenerator.seaLevel) // Don't apply to dry land + { return; + } // Set ground near sea level to concrete - if(surfaceY >= TerraformGenerator.seaLevel - 2) { + if (surfaceY >= TerraformGenerator.seaLevel - 2) { data.setType(rawX, surfaceY, rawZ, Material.WHITE_CONCRETE); - }else if(surfaceY >= TerraformGenerator.seaLevel - 4) { - if(random.nextBoolean()) + } + else if (surfaceY >= TerraformGenerator.seaLevel - 4) { + if (random.nextBoolean()) { data.setType(rawX, surfaceY, rawZ, Material.WHITE_CONCRETE); + } } - if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) return; + if (!BlockUtils.isStoneLike(data.getType(rawX, surfaceY, rawZ))) { + return; + } // SEA GRASS/KELP RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); @@ -67,10 +81,10 @@ public void populateSmallItems(@NotNull TerraformWorld world, @NotNull Random ra } } - @Override - public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { + @Override + public void populateLargeItems(TerraformWorld tw, Random random, PopulatorDataAbstract data) { - } + } } diff --git a/common/src/main/java/org/terraform/cave/CheeseCave.java b/common/src/main/java/org/terraform/cave/CheeseCave.java index a225f8ee..705ff65d 100644 --- a/common/src/main/java/org/terraform/cave/CheeseCave.java +++ b/common/src/main/java/org/terraform/cave/CheeseCave.java @@ -5,20 +5,24 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.NoiseCacheHandler; -public class CheeseCave extends NoiseCaveAbstract{ +public class CheeseCave extends NoiseCaveAbstract { @Override public boolean canCarve(@NotNull TerraformWorld tw, int rawX, int y, int rawZ, double height, float surfaceFilter) { - FastNoise cheeseNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheHandler.NoiseCacheEntry.CAVE_CHEESE_NOISE, world -> { - FastNoise n = new FastNoise((int) (tw.getSeed() + 723891)); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.03f); - n.SetFractalOctaves(2); - return n; - }); + FastNoise cheeseNoise = NoiseCacheHandler.getNoise( + tw, + NoiseCacheHandler.NoiseCacheEntry.CAVE_CHEESE_NOISE, + world -> { + FastNoise n = new FastNoise((int) (tw.getSeed() + 723891)); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.03f); + n.SetFractalOctaves(2); + return n; + } + ); // Stretch caves horizontally so that they're not excessively spherical - float cheese = cheeseNoise.GetNoise(rawX*0.5f,y,rawZ*0.5f); + float cheese = cheeseNoise.GetNoise(rawX * 0.5f, y, rawZ * 0.5f); - return surfaceFilter *cheese <= -0.3f; + return surfaceFilter * cheese <= -0.3f; } } diff --git a/common/src/main/java/org/terraform/cave/NoiseCaveAbstract.java b/common/src/main/java/org/terraform/cave/NoiseCaveAbstract.java index 8d441e49..bae5e858 100644 --- a/common/src/main/java/org/terraform/cave/NoiseCaveAbstract.java +++ b/common/src/main/java/org/terraform/cave/NoiseCaveAbstract.java @@ -9,7 +9,7 @@ public abstract class NoiseCaveAbstract { /** * @param surfaceFilter is a function of y that forces noise cave carvers to respect - * the world height and bedrock barriers. + * the world height and bedrock barriers. * @return if not null, that means a cave can be carved at this location with * specified material. */ diff --git a/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java b/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java index 03431c95..e8537e20 100644 --- a/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java +++ b/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java @@ -14,33 +14,41 @@ public class NoiseCaveRegistry { public NoiseCaveRegistry(TerraformWorld tw) { this.tw = tw; - this.noiseCaveCarvers = new NoiseCaveAbstract[]{ + this.noiseCaveCarvers = new NoiseCaveAbstract[] { new CheeseCave() }; - this.generateCaveCarvers = new NoiseCaveAbstract[]{ + this.generateCaveCarvers = new NoiseCaveAbstract[] { new NoiseRavine() }; } - public boolean canNoiseCarve(int x, int y, int z, double height){ - if(!TConfigOption.areCavesEnabled()) return false; + public boolean canNoiseCarve(int x, int y, int z, double height) { + if (!TConfigOption.areCavesEnabled()) { + return false; + } - float filterHeight = yBarrier(tw, x,y,z, (float)height, 10, 5); - float filterGround = yBarrier(tw, x,y,z, (float) TerraformGeneratorPlugin.injector.getMinY(), 20, 5); - float filter = filterHeight*filterGround; - for(NoiseCaveAbstract carver:noiseCaveCarvers) { - if(carver.canCarve(tw, x, y, z, height, filter)) return true; + float filterHeight = yBarrier(tw, x, y, z, (float) height, 10, 5); + float filterGround = yBarrier(tw, x, y, z, (float) TerraformGeneratorPlugin.injector.getMinY(), 20, 5); + float filter = filterHeight * filterGround; + for (NoiseCaveAbstract carver : noiseCaveCarvers) { + if (carver.canCarve(tw, x, y, z, height, filter)) { + return true; + } } return false; } - public boolean canGenerateCarve(int x, int y, int z, double height){ - if(!TConfigOption.areCavesEnabled()) return false; + public boolean canGenerateCarve(int x, int y, int z, double height) { + if (!TConfigOption.areCavesEnabled()) { + return false; + } // The sea filter is special, pass in HEIGHT as it's about scaling towards the sea - float filterSea = yBarrier(tw, x,(int)height,z, TerraformGenerator.seaLevel, 5, 1); - for(NoiseCaveAbstract carver:generateCaveCarvers) { - if(carver.canCarve(tw, x, y, z, height, filterSea)) return true; + float filterSea = yBarrier(tw, x, (int) height, z, TerraformGenerator.seaLevel, 5, 1); + for (NoiseCaveAbstract carver : generateCaveCarvers) { + if (carver.canCarve(tw, x, y, z, height, filterSea)) { + return true; + } } return false; } @@ -49,24 +57,28 @@ public boolean canGenerateCarve(int x, int y, int z, double height){ * Used to prevent functions from passing certain thresholds. * Useful for stuff like preventing caves from breaking out * the surface or under minimum Y + * * @return a value between 0 and 1 inclusive. 1 for all clear, * less than 1 to smooth an approach towards a barrier. */ - public float yBarrier(@NotNull TerraformWorld tw, float x, float y, float z, float v, float barrier, float limit){ + public float yBarrier(@NotNull TerraformWorld tw, float x, float y, float z, float v, float barrier, float limit) { - FastNoise boundaryNoise = new FastNoise((int) tw.getSeed()*5); + FastNoise boundaryNoise = new FastNoise((int) tw.getSeed() * 5); boundaryNoise.SetNoiseType(FastNoise.NoiseType.Simplex); boundaryNoise.SetFrequency(0.01f); - barrier += 3*boundaryNoise.GetNoise(x,z); // fuzz the boundary + barrier += 3 * boundaryNoise.GetNoise(x, z); // fuzz the boundary - if(Math.abs(y-v) <= limit) + if (Math.abs(y - v) <= limit) { return 0; + } else { float abs = Math.abs(y - v); - if(abs < barrier+limit) - return (abs-limit)/barrier; - else + if (abs < barrier + limit) { + return (abs - limit) / barrier; + } + else { return 1; + } } } } diff --git a/common/src/main/java/org/terraform/cave/NoiseRavine.java b/common/src/main/java/org/terraform/cave/NoiseRavine.java index c52c57e1..dc295791 100644 --- a/common/src/main/java/org/terraform/cave/NoiseRavine.java +++ b/common/src/main/java/org/terraform/cave/NoiseRavine.java @@ -6,39 +6,52 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.NoiseCacheHandler; -public class NoiseRavine extends NoiseCaveAbstract{ +public class NoiseRavine extends NoiseCaveAbstract { private static final int RAVINE_DEPTH = 50; + /** * Use similar logic to Rivers to carve ravines, filtered against Y-height relative to the sea. */ @Override public boolean canCarve(@NotNull TerraformWorld tw, int rawX, int y, int rawZ, double height, float filter) { - if(height < TerraformGenerator.seaLevel) return false; // Hard filter. - if(y < height-RAVINE_DEPTH) return false; - FastNoise ravineNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheHandler.NoiseCacheEntry.CAVE_XRAVINE_NOISE, world -> { - FastNoise n = new FastNoise(tw.getHashedRand(458930,16328,54981).nextInt()); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.007f); - n.SetFractalOctaves(3); - return n; - }); - FastNoise ravineFilter = NoiseCacheHandler.getNoise(tw, NoiseCacheHandler.NoiseCacheEntry.CAVE_XRAVINE_DETAILS, world -> { - FastNoise n = new FastNoise(tw.getHashedRand(156274631,456912,23458).nextInt()); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - n.SetFrequency(0.03f); - n.SetFractalOctaves(2); - return n; - }); + if (height < TerraformGenerator.seaLevel) { + return false; // Hard filter. + } + if (y < height - RAVINE_DEPTH) { + return false; + } + FastNoise ravineNoise = NoiseCacheHandler.getNoise( + tw, + NoiseCacheHandler.NoiseCacheEntry.CAVE_XRAVINE_NOISE, + world -> { + FastNoise n = new FastNoise(tw.getHashedRand(458930, 16328, 54981).nextInt()); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.007f); + n.SetFractalOctaves(3); + return n; + } + ); + FastNoise ravineFilter = NoiseCacheHandler.getNoise( + tw, + NoiseCacheHandler.NoiseCacheEntry.CAVE_XRAVINE_DETAILS, + world -> { + FastNoise n = new FastNoise(tw.getHashedRand(156274631, 456912, 23458).nextInt()); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + n.SetFrequency(0.03f); + n.SetFractalOctaves(2); + return n; + } + ); - float xzStretcher = ravineFilter.GetNoise(rawX,rawZ); - float sign = xzStretcher/Math.abs(xzStretcher); + float xzStretcher = ravineFilter.GetNoise(rawX, rawZ); + float sign = xzStretcher / Math.abs(xzStretcher); // Stretch caves vertically so that they're not excessively spherical - float ravine = ravineNoise.GetNoise(3*rawX,y*0.4f,3*rawZ); + float ravine = ravineNoise.GetNoise(3 * rawX, y * 0.4f, 3 * rawZ); // Multiply by a filter that varies with depth relative to height. // At depth 50 blocks, force to 0 - ravine *= (float) (filter*0.5885*Math.log(RAVINE_DEPTH+1-(height-y))); // ASSUMPTION: y <= height. + ravine *= (float) (filter * 0.5885 * Math.log(RAVINE_DEPTH + 1 - (height - y))); // ASSUMPTION: y <= height. return ravine <= -1.3f; } -// private static float smallest = 0; + // private static float smallest = 0; } diff --git a/common/src/main/java/org/terraform/command/BiomeConsoleCheckCommand.java b/common/src/main/java/org/terraform/command/BiomeConsoleCheckCommand.java index eeace2df..45c0dc79 100644 --- a/common/src/main/java/org/terraform/command/BiomeConsoleCheckCommand.java +++ b/common/src/main/java/org/terraform/command/BiomeConsoleCheckCommand.java @@ -36,20 +36,20 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(@NotNull CommandSender sender, Stack args) - { - World world = Bukkit.getWorld("world"); - for(int i = 0; i < 10; i++) { - int x = new Random().nextInt(1000); - int z = new Random().nextInt(1000); - - BiomeBank bank = TerraformWorld.get(world).getBiomeBank(x, z); - - sender.sendMessage("[Iteration] " + i + " (" + x + "," + z + ")"); - sender.sendMessage(" BiomeBank: " + bank + " (" + bank.getHandler().getBiome() + ")"); - sender.sendMessage(" Minecraft Biome [0]" + world.getBiome(x, 0, z)); - sender.sendMessage(" Minecraft Biome [60]" + world.getBiome(x, 60, z)); - sender.sendMessage(" Minecraft Biome [300]" + world.getBiome(x, 300, z)); - } + { + World world = Bukkit.getWorld("world"); + for (int i = 0; i < 10; i++) { + int x = new Random().nextInt(1000); + int z = new Random().nextInt(1000); + + BiomeBank bank = TerraformWorld.get(world).getBiomeBank(x, z); + + sender.sendMessage("[Iteration] " + i + " (" + x + "," + z + ")"); + sender.sendMessage(" BiomeBank: " + bank + " (" + bank.getHandler().getBiome() + ")"); + sender.sendMessage(" Minecraft Biome [0]" + world.getBiome(x, 0, z)); + sender.sendMessage(" Minecraft Biome [60]" + world.getBiome(x, 60, z)); + sender.sendMessage(" Minecraft Biome [300]" + world.getBiome(x, 300, z)); + } } } diff --git a/common/src/main/java/org/terraform/command/BiomeDistribCommand.java b/common/src/main/java/org/terraform/command/BiomeDistribCommand.java index ea334061..63658f6c 100644 --- a/common/src/main/java/org/terraform/command/BiomeDistribCommand.java +++ b/common/src/main/java/org/terraform/command/BiomeDistribCommand.java @@ -10,6 +10,7 @@ import org.terraform.command.contants.TerraCommand; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; + import java.util.HashMap; import java.util.Random; import java.util.Stack; @@ -38,91 +39,113 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(@NotNull CommandSender sender, Stack args) { - HashMap counts = new HashMap<>(); - HashMap climates = new HashMap<>(); + HashMap counts = new HashMap<>(); + HashMap climates = new HashMap<>(); MathValues temperature = new MathValues(); MathValues moisture = new MathValues(); double numOceans = 0; double numMountains = 0; - double total = 0; + double total = 0; TerraformWorld tw = TerraformWorld.get("world-" + new Random().nextInt(99999), new Random().nextInt(99999)); - for(int nx = -50; nx < 50; nx++) - for(int nz = -50; nz < 50; nz++) { - BiomeSection sect = BiomeBank.getBiomeSectionFromSectionCoords(tw, nx, nz, true); - if(sect.getBiomeBank().getType() == BiomeType.OCEANIC || sect.getBiomeBank().getType() == BiomeType.DEEP_OCEANIC) { - numOceans++; - } - if(sect.getBiomeBank().getType() == BiomeType.MOUNTAINOUS - || sect.getBiomeBank().getType() == BiomeType.HIGH_MOUNTAINOUS) - numMountains++; - - temperature.addValue(sect.getTemperature()); - moisture.addValue(sect.getMoisture()); - - if(!counts.containsKey(sect.getBiomeBank())) - counts.put(sect.getBiomeBank(), 1); - else - counts.put(sect.getBiomeBank(), counts.get(sect.getBiomeBank())+1); - - if(!climates.containsKey(sect.getBiomeBank().getClimate())) - climates.put(sect.getBiomeBank().getClimate(), 1); - else - climates.put(sect.getBiomeBank().getClimate(), climates.get(sect.getBiomeBank().getClimate())+1); - } - + for (int nx = -50; nx < 50; nx++) { + for (int nz = -50; nz < 50; nz++) { + BiomeSection sect = BiomeBank.getBiomeSectionFromSectionCoords(tw, nx, nz, true); + if (sect.getBiomeBank().getType() == BiomeType.OCEANIC + || sect.getBiomeBank().getType() == BiomeType.DEEP_OCEANIC) + { + numOceans++; + } + if (sect.getBiomeBank().getType() == BiomeType.MOUNTAINOUS + || sect.getBiomeBank().getType() == BiomeType.HIGH_MOUNTAINOUS) + { + numMountains++; + } + + temperature.addValue(sect.getTemperature()); + moisture.addValue(sect.getMoisture()); + + if (!counts.containsKey(sect.getBiomeBank())) { + counts.put(sect.getBiomeBank(), 1); + } + else { + counts.put(sect.getBiomeBank(), counts.get(sect.getBiomeBank()) + 1); + } + + if (!climates.containsKey(sect.getBiomeBank().getClimate())) { + climates.put(sect.getBiomeBank().getClimate(), 1); + } + else { + climates.put(sect.getBiomeBank().getClimate(), climates.get(sect.getBiomeBank().getClimate()) + 1); + } + } + } + sender.sendMessage("Temperature: " + temperature); sender.sendMessage("Moisture: " + moisture); - for(int val:counts.values()) total += val; - - - for(BiomeBank b:BiomeBank.values()) { - if(b.getType() != BiomeType.BEACH - && b.getType() != BiomeType.RIVER) { - String count = ""+counts.getOrDefault(b, 0); - String percent = "("+Math.round(100*counts.getOrDefault(b, 0)/total); - if(count.equals("0")) - count = ChatColor.RED + count; - if(100*counts.getOrDefault(b, 0)/total < 5) - percent = ChatColor.RED + percent; - - sender.sendMessage("%-35s(%-10s, %-10s): %-10s%s)" - .formatted(b.toString(), b.getClimate().getTemperatureRange(), b.getClimate().getMoistureRange(), - count, percent+"%)")); - } + for (int val : counts.values()) { + total += val; + } + + + for (BiomeBank b : BiomeBank.values()) { + if (b.getType() != BiomeType.BEACH && b.getType() != BiomeType.RIVER) { + String count = "" + counts.getOrDefault(b, 0); + String percent = "(" + Math.round(100 * counts.getOrDefault(b, 0) / total); + if (count.equals("0")) { + count = ChatColor.RED + count; + } + if (100 * counts.getOrDefault(b, 0) / total < 5) { + percent = ChatColor.RED + percent; + } + + sender.sendMessage("%-35s(%-10s, %-10s): %-10s%s)".formatted(b.toString(), + b.getClimate().getTemperatureRange(), + b.getClimate().getMoistureRange(), + count, + percent + "%)" + )); + } } - + sender.sendMessage("====================================="); - sender.sendMessage("Percent Ocean: " + (100.0*numOceans/total) + "%"); - sender.sendMessage("Percent Mountain: " + (100.0*numMountains/total) + "%"); + sender.sendMessage("Percent Ocean: " + (100.0 * numOceans / total) + "%"); + sender.sendMessage("Percent Mountain: " + (100.0 * numMountains / total) + "%"); sender.sendMessage("==================================="); total = 0; - for(int val:climates.values()) total += val; - for(BiomeClimate c:BiomeClimate.values()) { - String count = ""+climates.getOrDefault(c, 0); - String percent = "("+Math.round(100*climates.getOrDefault(c, 0)/total); - - if(count.equals("0")) - count = ChatColor.RED + count; - if(100*climates.getOrDefault(c, 0)/total < 5) - percent = ChatColor.RED + percent; - - int biomeTypes = 0; - for(BiomeBank b:BiomeBank.values()) - if(b.getClimate() == c && - (b.getType() == BiomeType.FLAT - || b.getType() == BiomeType.MOUNTAINOUS - || b.getType() == BiomeType.HIGH_MOUNTAINOUS)) - biomeTypes++; - - float biomesPerPercent = (float) (biomeTypes / (100*climates.getOrDefault(c, 0)/total));// Math.round(100*climates.getOrDefault(c, 0)/total)/((float)biomeTypes); - - sender.sendMessage("%-30s%-10s %-10s (%d registered biomes) (numBiomes/percent: %.2f)".formatted( - c.toString(), - count, - percent + "%)", - biomeTypes, - biomesPerPercent)); + for (int val : climates.values()) { + total += val; + } + for (BiomeClimate c : BiomeClimate.values()) { + String count = "" + climates.getOrDefault(c, 0); + String percent = "(" + Math.round(100 * climates.getOrDefault(c, 0) / total); + + if (count.equals("0")) { + count = ChatColor.RED + count; + } + if (100 * climates.getOrDefault(c, 0) / total < 5) { + percent = ChatColor.RED + percent; + } + + int biomeTypes = 0; + for (BiomeBank b : BiomeBank.values()) { + if (b.getClimate() == c && (b.getType() == BiomeType.FLAT + || b.getType() == BiomeType.MOUNTAINOUS + || b.getType() == BiomeType.HIGH_MOUNTAINOUS)) + { + biomeTypes++; + } + } + + float biomesPerPercent = (float) (biomeTypes / (100 * climates.getOrDefault(c, 0) + / total));// Math.round(100*climates.getOrDefault(c, 0)/total)/((float)biomeTypes); + + sender.sendMessage("%-30s%-10s %-10s (%d registered biomes) (numBiomes/percent: %.2f)".formatted(c.toString(), + count, + percent + "%)", + biomeTypes, + biomesPerPercent + )); } } @@ -138,8 +161,12 @@ public MathValues() { public void addValue(double value) { total += value; count++; - if (value < lowest) lowest = value; - if (value > highest) highest = value; + if (value < lowest) { + lowest = value; + } + if (value > highest) { + highest = value; + } } public double avg() { diff --git a/common/src/main/java/org/terraform/command/BiomeVisualiserCommand.java b/common/src/main/java/org/terraform/command/BiomeVisualiserCommand.java index 4fed375a..39def1a6 100644 --- a/common/src/main/java/org/terraform/command/BiomeVisualiserCommand.java +++ b/common/src/main/java/org/terraform/command/BiomeVisualiserCommand.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.command.contants.TerraCommand; import org.terraform.main.TerraformGeneratorPlugin; + import java.util.Stack; public class BiomeVisualiserCommand extends TerraCommand { @@ -36,20 +37,22 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(CommandSender sender, Stack args) { - Player p = (Player) sender; - World world = Bukkit.getWorld("world"); - // idk wtf im doing tbh this doesn't work - - for(int nx = -10; nx <= 10; nx++) - for(int nz = -10; nz <= 10; nz++) { - // Biome comp = TerraformWorld.get(world).getBiomeBank(p.getLocation().getBlockX() + nx, (p.getLocation().getBlockZ() + nz)).getHandler().getBiome(); - for(int y = 0; y < 130; y++) { - Location loc = new Location(world,p.getLocation().getX() + nx, y, p.getLocation().getZ() + nz); - Biome b = world.getBiome(loc); - if(b.toString().equals("PLAINS") && !world.getType(loc).isSolid()) - world.setType(loc, Material.RED_STAINED_GLASS); - } - } + Player p = (Player) sender; + World world = Bukkit.getWorld("world"); + // idk wtf im doing tbh this doesn't work + + for (int nx = -10; nx <= 10; nx++) { + for (int nz = -10; nz <= 10; nz++) { + // Biome comp = TerraformWorld.get(world).getBiomeBank(p.getLocation().getBlockX() + nx, (p.getLocation().getBlockZ() + nz)).getHandler().getBiome(); + for (int y = 0; y < 130; y++) { + Location loc = new Location(world, p.getLocation().getX() + nx, y, p.getLocation().getZ() + nz); + Biome b = world.getBiome(loc); + if (b.toString().equals("PLAINS") && !world.getType(loc).isSolid()) { + world.setType(loc, Material.RED_STAINED_GLASS); + } + } + } + } } } diff --git a/common/src/main/java/org/terraform/command/CaveCommand.java b/common/src/main/java/org/terraform/command/CaveCommand.java index 596a0459..0bfe4bcd 100644 --- a/common/src/main/java/org/terraform/command/CaveCommand.java +++ b/common/src/main/java/org/terraform/command/CaveCommand.java @@ -31,7 +31,7 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(@NotNull CommandSender sender, Stack args) - { + { sender.sendMessage("Unimplemented."); } } diff --git a/common/src/main/java/org/terraform/command/CheckHeightCommand.java b/common/src/main/java/org/terraform/command/CheckHeightCommand.java index de949b11..f8e74cc0 100644 --- a/common/src/main/java/org/terraform/command/CheckHeightCommand.java +++ b/common/src/main/java/org/terraform/command/CheckHeightCommand.java @@ -53,43 +53,66 @@ public void execute(CommandSender sender, Stack args) { BiomeBank.debugPrint = true; BiomeBank biome = tw.getBiomeBank(x, z); BiomeBank.debugPrint = false; - + BiomeSection section = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); p.sendMessage("[CH]==============================="); p.sendMessage("Core Height: " + HeightMap.CORE.getHeight(tw, x, z)); // p.sendMessage("Mountainous Height: " + HeightMap.MOUNTAIN.getHeight(tw, x, z)); p.sendMessage("Attrition Height: " + HeightMap.ATTRITION.getHeight(tw, x, z)); - p.sendMessage("Gradient (2,3,4): " + HeightMap.getNoiseGradient(tw, x, z, 2) + "," + HeightMap.getNoiseGradient(tw, x, z, 3) + "," + HeightMap.getNoiseGradient(tw, x, z,4)); - p.sendMessage("True Gradient (2,3,4): " + HeightMap.getTrueHeightGradient(data, x, z, 2) + "," + HeightMap.getTrueHeightGradient(data, x, z, 3) + "," + HeightMap.getTrueHeightGradient(data, x, z,4)); + p.sendMessage("Gradient (2,3,4): " + HeightMap.getNoiseGradient(tw, x, z, 2) + "," + HeightMap.getNoiseGradient( + tw, + x, + z, + 3 + ) + "," + HeightMap.getNoiseGradient(tw, x, z, 4)); + p.sendMessage("True Gradient (2,3,4): " + + HeightMap.getTrueHeightGradient(data, x, z, 2) + + "," + + HeightMap.getTrueHeightGradient(data, x, z, 3) + + "," + + HeightMap.getTrueHeightGradient(data, x, z, 4)); p.sendMessage("Result height: " + HeightMap.getBlockHeight(tw, x, z)); p.sendMessage("River Depth: " + HeightMap.getRawRiverDepth(tw, x, z)); p.sendMessage("Mega Chunk: " + mc.getX() + "," + mc.getZ()); p.sendMessage("Mega Chunk Center: " + mc.getCenterBlockCoords()[0] + "," + mc.getCenterBlockCoords()[1]); - p.sendMessage("Mega Chunk BiomeSection Center: " + mc.getCenterBiomeSectionBlockCoords()[0] + "," + mc.getCenterBiomeSectionBlockCoords()[1]); - + p.sendMessage("Mega Chunk BiomeSection Center: " + + mc.getCenterBiomeSectionBlockCoords()[0] + + "," + + mc.getCenterBiomeSectionBlockCoords()[1]); + p.sendMessage("Biome Section: " + section); p.sendMessage("Biome Section Climate: " + section.getClimate()); - p.sendMessage("Biome Section Elevation: " + section.getOceanLevel()); + p.sendMessage("Biome Section Elevation: " + section.getOceanLevel()); p.sendMessage("Surrounding Sections:"); - for(BiomeSection sect:BiomeSection.getSurroundingSections(tw, x, z)) { + for (BiomeSection sect : BiomeSection.getSurroundingSections(tw, x, z)) { p.sendMessage(" - " + sect.toString() + "(" + sect.getBiomeBank() + ")"); } - for(SingleMegaChunkStructurePopulator spop:StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { - if (spop == null) continue; - int[] coords = mc.getCenterBlockCoords(); // spop.getCoordsFromMegaChunk(tw, mc); - int dist = (int) Math.sqrt(Math.pow(x-coords[0], 2) + Math.pow(z-coords[1], 2)); - p.sendMessage(" - Structure Registered: " + spop.getClass().getSimpleName() + "(" + coords[0] + "," + coords[1] + ") " + dist + " blocks away"); + for (SingleMegaChunkStructurePopulator spop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { + if (spop == null) { + continue; + } + int[] coords = mc.getCenterBlockCoords(); // spop.getCoordsFromMegaChunk(tw, mc); + int dist = (int) Math.sqrt(Math.pow(x - coords[0], 2) + Math.pow(z - coords[1], 2)); + p.sendMessage(" - Structure Registered: " + + spop.getClass().getSimpleName() + + "(" + + coords[0] + + "," + + coords[1] + + ") " + + dist + + " blocks away"); } - p.sendMessage("Can decorate chunk: " + StructureBufferDistanceHandler.canDecorateChunk(tw, x>>4, z>>4)); + p.sendMessage("Can decorate chunk: " + StructureBufferDistanceHandler.canDecorateChunk(tw, x >> 4, z >> 4)); p.sendMessage("Temperature: " + BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getTemperature()); p.sendMessage("Moisture: " + BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z).getMoisture()); - p.sendMessage("Biome edge factor (Gorge): " + new BiomeBlender(tw, true, true) - .setGridBlendingFactor(2) - .setSmoothBlendTowardsRivers(7).getEdgeFactor(biome, x, z)); + p.sendMessage("Biome edge factor (Gorge): " + new BiomeBlender(tw, true, true).setGridBlendingFactor(2) + .setSmoothBlendTowardsRivers(7) + .getEdgeFactor(biome, x, z)); p.sendMessage("Result Biome: " + biome); p.sendMessage("Highest Ground: " + GenUtils.getHighestGround(data, x, z)); p.sendMessage("Transformed Height: " + GenUtils.getTransformedHeight(data.getTerraformWorld(), x, z)); - + } } diff --git a/common/src/main/java/org/terraform/command/CrappyDebugStructureCommand.java b/common/src/main/java/org/terraform/command/CrappyDebugStructureCommand.java index de58880c..f9303bd0 100644 --- a/common/src/main/java/org/terraform/command/CrappyDebugStructureCommand.java +++ b/common/src/main/java/org/terraform/command/CrappyDebugStructureCommand.java @@ -44,9 +44,9 @@ public void execute(CommandSender sender, Stack args) { int y = -24; int z = p.getLocation().getBlockZ(); TerraformWorld tw = TerraformWorld.get(p.getWorld()); - + new AncientCityPopulator().spawnAncientCity(tw, new Random(), data, x, y, z); - p.teleport(new Location(p.getWorld(), x,y+30,z)); + p.teleport(new Location(p.getWorld(), x, y + 30, z)); p.sendMessage("Done."); } diff --git a/common/src/main/java/org/terraform/command/DesertWellCommand.java b/common/src/main/java/org/terraform/command/DesertWellCommand.java index b2eb2aac..6d31bd38 100644 --- a/common/src/main/java/org/terraform/command/DesertWellCommand.java +++ b/common/src/main/java/org/terraform/command/DesertWellCommand.java @@ -40,11 +40,14 @@ public void execute(CommandSender sender, Stack args) { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); - new DesertWellPopulator().spawnDesertWell(TerraformWorld.get(p.getWorld()), new Random(), data, + new DesertWellPopulator().spawnDesertWell(TerraformWorld.get(p.getWorld()), + new Random(), + data, p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), - new Random().nextBoolean()); + new Random().nextBoolean() + ); } diff --git a/common/src/main/java/org/terraform/command/FixerCacheFlushCommand.java b/common/src/main/java/org/terraform/command/FixerCacheFlushCommand.java index b618af0f..3fc4e5cd 100644 --- a/common/src/main/java/org/terraform/command/FixerCacheFlushCommand.java +++ b/common/src/main/java/org/terraform/command/FixerCacheFlushCommand.java @@ -33,10 +33,10 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(@NotNull CommandSender sender, Stack args) - { - NativeGeneratorPatcherPopulator.flushChanges(); - PhysicsUpdaterPopulator.flushChanges(); - sender.sendMessage("Flushing changes."); + { + NativeGeneratorPatcherPopulator.flushChanges(); + PhysicsUpdaterPopulator.flushChanges(); + sender.sendMessage("Flushing changes."); } } diff --git a/common/src/main/java/org/terraform/command/FractalTreeCommand.java b/common/src/main/java/org/terraform/command/FractalTreeCommand.java index 317dafbc..a14fd9e6 100644 --- a/common/src/main/java/org/terraform/command/FractalTreeCommand.java +++ b/common/src/main/java/org/terraform/command/FractalTreeCommand.java @@ -37,8 +37,7 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { + public void execute(@NotNull CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); @@ -48,16 +47,24 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); try { - new FractalTreeBuilder((FractalTypes.Tree) this.parseArguments(sender, args).get(0)) - .build(tw, data, x, y, z); - } catch (IllegalArgumentException e) { + new FractalTreeBuilder((FractalTypes.Tree) this.parseArguments(sender, args).get(0)).build( + tw, + data, + x, + y, + z + ); + } + catch (IllegalArgumentException e) { sender.sendMessage(ChatColor.RED + "Invalid tree type."); sender.sendMessage(ChatColor.RED + "Valid types:"); StringBuilder types = new StringBuilder(); boolean b = true; for (FractalTypes.Tree type : FractalTypes.Tree.values()) { ChatColor col = ChatColor.RED; - if (b) col = ChatColor.DARK_RED; + if (b) { + col = ChatColor.DARK_RED; + } b = !b; types.append(col).append(type).append(' '); } diff --git a/common/src/main/java/org/terraform/command/GiantPumpkinCommand.java b/common/src/main/java/org/terraform/command/GiantPumpkinCommand.java index 0cd6105d..d0480e21 100644 --- a/common/src/main/java/org/terraform/command/GiantPumpkinCommand.java +++ b/common/src/main/java/org/terraform/command/GiantPumpkinCommand.java @@ -42,7 +42,7 @@ public void execute(CommandSender sender, Stack args) { int x = p.getLocation().getBlockX(); int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); -// TreeDB.spawnCoconutTree(new Random(), data, x,y,z); + // TreeDB.spawnCoconutTree(new Random(), data, x,y,z); new GiantPumpkinPopulator().spawnGiantPumpkin(TerraformWorld.get(p.getWorld()), new Random(), data, x, y, z); } } diff --git a/common/src/main/java/org/terraform/command/HelpCommand.java b/common/src/main/java/org/terraform/command/HelpCommand.java index e0acb7cf..eb5632c8 100644 --- a/common/src/main/java/org/terraform/command/HelpCommand.java +++ b/common/src/main/java/org/terraform/command/HelpCommand.java @@ -1,8 +1,5 @@ package org.terraform.command; -import java.util.ArrayList; -import java.util.Stack; - import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -11,85 +8,122 @@ import org.terraform.main.TerraformCommandManager; import org.terraform.main.TerraformGeneratorPlugin; +import java.util.ArrayList; +import java.util.Stack; + public class HelpCommand extends TerraCommand { - - private final TerraformCommandManager man; - public HelpCommand(TerraformGeneratorPlugin plugin, TerraformCommandManager man, String... string){ - super(plugin, string); - this.man = man; - } - - @Override - public boolean isInAcceptedParamRange(@NotNull Stack args){ - return args.size() <= 1; - } - @Override - public boolean canConsoleExec() { - return true; - } + private final TerraformCommandManager man; + + public HelpCommand(TerraformGeneratorPlugin plugin, TerraformCommandManager man, String... string) { + super(plugin, string); + this.man = man; + } + + @Override + public boolean isInAcceptedParamRange(@NotNull Stack args) { + return args.size() <= 1; + } + + @Override + public boolean canConsoleExec() { + return true; + } - @Override - public boolean hasPermission(CommandSender sender) { - return true; - } + @Override + public boolean hasPermission(CommandSender sender) { + return true; + } - @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) { - ArrayList cmds = new ArrayList<>(); - for(TerraCommand cmd:man.getCommands()){ - if(cmd.hasPermission(sender)) cmds.add(cmd); - } - int maxPages = (int) (double) (cmds.size() / 6); - int page = 0; - - if(!args.isEmpty()){ - try{ - page = Integer.parseInt(args.pop()); - if(page <= 0){ - sender.sendMessage(plugin.getLang().fetchLang("command.help.postive-pages")); - return; - } - page--; - }catch(NumberFormatException e){ - sender.sendMessage(plugin.getLang().fetchLang("command.help.postive-pages")); - return; - } - } - if(page > maxPages){ - page = maxPages; - } - String base = man.bases.get(0); - sender.sendMessage(ChatColor.GOLD + "============[" + ChatColor.AQUA + plugin.getName() + ChatColor.GOLD + "][" + ChatColor.YELLOW + "Pg. " + (page + 1) + ChatColor.GOLD + - "]============"); - sender.sendMessage(""); + @Override + public void execute(@NotNull CommandSender sender, @NotNull Stack args) { + ArrayList cmds = new ArrayList<>(); + for (TerraCommand cmd : man.getCommands()) { + if (cmd.hasPermission(sender)) { + cmds.add(cmd); + } + } + int maxPages = (int) (double) (cmds.size() / 6); + int page = 0; + + if (!args.isEmpty()) { + try { + page = Integer.parseInt(args.pop()); + if (page <= 0) { + sender.sendMessage(plugin.getLang().fetchLang("command.help.postive-pages")); + return; + } + page--; + } + catch (NumberFormatException e) { + sender.sendMessage(plugin.getLang().fetchLang("command.help.postive-pages")); + return; + } + } + if (page > maxPages) { + page = maxPages; + } + String base = man.bases.get(0); + sender.sendMessage(ChatColor.GOLD + + "============[" + + ChatColor.AQUA + + plugin.getName() + + ChatColor.GOLD + + "][" + + ChatColor.YELLOW + + "Pg. " + + (page + 1) + + ChatColor.GOLD + + "]============"); + sender.sendMessage(""); for (int i = 0; i < 6; i++) { if (cmds.size() > page * 5 + i) { - TerraCommand cmd = cmds.get(page * 5 + i); + TerraCommand cmd = cmds.get(page * 5 + i); StringBuilder params = new StringBuilder(); - params.append(ChatColor.YELLOW).append("/").append(base).append(" ").append(String.join("/", cmd.aliases)).append(' '); - for(TerraCommandArgument param:cmd.parameters){ - if(param.isOptional()){ - params.append(ChatColor.GRAY).append("<").append(param.getName()).append("> "); - }else - params.append(ChatColor.AQUA).append("[").append(param.getName()).append("] "); - } - params.append(ChatColor.DARK_GRAY).append("- ").append(ChatColor.YELLOW).append(plugin.getLang().fetchLang(cmd.getLangPath())); - sender.sendMessage(params.toString()); + params.append(ChatColor.YELLOW) + .append("/") + .append(base) + .append(" ") + .append(String.join("/", cmd.aliases)) + .append(' '); + for (TerraCommandArgument param : cmd.parameters) { + if (param.isOptional()) { + params.append(ChatColor.GRAY).append("<").append(param.getName()).append("> "); + } + else { + params.append(ChatColor.AQUA).append("[").append(param.getName()).append("] "); + } + } + params.append(ChatColor.DARK_GRAY) + .append("- ") + .append(ChatColor.YELLOW) + .append(plugin.getLang().fetchLang(cmd.getLangPath())); + sender.sendMessage(params.toString()); } } - sender.sendMessage(""); + sender.sendMessage(""); if (page != maxPages) { - sender.sendMessage(ChatColor.GRAY + "/" + base + " h " + (page+2) - + "" + ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + (page+1) + "/" + (maxPages+1)); - } else { - sender.sendMessage(ChatColor.AQUA + "" + (page+1) + "/" + (maxPages+1)); + sender.sendMessage(ChatColor.GRAY + + "/" + + base + + " h " + + (page + 2) + + "" + + ChatColor.DARK_GRAY + + "- " + + ChatColor.YELLOW + + (page + 1) + + "/" + + (maxPages + 1)); + } + else { + sender.sendMessage(ChatColor.AQUA + "" + (page + 1) + "/" + (maxPages + 1)); } - } + } - @Override - public @NotNull String getDefaultDescription() { - return "Displays a list of commands for this plugin."; - } + @Override + public @NotNull String getDefaultDescription() { + return "Displays a list of commands for this plugin."; + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/command/IceSpikeCommand.java b/common/src/main/java/org/terraform/command/IceSpikeCommand.java index a4560a44..8f5d4966 100644 --- a/common/src/main/java/org/terraform/command/IceSpikeCommand.java +++ b/common/src/main/java/org/terraform/command/IceSpikeCommand.java @@ -43,8 +43,8 @@ public void execute(CommandSender sender, Stack args) { int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); TerraformWorld tw = TerraformWorld.get(p.getWorld()); - IceSpikesHandler.genSpike(tw, new Random(), data, x, y, z, - GenUtils.randInt(3, 10), // radius - GenUtils.randInt(10, 50)); // height + IceSpikesHandler.genSpike(tw, new Random(), data, x, y, z, GenUtils.randInt(3, 10), // radius + GenUtils.randInt(10, 50) + ); // height } } diff --git a/common/src/main/java/org/terraform/command/InjectorDebugTestCommand.java b/common/src/main/java/org/terraform/command/InjectorDebugTestCommand.java index 5c9500f2..dde7124a 100644 --- a/common/src/main/java/org/terraform/command/InjectorDebugTestCommand.java +++ b/common/src/main/java/org/terraform/command/InjectorDebugTestCommand.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.command.contants.TerraCommand; import org.terraform.main.TerraformGeneratorPlugin; + import java.util.Stack; public class InjectorDebugTestCommand extends TerraCommand { @@ -36,11 +37,11 @@ public void execute(CommandSender sender, Stack args) { Player p = (Player) sender; World w = p.getWorld(); - - for(int y = -64; y < 320; y++) { - w.setBiome(p.getLocation().getBlockX(), y, p.getLocation().getBlockZ(), Biome.BADLANDS); + + for (int y = -64; y < 320; y++) { + w.setBiome(p.getLocation().getBlockX(), y, p.getLocation().getBlockZ(), Biome.BADLANDS); } p.sendMessage("Finished setting biome."); - + } } diff --git a/common/src/main/java/org/terraform/command/JigsawBuilderTestCommand.java b/common/src/main/java/org/terraform/command/JigsawBuilderTestCommand.java index 0dcab13e..56739571 100644 --- a/common/src/main/java/org/terraform/command/JigsawBuilderTestCommand.java +++ b/common/src/main/java/org/terraform/command/JigsawBuilderTestCommand.java @@ -42,9 +42,13 @@ public void execute(CommandSender sender, Stack args) { int x = p.getLocation().getBlockX(); int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); - PlainsVillageForgeJigsawBuilder builder = new PlainsVillageForgeJigsawBuilder( - new PlainsVillagePopulator(), - 15, 15, data, x, y - 1, z + PlainsVillageForgeJigsawBuilder builder = new PlainsVillageForgeJigsawBuilder(new PlainsVillagePopulator(), + 15, + 15, + data, + x, + y - 1, + z ); builder.generate(new Random()); builder.build(new Random()); diff --git a/common/src/main/java/org/terraform/command/LocateBiomeCommand.java b/common/src/main/java/org/terraform/command/LocateBiomeCommand.java index 01896115..90c64b29 100644 --- a/common/src/main/java/org/terraform/command/LocateBiomeCommand.java +++ b/common/src/main/java/org/terraform/command/LocateBiomeCommand.java @@ -50,7 +50,8 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) if (!args.isEmpty()) { try { - new Task(p.getUniqueId(), + new Task( + p.getUniqueId(), TerraformWorld.get(p.getWorld()), p.getLocation().getBlockX(), p.getLocation().getBlockZ(), diff --git a/common/src/main/java/org/terraform/command/MansionCommand.java b/common/src/main/java/org/terraform/command/MansionCommand.java index 9c3aa3e3..0fcaabcb 100644 --- a/common/src/main/java/org/terraform/command/MansionCommand.java +++ b/common/src/main/java/org/terraform/command/MansionCommand.java @@ -43,9 +43,12 @@ public void execute(CommandSender sender, Stack args) { int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); MansionJigsawBuilder builder = new MansionJigsawBuilder( - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), - data, x, y, z + TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), + TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), + data, + x, + y, + z ); builder.generate(new Random()); builder.build(new Random()); diff --git a/common/src/main/java/org/terraform/command/MazeCommand.java b/common/src/main/java/org/terraform/command/MazeCommand.java index f8431626..96fb8591 100644 --- a/common/src/main/java/org/terraform/command/MazeCommand.java +++ b/common/src/main/java/org/terraform/command/MazeCommand.java @@ -43,7 +43,7 @@ public void execute(CommandSender sender, Stack args) { int x = p.getLocation().getBlockX(); int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); -// TreeDB.spawnCoconutTree(new Random(), data, x,y,z); + // TreeDB.spawnCoconutTree(new Random(), data, x,y,z); MazeSpawner spawner = new MazeSpawner(new Random(), new SimpleBlock(data, x, y, z), 30, 30); spawner.setMazePeriod(5); spawner.prepareMaze(); diff --git a/common/src/main/java/org/terraform/command/MushroomCommand.java b/common/src/main/java/org/terraform/command/MushroomCommand.java index 246f7b1b..3093430e 100644 --- a/common/src/main/java/org/terraform/command/MushroomCommand.java +++ b/common/src/main/java/org/terraform/command/MushroomCommand.java @@ -40,8 +40,7 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { + public void execute(@NotNull CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); @@ -52,16 +51,24 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) if (!args.isEmpty()) { try { - new MushroomBuilder((FractalTypes.Mushroom) this.parseArguments(sender, args).get(0)) - .build(tw, data, x, y, z); - } catch (IllegalArgumentException e) { + new MushroomBuilder((FractalTypes.Mushroom) this.parseArguments(sender, args).get(0)).build( + tw, + data, + x, + y, + z + ); + } + catch (IllegalArgumentException e) { sender.sendMessage(ChatColor.RED + "Invalid mushroom type."); sender.sendMessage(ChatColor.RED + "Valid types:"); StringBuilder types = new StringBuilder(); boolean b = true; for (FractalTypes.Mushroom type : FractalTypes.Mushroom.values()) { ChatColor col = ChatColor.RED; - if (b) col = ChatColor.DARK_RED; + if (b) { + col = ChatColor.DARK_RED; + } b = !b; types.append(col).append(type).append(' '); } @@ -72,10 +79,22 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) return; } - if (new Random().nextBoolean()) - new MushroomBuilder(FractalTypes.Mushroom.GIANT_RED_MUSHROOM).build(TerraformWorld.get(p.getWorld()), data, x, y, z); - else - new MushroomBuilder(FractalTypes.Mushroom.GIANT_BROWN_MUSHROOM).build(TerraformWorld.get(p.getWorld()), data, x, y, z); + if (new Random().nextBoolean()) { + new MushroomBuilder(FractalTypes.Mushroom.GIANT_RED_MUSHROOM).build(TerraformWorld.get(p.getWorld()), + data, + x, + y, + z + ); + } + else { + new MushroomBuilder(FractalTypes.Mushroom.GIANT_BROWN_MUSHROOM).build(TerraformWorld.get(p.getWorld()), + data, + x, + y, + z + ); + } } } diff --git a/common/src/main/java/org/terraform/command/NMSChunkPacketRefreshCommand.java b/common/src/main/java/org/terraform/command/NMSChunkPacketRefreshCommand.java index 72fd220c..be72e243 100644 --- a/common/src/main/java/org/terraform/command/NMSChunkPacketRefreshCommand.java +++ b/common/src/main/java/org/terraform/command/NMSChunkPacketRefreshCommand.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.command.contants.TerraCommand; import org.terraform.main.TerraformGeneratorPlugin; + import java.util.Stack; public class NMSChunkPacketRefreshCommand extends TerraCommand { @@ -30,8 +31,8 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(CommandSender sender, Stack args) - { -// Commented out to prevent runtime errors for older versions + { + // Commented out to prevent runtime errors for older versions } } diff --git a/common/src/main/java/org/terraform/command/NMSChunkQueryCommand.java b/common/src/main/java/org/terraform/command/NMSChunkQueryCommand.java index e965007a..af551a35 100644 --- a/common/src/main/java/org/terraform/command/NMSChunkQueryCommand.java +++ b/common/src/main/java/org/terraform/command/NMSChunkQueryCommand.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.command.contants.TerraCommand; import org.terraform.main.TerraformGeneratorPlugin; + import java.util.Stack; public class NMSChunkQueryCommand extends TerraCommand { @@ -30,8 +31,8 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(CommandSender sender, Stack args) - { - // Commented out to prevent runtime errors for older versions + { + // Commented out to prevent runtime errors for older versions } } diff --git a/common/src/main/java/org/terraform/command/NewTreeCommand.java b/common/src/main/java/org/terraform/command/NewTreeCommand.java index b9ec7bf3..91890c25 100644 --- a/common/src/main/java/org/terraform/command/NewTreeCommand.java +++ b/common/src/main/java/org/terraform/command/NewTreeCommand.java @@ -40,8 +40,7 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { + public void execute(@NotNull CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); @@ -51,16 +50,18 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); try { - ((FractalTypes.Tree) this.parseArguments(sender, args).get(0)) - .build(tw, new SimpleBlock(data, x, y, z)); - } catch (IllegalArgumentException e) { + ((FractalTypes.Tree) this.parseArguments(sender, args).get(0)).build(tw, new SimpleBlock(data, x, y, z)); + } + catch (IllegalArgumentException e) { sender.sendMessage(ChatColor.RED + "Invalid tree type."); sender.sendMessage(ChatColor.RED + "Valid types:"); StringBuilder types = new StringBuilder(); boolean b = true; for (FractalTypes.Tree type : FractalTypes.Tree.values()) { ChatColor col = ChatColor.RED; - if (b) col = ChatColor.DARK_RED; + if (b) { + col = ChatColor.DARK_RED; + } b = !b; types.append(col).append(type).append(' '); } diff --git a/common/src/main/java/org/terraform/command/OreDitCommand.java b/common/src/main/java/org/terraform/command/OreDitCommand.java index e08950bb..cd82e6b4 100644 --- a/common/src/main/java/org/terraform/command/OreDitCommand.java +++ b/common/src/main/java/org/terraform/command/OreDitCommand.java @@ -36,53 +36,54 @@ public boolean hasPermission(@NotNull CommandSender sender) { @Override public void execute(CommandSender sender, Stack args) { - Material[] auditMat = new Material[] { - Material.DIORITE, - Material.ANDESITE, - Material.GRANITE, - Material.GRAVEL, - Material.COAL_ORE, - Material.IRON_ORE, - Material.GOLD_ORE, - Material.DIAMOND_ORE, - Material.LAPIS_ORE, - Material.REDSTONE_ORE, - Material.EMERALD_ORE, - Material.DRIPSTONE_BLOCK, + Material[] auditMat = new Material[] { + Material.DIORITE, + Material.ANDESITE, + Material.GRANITE, + Material.GRAVEL, + Material.COAL_ORE, + Material.IRON_ORE, + Material.GOLD_ORE, + Material.DIAMOND_ORE, + Material.LAPIS_ORE, + Material.REDSTONE_ORE, + Material.EMERALD_ORE, + Material.DRIPSTONE_BLOCK, Material.DEEPSLATE, Material.TUFF, Material.COPPER_ORE - }; + }; Player p = (Player) sender; Chunk c = p.getLocation().getChunk(); - HashMap ores = new HashMap<>(); - for(Material audit:auditMat) { - ores.put(audit, 0); + HashMap ores = new HashMap<>(); + for (Material audit : auditMat) { + ores.put(audit, 0); } p.sendMessage("Sampling surrounding chunk radius of 3..."); - - for(int cx = -3; cx <= 3; cx++) - for(int cz = -3; cz <= 3; cz++) { - Chunk target = p.getWorld().getChunkAt(c.getX()+cx, c.getZ()+cz); - - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - for(int y = (int) p.getLocation().getY(); y > p.getWorld().getMinHeight(); y--) { - Material mat = target.getBlock(x, y, z).getType(); - for(Material audit:auditMat) { - if(mat == audit) { - ores.put(audit, ores.get(audit)+1); - } - } - } + + for (int cx = -3; cx <= 3; cx++) { + for (int cz = -3; cz <= 3; cz++) { + Chunk target = p.getWorld().getChunkAt(c.getX() + cx, c.getZ() + cz); + + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = (int) p.getLocation().getY(); y > p.getWorld().getMinHeight(); y--) { + Material mat = target.getBlock(x, y, z).getType(); + for (Material audit : auditMat) { + if (mat == audit) { + ores.put(audit, ores.get(audit) + 1); + } + } + } } } } - + } + p.sendMessage("-----[Ore Count]-----"); - for(Material audit:auditMat) { - p.sendMessage(audit + " - " + ores.get(audit)); + for (Material audit : auditMat) { + p.sendMessage(audit + " - " + ores.get(audit)); } - + } } diff --git a/common/src/main/java/org/terraform/command/PreviewCommand.java b/common/src/main/java/org/terraform/command/PreviewCommand.java index d3589ad8..e2b1212d 100644 --- a/common/src/main/java/org/terraform/command/PreviewCommand.java +++ b/common/src/main/java/org/terraform/command/PreviewCommand.java @@ -1,15 +1,5 @@ package org.terraform.command; -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Random; -import java.util.Stack; -import java.util.UUID; - -import javax.imageio.ImageIO; - import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; @@ -26,6 +16,15 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.Random; +import java.util.Stack; +import java.util.UUID; + public class PreviewCommand extends TerraCommand { public PreviewCommand(TerraformGeneratorPlugin plugin, String... aliases) { @@ -47,43 +46,119 @@ public boolean hasPermission(@NotNull CommandSender sender) { return sender.isOp(); } - + @Override public void execute(CommandSender sender, Stack args) { // int seed = GenUtils.randInt(1, 1000000); - int maxX = 16*10; - int maxY = TerraformGeneratorPlugin.injector.getMaxY()-TerraformGeneratorPlugin.injector.getMinY(); + int maxX = 16 * 10; + int maxY = TerraformGeneratorPlugin.injector.getMaxY() - TerraformGeneratorPlugin.injector.getMinY(); - TerraformWorld tw = TerraformWorld.get("test-world-"+new Random().nextInt(99999), new Random().nextInt(99999));// TerraformWorld.get("test-world", 11111); + TerraformWorld tw = TerraformWorld.get( + "test-world-" + new Random().nextInt(99999), + new Random().nextInt(99999) + );// TerraformWorld.get("test-world", 11111); ImageWorldInfo iwi = new ImageWorldInfo(tw.getName(), tw.getSeed()); - BufferedImage img = new BufferedImage(maxX, maxY+maxX, BufferedImage.TYPE_INT_RGB); + BufferedImage img = new BufferedImage(maxX, maxY + maxX, BufferedImage.TYPE_INT_RGB); // Delete existing - File f = new File("terra-preview.png"); if (f.exists()) f.delete(); + File f = new File("terra-preview.png"); + if (f.exists()) { + f.delete(); + } TerraformGenerator generator = new TerraformGenerator(); // Generate both side and top-down - for (int x = (-maxX/2)>>4; x < (maxX/2)>>4; x++) { - for(int z = (-maxX/2)>>4; z < (maxX/2)>>4; z++) - { - ImageChunkData icd = new ImageChunkData(img, x,z, maxX, maxY); - generator.generateNoise(iwi, tw.getHashedRand(1, x,z), x, z, icd); - generator.generateSurface(iwi, tw.getHashedRand(1, x,z), x, z, icd); - generator.generateCaves(iwi, tw.getHashedRand(1, x,z), x, z, icd); + for (int x = (-maxX / 2) >> 4; x < (maxX / 2) >> 4; x++) { + for (int z = (-maxX / 2) >> 4; z < (maxX / 2) >> 4; z++) { + ImageChunkData icd = new ImageChunkData(img, x, z, maxX, maxY); + generator.generateNoise(iwi, tw.getHashedRand(1, x, z), x, z, icd); + generator.generateSurface(iwi, tw.getHashedRand(1, x, z), x, z, icd); + generator.generateCaves(iwi, tw.getHashedRand(1, x, z), x, z, icd); } } try { f = new java.io.File("terra-preview.png"); ImageIO.write(img, "png", f); - } catch (IOException e) { + } + catch (IOException e) { System.out.println(e); } System.out.println("Done."); } - private static class ImageChunkData implements ChunkGenerator.ChunkData{ + @SuppressWarnings("unused") + private Color getClimateColor(@NotNull BiomeBank bank) { + if (bank.getType() == BiomeType.OCEANIC || bank.getType() == BiomeType.DEEP_OCEANIC) { + return Color.blue; + } + return switch (bank.getClimate()) { + case HUMID_VEGETATION -> new Color(118, 163, 3); + case DRY_VEGETATION -> new Color(172, 187, 2); + case HOT_BARREN -> Color.red; + case COLD -> new Color(59, 255, 150); + case SNOWY -> Color.white; + case TRANSITION -> new Color(59, 255, 59); + }; + } + + @SuppressWarnings("unused") + private Color getBiomeColor(@NotNull BiomeBank bank) { + switch (bank) { + case SNOWY_WASTELAND: + return Color.white; + case SNOWY_TAIGA: + return new Color(217, 234, 211); + case ICE_SPIKES: + return new Color(207, 226, 243); + case TAIGA: + return new Color(56, 118, 29); + case PLAINS: + return new Color(59, 255, 59); + case ERODED_PLAINS: + return new Color(59, 255, 150); + case DARK_FOREST: + return new Color(39, 78, 19); + case SAVANNA: + return new Color(172, 187, 2); + case FOREST: + return new Color(106, 168, 79); + case JUNGLE: + return new Color(118, 163, 3); + case BAMBOO_FOREST: + return new Color(0, 255, 186); + case DESERT: + return Color.yellow; + case BADLANDS: + return Color.red; + default: + if (bank.getType() == BiomeType.OCEANIC || bank.getType() == BiomeType.DEEP_OCEANIC) { + return Color.blue; + } + else { + return Color.pink; + } + } + } + + @SuppressWarnings("unused") + private @NotNull Color getHeightColorFromNoise(int noise) { + if (noise <= 62) { // Sea level + return new Color(50, 50, 100 + (noise * 2));// Blue + } + else if (noise < 62 + 4) { // Beaches? + return new Color(240, 238, 108);// Yellow + } + else if (noise < 92) { + return new Color(37, (70 + (noise * 2)), 2);// Green + } + else { // Mountainous + return new Color(255, 255, 255);// White + } + } + + private static class ImageChunkData implements ChunkGenerator.ChunkData { final BufferedImage img; - final int chunkX,chunkZ,maxX,maxY; + final int chunkX, chunkZ, maxX, maxY; private final int[][] maxHeights = new int[16][16]; private ImageChunkData(BufferedImage img, int chunkX, int chunkZ, int maxX, int maxY) { @@ -99,7 +174,7 @@ private ImageChunkData(BufferedImage img, int chunkX, int chunkZ, int maxX, int @Override public void setBlock(int x, int y, int z, @NotNull Material material) { Color col; - switch(material){ + switch (material) { case STONE -> col = Color.LIGHT_GRAY; case DEEPSLATE -> col = Color.GRAY; case WATER -> col = Color.CYAN; @@ -108,24 +183,28 @@ public void setBlock(int x, int y, int z, @NotNull Material material) { } // Vertical slice at z=0 - if(z==0 && chunkZ == 0) + if (z == 0 && chunkZ == 0) { img.setRGB( - (maxX/2) + x+chunkX*16, - maxY-(y-TerraformGeneratorPlugin.injector.getMinY())-1, - col.getRGB()); + (maxX / 2) + x + chunkX * 16, + maxY - (y - TerraformGeneratorPlugin.injector.getMinY()) - 1, + col.getRGB() + ); + } // Top-Down slice - if(y>=maxHeights[x][z]) - { + if (y >= maxHeights[x][z]) { maxHeights[x][z] = y; - if((y-TerraformGenerator.seaLevel) % 3 == 0) { - if(y > TerraformGenerator.seaLevel) + if ((y - TerraformGenerator.seaLevel) % 3 == 0) { + if (y > TerraformGenerator.seaLevel) { col = col.brighter(); - else col = col.darker(); + } + else { + col = col.darker(); + } } - img.setRGB((maxX/2) + x+chunkX*16, - maxY+(maxX/2) + z+chunkZ*16,col.getRGB()); + img.setRGB((maxX / 2) + x + chunkX * 16, maxY + (maxX / 2) + z + chunkZ * 16, col.getRGB()); } } + @Override public void setBlock(int i, int i1, int i2, @NotNull BlockData blockData) { @@ -159,6 +238,7 @@ public BlockData getBlockData(int i, int i1, int i2) { public Biome getBiome(int i, int i1, int i2) { return null; } + @Override public void setBlock(int i, int i1, int i2, @NotNull MaterialData materialData) { @@ -191,7 +271,7 @@ public byte getData(int i, int i1, int i2) { } } - private static class ImageWorldInfo implements WorldInfo{ + private static class ImageWorldInfo implements WorldInfo { private final String name; private final long seed; @@ -233,68 +313,4 @@ public int getMaxHeight() { return 0; } } - @SuppressWarnings("unused") - private Color getClimateColor(@NotNull BiomeBank bank) { - if(bank.getType() == BiomeType.OCEANIC||bank.getType() == BiomeType.DEEP_OCEANIC) - return Color.blue; - return switch(bank.getClimate()) { - case HUMID_VEGETATION -> new Color(118, 163, 3); - case DRY_VEGETATION -> new Color(172, 187, 2); - case HOT_BARREN -> Color.red; - case COLD -> new Color(59, 255, 150); - case SNOWY -> Color.white; - case TRANSITION -> new Color(59, 255, 59); - }; - } - - @SuppressWarnings("unused") - private Color getBiomeColor(@NotNull BiomeBank bank) { - switch(bank) { - case SNOWY_WASTELAND: - return Color.white; - case SNOWY_TAIGA: - return new Color(217,234,211); - case ICE_SPIKES: - return new Color(207,226,243); - case TAIGA: - return new Color(56,118,29); - case PLAINS: - return new Color(59, 255, 59); - case ERODED_PLAINS: - return new Color(59, 255, 150); - case DARK_FOREST: - return new Color(39,78,19); - case SAVANNA: - return new Color(172,187,2); - case FOREST: - return new Color(106,168,79); - case JUNGLE: - return new Color(118,163,3); - case BAMBOO_FOREST: - return new Color(0,255,186); - case DESERT: - return Color.yellow; - case BADLANDS: - return Color.red; - default: - if(bank.getType() == BiomeType.OCEANIC || bank.getType() == BiomeType.DEEP_OCEANIC) - return Color.blue; - else - return Color.pink; - } - } - - - @SuppressWarnings("unused") - private @NotNull Color getHeightColorFromNoise(int noise) { - if (noise <= 62) { // Sea level - return new Color(50, 50, 100 + (noise * 2));// Blue - } else if (noise < 62 + 4) { // Beaches? - return new Color(240, 238, 108);// Yellow - } else if (noise < 92) { - return new Color(37, (70 + (noise * 2)), 2);// Green - } else { // Mountainous - return new Color(255, 255, 255);// White - } - } } diff --git a/common/src/main/java/org/terraform/command/RibCageCommand.java b/common/src/main/java/org/terraform/command/RibCageCommand.java index 957a89ec..3c142ac9 100644 --- a/common/src/main/java/org/terraform/command/RibCageCommand.java +++ b/common/src/main/java/org/terraform/command/RibCageCommand.java @@ -39,10 +39,10 @@ public void execute(CommandSender sender, Stack args) { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); - int x = p.getLocation().getBlockX(); - int y = p.getLocation().getBlockY(); - int z = p.getLocation().getBlockZ(); - new DesertHandler().spawnRibCage(new Random(), new SimpleBlock(data,x,y,z)); + int x = p.getLocation().getBlockX(); + int y = p.getLocation().getBlockY(); + int z = p.getLocation().getBlockZ(); + new DesertHandler().spawnRibCage(new Random(), new SimpleBlock(data, x, y, z)); } } diff --git a/common/src/main/java/org/terraform/command/SchematicLoadCommand.java b/common/src/main/java/org/terraform/command/SchematicLoadCommand.java index b91c2480..5dfcee35 100644 --- a/common/src/main/java/org/terraform/command/SchematicLoadCommand.java +++ b/common/src/main/java/org/terraform/command/SchematicLoadCommand.java @@ -38,9 +38,8 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { - try{ + public void execute(@NotNull CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { + try { ArrayList parsed = this.parseArguments(sender, args); TerraSchematic schem = (TerraSchematic) parsed.get(0); sender.sendMessage("Schematic Version: " + schem.getVersionValue()); @@ -48,8 +47,7 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) sender.sendMessage("Facing: " + schem.getFace()); schem.apply(); } - catch(IllegalArgumentException e) - { + catch (IllegalArgumentException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); } } diff --git a/common/src/main/java/org/terraform/command/SchematicSaveCommand.java b/common/src/main/java/org/terraform/command/SchematicSaveCommand.java index d373e819..316ac62d 100644 --- a/common/src/main/java/org/terraform/command/SchematicSaveCommand.java +++ b/common/src/main/java/org/terraform/command/SchematicSaveCommand.java @@ -41,8 +41,7 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { + public void execute(CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { Player p = (Player) sender; TerraRegion rg = SchematicListener.rgs.get(p.getUniqueId()); @@ -60,17 +59,20 @@ public void execute(CommandSender sender, @NotNull Stack args) TerraSchematic s = new TerraSchematic(p.getLocation().clone()); for (Block b : rg.getBlocks()) { - if (b.getType() == Material.AIR) + if (b.getType() == Material.AIR) { continue; - if (b.getType() == Material.BARRIER) + } + if (b.getType() == Material.BARRIER) { b.setType(Material.AIR); + } s.registerBlock(b); } try { s.export(name + ".terra"); p.sendMessage(ChatColor.GREEN + "Schematic saved with name " + name); - } catch (IOException e) { + } + catch (IOException e) { p.sendMessage(ChatColor.RED + "A problem occurred."); TerraformGeneratorPlugin.logger.stackTrace(e); } diff --git a/common/src/main/java/org/terraform/command/SeekCommand.java b/common/src/main/java/org/terraform/command/SeekCommand.java index fe73f50b..2b4b512e 100644 --- a/common/src/main/java/org/terraform/command/SeekCommand.java +++ b/common/src/main/java/org/terraform/command/SeekCommand.java @@ -15,11 +15,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.LangOpt; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.structure.MultiMegaChunkStructurePopulator; -import org.terraform.structure.SingleMegaChunkStructurePopulator; -import org.terraform.structure.StructureLocator; -import org.terraform.structure.StructurePopulator; -import org.terraform.structure.StructureRegistry; +import org.terraform.structure.*; import org.terraform.structure.stronghold.StrongholdPopulator; import java.util.ArrayList; @@ -51,18 +47,20 @@ public boolean hasPermission(@NotNull CommandSender sender) { } @Override - public void execute(@NotNull CommandSender sender, @NotNull Stack args) - throws InvalidArgumentException { + public void execute(@NotNull CommandSender sender, @NotNull Stack args) throws InvalidArgumentException { ArrayList params = this.parseArguments(sender, args); if (params.isEmpty()) { sender.sendMessage(LangOpt.COMMAND_LOCATE_LIST_HEADER.parse()); for (StructurePopulator spop : StructureRegistry.getAllPopulators()) { - sender.sendMessage(LangOpt.COMMAND_LOCATE_LIST_ENTRY.parse("%entry%", spop.getClass().getSimpleName().replace("Populator", ""))); + sender.sendMessage(LangOpt.COMMAND_LOCATE_LIST_ENTRY.parse( + "%entry%", + spop.getClass().getSimpleName().replace("Populator", "") + )); } sender.sendMessage(LangOpt.COMMAND_LOCATE_LIST_ENTRY.parse("%entry%", "Stronghold")); return; } - + StructurePopulator spop = (StructurePopulator) params.get(0); // TODO: Get populator by name if (!spop.isEnabled() && !(spop instanceof StrongholdPopulator)) { @@ -71,24 +69,28 @@ public void execute(@NotNull CommandSender sender, @NotNull Stack args) } World w = Objects.requireNonNull(Bukkit.getWorld("world")); - + // Stronghold Special Case if (spop instanceof StrongholdPopulator) { - int[] coords = ((StrongholdPopulator)spop).getNearestFeature(TerraformWorld.get(Objects.requireNonNull(Bukkit.getWorld("world"))), 0,0); + int[] coords = ((StrongholdPopulator) spop).getNearestFeature(TerraformWorld.get(Objects.requireNonNull( + Bukkit.getWorld("world"))), 0, 0); syncSendMessage(LangOpt.COMMAND_LOCATE_LOCATE_COORDS.parse("%x%", coords[0] + "", "%z%", coords[1] + "")); return; } if (spop instanceof SingleMegaChunkStructurePopulator) { generateSingleMegaChunkStructure(w, (SingleMegaChunkStructurePopulator) spop); - } else { + } + else { generateMultiMegaChunkStructure(w, (MultiMegaChunkStructurePopulator) spop); } } - private void generateMultiMegaChunkStructure(@NotNull World w, @NotNull MultiMegaChunkStructurePopulator populator) { + private void generateMultiMegaChunkStructure(@NotNull World w, + @NotNull MultiMegaChunkStructurePopulator populator) + { - MegaChunk center = new MegaChunk(0,0,0); + MegaChunk center = new MegaChunk(0, 0, 0); TerraformWorld tw = TerraformWorld.get(w); Bukkit.getConsoleSender().sendMessage(LangOpt.COMMAND_LOCATE_SEARCHING.parse()); @@ -96,26 +98,36 @@ private void generateMultiMegaChunkStructure(@NotNull World w, @NotNull MultiMeg BukkitRunnable runnable = new BukkitRunnable() { public void run() { - int[] loc = StructureLocator.locateMultiMegaChunkStructure(tw, center, populator, -1); - long timeTaken = System.currentTimeMillis() - startTime; - + int[] loc = StructureLocator.locateMultiMegaChunkStructure(tw, center, populator, -1); + long timeTaken = System.currentTimeMillis() - startTime; + syncSendMessage(LangOpt.COMMAND_LOCATE_COMPLETED_TASK.parse("%time%", timeTaken + "")); if (loc != null) { - syncSendMessage(ChatColor.GREEN + "[" + populator.getClass().getSimpleName() + "] " + LangOpt.COMMAND_LOCATE_LOCATE_COORDS.parse("%x%", loc[0] + "", - "%z%", loc[1] + "")); + syncSendMessage(ChatColor.GREEN + + "[" + + populator.getClass().getSimpleName() + + "] " + + LangOpt.COMMAND_LOCATE_LOCATE_COORDS.parse("%x%", + loc[0] + "", + "%z%", + loc[1] + "" + )); w.getChunkAt(new Location(w, loc[0], 0, loc[1])); } - else + else { syncSendMessage(ChatColor.RED + "Failed to find structure. Somehow."); + } } }; runnable.runTaskAsynchronously(plugin); } - private void generateSingleMegaChunkStructure(@NotNull World w, @NotNull SingleMegaChunkStructurePopulator populator) { + private void generateSingleMegaChunkStructure(@NotNull World w, + @NotNull SingleMegaChunkStructurePopulator populator) + { - MegaChunk center = new MegaChunk(0,0,0); + MegaChunk center = new MegaChunk(0, 0, 0); TerraformWorld tw = TerraformWorld.get(w); Bukkit.getConsoleSender().sendMessage(LangOpt.COMMAND_LOCATE_SEARCHING.parse()); @@ -123,18 +135,26 @@ private void generateSingleMegaChunkStructure(@NotNull World w, @NotNull SingleM BukkitRunnable runnable = new BukkitRunnable() { public void run() { - int[] loc = StructureLocator.locateSingleMegaChunkStructure(tw, center, populator, -1); - long timeTaken = System.currentTimeMillis() - startTime; - + int[] loc = StructureLocator.locateSingleMegaChunkStructure(tw, center, populator, -1); + long timeTaken = System.currentTimeMillis() - startTime; + syncSendMessage(LangOpt.COMMAND_LOCATE_COMPLETED_TASK.parse("%time%", timeTaken + "")); if (loc != null) { - syncSendMessage(ChatColor.GREEN + "[" + populator.getClass().getSimpleName() + "] " + LangOpt.COMMAND_LOCATE_LOCATE_COORDS.parse("%x%", loc[0] + "", - "%z%", loc[1] + "")); + syncSendMessage(ChatColor.GREEN + + "[" + + populator.getClass().getSimpleName() + + "] " + + LangOpt.COMMAND_LOCATE_LOCATE_COORDS.parse("%x%", + loc[0] + "", + "%z%", + loc[1] + "" + )); w.getChunkAt(new Location(w, loc[0], 0, loc[1])); } - else + else { syncSendMessage(ChatColor.RED + "Failed to find structure. Somehow."); + } } }; runnable.runTaskAsynchronously(plugin); @@ -152,32 +172,45 @@ public StructurePopulatorArgument(String name, boolean isOptional) { @Override public StructurePopulator parse(CommandSender arg0, @NotNull String arg1) { - if(arg1.equalsIgnoreCase("stronghold")||arg1.equalsIgnoreCase("strongholdpopulator")) + if (arg1.equalsIgnoreCase("stronghold") || arg1.equalsIgnoreCase("strongholdpopulator")) { return new StrongholdPopulator(); + } for (StructurePopulator spop : StructureRegistry.getAllPopulators()) { - if (spop.getClass().getSimpleName().equalsIgnoreCase(arg1) || - spop.getClass().getSimpleName().equalsIgnoreCase(arg1 + "populator")) + if (spop.getClass().getSimpleName().equalsIgnoreCase(arg1) || spop.getClass() + .getSimpleName() + .equalsIgnoreCase(arg1 + "populator")) + { return spop; + } } return null; } @Override public @NotNull String validate(CommandSender arg0, @NotNull String arg1) { - if (this.parse(arg0, arg1) != null) + if (this.parse(arg0, arg1) != null) { return ""; - else + } + else { return "Structure type does not exist"; + } } @Override public @NotNull ArrayList getTabOptions(String @NotNull [] args) { - if (args.length != 2) return new ArrayList<>(); + if (args.length != 2) { + return new ArrayList<>(); + } ArrayList values = new ArrayList<>(); for (StructurePopulator spop : StructureRegistry.getAllPopulators()) { - if(spop.getClass().getSimpleName().toUpperCase(Locale.ENGLISH).startsWith(args[1].toUpperCase(Locale.ENGLISH))) - values.add(spop.getClass().getSimpleName()); + if (spop.getClass() + .getSimpleName() + .toUpperCase(Locale.ENGLISH) + .startsWith(args[1].toUpperCase(Locale.ENGLISH))) + { + values.add(spop.getClass().getSimpleName()); + } } return values; diff --git a/common/src/main/java/org/terraform/command/TimingsCommand.java b/common/src/main/java/org/terraform/command/TimingsCommand.java index 8cf53ffd..4fc2c3d6 100644 --- a/common/src/main/java/org/terraform/command/TimingsCommand.java +++ b/common/src/main/java/org/terraform/command/TimingsCommand.java @@ -34,7 +34,14 @@ public boolean hasPermission(@NotNull CommandSender sender) { public void execute(@NotNull CommandSender sender, Stack args) { sender.sendMessage("=====Avg Timings====="); for (Map.Entry entry : TickTimer.TIMINGS.entrySet()) { - sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + entry.getKey() + ChatColor.DARK_GRAY + ": " + ChatColor.GOLD + entry.getValue()); + sender.sendMessage(ChatColor.GRAY + + "- " + + ChatColor.GREEN + + entry.getKey() + + ChatColor.DARK_GRAY + + ": " + + ChatColor.GOLD + + entry.getValue()); } } } diff --git a/common/src/main/java/org/terraform/command/ValuesCommand.java b/common/src/main/java/org/terraform/command/ValuesCommand.java index 658cbac0..c887cbc6 100644 --- a/common/src/main/java/org/terraform/command/ValuesCommand.java +++ b/common/src/main/java/org/terraform/command/ValuesCommand.java @@ -7,8 +7,8 @@ import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; @@ -35,54 +35,54 @@ public boolean hasPermission(@NotNull CommandSender sender) { return sender.isOp(); } - + @SuppressWarnings("unused") - private double warpSine(double tempUnwarpedSineX, int period, int seed) { - double warp = GenUtils.randInt(new Random(3L *seed),-3, 3); - if(warp == 0) warp = 1; - if(warp < 0) { - warp = (10-2*warp)/10.0; - } - - double warpedValue; - if(tempUnwarpedSineX == 0 && warp == 0) { // Prevent math error - warpedValue = 0; - }else { - warpedValue = Math.pow(Math.abs(tempUnwarpedSineX),warp); - } - if(tempUnwarpedSineX < 0) { - warpedValue = -warpedValue; // Preserve sign - } - return warpedValue; - } + private double warpSine(double tempUnwarpedSineX, int period, int seed) { + double warp = GenUtils.randInt(new Random(3L * seed), -3, 3); + if (warp == 0) { + warp = 1; + } + if (warp < 0) { + warp = (10 - 2 * warp) / 10.0; + } + + double warpedValue; + if (tempUnwarpedSineX == 0 && warp == 0) { // Prevent math error + warpedValue = 0; + } + else { + warpedValue = Math.pow(Math.abs(tempUnwarpedSineX), warp); + } + if (tempUnwarpedSineX < 0) { + warpedValue = -warpedValue; // Preserve sign + } + return warpedValue; + } @SuppressWarnings("unused") - @Override + @Override public void execute(@NotNull CommandSender sender, Stack args) { - + MathValues vals = new MathValues(); MathValues unwarped = new MathValues(); MathValues warped = new MathValues(); - + TerraformWorld tw = TerraformWorld.get("world-1232341234", new Random().nextInt(99999)); - - FastNoise carverEntranceStandard = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.CARVER_STANDARD, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 111)); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(4); - n.SetFrequency(0.07f); - return n; - }); - + + FastNoise carverEntranceStandard = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.CARVER_STANDARD, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 111)); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(4); + n.SetFrequency(0.07f); + return n; + }); + int period = 4; for (int x = 0; x < 9000000; x++) { - int y = GenUtils.randInt(0,100); + int y = GenUtils.randInt(0, 100); int z = GenUtils.randInt(-10000, 10000); vals.addValue(carverEntranceStandard.GetNoise(x, y, z)); - // vals.addValue(50.0*tw.getOceanicNoise().GetNoise(x,z)); + // vals.addValue(50.0*tw.getOceanicNoise().GetNoise(x,z)); } sender.sendMessage("Finished"); sender.sendMessage("Highest: " + vals.getHighest()); @@ -104,8 +104,12 @@ public MathValues() { public void addValue(double value) { total += value; count++; - if (value < lowest) lowest = value; - if (value > highest) highest = value; + if (value < lowest) { + lowest = value; + } + if (value > highest) { + highest = value; + } } public double avg() { diff --git a/common/src/main/java/org/terraform/command/WitchHutCommand.java b/common/src/main/java/org/terraform/command/WitchHutCommand.java index 338d4df0..8e8808f4 100644 --- a/common/src/main/java/org/terraform/command/WitchHutCommand.java +++ b/common/src/main/java/org/terraform/command/WitchHutCommand.java @@ -39,10 +39,10 @@ public void execute(CommandSender sender, Stack args) { Player p = (Player) sender; PopulatorDataPostGen data = new PopulatorDataPostGen(p.getLocation().getChunk()); - int x = p.getLocation().getBlockX(); - int y = p.getLocation().getBlockY(); - int z = p.getLocation().getBlockZ(); - new WitchHutPopulator().spawnSwampHut(TerraformWorld.get(p.getWorld()),new Random(),data,x,y,z); + int x = p.getLocation().getBlockX(); + int y = p.getLocation().getBlockY(); + int z = p.getLocation().getBlockZ(); + new WitchHutPopulator().spawnSwampHut(TerraformWorld.get(p.getWorld()), new Random(), data, x, y, z); } diff --git a/common/src/main/java/org/terraform/command/contants/FilenameArgument.java b/common/src/main/java/org/terraform/command/contants/FilenameArgument.java index ae4e6916..282a14e1 100644 --- a/common/src/main/java/org/terraform/command/contants/FilenameArgument.java +++ b/common/src/main/java/org/terraform/command/contants/FilenameArgument.java @@ -19,13 +19,19 @@ public String parse(CommandSender sender, String value) { @Override public @NotNull String validate(CommandSender sender, @NotNull String value) { - File schematicFolder = new File(TerraformGeneratorPlugin.get().getDataFolder(), TerraSchematic.SCHEMATIC_FOLDER); + File schematicFolder = new File( + TerraformGeneratorPlugin.get().getDataFolder(), + TerraSchematic.SCHEMATIC_FOLDER + ); File file = new File(schematicFolder, value); try { - if(file.getName().endsWith(File.pathSeparator) - || !file.getCanonicalPath().startsWith(schematicFolder.getCanonicalPath())) + if (file.getName().endsWith(File.pathSeparator) || !file.getCanonicalPath() + .startsWith(schematicFolder.getCanonicalPath())) + { return "Schematic name contained illegal characters (i.e. periods)"; - } catch(Exception e) { + } + } + catch (Exception e) { return "Schematic name contained illegal characters (i.e. periods)"; } return ""; diff --git a/common/src/main/java/org/terraform/command/contants/FractalTreeTypeArgument.java b/common/src/main/java/org/terraform/command/contants/FractalTreeTypeArgument.java index d6d5f0b5..474b741a 100644 --- a/common/src/main/java/org/terraform/command/contants/FractalTreeTypeArgument.java +++ b/common/src/main/java/org/terraform/command/contants/FractalTreeTypeArgument.java @@ -1,13 +1,13 @@ package org.terraform.command.contants; -import java.util.ArrayList; -import java.util.Locale; - import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.terraform.tree.FractalTypes; import org.terraform.tree.FractalTypes.Tree; +import java.util.ArrayList; +import java.util.Locale; + public class FractalTreeTypeArgument extends TerraCommandArgument { public FractalTreeTypeArgument(String name, boolean isOptional) { @@ -25,22 +25,26 @@ public FractalTreeTypeArgument(String name, boolean isOptional) { public @NotNull String validate(CommandSender sender, @NotNull String value) { try { parse(sender, value); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { return "Tree type does not exist!"; } return ""; } - + @Override public @NotNull ArrayList getTabOptions(String @NotNull [] args) { - if (args.length != 2) return new ArrayList<>(); + if (args.length != 2) { + return new ArrayList<>(); + } ArrayList values = new ArrayList<>(); - for(Tree type: FractalTypes.Tree.values()) { - if(type.toString().startsWith(args[1].toUpperCase(Locale.ENGLISH))) - values.add(type.toString()); + for (Tree type : FractalTypes.Tree.values()) { + if (type.toString().startsWith(args[1].toUpperCase(Locale.ENGLISH))) { + values.add(type.toString()); + } } - + return values; } diff --git a/common/src/main/java/org/terraform/command/contants/InvalidArgumentException.java b/common/src/main/java/org/terraform/command/contants/InvalidArgumentException.java index 767f2829..8eda9b40 100644 --- a/common/src/main/java/org/terraform/command/contants/InvalidArgumentException.java +++ b/common/src/main/java/org/terraform/command/contants/InvalidArgumentException.java @@ -1,14 +1,15 @@ package org.terraform.command.contants; public class InvalidArgumentException extends Exception { - - private final String problem; - public InvalidArgumentException(String problem){ - this.problem = problem; - } - - public String getProblem(){ - return problem; - } + + private final String problem; + + public InvalidArgumentException(String problem) { + this.problem = problem; + } + + public String getProblem() { + return problem; + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/command/contants/MushroomTypeArgument.java b/common/src/main/java/org/terraform/command/contants/MushroomTypeArgument.java index 45b6ac44..40bab22b 100644 --- a/common/src/main/java/org/terraform/command/contants/MushroomTypeArgument.java +++ b/common/src/main/java/org/terraform/command/contants/MushroomTypeArgument.java @@ -1,13 +1,13 @@ package org.terraform.command.contants; -import java.util.ArrayList; -import java.util.Locale; - import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.terraform.tree.FractalTypes; import org.terraform.tree.FractalTypes.Mushroom; +import java.util.ArrayList; +import java.util.Locale; + public class MushroomTypeArgument extends TerraCommandArgument { public MushroomTypeArgument(String name, boolean isOptional) { @@ -25,23 +25,27 @@ public MushroomTypeArgument(String name, boolean isOptional) { public @NotNull String validate(CommandSender sender, @NotNull String value) { try { parse(sender, value); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { return "Mushroom type does not exist!"; } return ""; } - + @Override public @NotNull ArrayList getTabOptions(String @NotNull [] args) { - if (args.length != 2) return new ArrayList<>(); + if (args.length != 2) { + return new ArrayList<>(); + } ArrayList values = new ArrayList<>(); - for(Mushroom type: FractalTypes.Mushroom.values()) { - if(type.toString().startsWith(args[1].toUpperCase(Locale.ENGLISH))) - values.add(type.toString()); + for (Mushroom type : FractalTypes.Mushroom.values()) { + if (type.toString().startsWith(args[1].toUpperCase(Locale.ENGLISH))) { + values.add(type.toString()); + } } - + return values; } diff --git a/common/src/main/java/org/terraform/command/contants/SchematicArgument.java b/common/src/main/java/org/terraform/command/contants/SchematicArgument.java index 89fedd82..1cc7c351 100644 --- a/common/src/main/java/org/terraform/command/contants/SchematicArgument.java +++ b/common/src/main/java/org/terraform/command/contants/SchematicArgument.java @@ -20,7 +20,8 @@ public TerraSchematic parse(@NotNull CommandSender sender, String value) { try { return TerraSchematic.load(value, new SimpleBlock(((Player) sender).getLocation())); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } return null; @@ -31,7 +32,8 @@ public TerraSchematic parse(@NotNull CommandSender sender, String value) { try { // Path validation is done inside TerraSchematic.load TerraSchematic.load(value, new SimpleBlock(((Player) sender).getLocation())); - } catch (Throwable e) { + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return "Problem loading schematic. Check console for error"; } diff --git a/common/src/main/java/org/terraform/command/contants/TerraCommandArgument.java b/common/src/main/java/org/terraform/command/contants/TerraCommandArgument.java index a396842a..ae6400db 100644 --- a/common/src/main/java/org/terraform/command/contants/TerraCommandArgument.java +++ b/common/src/main/java/org/terraform/command/contants/TerraCommandArgument.java @@ -1,4 +1,5 @@ package org.terraform.command.contants; + import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -6,54 +7,54 @@ import java.util.ArrayList; public abstract class TerraCommandArgument { - - private String name; - private boolean isOptional; - - public TerraCommandArgument(String name, boolean isOptional) { - this.name = name; - this.isOptional = isOptional; - } + private String name; + + private boolean isOptional; + + public TerraCommandArgument(String name, boolean isOptional) { + this.name = name; + this.isOptional = isOptional; + } + + public abstract @Nullable T parse(CommandSender sender, String value); - public abstract @Nullable T parse(CommandSender sender, String value); - - public abstract String validate(CommandSender sender, String value); + public abstract String validate(CommandSender sender, String value); /** * Should return a list of valid parameters * to show when tab completing the command */ - public @NotNull ArrayList getTabOptions(String[] args) { - return new ArrayList<>(); + public @NotNull ArrayList getTabOptions(String[] args) { + return new ArrayList<>(); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the isOptional + */ + public boolean isOptional() { + return isOptional; } - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the isOptional - */ - public boolean isOptional() { - return isOptional; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param isOptional the isOptional to set - */ - public void setOptional(boolean isOptional) { - this.isOptional = isOptional; - } + /** + * @param isOptional the isOptional to set + */ + public void setOptional(boolean isOptional) { + this.isOptional = isOptional; + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/coregen/ChunkCache.java b/common/src/main/java/org/terraform/coregen/ChunkCache.java index 0ba4d01c..05fbf9ed 100644 --- a/common/src/main/java/org/terraform/coregen/ChunkCache.java +++ b/common/src/main/java/org/terraform/coregen/ChunkCache.java @@ -16,8 +16,8 @@ public class ChunkCache { public final int chunkX, chunkZ; /** - * heightCache caches the FINAL height of the terrain (the one applied to the - * world). + * heightCache caches the FINAL height of the terrain (the one applied to the + * world). *
    * dominantBiomeHeightCache holds the non-final height calculation of * the most dominant biome at those coordinates. @@ -69,7 +69,7 @@ public void initInternalCache() { Problems might occur because the lib itself uses a for loop. Optimization lies entirely at the mercy of the running JVM. */ - Arrays.fill(arrayCache, TerraformGeneratorPlugin.injector.getMinY()-1); + Arrays.fill(arrayCache, TerraformGeneratorPlugin.injector.getMinY() - 1); biomeCache = new BiomeBank[256]; } @@ -82,62 +82,60 @@ public float getDominantBiomeHeight(int rawX, int rawZ) { happens because the chunk coordinates are the LSB, so ANDing by 0xF will return the bits needed to give 0-15. */ - return arrayCache[(rawX&0xF)+16*(rawZ&0xF)]; + return arrayCache[(rawX & 0xF) + 16 * (rawZ & 0xF)]; } /** - * - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value dominant biome height to cache */ public void cacheDominantBiomeHeight(int rawX, int rawZ, float value) { - arrayCache[(rawX&0xF)+16*(rawZ&0xF)] = value; + arrayCache[(rawX & 0xF) + 16 * (rawZ & 0xF)] = value; } public double getHeightMapHeight(int rawX, int rawZ) { - return arrayCache[768 + (rawX&0xF)+16*(rawZ&0xF)]; + return arrayCache[768 + (rawX & 0xF) + 16 * (rawZ & 0xF)]; } public short getHighestGround(int rawX, int rawZ) { - return (short) arrayCache[1024 + (rawX&0xF)+16*(rawZ&0xF)]; + return (short) arrayCache[1024 + (rawX & 0xF) + 16 * (rawZ & 0xF)]; } /** * This is solely for surface cave carving use as surface * caves may modify heights. + * * @return the ACTUAL mutable copy from the cache. */ - public short getTransformedHeight(int chunkSubX, int chunkSubZ){ - return (short) arrayCache[1280 + chunkSubX + 16*chunkSubZ]; + public short getTransformedHeight(int chunkSubX, int chunkSubZ) { + return (short) arrayCache[1280 + chunkSubX + 16 * chunkSubZ]; } - public void writeTransformedHeight(int chunkSubX, int chunkSubZ, short val){ - arrayCache[1280 + chunkSubX + 16*chunkSubZ] = val; + public void writeTransformedHeight(int chunkSubX, int chunkSubZ, short val) { + arrayCache[1280 + chunkSubX + 16 * chunkSubZ] = val; } /** - * - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value height to cache */ public void cacheHeightMap(int rawX, int rawZ, double value) { - arrayCache[768 + (rawX&0xF)+16*(rawZ&0xF)] = (float) value; + arrayCache[768 + (rawX & 0xF) + 16 * (rawZ & 0xF)] = (float) value; } /** - * - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value height to cache */ public void cacheHighestGround(int rawX, int rawZ, short value) { - arrayCache[1024 + (rawX&0xF)+16*(rawZ&0xF)] = value; + arrayCache[1024 + (rawX & 0xF) + 16 * (rawZ & 0xF)] = value; } - + public float getBlurredHeight(int rawX, int rawZ) { - return arrayCache[256 + (rawX&0xF)+16*(rawZ&0xF)]; + return arrayCache[256 + (rawX & 0xF) + 16 * (rawZ & 0xF)]; } /** @@ -145,43 +143,42 @@ public float getBlurredHeight(int rawX, int rawZ) { */ public double getIntermediateBlurHeight(int rawX, int rawZ) { - return arrayCache[512 + (rawX&0xF)+16*(rawZ&0xF)]; + return arrayCache[512 + (rawX & 0xF) + 16 * (rawZ & 0xF)]; } /** - * - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value height to cache */ public void cacheBlurredHeight(int rawX, int rawZ, float value) { - arrayCache[256 + (rawX&0xF)+16*(rawZ&0xF)] = value; + arrayCache[256 + (rawX & 0xF) + 16 * (rawZ & 0xF)] = value; } /** * MEANT FOR USE ONLY IN THE BLURRING PROCESS. - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value height to cache */ public void cacheIntermediateBlurredHeight(int rawX, int rawZ, float value) { - arrayCache[512 + (rawX&0xF)+16*(rawZ&0xF)] = value; + arrayCache[512 + (rawX & 0xF) + 16 * (rawZ & 0xF)] = value; } public BiomeBank getBiome(int rawX, int rawZ) { - return biomeCache[(rawX&0xF)+16*(rawZ&0xF)]; + return biomeCache[(rawX & 0xF) + 16 * (rawZ & 0xF)]; } /** - * - * @param rawX BLOCK COORD x - * @param rawZ BLOCK COORD z + * @param rawX BLOCK COORD x + * @param rawZ BLOCK COORD z * @param value biome to cache */ public BiomeBank cacheBiome(int rawX, int rawZ, BiomeBank value) { - biomeCache[(rawX&0xF)+16*(rawZ&0xF)] = value; + biomeCache[(rawX & 0xF) + 16 * (rawZ & 0xF)] = value; return value; } @@ -196,9 +193,9 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof ChunkCache chunk)) return false; - return this.tw == chunk.tw - && this.chunkX == chunk.chunkX - && this.chunkZ == chunk.chunkZ; + if (!(obj instanceof ChunkCache chunk)) { + return false; + } + return this.tw == chunk.tw && this.chunkX == chunk.chunkX && this.chunkZ == chunk.chunkZ; } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/coregen/ChunkCacheLoader.java b/common/src/main/java/org/terraform/coregen/ChunkCacheLoader.java index 95d5635d..3747db80 100644 --- a/common/src/main/java/org/terraform/coregen/ChunkCacheLoader.java +++ b/common/src/main/java/org/terraform/coregen/ChunkCacheLoader.java @@ -5,10 +5,10 @@ public class ChunkCacheLoader extends CacheLoader { - @Override - public @NotNull ChunkCache load(@NotNull ChunkCache key) { - key.initInternalCache(); - return key; - } + @Override + public @NotNull ChunkCache load(@NotNull ChunkCache key) { + key.initInternalCache(); + return key; + } } diff --git a/common/src/main/java/org/terraform/coregen/HeightMap.java b/common/src/main/java/org/terraform/coregen/HeightMap.java index 500b39f1..7f8f1823 100644 --- a/common/src/main/java/org/terraform/coregen/HeightMap.java +++ b/common/src/main/java/org/terraform/coregen/HeightMap.java @@ -9,8 +9,8 @@ import org.terraform.main.config.TConfigOption; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; public enum HeightMap { @@ -29,8 +29,7 @@ public double getHeight(TerraformWorld tw, int x, int z) { }); return 15 - 200 * Math.abs(noise.GetNoise(x, z)); } - }, - CORE { + }, CORE { @Override public double getHeight(TerraformWorld tw, int x, int z) { FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.HEIGHTMAP_CORE, world -> { @@ -42,7 +41,7 @@ public double getHeight(TerraformWorld tw, int x, int z) { }); // 7 blocks elevated from the sea level - double height = 10*noise.GetNoise(x, z) + 7 + TerraformGenerator.seaLevel; + double height = 10 * noise.GetNoise(x, z) + 7 + TerraformGenerator.seaLevel; // Plateau-out height to make it flat-ish if (height > TerraformGenerator.seaLevel + 10) { @@ -53,12 +52,11 @@ public double getHeight(TerraformWorld tw, int x, int z) { return height; } - }, - ATTRITION { + }, ATTRITION { @Override public double getHeight(TerraformWorld tw, int x, int z) { FastNoise perlin = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.HEIGHTMAP_ATTRITION, world -> { - FastNoise n = new FastNoise((int) world.getSeed()+113); + FastNoise n = new FastNoise((int) world.getSeed() + 113); n.SetNoiseType(NoiseType.PerlinFractal); n.SetFractalOctaves(4); n.SetFrequency(0.02f); @@ -72,6 +70,8 @@ public double getHeight(TerraformWorld tw, int x, int z) { public static final int defaultSeaLevel = 62; public static final float heightAmplifier = TConfigOption.HEIGHT_MAP_LAND_HEIGHT_AMPLIFIER.getFloat(); + private static final int upscaleSize = 3; + public static int spawnFlatRadiusSquared = -324534; /** * Returns the average increase or decrease in height for surrounding blocks compared to the provided height at those coords. @@ -82,13 +82,16 @@ public static double getNoiseGradient(TerraformWorld tw, int x, int z, int radiu double totalChangeInGradient = 0; int count = 0; double centerNoise = getBlockHeight(tw, x, z); - for (int nx = -radius; nx <= radius; nx++) + for (int nx = -radius; nx <= radius; nx++) { for (int nz = -radius; nz <= radius; nz++) { - if (nx == 0 && nz == 0) continue; + if (nx == 0 && nz == 0) { + continue; + } // Bukkit.getLogger().info(nx + "," + nz + ":"+(getHeight(tw,x+nx,z+nz)-centerNoise)); totalChangeInGradient += Math.abs(getBlockHeight(tw, x + nx, z + nz) - centerNoise); count++; } + } return totalChangeInGradient / count; } @@ -105,68 +108,73 @@ public static double getTrueHeightGradient(PopulatorDataAbstract data, int x, in double totalChangeInGradient = 0; int count = 0; double centerNoise = GenUtils.getHighestGround(data, x, z); // getBlockHeight(tw, x, z); - for (int nx = -radius; nx <= radius; nx++) + for (int nx = -radius; nx <= radius; nx++) { for (int nz = -radius; nz <= radius; nz++) { - if (nx == 0 && nz == 0) continue; + if (nx == 0 && nz == 0) { + continue; + } // Bukkit.getLogger().info(nx + "," + nz + ":"+(getHeight(tw,x+nx,z+nz)-centerNoise)); - totalChangeInGradient += Math.abs(GenUtils.getHighestGround(data, x+nx, z+nz) - centerNoise); + totalChangeInGradient += Math.abs(GenUtils.getHighestGround(data, x + nx, z + nz) - centerNoise); count++; } + } return totalChangeInGradient / count; } public static double getRawRiverDepth(TerraformWorld tw, int x, int z) { - if(Math.pow(x,2) + Math.pow(z,2) < spawnFlatRadiusSquared) + if (Math.pow(x, 2) + Math.pow(z, 2) < spawnFlatRadiusSquared) { return 0; + } double depth = HeightMap.RIVER.getHeight(tw, x, z); depth = depth < 0 ? 0 : depth; return depth; } - public static int spawnFlatRadiusSquared = -324534; public static double getPreciseHeight(TerraformWorld tw, int x, int z) { ChunkCache cache = TerraformGenerator.getCache(tw, x, z); double cachedValue = cache.getHeightMapHeight(x, z); - if (cachedValue != TerraformGeneratorPlugin.injector.getMinY()-1) return cachedValue; + if (cachedValue != TerraformGeneratorPlugin.injector.getMinY() - 1) { + return cachedValue; + } - double height = getRiverlessHeight(tw,x,z); + double height = getRiverlessHeight(tw, x, z); // River Depth - double depth = getRawRiverDepth(tw,x,z); + double depth = getRawRiverDepth(tw, x, z); // Normal scenario: Shallow area if (height - depth >= TerraformGenerator.seaLevel - 15) { height -= depth; // Fix for underwater river carving: Don't carve deeply - } else if (height > TerraformGenerator.seaLevel - 15 - && height - depth < TerraformGenerator.seaLevel - 15) { + } + else if (height > TerraformGenerator.seaLevel - 15 && height - depth < TerraformGenerator.seaLevel - 15) { height = TerraformGenerator.seaLevel - 15; } - if (heightAmplifier != 1f && height > TerraformGenerator.seaLevel) + if (heightAmplifier != 1f && height > TerraformGenerator.seaLevel) { height += heightAmplifier * (height - TerraformGenerator.seaLevel); + } cache.cacheHeightMap(x, z, height); return height; } - private static final int upscaleSize = 3; private static float getDominantBiomeHeight(TerraformWorld tw, int x, int z) { ChunkCache cache = TerraformGenerator.getCache(tw, x, z); float h = cache.getDominantBiomeHeight(x, z); - if(h == TerraformGeneratorPlugin.injector.getMinY()-1) { + if (h == TerraformGeneratorPlugin.injector.getMinY() - 1) { // Upscale the biome - if(x % upscaleSize != 0 && z % upscaleSize != 0) - h = getDominantBiomeHeight(tw, x-(x%upscaleSize),z-(z%upscaleSize)); - else - { - h = (float) BiomeBank.calculateHeightIndependentBiome(tw, x, z) - .getHandler().calculateHeight(tw, x, z); - if(Math.pow(x,2) + Math.pow(z,2) < spawnFlatRadiusSquared) - h = (float) HeightMap.CORE.getHeight(tw,x,z); + if (x % upscaleSize != 0 && z % upscaleSize != 0) { + h = getDominantBiomeHeight(tw, x - (x % upscaleSize), z - (z % upscaleSize)); + } + else { + h = (float) BiomeBank.calculateHeightIndependentBiome(tw, x, z).getHandler().calculateHeight(tw, x, z); + if (Math.pow(x, 2) + Math.pow(z, 2) < spawnFlatRadiusSquared) { + h = (float) HeightMap.CORE.getHeight(tw, x, z); + } } } cache.cacheDominantBiomeHeight(x, z, h); @@ -177,50 +185,54 @@ private static float getDominantBiomeHeight(TerraformWorld tw, int x, int z) { * Biome calculations are done here as well. *
    * This function is responsible for applying blurring to merge biomes together + * * @return Near-final world height without rivers accounted for */ public static double getRiverlessHeight(TerraformWorld tw, int x, int z) { int maskRadius = 5; - int maskDiameter = (maskRadius*2) + 1; + int maskDiameter = (maskRadius * 2) + 1; // int maskDiameterSquared = maskDiameter*maskDiameter; double coreHeight; ChunkCache mainCache = TerraformGenerator.getCache(tw, x, z); // If this chunk cache hasn't cached a blurred value, - if(mainCache.getBlurredHeight(x, z) == TerraformGeneratorPlugin.injector.getMinY()-1) { + if (mainCache.getBlurredHeight(x, z) == TerraformGeneratorPlugin.injector.getMinY() - 1) { // Box blur across the biome section // MegaChunk mc = new MegaChunk(x, 0, z); BiomeSection sect = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); // For every point in the biome section, blur across the X axis. - for(int relX = sect.getLowerBounds().getX(); relX <= sect.getUpperBounds().getX(); relX++) { - for(int relZ = sect.getLowerBounds().getZ() - maskRadius; relZ <= sect.getUpperBounds().getZ() + maskRadius; relZ++) { + for (int relX = sect.getLowerBounds().getX(); relX <= sect.getUpperBounds().getX(); relX++) { + for (int relZ = sect.getLowerBounds().getZ() - maskRadius; + relZ <= sect.getUpperBounds().getZ() + maskRadius; + relZ++) { ChunkCache targetCache = TerraformGenerator.getCache(tw, relX, relZ); float lineTotalHeight = 0; - for(int offsetX = -maskRadius; offsetX <= maskRadius; offsetX++) { + for (int offsetX = -maskRadius; offsetX <= maskRadius; offsetX++) { lineTotalHeight += getDominantBiomeHeight(tw, relX + offsetX, relZ); } // Temporarily cache these X-Blurred values into chunkcache. // Do not purge values that are legitimate. - if(targetCache.getIntermediateBlurHeight(relX, relZ) == TerraformGeneratorPlugin.injector.getMinY()-1) + if (targetCache.getIntermediateBlurHeight(relX, relZ) + == TerraformGeneratorPlugin.injector.getMinY() - 1) { - targetCache.cacheIntermediateBlurredHeight(relX, relZ, lineTotalHeight/maskDiameter); + targetCache.cacheIntermediateBlurredHeight(relX, relZ, lineTotalHeight / maskDiameter); } } } // For every point in the biome section, blur across the Z axis. - for(int relX = sect.getLowerBounds().getX(); relX <= sect.getUpperBounds().getX(); relX++) { - for(int relZ = sect.getLowerBounds().getZ(); relZ <= sect.getUpperBounds().getZ(); relZ++) { + for (int relX = sect.getLowerBounds().getX(); relX <= sect.getUpperBounds().getX(); relX++) { + for (int relZ = sect.getLowerBounds().getZ(); relZ <= sect.getUpperBounds().getZ(); relZ++) { ChunkCache targetCache = TerraformGenerator.getCache(tw, relX, relZ); float lineTotalHeight = 0; - for(int offsetZ = -maskRadius; offsetZ <= maskRadius; offsetZ++) { + for (int offsetZ = -maskRadius; offsetZ <= maskRadius; offsetZ++) { ChunkCache queryCache = TerraformGenerator.getCache(tw, relX, relZ + offsetZ); // Note, this may accidentally blur twice for some Z values if @@ -228,7 +240,7 @@ public static double getRiverlessHeight(TerraformWorld tw, int x, int z) { lineTotalHeight += (float) queryCache.getIntermediateBlurHeight(relX, relZ + offsetZ); } // final blurred value - targetCache.cacheBlurredHeight(relX, relZ, lineTotalHeight/maskDiameter); + targetCache.cacheBlurredHeight(relX, relZ, lineTotalHeight / maskDiameter); } } } diff --git a/common/src/main/java/org/terraform/coregen/NMSInjectorAbstract.java b/common/src/main/java/org/terraform/coregen/NMSInjectorAbstract.java index 81e6a228..d7feb05d 100644 --- a/common/src/main/java/org/terraform/coregen/NMSInjectorAbstract.java +++ b/common/src/main/java/org/terraform/coregen/NMSInjectorAbstract.java @@ -8,9 +8,10 @@ import org.terraform.coregen.populatordata.PopulatorDataICAAbstract; public abstract class NMSInjectorAbstract { - - public void startupTasks() {} - + + public void startupTasks() { + } + public @Nullable BlockDataFixerAbstract getBlockDataFixer() { return null; } @@ -39,19 +40,19 @@ public void startupTasks() {} * for this. */ public abstract void storeBee(Beehive hive); - + /** * Force an NMS physics update at the location. */ public void updatePhysics(World world, org.bukkit.block.Block block) { - throw new UnsupportedOperationException("Tried to update physics without implementing."); + throw new UnsupportedOperationException("Tried to update physics without implementing."); } public int getMinY() { - return 0; + return 0; } - + public int getMaxY() { - return 256; + return 256; } } diff --git a/common/src/main/java/org/terraform/coregen/NaturalSpawnType.java b/common/src/main/java/org/terraform/coregen/NaturalSpawnType.java index 622bb675..d8a23eb4 100644 --- a/common/src/main/java/org/terraform/coregen/NaturalSpawnType.java +++ b/common/src/main/java/org/terraform/coregen/NaturalSpawnType.java @@ -1,5 +1,5 @@ package org.terraform.coregen; public enum NaturalSpawnType { - GUARDIAN, PILLAGER + GUARDIAN, PILLAGER } diff --git a/common/src/main/java/org/terraform/coregen/TerraLootTable.java b/common/src/main/java/org/terraform/coregen/TerraLootTable.java index 3a084bcc..559203eb 100644 --- a/common/src/main/java/org/terraform/coregen/TerraLootTable.java +++ b/common/src/main/java/org/terraform/coregen/TerraLootTable.java @@ -127,7 +127,8 @@ public enum TerraLootTable { TerraLootTable(String key) { this.key = key; } - public @Nullable LootTable bukkit(){ + + public @Nullable LootTable bukkit() { return Bukkit.getLootTable(NamespacedKey.minecraft(this.key)); } } diff --git a/common/src/main/java/org/terraform/coregen/TerraformPopulator.java b/common/src/main/java/org/terraform/coregen/TerraformPopulator.java index 2eb6cf29..ad27ab0f 100644 --- a/common/src/main/java/org/terraform/coregen/TerraformPopulator.java +++ b/common/src/main/java/org/terraform/coregen/TerraformPopulator.java @@ -21,47 +21,65 @@ import java.util.Random; public class TerraformPopulator extends BlockPopulator { - + private static final OrePopulator[] ORE_POPS = { // Ores - new OrePopulator(Material.DEEPSLATE, TConfigOption.ORE_DEEPSLATE_CHANCE.getInt(), TConfigOption.ORE_DEEPSLATE_VEINSIZE.getInt(), - TConfigOption.ORE_DEEPSLATE_MAXVEINNUMBER.getInt(), TConfigOption.ORE_DEEPSLATE_MINSPAWNHEIGHT.getInt(), TConfigOption.ORE_DEEPSLATE_COMMONSPAWNHEIGHT.getInt(), + new OrePopulator(Material.DEEPSLATE, + TConfigOption.ORE_DEEPSLATE_CHANCE.getInt(), + TConfigOption.ORE_DEEPSLATE_VEINSIZE.getInt(), + TConfigOption.ORE_DEEPSLATE_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_DEEPSLATE_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_DEEPSLATE_COMMONSPAWNHEIGHT.getInt(), TConfigOption.ORE_DEEPSLATE_MAXSPAWNHEIGHT.getInt(), - true),// deepslate - new OrePopulator(Material.TUFF, TConfigOption.ORE_TUFF_CHANCE.getInt(), TConfigOption.ORE_TUFF_VEINSIZE.getInt(), - TConfigOption.ORE_TUFF_MAXVEINNUMBER.getInt(), TConfigOption.ORE_TUFF_MINSPAWNHEIGHT.getInt(), TConfigOption.ORE_TUFF_COMMONSPAWNHEIGHT.getInt(), + true + ),// deepslate + new OrePopulator(Material.TUFF, + TConfigOption.ORE_TUFF_CHANCE.getInt(), + TConfigOption.ORE_TUFF_VEINSIZE.getInt(), + TConfigOption.ORE_TUFF_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_TUFF_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_TUFF_COMMONSPAWNHEIGHT.getInt(), TConfigOption.ORE_TUFF_MAXSPAWNHEIGHT.getInt(), - true),// tuff - new OrePopulator(Material.COPPER_ORE, TConfigOption.ORE_COPPER_CHANCE.getInt(), TConfigOption.ORE_COPPER_VEINSIZE.getInt(), - TConfigOption.ORE_COPPER_MAXVEINNUMBER.getInt(), TConfigOption.ORE_COPPER_MINSPAWNHEIGHT.getInt(), TConfigOption.ORE_COPPER_COMMONSPAWNHEIGHT.getInt(), + true + ),// tuff + new OrePopulator(Material.COPPER_ORE, + TConfigOption.ORE_COPPER_CHANCE.getInt(), + TConfigOption.ORE_COPPER_VEINSIZE.getInt(), + TConfigOption.ORE_COPPER_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_COPPER_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_COPPER_COMMONSPAWNHEIGHT.getInt(), TConfigOption.ORE_COPPER_MAXSPAWNHEIGHT.getInt(), - false),// Space for copper + false + ),// Space for copper new OrePopulator(Material.COAL_ORE, - TConfigOption.ORE_COAL_CHANCE.getInt(), - TConfigOption.ORE_COAL_VEINSIZE.getInt(), - TConfigOption.ORE_COAL_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_COAL_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COAL_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COAL_MAXSPAWNHEIGHT.getInt(), - false), - + TConfigOption.ORE_COAL_CHANCE.getInt(), + TConfigOption.ORE_COAL_VEINSIZE.getInt(), + TConfigOption.ORE_COAL_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_COAL_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_COAL_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_COAL_MAXSPAWNHEIGHT.getInt(), + false + ), + new OrePopulator(Material.IRON_ORE, - TConfigOption.ORE_IRON_CHANCE.getInt(), - TConfigOption.ORE_IRON_VEINSIZE.getInt(), - TConfigOption.ORE_IRON_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_IRON_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_IRON_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_IRON_MAXSPAWNHEIGHT.getInt(), - false), - + TConfigOption.ORE_IRON_CHANCE.getInt(), + TConfigOption.ORE_IRON_VEINSIZE.getInt(), + TConfigOption.ORE_IRON_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_IRON_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_IRON_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_IRON_MAXSPAWNHEIGHT.getInt(), + false + ), + new OrePopulator(Material.GOLD_ORE, - TConfigOption.ORE_GOLD_CHANCE.getInt(), - TConfigOption.ORE_GOLD_VEINSIZE.getInt(), - TConfigOption.ORE_GOLD_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GOLD_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GOLD_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GOLD_MAXSPAWNHEIGHT.getInt(), - false), + TConfigOption.ORE_GOLD_CHANCE.getInt(), + TConfigOption.ORE_GOLD_VEINSIZE.getInt(), + TConfigOption.ORE_GOLD_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_GOLD_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GOLD_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GOLD_MAXSPAWNHEIGHT.getInt(), + false + ), // BADLANDS SPAWNRATE new OrePopulator(Material.GOLD_ORE, @@ -76,109 +94,120 @@ public class TerraformPopulator extends BlockPopulator { BiomeBank.BADLANDS_CANYON, BiomeBank.BADLANDS_CANYON_PEAK, BiomeBank.BADLANDS_BEACH, - BiomeBank.BADLANDS_RIVER), - + BiomeBank.BADLANDS_RIVER + ), + new OrePopulator(Material.DIAMOND_ORE, - TConfigOption.ORE_DIAMOND_CHANCE.getInt(), - TConfigOption.ORE_DIAMOND_VEINSIZE.getInt(), - TConfigOption.ORE_DIAMOND_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_DIAMOND_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIAMOND_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIAMOND_MAXSPAWNHEIGHT.getInt(), - false), - - + TConfigOption.ORE_DIAMOND_CHANCE.getInt(), + TConfigOption.ORE_DIAMOND_VEINSIZE.getInt(), + TConfigOption.ORE_DIAMOND_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_DIAMOND_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_DIAMOND_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_DIAMOND_MAXSPAWNHEIGHT.getInt(), + false + ), + + // Emeralds only spawn in mountainous biomes (except deserts) new OrePopulator(Material.EMERALD_ORE, - TConfigOption.ORE_EMERALD_CHANCE.getInt(), - TConfigOption.ORE_EMERALD_VEINSIZE.getInt(), - TConfigOption.ORE_EMERALD_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_EMERALD_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_EMERALD_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_EMERALD_MAXSPAWNHEIGHT.getInt(), - false, - BiomeBank.BIRCH_MOUNTAINS, - BiomeBank.ROCKY_MOUNTAINS, - BiomeBank.SNOWY_MOUNTAINS, - BiomeBank.FORESTED_MOUNTAINS, - BiomeBank.COLD_JAGGED_PEAKS, - BiomeBank.JAGGED_PEAKS, - BiomeBank.FORESTED_PEAKS), - - + TConfigOption.ORE_EMERALD_CHANCE.getInt(), + TConfigOption.ORE_EMERALD_VEINSIZE.getInt(), + TConfigOption.ORE_EMERALD_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_EMERALD_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_EMERALD_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_EMERALD_MAXSPAWNHEIGHT.getInt(), + false, + BiomeBank.BIRCH_MOUNTAINS, + BiomeBank.ROCKY_MOUNTAINS, + BiomeBank.SNOWY_MOUNTAINS, + BiomeBank.FORESTED_MOUNTAINS, + BiomeBank.COLD_JAGGED_PEAKS, + BiomeBank.JAGGED_PEAKS, + BiomeBank.FORESTED_PEAKS + ), + + new OrePopulator(Material.LAPIS_ORE, - TConfigOption.ORE_LAPIS_CHANCE.getInt(), - TConfigOption.ORE_LAPIS_VEINSIZE.getInt(), - TConfigOption.ORE_LAPIS_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_LAPIS_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_LAPIS_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_LAPIS_MAXSPAWNHEIGHT.getInt(), - false), - + TConfigOption.ORE_LAPIS_CHANCE.getInt(), + TConfigOption.ORE_LAPIS_VEINSIZE.getInt(), + TConfigOption.ORE_LAPIS_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_LAPIS_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_LAPIS_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_LAPIS_MAXSPAWNHEIGHT.getInt(), + false + ), + new OrePopulator(Material.REDSTONE_ORE, - TConfigOption.ORE_REDSTONE_CHANCE.getInt(), - TConfigOption.ORE_REDSTONE_VEINSIZE.getInt(), - TConfigOption.ORE_REDSTONE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_REDSTONE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_REDSTONE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_REDSTONE_MAXSPAWNHEIGHT.getInt(), - false), - - + TConfigOption.ORE_REDSTONE_CHANCE.getInt(), + TConfigOption.ORE_REDSTONE_VEINSIZE.getInt(), + TConfigOption.ORE_REDSTONE_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_REDSTONE_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_REDSTONE_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_REDSTONE_MAXSPAWNHEIGHT.getInt(), + false + ), + + // Non-ores new OrePopulator(Material.GRAVEL, - TConfigOption.ORE_GRAVEL_CHANCE.getInt(), - TConfigOption.ORE_GRAVEL_VEINSIZE.getInt(), - TConfigOption.ORE_GRAVEL_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GRAVEL_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRAVEL_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRAVEL_MAXSPAWNHEIGHT.getInt(), - true), - + TConfigOption.ORE_GRAVEL_CHANCE.getInt(), + TConfigOption.ORE_GRAVEL_VEINSIZE.getInt(), + TConfigOption.ORE_GRAVEL_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_GRAVEL_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GRAVEL_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GRAVEL_MAXSPAWNHEIGHT.getInt(), + true + ), + new OrePopulator(Material.ANDESITE, - TConfigOption.ORE_ANDESITE_CHANCE.getInt(), - TConfigOption.ORE_ANDESITE_VEINSIZE.getInt(), - TConfigOption.ORE_ANDESITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_ANDESITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_ANDESITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_ANDESITE_MAXSPAWNHEIGHT.getInt(), - true), - + TConfigOption.ORE_ANDESITE_CHANCE.getInt(), + TConfigOption.ORE_ANDESITE_VEINSIZE.getInt(), + TConfigOption.ORE_ANDESITE_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_ANDESITE_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_ANDESITE_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_ANDESITE_MAXSPAWNHEIGHT.getInt(), + true + ), + new OrePopulator(Material.DIORITE, - TConfigOption.ORE_DIORITE_CHANCE.getInt(), - TConfigOption.ORE_DIORITE_VEINSIZE.getInt(), - TConfigOption.ORE_DIORITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_DIORITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIORITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIORITE_MAXSPAWNHEIGHT.getInt(), - true), - + TConfigOption.ORE_DIORITE_CHANCE.getInt(), + TConfigOption.ORE_DIORITE_VEINSIZE.getInt(), + TConfigOption.ORE_DIORITE_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_DIORITE_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_DIORITE_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_DIORITE_MAXSPAWNHEIGHT.getInt(), + true + ), + new OrePopulator(Material.GRANITE, - TConfigOption.ORE_GRANITE_CHANCE.getInt(), - TConfigOption.ORE_GRANITE_VEINSIZE.getInt(), - TConfigOption.ORE_GRANITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GRANITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRANITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRANITE_MAXSPAWNHEIGHT.getInt(), - true) - }; - - private final AmethystGeodePopulator amethystGeodePopulator = new AmethystGeodePopulator( - TConfigOption.ORE_AMETHYST_GEODE_SIZE.getInt(), + TConfigOption.ORE_GRANITE_CHANCE.getInt(), + TConfigOption.ORE_GRANITE_VEINSIZE.getInt(), + TConfigOption.ORE_GRANITE_MAXVEINNUMBER.getInt(), + TConfigOption.ORE_GRANITE_MINSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GRANITE_COMMONSPAWNHEIGHT.getInt(), + TConfigOption.ORE_GRANITE_MAXSPAWNHEIGHT.getInt(), + true + ) + }; + + private final AmethystGeodePopulator amethystGeodePopulator = new AmethystGeodePopulator(TConfigOption.ORE_AMETHYST_GEODE_SIZE.getInt(), TConfigOption.ORE_AMETHYST_CHANCE.getDouble(), TConfigOption.ORE_AMETHYST_MIN_DEPTH.getInt(), - TConfigOption.ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE.getInt()); + TConfigOption.ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE.getInt() + ); + private final MasterCavePopulatorDistributor caveDistributor = new MasterCavePopulatorDistributor(); + public TerraformPopulator(TerraformWorld tw) { } - - private final MasterCavePopulatorDistributor caveDistributor = new MasterCavePopulatorDistributor(); @Override - public void populate(@NotNull org.bukkit.generator.WorldInfo worldInfo, @NotNull java.util.Random random, - int chunkX, int chunkZ, + public void populate(@NotNull org.bukkit.generator.WorldInfo worldInfo, + @NotNull java.util.Random random, + int chunkX, + int chunkZ, @NotNull org.bukkit.generator.LimitedRegion limitedRegion) { - TerraformWorld tw = TerraformWorld.get(worldInfo.getName(),worldInfo.getSeed()); + TerraformWorld tw = TerraformWorld.get(worldInfo.getName(), worldInfo.getSeed()); PopulatorDataAbstract data = new PopulatorDataSpigotAPI(limitedRegion, tw, chunkX, chunkZ); this.populate(tw, data); } @@ -189,7 +218,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract for (OrePopulator ore : ORE_POPS) { ore.populate(tw, random, data); } - + // Amethysts amethystGeodePopulator.populate(tw, random, data); @@ -199,37 +228,45 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract boolean canDecorate = StructureBufferDistanceHandler.canDecorateChunk(tw, data.getChunkX(), data.getChunkZ()); // Small Populators run per block. - for(int rawX = data.getChunkX()*16; rawX <= data.getChunkX()*16+16; rawX++) - for(int rawZ = data.getChunkZ()*16; rawZ <= data.getChunkZ()*16+16; rawZ++) - { + for (int rawX = data.getChunkX() * 16; rawX <= data.getChunkX() * 16 + 16; rawX++) { + for (int rawZ = data.getChunkZ() * 16; rawZ <= data.getChunkZ() * 16 + 16; rawZ++) { int surfaceY = GenUtils.getTransformedHeight(data.getTerraformWorld(), rawX, rawZ); - BiomeBank bank = tw.getBiomeBank(rawX,surfaceY,rawZ); + BiomeBank bank = tw.getBiomeBank(rawX, surfaceY, rawZ); banks.add(bank); // Don't populate wet stuff in places that aren't wet - if(!bank.isDry() && data.getType(rawX,surfaceY+1,rawZ) != Material.WATER) + if (!bank.isDry() && data.getType(rawX, surfaceY + 1, rawZ) != Material.WATER) { continue; + } bank.getHandler().populateSmallItems(tw, random, rawX, surfaceY, rawZ, data); } + } // Only decorate disruptive features if the structures allow for them - if(canDecorate) - for (BiomeBank bank : banks) + if (canDecorate) { + for (BiomeBank bank : banks) { bank.getHandler().populateLargeItems(tw, random, data); + } + } - - // Cave populators + + // Cave populators // They will recalculate biomes per block. - caveDistributor.populate(tw, random, data); + caveDistributor.populate(tw, random, data); - // Multi-megachunk structures + // Multi-megachunk structures for (MultiMegaChunkStructurePopulator spop : StructureRegistry.smallStructureRegistry) { if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, data.getChunkX(), data.getChunkZ())) { - TerraformGeneratorPlugin.logger.info("Generating " + spop.getClass().getName() + " at chunk: " + data.getChunkX() + "," + data.getChunkZ()); - + TerraformGeneratorPlugin.logger.info("Generating " + + spop.getClass().getName() + + " at chunk: " + + data.getChunkX() + + "," + + data.getChunkZ()); + // No async events // Bukkit.getPluginManager().callEvent(new TerraformStructureSpawnEvent(data.getChunkX()*16+8, data.getChunkZ()*16+8, spop.getClass().getName())); - + spop.populate(tw, data); } } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java index 7d7302c3..0d93924c 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java @@ -21,78 +21,82 @@ import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -public class NativeGeneratorPatcherPopulator extends BlockPopulator implements Listener{ - - private static boolean flushIsQueued = false; +public class NativeGeneratorPatcherPopulator extends BlockPopulator implements Listener { + // SimpleChunkLocation to a collection of location:blockdata entries marked for repair. public static final @NotNull Map> cache = new ConcurrentHashMap<>(); + private static boolean flushIsQueued = false; public NativeGeneratorPatcherPopulator() { // this.tw = tw; - Bukkit.getPluginManager().registerEvents(this, TerraformGeneratorPlugin.get()); + Bukkit.getPluginManager().registerEvents(this, TerraformGeneratorPlugin.get()); } - + public static void pushChange(String world, int x, int y, int z, BlockData data) { - - if(!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { - flushIsQueued = true; - new BukkitRunnable() { - @Override - public void run() { - flushChanges(); - flushIsQueued = false; - } - }.runTask(TerraformGeneratorPlugin.get()); - } - + + if (!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { + flushIsQueued = true; + new BukkitRunnable() { + @Override + public void run() { + flushChanges(); + flushIsQueued = false; + } + }.runTask(TerraformGeneratorPlugin.get()); + } + SimpleChunkLocation scl = new SimpleChunkLocation(world, x, y, z); - if (!cache.containsKey(scl)) + if (!cache.containsKey(scl)) { cache.put(scl, new ArrayList<>()); -// cacheContents.put(data.getMaterial(), cacheContents.getOrDefault(data.getMaterial(),0)+1); - cache.get(scl).add(new Object[]{ - new int[]{x, y, z}, - data + } + // cacheContents.put(data.getMaterial(), cacheContents.getOrDefault(data.getMaterial(),0)+1); + cache.get(scl).add(new Object[] { + new int[] {x, y, z}, data }); } - + public static void flushChanges() { - if(cache.isEmpty()) - return; - TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs (" + cache.size() + " chunks), pushed by cache size"); + if (cache.isEmpty()) { + return; + } + TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs (" + + cache.size() + + " chunks), pushed by cache size"); ArrayList locs = new ArrayList<>(cache.keySet()); - for(SimpleChunkLocation scl:locs) { - World w = Bukkit.getWorld(scl.getWorld()); - if(w == null) continue; - if(w.isChunkLoaded(scl.getX(), scl.getZ())) { - // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] - Flushing changes to loaded chunk..."); - Collection changes = cache.remove(scl); - if (changes != null) { - for (Object[] entry : changes) { - int[] loc = (int[]) entry[0]; - BlockData data = (BlockData) entry[1]; - w.getBlockAt(loc[0], loc[1], loc[2]) - .setBlockData(data, false); - } - } - } else { - // Let the event handler do it - // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] - Loading a chunk to flush changes..."); - w.loadChunk(scl.getX(), scl.getZ()); - } - } + for (SimpleChunkLocation scl : locs) { + World w = Bukkit.getWorld(scl.getWorld()); + if (w == null) { + continue; + } + if (w.isChunkLoaded(scl.getX(), scl.getZ())) { + // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] - Flushing changes to loaded chunk..."); + Collection changes = cache.remove(scl); + if (changes != null) { + for (Object[] entry : changes) { + int[] loc = (int[]) entry[0]; + BlockData data = (BlockData) entry[1]; + w.getBlockAt(loc[0], loc[1], loc[2]).setBlockData(data, false); + } + } + } + else { + // Let the event handler do it + // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] - Loading a chunk to flush changes..."); + w.loadChunk(scl.getX(), scl.getZ()); + } + } } - + @Override public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { SimpleChunkLocation scl = new SimpleChunkLocation(chunk); Collection changes = cache.remove(scl); if (changes != null) { - // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs (" + cache.size() + " chunks), pushed by BlockPopulator"); + // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs (" + cache.size() + " chunks), pushed by BlockPopulator"); for (Object[] entry : changes) { int[] loc = (int[]) entry[0]; BlockData data = (BlockData) entry[1]; - world.getBlockAt(loc[0], loc[1], loc[2]) - .setBlockData(data, false); + world.getBlockAt(loc[0], loc[1], loc[2]).setBlockData(data, false); } } } @@ -102,38 +106,47 @@ public void onChunkLoad(@NotNull ChunkLoadEvent event) { SimpleChunkLocation scl = new SimpleChunkLocation(event.getChunk()); Collection changes = cache.remove(scl); if (changes != null) { - // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs for 1 chunk (" + scl.getX() + "," + scl.getZ() + "), pushed by chunkloadevent"); + // TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs for 1 chunk (" + scl.getX() + "," + scl.getZ() + "), pushed by chunkloadevent"); for (Object[] entry : changes) { int[] loc = (int[]) entry[0]; BlockData data = (BlockData) entry[1]; - event.getChunk().getWorld().getBlockAt(loc[0], loc[1], loc[2]) - .setBlockData(data, false); + event.getChunk().getWorld().getBlockAt(loc[0], loc[1], loc[2]).setBlockData(data, false); } } } - + @EventHandler public void onWorldUnload(@NotNull WorldUnloadEvent event) { - TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs for " + event.getWorld().getName() + " (" + cache.size() + " chunks in cache), triggered by world unload"); - - int processed = 0; - for(SimpleChunkLocation scl:cache.keySet()) { - if(!scl.getWorld().equals(event.getWorld().getName())) - continue; - Collection changes = cache.get(scl); - if (changes != null) { - for (Object[] entry : changes) { - int[] loc = (int[]) entry[0]; - BlockData data = (BlockData) entry[1]; - event.getWorld().getBlockAt(loc[0], loc[1], loc[2]) - .setBlockData(data, false); - } - } - - processed++; - if(processed % 20 == 0) - TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Processed " + processed + "/" + cache.size() + " chunks"); - } + TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Flushing repairs for " + + event.getWorld() + .getName() + + " (" + + cache.size() + + " chunks in cache), triggered by world unload"); + + int processed = 0; + for (SimpleChunkLocation scl : cache.keySet()) { + if (!scl.getWorld().equals(event.getWorld().getName())) { + continue; + } + Collection changes = cache.get(scl); + if (changes != null) { + for (Object[] entry : changes) { + int[] loc = (int[]) entry[0]; + BlockData data = (BlockData) entry[1]; + event.getWorld().getBlockAt(loc[0], loc[1], loc[2]).setBlockData(data, false); + } + } + + processed++; + if (processed % 20 == 0) { + TerraformGeneratorPlugin.logger.info("[NativeGeneratorPatcher] Processed " + + processed + + "/" + + cache.size() + + " chunks"); + } + } } } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java index 8936421e..77e2528e 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java @@ -23,108 +23,124 @@ import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -public class PhysicsUpdaterPopulator extends BlockPopulator implements Listener{ - - private static boolean flushIsQueued = false; +public class PhysicsUpdaterPopulator extends BlockPopulator implements Listener { + // SimpleChunkLocation to a collection of simplelocations public static final @NotNull Map> cache = new ConcurrentHashMap<>(); + private static boolean flushIsQueued = false; // private final TerraformWorld tw; public PhysicsUpdaterPopulator() { // this.tw = tw; - Bukkit.getPluginManager().registerEvents(this, TerraformGeneratorPlugin.get()); + Bukkit.getPluginManager().registerEvents(this, TerraformGeneratorPlugin.get()); } - + public static void pushChange(String world, @NotNull SimpleLocation loc) { - - if(!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { - flushIsQueued = true; - new BukkitRunnable() { - @Override - public void run() { - flushChanges(); - flushIsQueued = false; - } - }.runTask(TerraformGeneratorPlugin.get()); - } - - SimpleChunkLocation scl = new SimpleChunkLocation(world, loc.getX(), loc.getY(),loc.getZ()); - if (!cache.containsKey(scl)) + + if (!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { + flushIsQueued = true; + new BukkitRunnable() { + @Override + public void run() { + flushChanges(); + flushIsQueued = false; + } + }.runTask(TerraformGeneratorPlugin.get()); + } + + SimpleChunkLocation scl = new SimpleChunkLocation(world, loc.getX(), loc.getY(), loc.getZ()); + if (!cache.containsKey(scl)) { cache.put(scl, new ArrayList<>()); + } cache.get(scl).add(loc); } - + public static void flushChanges() { - if(cache.isEmpty()) - return; - TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Flushing repairs (" + cache.size() + " chunks)"); + if (cache.isEmpty()) { + return; + } + TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Flushing repairs (" + + cache.size() + + " chunks)"); ArrayList locs = new ArrayList<>(cache.keySet()); - for(SimpleChunkLocation scl:locs) { - World w = Bukkit.getWorld(scl.getWorld()); - if(w == null) continue; - if(w.isChunkLoaded(scl.getX(), scl.getZ())) { - Collection changes = cache.remove(scl); - if (changes != null) { - for (SimpleLocation entry : changes) { - Block target = w.getBlockAt(entry.getX(), entry.getY(), entry.getZ()); - // Set block physics by calling setBlockData - // Note that this should not be used for complex blocks. - BlockData old = target.getBlockData(); - TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] " + target.getLocation()); - target.setType(Material.AIR); - target.setBlockData(old, true); - } - } - } else { - // Let the event handler do it - w.loadChunk(scl.getX(), scl.getZ()); - } - } + for (SimpleChunkLocation scl : locs) { + World w = Bukkit.getWorld(scl.getWorld()); + if (w == null) { + continue; + } + if (w.isChunkLoaded(scl.getX(), scl.getZ())) { + Collection changes = cache.remove(scl); + if (changes != null) { + for (SimpleLocation entry : changes) { + Block target = w.getBlockAt(entry.getX(), entry.getY(), entry.getZ()); + // Set block physics by calling setBlockData + // Note that this should not be used for complex blocks. + BlockData old = target.getBlockData(); + TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] " + target.getLocation()); + target.setType(Material.AIR); + target.setBlockData(old, true); + } + } + } + else { + // Let the event handler do it + w.loadChunk(scl.getX(), scl.getZ()); + } + } } - + @Override public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { SimpleChunkLocation scl = new SimpleChunkLocation(chunk); - Collection changes = cache.remove(scl); + Collection changes = cache.remove(scl); if (changes != null) { - // TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Detected anomalous generation by NMS on " + scl + ". Running repairs on " + changes.size() + " blocks"); - for (SimpleLocation entry : changes) { - Block target = world.getBlockAt(entry.getX(), entry.getY(), entry.getZ()); - // Set block physics by calling setBlockData - // Note that this should not be used for complex blocks. - BlockData old = target.getBlockData(); - target.setType(Material.AIR); - target.setBlockData(old, true); - } + // TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Detected anomalous generation by NMS on " + scl + ". Running repairs on " + changes.size() + " blocks"); + for (SimpleLocation entry : changes) { + Block target = world.getBlockAt(entry.getX(), entry.getY(), entry.getZ()); + // Set block physics by calling setBlockData + // Note that this should not be used for complex blocks. + BlockData old = target.getBlockData(); + target.setType(Material.AIR); + target.setBlockData(old, true); + } } } -@EventHandler + @EventHandler public void onWorldUnload(@NotNull WorldUnloadEvent event) { - TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Flushing repairs for " + event.getWorld().getName() + " (" + cache.size() + " chunks in cache)"); - - int processed = 0; - for(SimpleChunkLocation scl:cache.keySet()) { - if(!scl.getWorld().equals(event.getWorld().getName())) - continue; - Collection changes = cache.remove(scl); + TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Flushing repairs for " + + event.getWorld() + .getName() + + " (" + + cache.size() + + " chunks in cache)"); + + int processed = 0; + for (SimpleChunkLocation scl : cache.keySet()) { + if (!scl.getWorld().equals(event.getWorld().getName())) { + continue; + } + Collection changes = cache.remove(scl); if (changes != null) { - // TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Detected anomalous generation by NMS on " + scl + ". Running repairs on " + changes.size() + " blocks"); - for (SimpleLocation entry : changes) { - Block target = event.getWorld().getBlockAt(entry.getX(), entry.getY(), entry.getZ()); - // Set block physics by calling setBlockData - // Note that this should not be used for complex blocks. - BlockData old = target.getBlockData(); - target.setType(Material.AIR); - target.setBlockData(old, true); - } + // TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Detected anomalous generation by NMS on " + scl + ". Running repairs on " + changes.size() + " blocks"); + for (SimpleLocation entry : changes) { + Block target = event.getWorld().getBlockAt(entry.getX(), entry.getY(), entry.getZ()); + // Set block physics by calling setBlockData + // Note that this should not be used for complex blocks. + BlockData old = target.getBlockData(); + target.setType(Material.AIR); + target.setBlockData(old, true); + } + } + + processed++; + if (processed % 20 == 0) { + TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Processed " + + processed + + " more chunks"); } - - processed++; - if(processed % 20 == 0) - TerraformGeneratorPlugin.logger.info("[PhysicsUpdaterPopulator] Processed " + processed + " more chunks"); - } + } } } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java index a3a12d68..4866abbc 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java @@ -17,125 +17,361 @@ public class TerraformAnimalPopulator extends BlockPopulator { - private final TerraformWorld tw; - private static final AnimalPopulator[] ANIMAL_POPULATORS = { - null, // Slot for goat + null, // Slot for goat null, // Slot for armadillo - - new AnimalPopulator(EntityType.PIG, TConfigOption.ANIMALS_PIG_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_PIG_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PIG_CHANCE.getInt(), false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, BiomeBank.MUSHROOM_BEACH,BiomeBank.RIVER, BiomeBank.FROZEN_RIVER, BiomeBank.OCEAN, BiomeBank.COLD_OCEAN, BiomeBank.FROZEN_OCEAN, - BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_COLD_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, - BiomeBank.DEEP_WARM_OCEAN, BiomeBank.SWAMP, BiomeBank.DESERT, BiomeBank.DESERT_MOUNTAINS, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON), - - new AnimalPopulator(EntityType.COW, TConfigOption.ANIMALS_COW_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_COW_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_COW_CHANCE.getInt(), false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, BiomeBank.MUSHROOM_BEACH, BiomeBank.RIVER, BiomeBank.FROZEN_RIVER, BiomeBank.OCEAN, BiomeBank.COLD_OCEAN, BiomeBank.FROZEN_OCEAN, - BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_COLD_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, - BiomeBank.DEEP_WARM_OCEAN, BiomeBank.SWAMP, BiomeBank.DESERT, BiomeBank.DESERT_MOUNTAINS, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON), - - new AnimalPopulator(EntityType.SHEEP, TConfigOption.ANIMALS_SHEEP_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_SHEEP_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SHEEP_CHANCE.getInt(), false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, BiomeBank.MUSHROOM_BEACH, BiomeBank.RIVER, BiomeBank.FROZEN_RIVER, BiomeBank.OCEAN, BiomeBank.COLD_OCEAN, BiomeBank.FROZEN_OCEAN, - BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_COLD_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, - BiomeBank.DEEP_WARM_OCEAN, BiomeBank.SWAMP, BiomeBank.DESERT, BiomeBank.DESERT_MOUNTAINS, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON), - - new AnimalPopulator(EntityType.CHICKEN, TConfigOption.ANIMALS_CHICKEN_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_CHICKEN_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_CHICKEN_CHANCE.getInt(), false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, BiomeBank.MUSHROOM_BEACH, BiomeBank.RIVER, BiomeBank.FROZEN_RIVER, BiomeBank.OCEAN, BiomeBank.COLD_OCEAN, BiomeBank.FROZEN_OCEAN, - BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_COLD_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, - BiomeBank.DEEP_WARM_OCEAN, BiomeBank.SWAMP, BiomeBank.DESERT, BiomeBank.DESERT_MOUNTAINS, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON), - - new AnimalPopulator(EntityType.HORSE, TConfigOption.ANIMALS_HORSE_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_HORSE_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_HORSE_CHANCE.getInt(), true, BiomeBank.PLAINS, BiomeBank.SAVANNA), - - new AnimalPopulator(EntityType.DONKEY, TConfigOption.ANIMALS_DONKEY_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_DONKEY_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_DONKEY_CHANCE.getInt(), true, BiomeBank.PLAINS, BiomeBank.SAVANNA), - - new AnimalPopulator(EntityType.RABBIT, TConfigOption.ANIMALS_RABBIT_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_RABBIT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_RABBIT_CHANCE.getInt(), true, BiomeBank.DESERT, BiomeBank.FOREST, BiomeBank.TAIGA, BiomeBank.SNOWY_TAIGA, BiomeBank.ROCKY_BEACH, - BiomeBank.SNOWY_WASTELAND), - - new AnimalPopulator(EntityType.POLAR_BEAR, TConfigOption.ANIMALS_POLAR_BEAR_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_POLAR_BEAR_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_POLAR_BEAR_CHANCE.getInt(), true, BiomeBank.ICE_SPIKES, BiomeBank.SNOWY_TAIGA, BiomeBank.ICY_BEACH, BiomeBank.SNOWY_WASTELAND), - - new AnimalPopulator(EntityType.PANDA, TConfigOption.ANIMALS_PANDA_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_PANDA_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PANDA_CHANCE.getInt(), true, BiomeBank.BAMBOO_FOREST), - - new AnimalPopulator(EntityType.FOX, TConfigOption.ANIMALS_FOX_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_FOX_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_FOX_CHANCE.getInt(), true, BiomeBank.TAIGA, BiomeBank.SNOWY_TAIGA), - - new AnimalPopulator(EntityType.LLAMA, TConfigOption.ANIMALS_LLAMA_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_LLAMA_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_LLAMA_CHANCE.getInt(), true, BiomeBank.SAVANNA, BiomeBank.ROCKY_MOUNTAINS), - - new AnimalPopulator(EntityType.PARROT, TConfigOption.ANIMALS_PARROT_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_PARROT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PARROT_CHANCE.getInt(), true, BiomeBank.JUNGLE), - - new AnimalPopulator(EntityType.OCELOT, TConfigOption.ANIMALS_OCELOT_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_OCELOT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_OCELOT_CHANCE.getInt(), true, BiomeBank.JUNGLE, BiomeBank.BAMBOO_FOREST), - - new AnimalPopulator(EntityType.WOLF, TConfigOption.ANIMALS_WOLF_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_WOLF_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_WOLF_CHANCE.getInt(), true, BiomeBank.FOREST, BiomeBank.TAIGA, BiomeBank.SNOWY_TAIGA, BiomeBank.DARK_FOREST), - - new AnimalPopulator(EntityType.TURTLE, TConfigOption.ANIMALS_TURTLE_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_TURTLE_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_TURTLE_CHANCE.getInt(), true, BiomeBank.SANDY_BEACH), - - new AnimalPopulator(EntityType.DOLPHIN, TConfigOption.ANIMALS_DOLPHIN_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_DOLPHIN_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_DOLPHIN_CHANCE.getInt(), true, BiomeBank.OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_WARM_OCEAN) - .setAquatic(true), - - new AnimalPopulator(EntityType.COD, TConfigOption.ANIMALS_COD_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_COD_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_COD_CHANCE.getInt(), true, BiomeBank.OCEAN, BiomeBank.DEEP_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.COLD_OCEAN, BiomeBank.DEEP_COLD_OCEAN) - .setAquatic(true), - - new AnimalPopulator(EntityType.SQUID, TConfigOption.ANIMALS_SQUID_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_SQUID_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SQUID_CHANCE.getInt(), true, - BiomeBank.FROZEN_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, - BiomeBank.COLD_OCEAN, BiomeBank.DEEP_COLD_OCEAN, - BiomeBank.BLACK_OCEAN,BiomeBank.DEEP_BLACK_OCEAN, - BiomeBank.OCEAN, BiomeBank.DEEP_OCEAN, - BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, - BiomeBank.WARM_OCEAN, BiomeBank.DEEP_WARM_OCEAN, - BiomeBank.RIVER, BiomeBank.FROZEN_RIVER, BiomeBank.JUNGLE_RIVER) - .setAquatic(true), - - new AnimalPopulator(EntityType.SALMON, TConfigOption.ANIMALS_SALMON_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_SALMON_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SALMON_CHANCE.getInt(), true, - BiomeBank.COLD_OCEAN, BiomeBank.DEEP_COLD_OCEAN, - BiomeBank.FROZEN_OCEAN, BiomeBank.DEEP_COLD_OCEAN, - BiomeBank.RIVER, BiomeBank.FROZEN_RIVER) - .setAquatic(true), - - new AnimalPopulator(EntityType.PUFFERFISH, TConfigOption.ANIMALS_PUFFERFISH_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_PUFFERFISH_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PUFFERFISH_CHANCE.getInt(), true, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.WARM_OCEAN, BiomeBank.DEEP_WARM_OCEAN) - .setAquatic(true), - - new AnimalPopulator(EntityType.TROPICAL_FISH, TConfigOption.ANIMALS_TROPICALFISH_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_TROPICALFISH_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_TROPICALFISH_CHANCE.getInt(), true, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.WARM_OCEAN) - .setAquatic(true), - - new AnimalPopulator(EntityType.MUSHROOM_COW, TConfigOption.ANIMALS_MOOSHROOM_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_MOOSHROOM_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_MOOSHROOM_CHANCE.getInt(), true, BiomeBank.MUSHROOM_BEACH, BiomeBank.MUSHROOM_ISLANDS), - }; - + + new AnimalPopulator(EntityType.PIG, + TConfigOption.ANIMALS_PIG_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_PIG_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_PIG_CHANCE.getInt(), + false, + BiomeBank.BLACK_OCEAN, + BiomeBank.MUSHROOM_ISLANDS, + BiomeBank.MUSHROOM_BEACH, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER, + BiomeBank.OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.DEEP_FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN, + BiomeBank.SWAMP, + BiomeBank.DESERT, + BiomeBank.DESERT_MOUNTAINS, + BiomeBank.BADLANDS, + BiomeBank.BADLANDS_CANYON + ), + + new AnimalPopulator(EntityType.COW, + TConfigOption.ANIMALS_COW_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_COW_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_COW_CHANCE.getInt(), + false, + BiomeBank.BLACK_OCEAN, + BiomeBank.MUSHROOM_ISLANDS, + BiomeBank.MUSHROOM_BEACH, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER, + BiomeBank.OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.DEEP_FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN, + BiomeBank.SWAMP, + BiomeBank.DESERT, + BiomeBank.DESERT_MOUNTAINS, + BiomeBank.BADLANDS, + BiomeBank.BADLANDS_CANYON + ), + + new AnimalPopulator(EntityType.SHEEP, + TConfigOption.ANIMALS_SHEEP_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_SHEEP_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_SHEEP_CHANCE.getInt(), + false, + BiomeBank.BLACK_OCEAN, + BiomeBank.MUSHROOM_ISLANDS, + BiomeBank.MUSHROOM_BEACH, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER, + BiomeBank.OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.DEEP_FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN, + BiomeBank.SWAMP, + BiomeBank.DESERT, + BiomeBank.DESERT_MOUNTAINS, + BiomeBank.BADLANDS, + BiomeBank.BADLANDS_CANYON + ), + + new AnimalPopulator(EntityType.CHICKEN, + TConfigOption.ANIMALS_CHICKEN_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_CHICKEN_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_CHICKEN_CHANCE.getInt(), + false, + BiomeBank.BLACK_OCEAN, + BiomeBank.MUSHROOM_ISLANDS, + BiomeBank.MUSHROOM_BEACH, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER, + BiomeBank.OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.DEEP_FROZEN_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN, + BiomeBank.SWAMP, + BiomeBank.DESERT, + BiomeBank.DESERT_MOUNTAINS, + BiomeBank.BADLANDS, + BiomeBank.BADLANDS_CANYON + ), + + new AnimalPopulator(EntityType.HORSE, + TConfigOption.ANIMALS_HORSE_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_HORSE_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_HORSE_CHANCE.getInt(), + true, + BiomeBank.PLAINS, + BiomeBank.SAVANNA + ), + + new AnimalPopulator(EntityType.DONKEY, + TConfigOption.ANIMALS_DONKEY_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_DONKEY_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_DONKEY_CHANCE.getInt(), + true, + BiomeBank.PLAINS, + BiomeBank.SAVANNA + ), + + new AnimalPopulator(EntityType.RABBIT, + TConfigOption.ANIMALS_RABBIT_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_RABBIT_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_RABBIT_CHANCE.getInt(), + true, + BiomeBank.DESERT, + BiomeBank.FOREST, + BiomeBank.TAIGA, + BiomeBank.SNOWY_TAIGA, + BiomeBank.ROCKY_BEACH, + BiomeBank.SNOWY_WASTELAND + ), + + new AnimalPopulator(EntityType.POLAR_BEAR, + TConfigOption.ANIMALS_POLAR_BEAR_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_POLAR_BEAR_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_POLAR_BEAR_CHANCE.getInt(), + true, + BiomeBank.ICE_SPIKES, + BiomeBank.SNOWY_TAIGA, + BiomeBank.ICY_BEACH, + BiomeBank.SNOWY_WASTELAND + ), + + new AnimalPopulator(EntityType.PANDA, + TConfigOption.ANIMALS_PANDA_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_PANDA_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_PANDA_CHANCE.getInt(), + true, + BiomeBank.BAMBOO_FOREST + ), + + new AnimalPopulator(EntityType.FOX, + TConfigOption.ANIMALS_FOX_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_FOX_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_FOX_CHANCE.getInt(), + true, + BiomeBank.TAIGA, + BiomeBank.SNOWY_TAIGA + ), + + new AnimalPopulator(EntityType.LLAMA, + TConfigOption.ANIMALS_LLAMA_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_LLAMA_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_LLAMA_CHANCE.getInt(), + true, + BiomeBank.SAVANNA, + BiomeBank.ROCKY_MOUNTAINS + ), + + new AnimalPopulator(EntityType.PARROT, + TConfigOption.ANIMALS_PARROT_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_PARROT_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_PARROT_CHANCE.getInt(), + true, + BiomeBank.JUNGLE + ), + + new AnimalPopulator(EntityType.OCELOT, + TConfigOption.ANIMALS_OCELOT_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_OCELOT_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_OCELOT_CHANCE.getInt(), + true, + BiomeBank.JUNGLE, + BiomeBank.BAMBOO_FOREST + ), + + new AnimalPopulator(EntityType.WOLF, + TConfigOption.ANIMALS_WOLF_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_WOLF_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_WOLF_CHANCE.getInt(), + true, + BiomeBank.FOREST, + BiomeBank.TAIGA, + BiomeBank.SNOWY_TAIGA, + BiomeBank.DARK_FOREST + ), + + new AnimalPopulator(EntityType.TURTLE, + TConfigOption.ANIMALS_TURTLE_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_TURTLE_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_TURTLE_CHANCE.getInt(), + true, + BiomeBank.SANDY_BEACH + ), + + new AnimalPopulator(EntityType.DOLPHIN, + TConfigOption.ANIMALS_DOLPHIN_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_DOLPHIN_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_DOLPHIN_CHANCE.getInt(), + true, + BiomeBank.OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN + ).setAquatic(true), + + new AnimalPopulator(EntityType.COD, + TConfigOption.ANIMALS_COD_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_COD_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_COD_CHANCE.getInt(), + true, + BiomeBank.OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.DEEP_COLD_OCEAN + ).setAquatic(true), + + new AnimalPopulator(EntityType.SQUID, + TConfigOption.ANIMALS_SQUID_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_SQUID_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_SQUID_CHANCE.getInt(), + true, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_FROZEN_OCEAN, + BiomeBank.COLD_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.BLACK_OCEAN, + BiomeBank.DEEP_BLACK_OCEAN, + BiomeBank.OCEAN, + BiomeBank.DEEP_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER, + BiomeBank.JUNGLE_RIVER + ).setAquatic(true), + + new AnimalPopulator(EntityType.SALMON, + TConfigOption.ANIMALS_SALMON_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_SALMON_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_SALMON_CHANCE.getInt(), + true, + BiomeBank.COLD_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.FROZEN_OCEAN, + BiomeBank.DEEP_COLD_OCEAN, + BiomeBank.RIVER, + BiomeBank.FROZEN_RIVER + ).setAquatic(true), + + new AnimalPopulator(EntityType.PUFFERFISH, + TConfigOption.ANIMALS_PUFFERFISH_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_PUFFERFISH_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_PUFFERFISH_CHANCE.getInt(), + true, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.WARM_OCEAN, + BiomeBank.DEEP_WARM_OCEAN + ).setAquatic(true), + + new AnimalPopulator(EntityType.TROPICAL_FISH, + TConfigOption.ANIMALS_TROPICALFISH_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_TROPICALFISH_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_TROPICALFISH_CHANCE.getInt(), + true, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.CORAL_REEF_OCEAN, + BiomeBank.DEEP_LUKEWARM_OCEAN, + BiomeBank.WARM_OCEAN + ).setAquatic(true), + + new AnimalPopulator(EntityType.MUSHROOM_COW, + TConfigOption.ANIMALS_MOOSHROOM_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_MOOSHROOM_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_MOOSHROOM_CHANCE.getInt(), + true, + BiomeBank.MUSHROOM_BEACH, + BiomeBank.MUSHROOM_ISLANDS + ), + }; + private final TerraformWorld tw; + public TerraformAnimalPopulator(TerraformWorld tw) { this.tw = tw; - if(Version.isAtLeast(17)) { - ANIMAL_POPULATORS[0] = new AnimalPopulator(EntityType.valueOf("GOAT"), TConfigOption.ANIMALS_GOAT_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_GOAT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_GOAT_CHANCE.getInt(), true, BiomeBank.ROCKY_MOUNTAINS, BiomeBank.SNOWY_MOUNTAINS); + if (Version.isAtLeast(17)) { + ANIMAL_POPULATORS[0] = new AnimalPopulator(EntityType.valueOf("GOAT"), + TConfigOption.ANIMALS_GOAT_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_GOAT_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_GOAT_CHANCE.getInt(), + true, + BiomeBank.ROCKY_MOUNTAINS, + BiomeBank.SNOWY_MOUNTAINS + ); } - if(Version.isAtLeast(20.5)) { - ANIMAL_POPULATORS[1] = new AnimalPopulator(OneTwentyFiveBlockHandler.ARMADILLO, TConfigOption.ANIMALS_ARMADILLO_MINHERDSIZE.getInt(), TConfigOption.ANIMALS_ARMADILLO_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_ARMADILLO_CHANCE.getInt(), true, BiomeBank.SAVANNA, BiomeBank.SHATTERED_SAVANNA, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON); + if (Version.isAtLeast(20.5)) { + ANIMAL_POPULATORS[1] = new AnimalPopulator(OneTwentyFiveBlockHandler.ARMADILLO, + TConfigOption.ANIMALS_ARMADILLO_MINHERDSIZE.getInt(), + TConfigOption.ANIMALS_ARMADILLO_MAXHERDSIZE.getInt(), + TConfigOption.ANIMALS_ARMADILLO_CHANCE.getInt(), + true, + BiomeBank.SAVANNA, + BiomeBank.SHATTERED_SAVANNA, + BiomeBank.BADLANDS, + BiomeBank.BADLANDS_CANYON + ); } } @Override public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { - - PopulatorDataPostGen data = new PopulatorDataPostGen(chunk); - for (AnimalPopulator pop : ANIMAL_POPULATORS) { - if(pop == null) continue; + PopulatorDataPostGen data = new PopulatorDataPostGen(chunk); + + for (AnimalPopulator pop : ANIMAL_POPULATORS) { + if (pop == null) { + continue; + } if (pop.canSpawn(tw.getHashedRand(chunk.getX(), pop.hashCode(), chunk.getZ()))) { - pop.populate(tw, tw.getHashedRand(chunk.getX(), 111+pop.hashCode(), chunk.getZ()), data); + pop.populate(tw, tw.getHashedRand(chunk.getX(), 111 + pop.hashCode(), chunk.getZ()), data); } } } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformBukkitBlockPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformBukkitBlockPopulator.java index 915272b0..b698054c 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformBukkitBlockPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformBukkitBlockPopulator.java @@ -13,9 +13,10 @@ /** * This class is used to control the order in which the bukkit populator is used * to perform various actions. + * * @author Hex_27 */ -public class TerraformBukkitBlockPopulator extends BlockPopulator{ +public class TerraformBukkitBlockPopulator extends BlockPopulator { protected final TerraformWorld tw; private final @NotNull TerraformStructurePopulator structurePopulator; @@ -37,7 +38,7 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun // Run the fixers first this.nativePatcherPopulator.populate(world, random, chunk); this.physicsUpdaterPopulator.populate(world, random, chunk); - + // Populate structures next this.structurePopulator.populate(world, random, chunk); @@ -46,12 +47,17 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun } @Override - public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ, @NotNull LimitedRegion lr) { + public void populate(@NotNull WorldInfo worldInfo, + @NotNull Random random, + int chunkX, + int chunkZ, + @NotNull LimitedRegion lr) + { this.structurePopulator.populate(worldInfo, random, chunkX, chunkZ, lr); } - public @NotNull TerraformStructurePopulator getStructurePopulator() { - return structurePopulator; - } - + public @NotNull TerraformStructurePopulator getStructurePopulator() { + return structurePopulator; + } + } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformChunkData.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformChunkData.java index c30455e8..8bb2fcbe 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformChunkData.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformChunkData.java @@ -12,85 +12,89 @@ @SuppressWarnings("deprecation") public class TerraformChunkData implements ChunkData { - private final PopulatorDataAbstract popData; - public TerraformChunkData(PopulatorDataAbstract popData) - { - this.popData = popData; - } - - // private static boolean debug = true; - public int getBaseHeight(int x, int z) { - int height = -64; - if(popData instanceof IPopulatorDataBaseHeightAccess) { - height = ((IPopulatorDataBaseHeightAccess) popData).getBaseHeight(x + (popData.getChunkX()*16), z + (popData.getChunkZ()*16)); - } - return height; - } - - @Override - public @NotNull Biome getBiome(int x, int y, int z) { - return popData.getBiome(x + (popData.getChunkX()*16), z + (popData.getChunkZ()*16)); - } - - @Override - public @NotNull BlockData getBlockData(int x, int y, int z) { - return popData.getBlockData(x + (popData.getChunkX()*16), y, z + (popData.getChunkZ()*16)); - } - - @Override - public byte getData(int x, int y, int z) { - throw new UnsupportedOperationException("getData was called on TerraformChunkData!"); - } - - @Override - public int getMaxHeight() { - return popData.getTerraformWorld().maxY; - } - - @Override - public int getMinHeight() { - return popData.getTerraformWorld().minY; - } - - @Override - public @NotNull Material getType(int x, int y, int z) { - return popData.getType(x + (popData.getChunkX()*16), y, z + (popData.getChunkZ()*16)); - } - - @Override - public @NotNull MaterialData getTypeAndData(int x, int y, int z) { - throw new UnsupportedOperationException("getTypeAndData was called on TerraformChunkData with MaterialData!"); - } - - @Override - public void setBlock(int x, int y, int z, @NotNull Material arg3) { - // TerraformGeneratorPlugin.logger.info("Called setBlock at " + x + "," + y + "," + z); - popData.setType(x + (popData.getChunkX()*16), y, z + (popData.getChunkZ()*16), arg3); - } - - @Override - public void setBlock(int x, int y, int z, @NotNull MaterialData arg3) { - throw new UnsupportedOperationException("setBlock was called on TerraformChunkData with MaterialData!"); - } - - @Override - public void setBlock(int x, int y, int z, @NotNull BlockData arg3) { - popData.setBlockData(x + (popData.getChunkX()*16), y, z + (popData.getChunkZ()*16), arg3); - } - - @Override - public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull Material arg6) { - throw new UnsupportedOperationException("setRegion was called on TerraformChunkData!"); - } - - @Override - public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull MaterialData arg6) { - throw new UnsupportedOperationException("setRegion was called on TerraformChunkData with MaterialData!"); - } - - @Override - public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull BlockData arg6) { - throw new UnsupportedOperationException("setRegion was called on TerraformChunkData!"); - } + private final PopulatorDataAbstract popData; + + public TerraformChunkData(PopulatorDataAbstract popData) + { + this.popData = popData; + } + + // private static boolean debug = true; + public int getBaseHeight(int x, int z) { + int height = -64; + if (popData instanceof IPopulatorDataBaseHeightAccess) { + height = ((IPopulatorDataBaseHeightAccess) popData).getBaseHeight( + x + (popData.getChunkX() * 16), + z + (popData.getChunkZ() * 16) + ); + } + return height; + } + + @Override + public @NotNull Biome getBiome(int x, int y, int z) { + return popData.getBiome(x + (popData.getChunkX() * 16), z + (popData.getChunkZ() * 16)); + } + + @Override + public @NotNull BlockData getBlockData(int x, int y, int z) { + return popData.getBlockData(x + (popData.getChunkX() * 16), y, z + (popData.getChunkZ() * 16)); + } + + @Override + public byte getData(int x, int y, int z) { + throw new UnsupportedOperationException("getData was called on TerraformChunkData!"); + } + + @Override + public int getMaxHeight() { + return popData.getTerraformWorld().maxY; + } + + @Override + public int getMinHeight() { + return popData.getTerraformWorld().minY; + } + + @Override + public @NotNull Material getType(int x, int y, int z) { + return popData.getType(x + (popData.getChunkX() * 16), y, z + (popData.getChunkZ() * 16)); + } + + @Override + public @NotNull MaterialData getTypeAndData(int x, int y, int z) { + throw new UnsupportedOperationException("getTypeAndData was called on TerraformChunkData with MaterialData!"); + } + + @Override + public void setBlock(int x, int y, int z, @NotNull Material arg3) { + // TerraformGeneratorPlugin.logger.info("Called setBlock at " + x + "," + y + "," + z); + popData.setType(x + (popData.getChunkX() * 16), y, z + (popData.getChunkZ() * 16), arg3); + } + + @Override + public void setBlock(int x, int y, int z, @NotNull MaterialData arg3) { + throw new UnsupportedOperationException("setBlock was called on TerraformChunkData with MaterialData!"); + } + + @Override + public void setBlock(int x, int y, int z, @NotNull BlockData arg3) { + popData.setBlockData(x + (popData.getChunkX() * 16), y, z + (popData.getChunkZ() * 16), arg3); + } + + @Override + public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull Material arg6) { + throw new UnsupportedOperationException("setRegion was called on TerraformChunkData!"); + } + + @Override + public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull MaterialData arg6) { + throw new UnsupportedOperationException("setRegion was called on TerraformChunkData with MaterialData!"); + } + + @Override + public void setRegion(int x, int y, int z, int x2, int y2, int z2, @NotNull BlockData arg6) { + throw new UnsupportedOperationException("setRegion was called on TerraformChunkData!"); + } } diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java index 79e7b552..931db7c6 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java @@ -27,7 +27,8 @@ public class TerraformGenerator extends ChunkGenerator { public static final List preWorldInitGen = new ArrayList<>(); - + // Explode if a read is attempted. Transform Handlers are not supposed to read. + private static final DudChunkData DUD = new DudChunkData(); public static LoadingCache CHUNK_CACHE; public static int seaLevel = 62; @@ -40,17 +41,64 @@ public static void updateSeaLevelFromConfig() { */ public static @NotNull ChunkCache getCache(TerraformWorld tw, int x, int z) { ChunkCache cache = new ChunkCache(tw, x, 0, z); - // Note how it DOES NOT initInternalCache here + // Note how it DOES NOT initInternalCache here // Cos this is the damn key // Don't fucking run calculations here try { - return CHUNK_CACHE.get(cache); - } catch (ExecutionException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - TerraformGeneratorPlugin.logger.stackTrace(e.getCause()); - cache.initInternalCache(); - return cache; - } + return CHUNK_CACHE.get(cache); + } + catch (ExecutionException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + TerraformGeneratorPlugin.logger.stackTrace(e.getCause()); + cache.initInternalCache(); + return cache; + } + } + + // This method ONLY fills transformedHeight with meaningful values, + // and writes nothing. + public static void buildFilledCache(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull ChunkCache cache) { + // TerraformGeneratorPlugin.watchdogSuppressant.tickWatchdog(); don't unnecessarily tick this shit + + // Ensure that this shit is the same as the one in generateSurface + Random random = tw.getHashedRand(chunkX, chunkZ, 31278); + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + int rawX = chunkX * 16 + x; + int rawZ = chunkZ * 16 + z; + + double preciseHeight = HeightMap.getPreciseHeight( + tw, + rawX, + rawZ + ); // bank.getHandler().calculateHeight(tw, rawX, rawZ); + cache.writeTransformedHeight(x, z, (short) preciseHeight); + + // Carve caves + for (int y = (int) preciseHeight; y >= TerraformGeneratorPlugin.injector.getMinY(); y--) + // Set stone if a cave CANNOT be carved here + // Check canNoiseCarve because carver caves may expose + // noise caves below, which contribute to height changes + { + if (tw.noiseCaveRegistry.canGenerateCarve(rawX, y, rawZ, preciseHeight) + || tw.noiseCaveRegistry.canNoiseCarve(rawX, y, rawZ, preciseHeight)) + { + cache.writeTransformedHeight(x, z, (short) (y - 1)); + } + else { + break; + } + } + + // Apply biome transforms to get real height + BiomeBank bank = tw.getBiomeBank(rawX, (int) preciseHeight, rawZ); + BiomeHandler transformHandler = bank.getHandler().getTransformHandler(); + + if (transformHandler != null) { + transformHandler.transformTerrain(cache, tw, random, DUD, x, z, chunkX, chunkZ); + } + } + } } @Override @@ -71,11 +119,16 @@ public boolean isParallelCapable() { * then flush it into the CHUNK_CACHE after generation, which is * dumb. That's dumb. */ - public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random dontCareRandom, int chunkX, int chunkZ, @NotNull ChunkData chunkData) { + public void generateNoise(@NotNull WorldInfo worldInfo, + @NotNull Random dontCareRandom, + int chunkX, + int chunkZ, + @NotNull ChunkData chunkData) + { TerraformGeneratorPlugin.watchdogSuppressant.tickWatchdog(); - TerraformWorld tw = TerraformWorld.get(worldInfo.getName(),worldInfo.getSeed()); - ChunkCache cache = getCache(tw, chunkX*16,chunkZ*16); + TerraformWorld tw = TerraformWorld.get(worldInfo.getName(), worldInfo.getSeed()); + ChunkCache cache = getCache(tw, chunkX * 16, chunkZ * 16); // For transformation ONLY Random transformRandom = tw.getHashedRand(chunkX, chunkZ, 31278); @@ -85,21 +138,27 @@ public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random dontCare int rawX = chunkX * 16 + x; int rawZ = chunkZ * 16 + z; - double height = HeightMap.getPreciseHeight(tw, rawX, rawZ); // bank.getHandler().calculateHeight(tw, rawX, rawZ); - cache.writeTransformedHeight(x,z, (short) height); + double height = HeightMap.getPreciseHeight( + tw, + rawX, + rawZ + ); // bank.getHandler().calculateHeight(tw, rawX, rawZ); + cache.writeTransformedHeight(x, z, (short) height); // Fill stone up to the world height. Differentiate between deepslate or not. - for(int y = (int) height; y >= TerraformGeneratorPlugin.injector.getMinY(); y--) - { + for (int y = (int) height; y >= TerraformGeneratorPlugin.injector.getMinY(); y--) { Material stoneType = Material.STONE; - if(y < 0) + if (y < 0) { stoneType = Material.DEEPSLATE; - else if(y <= 2) + } + else if (y <= 2) { stoneType = GenUtils.randChoice(Material.DEEPSLATE, Material.STONE); + } // Set stone if a cave CANNOT be carved here - if(!tw.noiseCaveRegistry.canNoiseCarve(rawX,y,rawZ,height)) + if (!tw.noiseCaveRegistry.canNoiseCarve(rawX, y, rawZ, height)) { chunkData.setBlock(x, y, z, stoneType); + } } @@ -108,43 +167,48 @@ else if(y <= 2) int index = 0; Material[] crust = bank.getHandler().getSurfaceCrust(dontCareRandom); while (index < crust.length) { - chunkData.setBlock(x, (int) (height-index), z, crust[index]); + chunkData.setBlock(x, (int) (height - index), z, crust[index]); index++; } // Water for below certain heights - for(int y = (int) (height+1); y <= seaLevel; y++) - { - chunkData.setBlock(x,y,z,Material.WATER); + for (int y = (int) (height + 1); y <= seaLevel; y++) { + chunkData.setBlock(x, y, z, Material.WATER); } // Carve caves HERE. boolean mustUpdateHeight = true; - for(int y = (int) height; y > TerraformGeneratorPlugin.injector.getMinY(); y--) - { - if(tw.noiseCaveRegistry.canGenerateCarve(rawX,y,rawZ,height) - || !chunkData.getType(x,y,z).isSolid()) + for (int y = (int) height; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { + if (tw.noiseCaveRegistry.canGenerateCarve(rawX, y, rawZ, height) || !chunkData.getType(x, y, z) + .isSolid()) { chunkData.setBlock(x, y, z, Material.CAVE_AIR); - if(mustUpdateHeight) - cache.writeTransformedHeight (x,z, (short) (y-1)); - }else mustUpdateHeight = false; + if (mustUpdateHeight) { + cache.writeTransformedHeight(x, z, (short) (y - 1)); + } + } + else { + mustUpdateHeight = false; + } } // Transform height AFTER sea level is written. // Transformed below-sea areas are not supposed to be water. BiomeHandler transformHandler = bank.getHandler().getTransformHandler(); - if(transformHandler != null) - transformHandler.transformTerrain(cache, tw, transformRandom, chunkData, x, z,chunkX, chunkZ); + if (transformHandler != null) { + transformHandler.transformTerrain(cache, tw, transformRandom, chunkData, x, z, chunkX, chunkZ); + } // After this whole song and dance, place bedrock chunkData.setBlock(x, TerraformGeneratorPlugin.injector.getMinY(), z, Material.BEDROCK); // Up till y = minY+HEIGHT_MAP_BEDROCK_HEIGHT - for(int i = 1; i < TConfigOption.HEIGHT_MAP_BEDROCK_HEIGHT.getInt(); i++) { - if(GenUtils.chance(dontCareRandom, TConfigOption.HEIGHT_MAP_BEDROCK_DENSITY.getInt(), 100)) - chunkData.setBlock(x, TerraformGeneratorPlugin.injector.getMinY()+i, z, Material.BEDROCK); - else + for (int i = 1; i < TConfigOption.HEIGHT_MAP_BEDROCK_HEIGHT.getInt(); i++) { + if (GenUtils.chance(dontCareRandom, TConfigOption.HEIGHT_MAP_BEDROCK_DENSITY.getInt(), 100)) { + chunkData.setBlock(x, TerraformGeneratorPlugin.injector.getMinY() + i, z, Material.BEDROCK); + } + else { break; + } } } } @@ -154,54 +218,31 @@ else if(y <= 2) /** * Responsible for setting surface biome blocks and biomeTransforms */ - public void generateSurface(@NotNull WorldInfo worldInfo, @NotNull Random dontCareRandom, int chunkX, int chunkZ, @NotNull ChunkData chunkData) { - - } - - public void generateBedrock(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ, @NotNull ChunkData chunkData) { + public void generateSurface(@NotNull WorldInfo worldInfo, + @NotNull Random dontCareRandom, + int chunkX, + int chunkZ, + @NotNull ChunkData chunkData) + { } - public void generateCaves(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ, @NotNull ChunkData chunkData) { + public void generateBedrock(@NotNull WorldInfo worldInfo, + @NotNull Random random, + int chunkX, + int chunkZ, + @NotNull ChunkData chunkData) + { } - // Explode if a read is attempted. Transform Handlers are not supposed to read. - private static final DudChunkData DUD = new DudChunkData(); - - // This method ONLY fills transformedHeight with meaningful values, - // and writes nothing. - public static void buildFilledCache(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull ChunkCache cache){ - // TerraformGeneratorPlugin.watchdogSuppressant.tickWatchdog(); don't unnecessarily tick this shit - - // Ensure that this shit is the same as the one in generateSurface - Random random = tw.getHashedRand(chunkX, chunkZ, 31278); - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - int rawX = chunkX * 16 + x; - int rawZ = chunkZ * 16 + z; + public void generateCaves(@NotNull WorldInfo worldInfo, + @NotNull Random random, + int chunkX, + int chunkZ, + @NotNull ChunkData chunkData) + { - double preciseHeight = HeightMap.getPreciseHeight(tw, rawX, rawZ); // bank.getHandler().calculateHeight(tw, rawX, rawZ); - cache.writeTransformedHeight(x,z, (short) preciseHeight); - - // Carve caves - for(int y = (int) preciseHeight; y >= TerraformGeneratorPlugin.injector.getMinY(); y--) - // Set stone if a cave CANNOT be carved here - // Check canNoiseCarve because carver caves may expose - // noise caves below, which contribute to height changes - if(tw.noiseCaveRegistry.canGenerateCarve(rawX,y,rawZ,preciseHeight) - || tw.noiseCaveRegistry.canNoiseCarve(rawX,y,rawZ,preciseHeight)) - cache.writeTransformedHeight(x,z, (short) (y-1)); - else break; - - // Apply biome transforms to get real height - BiomeBank bank = tw.getBiomeBank(rawX, (int) preciseHeight,rawZ); - BiomeHandler transformHandler = bank.getHandler().getTransformHandler(); - - if(transformHandler != null) - transformHandler.transformTerrain(cache, tw, random, DUD, x, z,chunkX, chunkZ); - } - } } @Override @@ -212,7 +253,7 @@ public Location getFixedSpawnLocation(@NotNull World world, @NotNull Random rand @Override public @NotNull List getDefaultPopulators(@NotNull World world) { TerraformWorld tw = TerraformWorld.get(world); - return new ArrayList<>(){{ + return new ArrayList<>() {{ add(new TerraformPopulator(tw)); add(new TerraformBukkitBlockPopulator(tw)); }}; diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java index f255e0c6..ca04f1ad 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java @@ -39,8 +39,8 @@ public class TerraformStructurePopulator extends BlockPopulator { private final LoadingCache jigsawCache = CacheBuilder.newBuilder() - .maximumSize(20) - .build(CacheLoader.from((mc)->null)); + .maximumSize(20) + .build(CacheLoader.from((mc) -> null)); private final TerraformWorld tw; public TerraformStructurePopulator(TerraformWorld tw) { @@ -50,24 +50,34 @@ public TerraformStructurePopulator(TerraformWorld tw) { // NEW BLOCK POPULATOR API // Used to generate small paths and small rooms @Override - public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ, @NotNull LimitedRegion lr) { + public void populate(@NotNull WorldInfo worldInfo, + @NotNull Random random, + int chunkX, + int chunkZ, + @NotNull LimitedRegion lr) + { // Check if the nearest structure in this megachunk is close enough MegaChunk mc = new MegaChunk(chunkX, chunkZ); BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); JigsawState state = jigsawCache.getIfPresent(mc); - if(state == null) - { + if (state == null) { SingleMegaChunkStructurePopulator spop = getMegachunkStructure(mc, tw, biome); - if(spop == null) return; - if(!(spop instanceof JigsawStructurePopulator jsp)) return; + if (spop == null) { + return; + } + if (!(spop instanceof JigsawStructurePopulator jsp)) { + return; + } state = jsp.calculateRoomPopulators(tw, mc); TerraformGeneratorPlugin.logger.info("Calculated structure at " + chunkX + "," + chunkZ); jigsawCache.put(mc, state); } // Check if the room will be in range - if(!state.isInRange(chunkX, chunkZ)) return; + if (!state.isInRange(chunkX, chunkZ)) { + return; + } PopulatorDataAbstract data = new PopulatorDataSpigotAPI(lr, tw, chunkX, chunkZ); @@ -76,39 +86,42 @@ public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int c state.roomPopulatorStates.forEach(roomLayoutGenerator -> { final PathState pathState = roomLayoutGenerator.getOrCalculatePathState(tw); pathState.nodes.stream() - // Filter to only those inside this chunk - .filter(node->node.center.getX() >> 4 == chunkX && node.center.getZ() >> 4 == chunkZ) - .forEach(node->{ - pathState.writer.apply(data, tw, node); - seenNodes.add(node); - }); + // Filter to only those inside this chunk + .filter(node -> node.center.getX() >> 4 == chunkX && node.center.getZ() >> 4 == chunkZ) + .forEach(node -> { + pathState.writer.apply(data, tw, node); + seenNodes.add(node); + }); }); // Carve each room ArrayList seenRooms = new ArrayList<>(); - state.roomPopulatorStates.forEach(roomLayoutGenerator -> - roomLayoutGenerator.getRooms().stream() - // No rooms that have bounds beyond LR - .filter(room->room.isInRegion(lr)) - .forEach(room-> - { - seenRooms.add(room); - roomLayoutGenerator.roomCarver.carveRoom(data, room, roomLayoutGenerator.wallMaterials); - })); + state.roomPopulatorStates.forEach(roomLayoutGenerator -> roomLayoutGenerator.getRooms() + .stream() + // No rooms that have bounds beyond LR + .filter(room -> room.isInRegion(lr)) + .forEach(room -> { + seenRooms.add(room); + roomLayoutGenerator.roomCarver.carveRoom( + data, + room, + roomLayoutGenerator.wallMaterials + ); + })); // Populate the paths - seenNodes.forEach((node)->{ + seenNodes.forEach((node) -> { // If the path has a direction of up, it is a crossway. - if(node.populator != null) - node.populator.populate(new PathPopulatorData( - new Wall(new SimpleBlock(data, node.center), - node.connected.size() == 1 ? node.connected.stream().findAny().get() - : BlockFace.UP), - node.pathWidth)); + if (node.populator != null) { + node.populator.populate(new PathPopulatorData(new Wall( + new SimpleBlock(data, node.center), + node.connected.size() == 1 ? node.connected.stream().findAny().get() : BlockFace.UP + ), node.pathWidth)); + } }); // Populate the rooms - seenRooms.forEach(room-> room.getPop().populate(data, room)); + seenRooms.forEach(room -> room.getPop().populate(data, room)); } // OLDER BLOCK POPULATOR API @@ -119,39 +132,70 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun // Structuregen will freeze for long periods TerraformGeneratorPlugin.watchdogSuppressant.tickWatchdog(); // Don't attempt generation pre-injection. - if(!TerraformGeneratorPlugin.INJECTED_WORLDS.contains(world.getName())) return; + if (!TerraformGeneratorPlugin.INJECTED_WORLDS.contains(world.getName())) { + return; + } PopulatorDataPostGen data = new PopulatorDataPostGen(chunk); // Use IChunkAccess to place blocks instead. Known to cause lighting problems. // Since people keep turning this on for fun, then reporting bugs, I'm removing it. -// if (TConfigOption.DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT.getBoolean()) -// data = new PopulatorDataRecursiveICA(chunk); + // if (TConfigOption.DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT.getBoolean()) + // data = new PopulatorDataRecursiveICA(chunk); // Spawn large structures MegaChunk mc = new MegaChunk(chunk.getX(), chunk.getZ()); BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // Special Case - if(!TConfigOption.areStructuresEnabled() && new StrongholdPopulator().canSpawn(tw, data.getChunkX(), data.getChunkZ(), biome)) { - TerraformGeneratorPlugin.logger.info("Generating Stronghold at chunk: " + data.getChunkX() + "," + data.getChunkZ()); + if (!TConfigOption.areStructuresEnabled() && new StrongholdPopulator().canSpawn( + tw, + data.getChunkX(), + data.getChunkZ(), + biome + )) + { + TerraformGeneratorPlugin.logger.info("Generating Stronghold at chunk: " + + data.getChunkX() + + "," + + data.getChunkZ()); new StrongholdPopulator().populate(tw, data); } // Only check singlemegachunkstructures if this chunk is a central chunk. int[] chunkCoords = mc.getCenterBiomeSectionChunkCoords(); // TerraformGeneratorPlugin.logger.info("[v] MC(" + mc.getX() + "," + mc.getZ() + ") - " + data.getChunkX() + "," + data.getChunkZ() + " - Center: " + chunkCoords[0] + "," + chunkCoords[1]); - if(chunkCoords[0] == data.getChunkX() - && chunkCoords[1] == data.getChunkZ()) { + if (chunkCoords[0] == data.getChunkX() && chunkCoords[1] == data.getChunkZ()) { int[] blockCoords = mc.getCenterBiomeSectionBlockCoords(); // TerraformGeneratorPlugin.logger.info("[!] MC(" + mc.getX() + "," + mc.getZ() + ") - " + data.getChunkX() + "," + data.getChunkZ() + " - Center: " + chunkCoords[0] + "," + chunkCoords[1]); - for(SingleMegaChunkStructurePopulator spop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { - if(spop == null) continue; - if(!spop.isEnabled()) continue; - if(spop instanceof StrongholdPopulator) continue; - if(TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, data.getChunkX(), data.getChunkZ(), biome)) { - TerraformGeneratorPlugin.logger.info("Generating " + spop.getClass().getName() + " at chunk: " + data.getChunkX() + "," + data.getChunkZ()); - Bukkit.getPluginManager().callEvent(new TerraformStructureSpawnEvent(blockCoords[0], blockCoords[1], spop.getClass().getName())); + for (SingleMegaChunkStructurePopulator spop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { + if (spop == null) { + continue; + } + if (!spop.isEnabled()) { + continue; + } + if (spop instanceof StrongholdPopulator) { + continue; + } + if (TConfigOption.areStructuresEnabled() && spop.canSpawn( + tw, + data.getChunkX(), + data.getChunkZ(), + biome + )) + { + TerraformGeneratorPlugin.logger.info("Generating " + + spop.getClass().getName() + + " at chunk: " + + data.getChunkX() + + "," + + data.getChunkZ()); + Bukkit.getPluginManager() + .callEvent(new TerraformStructureSpawnEvent(blockCoords[0], + blockCoords[1], + spop.getClass().getName() + )); spop.populate(tw, data); break; } @@ -159,14 +203,23 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun } } - public @Nullable SingleMegaChunkStructurePopulator getMegachunkStructure(@NotNull MegaChunk mc, @NotNull TerraformWorld tw, BiomeBank biome){ + public @Nullable SingleMegaChunkStructurePopulator getMegachunkStructure(@NotNull MegaChunk mc, + @NotNull TerraformWorld tw, + BiomeBank biome) + { int[] chunkCoords = mc.getCenterBiomeSectionChunkCoords(); - for(SingleMegaChunkStructurePopulator spop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { - if(spop == null) continue; - if(!spop.isEnabled()) continue; - if(spop instanceof StrongholdPopulator) continue; + for (SingleMegaChunkStructurePopulator spop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { + if (spop == null) { + continue; + } + if (!spop.isEnabled()) { + continue; + } + if (spop instanceof StrongholdPopulator) { + continue; + } // TerraformGeneratorPlugin.logger.info("[v] MC(" + mc.getX() + "," + mc.getZ() + ") - Checking " + spop.getClass().getName()); - if(TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { + if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { return spop; } } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBaseHeightAccess.java b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBaseHeightAccess.java index 2b456754..6a599f19 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBaseHeightAccess.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBaseHeightAccess.java @@ -2,6 +2,6 @@ public interface IPopulatorDataBaseHeightAccess { - int getBaseHeight(int rawX, int rawZ); - + int getBaseHeight(int rawX, int rawZ); + } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBeehiveEditor.java b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBeehiveEditor.java index 258a29fc..005f1b8d 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBeehiveEditor.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataBeehiveEditor.java @@ -2,6 +2,6 @@ public interface IPopulatorDataBeehiveEditor { - void setBeehiveWithBee(int rawX, int rawY, int rawZ); - + void setBeehiveWithBee(int rawX, int rawY, int rawZ); + } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataPhysicsCapable.java b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataPhysicsCapable.java index ed85a197..baee5dd1 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataPhysicsCapable.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/IPopulatorDataPhysicsCapable.java @@ -5,6 +5,7 @@ public interface IPopulatorDataPhysicsCapable { - void setType(int x, int y, int z, Material type, boolean updatePhysics); - void setBlockData(int x, int y, int z, BlockData type, boolean updatePhysics); + void setType(int x, int y, int z, Material type, boolean updatePhysics); + + void setBlockData(int x, int y, int z, BlockData type, boolean updatePhysics); } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataAbstract.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataAbstract.java index a352ac5a..99fbf2f7 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataAbstract.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataAbstract.java @@ -1,8 +1,5 @@ package org.terraform.coregen.populatordata; -import java.util.EnumSet; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -13,13 +10,17 @@ import org.terraform.coregen.TerraLootTable; import org.terraform.data.TerraformWorld; +import java.util.EnumSet; +import java.util.Random; + public abstract class PopulatorDataAbstract { /** * Refers to raw x,y,z coords, not the chunk 0-15 coords. */ public abstract @Nullable Material getType(int x, int y, int z); - public @Nullable Material getType(@NotNull Vector v){ - return getType((int)Math.round(v.getX()),(int)Math.round(v.getY()),(int)Math.round(v.getZ())); + + public @Nullable Material getType(@NotNull Vector v) { + return getType((int) Math.round(v.getX()), (int) Math.round(v.getY()), (int) Math.round(v.getZ())); } /** @@ -31,33 +32,33 @@ public abstract class PopulatorDataAbstract { * Refers to raw x,y,z coords, not the chunk 0-15 coords. */ public abstract void setType(int x, int y, int z, Material type); - + public void setType(int x, int y, int z, Material @NotNull ... type) { - setType(x,y,z,type[new Random().nextInt(type.length)]); + setType(x, y, z, type[new Random().nextInt(type.length)]); } /** * This method will ROUND vector coordinates. Be very aware of that. */ public void setType(@NotNull Vector add, Material... mat) { - setType((int)Math.round(add.getX()), - (int)Math.round(add.getY()), - (int)Math.round(add.getZ()), mat); + setType((int) Math.round(add.getX()), (int) Math.round(add.getY()), (int) Math.round(add.getZ()), mat); } + public void setBlockData(@NotNull Vector add, BlockData data) { - setBlockData((int)Math.round(add.getX()), - (int)Math.round(add.getY()), - (int)Math.round(add.getZ()), data); + setBlockData((int) Math.round(add.getX()), (int) Math.round(add.getY()), (int) Math.round(add.getZ()), data); } public void lsetType(int x, int y, int z, Material... type) { - if(!getType(x,y,z).isSolid()) - setType(x,y,z,type); + if (!getType(x, y, z).isSolid()) { + setType(x, y, z, type); + } } + public void lsetType(@NotNull Vector v, Material... type) { - if(!getType(v).isSolid()) - setType(v,type); + if (!getType(v).isSolid()) { + setType(v, type); + } } /** @@ -66,19 +67,24 @@ public void lsetType(@NotNull Vector v, Material... type) { */ public void rsetType(@NotNull Vector v, @NotNull EnumSet replaceable, Material... toSet) { - if(!replaceable.contains(getType(v))) return; + if (!replaceable.contains(getType(v))) { + return; + } setType(v, toSet); } + /** * Set the material at the location if the current material is in * the enum set */ public void rsetBlockData(@NotNull Vector v, @NotNull EnumSet replaceable, BlockData data) { - if(!replaceable.contains(getType(v))) return; + if (!replaceable.contains(getType(v))) { + return; + } setBlockData(v, data); } - + /** * Refers to raw x,y,z coords, not the chunk 0-15 coords. */ @@ -115,8 +121,12 @@ public int hashCode() { */ @Override public boolean equals(@Nullable Object obj) { - if (this == obj) return true; - if (obj == null) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } return obj instanceof PopulatorDataAbstract; } } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataColumn.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataColumn.java index b6676ab0..2bcad21f 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataColumn.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataColumn.java @@ -10,10 +10,10 @@ /** * Same thing as the spigot one, but it will forcefully constrain internal x and z */ -public class PopulatorDataColumn extends PopulatorDataAbstract{ +public class PopulatorDataColumn extends PopulatorDataAbstract { + private final PopulatorDataAbstract delegate; int constrainX = 0; int constrainZ = 0; - private final PopulatorDataAbstract delegate; public PopulatorDataColumn(PopulatorDataAbstract delegate) { @@ -28,37 +28,47 @@ public void setConstraints(int constrainX, int constrainZ) @Override public Material getType(int x, int y, int z) { - if(x!=constrainX || z!=constrainZ) throw new IllegalArgumentException("Column Constraint Read Violation"); - return delegate.getType(x,y,z); + if (x != constrainX || z != constrainZ) { + throw new IllegalArgumentException("Column Constraint Read Violation"); + } + return delegate.getType(x, y, z); } @Override public BlockData getBlockData(int x, int y, int z) { - if(x!=constrainX || z!=constrainZ) throw new IllegalArgumentException("Column Constraint Read Violation"); - return delegate.getBlockData(x,y,z); + if (x != constrainX || z != constrainZ) { + throw new IllegalArgumentException("Column Constraint Read Violation"); + } + return delegate.getBlockData(x, y, z); } @Override public void setType(int x, int y, int z, Material type) { - if(x!=constrainX || z!=constrainZ) throw new IllegalArgumentException("Column Constraint Write Violation"); - delegate.setType(x,y,z,type); + if (x != constrainX || z != constrainZ) { + throw new IllegalArgumentException("Column Constraint Write Violation"); + } + delegate.setType(x, y, z, type); } @Override public void setBlockData(int x, int y, int z, BlockData data) { - if(x!=constrainX || z!=constrainZ) throw new IllegalArgumentException("Column Constraint Write Violation"); - delegate.setBlockData(x,y,z,data); + if (x != constrainX || z != constrainZ) { + throw new IllegalArgumentException("Column Constraint Write Violation"); + } + delegate.setBlockData(x, y, z, data); } @Override public Biome getBiome(int rawX, int rawZ) { - return delegate.getBiome(rawX,rawZ); + return delegate.getBiome(rawX, rawZ); } @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - if(rawX!=constrainX || rawZ!=constrainZ) throw new IllegalArgumentException("Column Constraint Write Violation"); - delegate.addEntity(rawX,rawY,rawZ,type); + if (rawX != constrainX || rawZ != constrainZ) { + throw new IllegalArgumentException("Column Constraint Write Violation"); + } + delegate.addEntity(rawX, rawY, rawZ, type); } @Override @@ -73,14 +83,18 @@ public int getChunkZ() { @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if(rawX!=constrainX || rawZ!=constrainZ) throw new IllegalArgumentException("Column Constraint Write Violation"); - delegate.setSpawner(rawX,rawY,rawZ,type); + if (rawX != constrainX || rawZ != constrainZ) { + throw new IllegalArgumentException("Column Constraint Write Violation"); + } + delegate.setSpawner(rawX, rawY, rawZ, type); } @Override public void lootTableChest(int x, int y, int z, TerraLootTable table) { - if(x!=constrainX || z!=constrainZ) throw new IllegalArgumentException("Column Constraint Write Violation"); - delegate.lootTableChest(x,y,z,table); + if (x != constrainX || z != constrainZ) { + throw new IllegalArgumentException("Column Constraint Write Violation"); + } + delegate.lootTableChest(x, y, z, table); } @Override diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICAAbstract.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICAAbstract.java index 8a6d027f..fb2e1e17 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICAAbstract.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICAAbstract.java @@ -4,7 +4,7 @@ public abstract class PopulatorDataICAAbstract extends PopulatorDataAbstract implements IPopulatorDataMinecartSpawner { - - public abstract void registerNaturalSpawns(NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1); + + public abstract void registerNaturalSpawns(NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1); } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICABiomeWriterAbstract.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICABiomeWriterAbstract.java index 313638fe..14306522 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICABiomeWriterAbstract.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataICABiomeWriterAbstract.java @@ -7,12 +7,13 @@ public abstract class PopulatorDataICABiomeWriterAbstract extends PopulatorDataICAAbstract { - public abstract void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback); - public void setBiome(int rawX, int rawY, int rawZ, @NotNull BiomeBank biomebank) - { - setBiome(rawX,rawY,rawZ,biomebank.getHandler().getCustomBiome(), biomebank.getHandler().getBiome()); - } + public abstract void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback); + + public void setBiome(int rawX, int rawY, int rawZ, @NotNull BiomeBank biomebank) + { + setBiome(rawX, rawY, rawZ, biomebank.getHandler().getCustomBiome(), biomebank.getHandler().getBiome()); + } public abstract void setBiome(int rawX, int rawY, int rawZ, Biome biome); - + } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java index de921797..d99bad0d 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java @@ -1,13 +1,6 @@ package org.terraform.coregen.populatordata; -import java.util.Random; - -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Tag; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -26,7 +19,10 @@ import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.main.config.TConfigOption; +import java.util.Random; + public class PopulatorDataPostGen extends PopulatorDataICABiomeWriterAbstract implements IPopulatorDataPhysicsCapable { + private static int spawnerRetries = 0; private final @NotNull World w; private final @NotNull Chunk c; @@ -42,7 +38,6 @@ public PopulatorDataPostGen(@NotNull Chunk c) { return w; } - /** * @return the c */ @@ -50,7 +45,6 @@ public PopulatorDataPostGen(@NotNull Chunk c) { return c; } - @Override public @Nullable Material getType(int x, int y, int z) { return w.getBlockAt(x, y, z).getType(); @@ -63,24 +57,24 @@ public PopulatorDataPostGen(@NotNull Chunk c) { @Override public void setType(int x, int y, int z, @NotNull Material type) { - boolean isFragile = Tag.DOORS.isTagged(type) || - Tag.CARPETS.isTagged(type) || - type == Material.FARMLAND || - type == Material.WATER; + boolean isFragile = Tag.DOORS.isTagged(type) + || Tag.CARPETS.isTagged(type) + || type == Material.FARMLAND + || type == Material.WATER; Block b = w.getBlockAt(x, y, z); b.setType(type, !isFragile); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - boolean isFragile = Tag.DOORS.isTagged(data.getMaterial()) || - Tag.CARPETS.isTagged(data.getMaterial()) || - data.getMaterial() == Material.FARMLAND || - data.getMaterial() == Material.WATER; + boolean isFragile = Tag.DOORS.isTagged(data.getMaterial()) + || Tag.CARPETS.isTagged(data.getMaterial()) + || data.getMaterial() == Material.FARMLAND + || data.getMaterial() == Material.WATER; Block b = w.getBlockAt(x, y, z); b.setBlockData(data.clone(), !isFragile); } - + @Override public void setType(int x, int y, int z, @NotNull Material type, boolean updatePhysics) { Block b = w.getBlockAt(x, y, z); @@ -128,18 +122,20 @@ public int getChunkZ() { @Override public void addEntity(int x, int y, int z, @NotNull EntityType type) { - // Always offset by 0.5 to prevent them spawning in corners. - // Y is offset by a small bit to prevent falling through weird spawning areas - Entity e = c.getWorld().spawnEntity(new Location(c.getWorld(),x+0.5,y+0.3,z+0.5), type); + // Always offset by 0.5 to prevent them spawning in corners. + // Y is offset by a small bit to prevent falling through weird spawning areas + Entity e = c.getWorld().spawnEntity(new Location(c.getWorld(), x + 0.5, y + 0.3, z + 0.5), type); e.setPersistent(true); - if(e instanceof LivingEntity) + if (e instanceof LivingEntity) { ((LivingEntity) e).setRemoveWhenFarAway(false); + } } - - private static int spawnerRetries = 0; + @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } Block b = w.getBlockAt(rawX, rawY, rawZ); b.setType(Material.SPAWNER, false); @@ -148,16 +144,23 @@ public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { spawner.setSpawnedType(type); spawner.update(); } - catch(IllegalStateException | ClassCastException e) - { - spawnerRetries++; - if(spawnerRetries > 10){ - Bukkit.getLogger().info("Giving up on spawner at " + rawX + "," + rawY + "," + rawZ); - spawnerRetries = 0; - return; - } - Bukkit.getLogger().info("Failed to get state for spawner at " + rawX + "," + rawY + "," + rawZ + ", try " + spawnerRetries); - setSpawner(rawX, rawY, rawZ, type); + catch (IllegalStateException | ClassCastException e) { + spawnerRetries++; + if (spawnerRetries > 10) { + Bukkit.getLogger().info("Giving up on spawner at " + rawX + "," + rawY + "," + rawZ); + spawnerRetries = 0; + return; + } + Bukkit.getLogger() + .info("Failed to get state for spawner at " + + rawX + + "," + + rawY + + "," + + rawZ + + ", try " + + spawnerRetries); + setSpawner(rawX, rawY, rawZ, type); } } @@ -166,29 +169,34 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(x, y, z).getChunk()).lootTableChest(x, y, z, table); } - @Override - public TerraformWorld getTerraformWorld() { - return TerraformWorld.get(w); - } + @Override + public TerraformWorld getTerraformWorld() { + return TerraformWorld.get(w); + } - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(rawX, rawY, rawZ).getChunk()); - if(icad instanceof PopulatorDataICABiomeWriterAbstract biomeWriter) + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(rawX, rawY, rawZ) + .getChunk()); + if (icad instanceof PopulatorDataICABiomeWriterAbstract biomeWriter) { biomeWriter.setBiome(rawX, rawY, rawZ, cbt, fallback); - } - - @Override - public void registerNaturalSpawns(NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(x0,y0,z0).getChunk()); - if(icad instanceof PopulatorDataICABiomeWriterAbstract) - icad.registerNaturalSpawns(type, x0, y0, z0, x1, y1, z1); - } - - @Override - public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, Random random) { - PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(x,y,z).getChunk()); - if(icad instanceof PopulatorDataICABiomeWriterAbstract) - icad.spawnMinecartWithChest(x,y,z,table,random); - } + } + } + + @Override + public void registerNaturalSpawns(NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { + PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(x0, y0, z0) + .getChunk()); + if (icad instanceof PopulatorDataICABiomeWriterAbstract) { + icad.registerNaturalSpawns(type, x0, y0, z0, x1, y1, z1); + } + } + + @Override + public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, Random random) { + PopulatorDataICAAbstract icad = TerraformGeneratorPlugin.injector.getICAData(w.getBlockAt(x, y, z).getChunk()); + if (icad instanceof PopulatorDataICABiomeWriterAbstract) { + icad.spawnMinecartWithChest(x, y, z, table, random); + } + } } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataRecursiveICA.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataRecursiveICA.java index e0e90514..7c776447 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataRecursiveICA.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataRecursiveICA.java @@ -30,12 +30,17 @@ public PopulatorDataRecursiveICA(@NotNull Chunk c) { */ private @NotNull PopulatorDataICAAbstract getData(int x, int z) { SimpleChunkLocation scl = new SimpleChunkLocation(w.getName(), x, z); - synchronized(loadedChunks) { + synchronized (loadedChunks) { return loadedChunks.computeIfAbsent(scl, k -> { int chunkX = x >> 4; int chunkZ = z >> 4; - if(!w.isChunkLoaded(chunkX, chunkZ)) w.loadChunk(chunkX, chunkZ); - PopulatorDataICAAbstract data = TerraformGeneratorPlugin.injector.getICAData(w.getChunkAt(chunkX, chunkZ)); + if (!w.isChunkLoaded(chunkX, chunkZ)) { + w.loadChunk(chunkX, chunkZ); + } + PopulatorDataICAAbstract data = TerraformGeneratorPlugin.injector.getICAData(w.getChunkAt( + chunkX, + chunkZ + )); loadedChunks.put(scl, data); return data; }); diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java index 5a912405..cb0105c6 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java @@ -22,10 +22,12 @@ import java.util.Random; -public class PopulatorDataSpigotAPI extends PopulatorDataAbstract implements IPopulatorDataBeehiveEditor,IPopulatorDataMinecartSpawner { +public class PopulatorDataSpigotAPI extends PopulatorDataAbstract + implements IPopulatorDataBeehiveEditor, IPopulatorDataMinecartSpawner +{ public final LimitedRegion lr; private final TerraformWorld tw; - private final int chunkX,chunkZ; + private final int chunkX, chunkZ; public PopulatorDataSpigotAPI(LimitedRegion lr, TerraformWorld tw, int chunkX, int chunkZ) { this.lr = lr; @@ -36,43 +38,45 @@ public PopulatorDataSpigotAPI(LimitedRegion lr, TerraformWorld tw, int chunkX, i @Override public Material getType(int x, int y, int z) { - if(!lr.isInRegion(x,y,z)) - { + if (!lr.isInRegion(x, y, z)) { // yes i fucking know this is bad return y > TerraformGenerator.seaLevel ? Material.AIR : Material.WATER; } - return lr.getType(x,y,z); + return lr.getType(x, y, z); } @Override public BlockData getBlockData(int x, int y, int z) { - if(!lr.isInRegion(x,y,z)) - return y > TerraformGenerator.seaLevel ? Bukkit.createBlockData(Material.AIR) : Bukkit.createBlockData(Material.WATER); + if (!lr.isInRegion(x, y, z)) { + return y > TerraformGenerator.seaLevel + ? Bukkit.createBlockData(Material.AIR) + : Bukkit.createBlockData(Material.WATER); + } - return lr.getBlockData(x,y,z); + return lr.getBlockData(x, y, z); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if(!lr.isInRegion(x,y,z)){ - NativeGeneratorPatcherPopulator.pushChange(tw.getName(), x,y,z,Bukkit.createBlockData(type)); + if (!lr.isInRegion(x, y, z)) { + NativeGeneratorPatcherPopulator.pushChange(tw.getName(), x, y, z, Bukkit.createBlockData(type)); return; } - lr.setType(x,y,z,type); + lr.setType(x, y, z, type); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if(!lr.isInRegion(x,y,z)){ - NativeGeneratorPatcherPopulator.pushChange(tw.getName(), x,y,z,data); + if (!lr.isInRegion(x, y, z)) { + NativeGeneratorPatcherPopulator.pushChange(tw.getName(), x, y, z, data); return; } - lr.setBlockData(x,y,z,data); + lr.setBlockData(x, y, z, data); } @Override public Biome getBiome(int rawX, int rawZ) { - return lr.getBiome(rawX,50,rawZ); + return lr.getBiome(rawX, 50, rawZ); } @Override @@ -92,27 +96,30 @@ public int getChunkZ() { @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } - setType(rawX,rawY,rawZ,Material.SPAWNER); - try{ + setType(rawX, rawY, rawZ, Material.SPAWNER); + try { // This will give class cast exception sometimes. I'm not sure why. // Additionally, if rawX/rawZ is outside the region, this will correctly // throw an error - CreatureSpawner spawner = (CreatureSpawner) lr.getBlockState(rawX,rawY,rawZ); + CreatureSpawner spawner = (CreatureSpawner) lr.getBlockState(rawX, rawY, rawZ); spawner.setSpawnedType(type); - spawner.update(true,false); - }catch(ClassCastException e){ + spawner.update(true, false); + } + catch (ClassCastException e) { TerraformGeneratorPlugin.logger.info("Failed to set spawner at " + rawX + "," + rawY + "," + rawZ); } } @Override public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { - BlockState s = lr.getBlockState(x,y,z); - if(s instanceof Lootable t){ + BlockState s = lr.getBlockState(x, y, z); + if (s instanceof Lootable t) { t.setLootTable(table.bukkit()); - s.update(true,false); + s.update(true, false); } } @@ -123,18 +130,19 @@ public TerraformWorld getTerraformWorld() { @Override public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { - if(!lr.isInRegion(rawX, rawY, rawZ)) return; // just forget it + if (!lr.isInRegion(rawX, rawY, rawZ)) { + return; // just forget it + } setType(rawX, rawY, rawZ, Material.BEE_NEST); // I guess the above can fail sometimes. I don't know why. // Catch and throw because that's fucking stupid try { - Beehive bukkitBeehive = (Beehive) lr.getBlockState(rawX,rawY,rawZ); + Beehive bukkitBeehive = (Beehive) lr.getBlockState(rawX, rawY, rawZ); TerraformGeneratorPlugin.injector.storeBee(bukkitBeehive); } - catch(ClassCastException e) - { + catch (ClassCastException e) { TerraformGeneratorPlugin.logger.info("Failed to set beehive at " + rawX + "," + rawY + "," + rawZ); } @@ -143,7 +151,10 @@ public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { @Override public void spawnMinecartWithChest(int x, int y, int z, @NotNull TerraLootTable table, Random random) { - StorageMinecart e = (StorageMinecart) lr.spawnEntity(new Location(tw.getWorld(), x+0.5f, y+0.5f, z+0.5f), EntityType.MINECART_CHEST); - e.setLootTable(table.bukkit()); + StorageMinecart e = (StorageMinecart) lr.spawnEntity( + new Location(tw.getWorld(), x + 0.5f, y + 0.5f, z + 0.5f), + EntityType.MINECART_CHEST + ); + e.setLootTable(table.bukkit()); } } diff --git a/common/src/main/java/org/terraform/coregen/sqlite/PopulatorDataSQLite.java b/common/src/main/java/org/terraform/coregen/sqlite/PopulatorDataSQLite.java index 0b340153..2c9a4fe8 100644 --- a/common/src/main/java/org/terraform/coregen/sqlite/PopulatorDataSQLite.java +++ b/common/src/main/java/org/terraform/coregen/sqlite/PopulatorDataSQLite.java @@ -11,7 +11,7 @@ import org.terraform.data.TerraformWorld; public class PopulatorDataSQLite extends PopulatorDataAbstract { - private final int chunkX; + private final int chunkX; private final int chunkZ; public PopulatorDataSQLite(int chunkX, int chunkZ, ChunkData c) { @@ -21,9 +21,15 @@ public PopulatorDataSQLite(int chunkX, int chunkZ, ChunkData c) { @SuppressWarnings("unused") private boolean isInBounds(int x, int z) { - if (x < chunkX * 16) return false; - if (x > (chunkX * 16) + 15) return false; - if (z < chunkZ * 16) return false; + if (x < chunkX * 16) { + return false; + } + if (x > (chunkX * 16) + 15) { + return false; + } + if (z < chunkZ * 16) { + return false; + } return z <= (chunkZ * 16) + 15; } @@ -83,9 +89,9 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { } - @Override - public TerraformWorld getTerraformWorld() { - // TODO Auto-generated method stub - return null; - } + @Override + public TerraformWorld getTerraformWorld() { + // TODO Auto-generated method stub + return null; + } } diff --git a/common/src/main/java/org/terraform/coregen/sqlite/SQLiteDB.java b/common/src/main/java/org/terraform/coregen/sqlite/SQLiteDB.java index 8c9587ac..888331a0 100644 --- a/common/src/main/java/org/terraform/coregen/sqlite/SQLiteDB.java +++ b/common/src/main/java/org/terraform/coregen/sqlite/SQLiteDB.java @@ -6,11 +6,7 @@ import org.terraform.main.TerraformGeneratorPlugin; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.HashSet; import java.util.Set; @@ -24,7 +20,9 @@ public class SQLiteDB { private static SQLiteDB i; public static @NotNull SQLiteDB get() { - if (i == null) i = new SQLiteDB(); + if (i == null) { + i = new SQLiteDB(); + } return i; } @@ -32,13 +30,11 @@ public class SQLiteDB { * Ensures that the database and all relevant tables exist. */ public static void createTableIfNotExists(String world) { - if (PREPARED_WORLDS.contains(world)) return; + if (PREPARED_WORLDS.contains(world)) { + return; + } Connection conn = null; - String dir = "plugins" - + File.separator - + "TerraformGenerator" - + File.separator - + world + ".db"; + String dir = "plugins" + File.separator + "TerraformGenerator" + File.separator + world + ".db"; try { // db parameters String url = "jdbc:sqlite:" + dir; @@ -47,25 +43,27 @@ public static void createTableIfNotExists(String world) { // Create Chunks Table conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); - String sql = "CREATE TABLE IF NOT EXISTS CHUNKS " + - "(CHUNK STRING PRIMARY KEY NOT NULL," + - " POPULATED BOOLEAN NOT NULL); "; + String sql = "CREATE TABLE IF NOT EXISTS CHUNKS " + + "(CHUNK STRING PRIMARY KEY NOT NULL," + + " POPULATED BOOLEAN NOT NULL); "; stmt.executeUpdate(sql); stmt.close(); // Create BlockData table stmt = conn.createStatement(); - sql = "CREATE TABLE IF NOT EXISTS BLOCKDATA " + - "(CHUNK STRING NOT NULL," - + "COORDS STRING NOT NULL," + - " DATA STRING NOT NULL," - + "PRIMARY KEY (CHUNK,COORDS)); "; + sql = "CREATE TABLE IF NOT EXISTS BLOCKDATA " + + "(CHUNK STRING NOT NULL," + + "COORDS STRING NOT NULL," + + " DATA STRING NOT NULL," + + "PRIMARY KEY (CHUNK,COORDS)); "; stmt.executeUpdate(sql); stmt.close(); PREPARED_WORLDS.add(world); - } catch (SQLException e) { + } + catch (SQLException e) { TerraformGeneratorPlugin.logger.stackTrace(e); - } finally { + } + finally { closeConn(conn); } } @@ -75,7 +73,8 @@ private static void closeConn(@Nullable Connection conn) { if (conn != null) { conn.close(); } - } catch (SQLException ex) { + } + catch (SQLException ex) { TerraformGeneratorPlugin.logger.stackTrace(ex); } } @@ -85,11 +84,7 @@ private static void closeConn(@Nullable Connection conn) { */ public void updateBlockData(String world, int chunkX, int chunkZ, int x, int y, int z, @NotNull BlockData data) { createTableIfNotExists(world); - String dir = "plugins" - + File.separator - + "TerraformGenerator" - + File.separator - + world + ".db"; + String dir = "plugins" + File.separator + "TerraformGenerator" + File.separator + world + ".db"; String CHUNK = chunkX + "," + chunkZ; String COORDS = x + "," + y + "," + z; String DATA = data.toString(); @@ -98,21 +93,25 @@ public void updateBlockData(String world, int chunkX, int chunkZ, int x, int y, Connection c = DriverManager.getConnection("jdbc:sqlite:" + dir); c.setAutoCommit(false); - Statement stmt = c.createStatement(); - String sql = "DELETE from BLOCKDATA where CHUNK='" + CHUNK + "' and" - + " COORDS='" + COORDS + "';"; + Statement stmt = c.createStatement(); + String sql = "DELETE from BLOCKDATA where CHUNK='" + CHUNK + "' and" + " COORDS='" + COORDS + "';"; stmt.executeUpdate(sql); - sql = "INSERT INTO BLOCKDATA (CHUNK,COORDS,DATA) " + - "VALUES ('" + CHUNK + "', '" - + COORDS + "', '" - + DATA + "');"; + sql = "INSERT INTO BLOCKDATA (CHUNK,COORDS,DATA) " + + "VALUES ('" + + CHUNK + + "', '" + + COORDS + + "', '" + + DATA + + "');"; stmt.executeUpdate(sql); stmt.close(); c.commit(); c.close(); - } catch (Exception e) { + } + catch (Exception e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } @@ -123,11 +122,7 @@ public void updateBlockData(String world, int chunkX, int chunkZ, int x, int y, */ public boolean[] fetchFromChunks(String world, int chunkX, int chunkZ) { createTableIfNotExists(world); - String dir = "plugins" - + File.separator - + "TerraformGenerator" - + File.separator - + world + ".db"; + String dir = "plugins" + File.separator + "TerraformGenerator" + File.separator + world + ".db"; String key = chunkX + "," + chunkZ; boolean[] queryReply = {false, false}; try { @@ -138,14 +133,16 @@ public boolean[] fetchFromChunks(String world, int chunkX, int chunkZ) { Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM CHUNKS WHERE CHUNK='" + key + "';"); if (rs.next()) { - queryReply = new boolean[]{true, rs.getBoolean("POPULATED")}; - } else { - queryReply = new boolean[]{false, false}; + queryReply = new boolean[] {true, rs.getBoolean("POPULATED")}; + } + else { + queryReply = new boolean[] {false, false}; } rs.close(); stmt.close(); c.close(); - } catch (Exception e) { + } + catch (Exception e) { TerraformGeneratorPlugin.logger.stackTrace(e); // Bukkit.getLogger().severe(e.getClass().getName() + "[" + e.getCause() +"]" + ":" + e.getMessage() ); } @@ -158,11 +155,7 @@ public boolean[] fetchFromChunks(String world, int chunkX, int chunkZ) { */ public void putChunk(String world, int chunkX, int chunkZ, boolean populated) { createTableIfNotExists(world); - String dir = "plugins" - + File.separator - + "TerraformGenerator" - + File.separator - + world + ".db"; + String dir = "plugins" + File.separator + "TerraformGenerator" + File.separator + world + ".db"; try { Class.forName("org.sqlite.JDBC"); Connection c = DriverManager.getConnection("jdbc:sqlite:" + dir); @@ -173,15 +166,14 @@ public void putChunk(String world, int chunkX, int chunkZ, boolean populated) { String sql = "DELETE from CHUNKS where CHUNK='" + key + "';"; stmt.executeUpdate(sql); - sql = "INSERT INTO CHUNKS (CHUNK,POPULATED) " + - "VALUES ('" + key + "', '" - + populated + "');"; + sql = "INSERT INTO CHUNKS (CHUNK,POPULATED) " + "VALUES ('" + key + "', '" + populated + "');"; stmt.executeUpdate(sql); stmt.close(); c.commit(); c.close(); - } catch (Exception e) { + } + catch (Exception e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } diff --git a/common/src/main/java/org/terraform/data/MegaChunk.java b/common/src/main/java/org/terraform/data/MegaChunk.java index 7e9f7cf4..3b2ae545 100644 --- a/common/src/main/java/org/terraform/data/MegaChunk.java +++ b/common/src/main/java/org/terraform/data/MegaChunk.java @@ -9,7 +9,8 @@ import java.util.Random; public class MegaChunk { - public static final int megaChunkBlockWidth = BiomeSection.sectionWidth*TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt(); + public static final int megaChunkBlockWidth = BiomeSection.sectionWidth + * TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt(); private int x, z; public MegaChunk(@NotNull SimpleChunkLocation sLoc) { @@ -20,12 +21,28 @@ public MegaChunk(int x, int y, int z) { this.x = blockCoordsToMega(x); this.z = blockCoordsToMega(z); } - + // A megachunk consists of a bunch of biome sections. // The big structures spawn right in the middle of them. public MegaChunk(int chunkX, int chunkZ) { - this(chunkX*16,0,chunkZ*16); + this(chunkX * 16, 0, chunkZ * 16); + + } + + private static int blockCoordsToMega(int coord) { + if (coord >= 0) { + return (int) (double) (coord / megaChunkBlockWidth); + } + else { + return (int) (-1.0 * (Math.ceil(((double) Math.abs(coord)) / ((double) megaChunkBlockWidth)))); + } + } + /** + * @return lower bounds of block coords within the megachunk. + */ + private static int megaToBlockCoords(int coord) { + return coord * (megaChunkBlockWidth); } public @NotNull MegaChunk getRelative(int x, int z) { @@ -39,23 +56,23 @@ public MegaChunk(int chunkX, int chunkZ) { * @return A random pair of xz block coords within the mega chunk */ public int[] getRandomCoords(@NotNull Random rand) { - + int lowX = megaToBlockCoords(this.x); int lowZ = megaToBlockCoords(this.z); - int highX = lowX + megaChunkBlockWidth-1; - int highZ = lowZ + megaChunkBlockWidth-1; + int highX = lowX + megaChunkBlockWidth - 1; + int highZ = lowZ + megaChunkBlockWidth - 1; // Pad the sides. Never generate on the side of a mega chunk. - int x = GenUtils.randInt(rand, lowX + megaChunkBlockWidth/10, highX - megaChunkBlockWidth/10); - int z = GenUtils.randInt(rand, lowZ + megaChunkBlockWidth/10, highZ - megaChunkBlockWidth/10); - return new int[]{x, z}; + int x = GenUtils.randInt(rand, lowX + megaChunkBlockWidth / 10, highX - megaChunkBlockWidth / 10); + int z = GenUtils.randInt(rand, lowZ + megaChunkBlockWidth / 10, highZ - megaChunkBlockWidth / 10); + return new int[] {x, z}; } /** * @return A random pair of xz block coords within the mega chunk. This pair of coords WILL be in the middle of a chunk. */ public int[] getRandomCenterChunkBlockCoords(@NotNull Random rand) { - + int lowX = this.getLowerCornerChunkCoords()[0]; int lowZ = this.getLowerCornerChunkCoords()[1]; int highX = this.getUpperCornerChunkCoords()[0]; @@ -64,75 +81,76 @@ public int[] getRandomCenterChunkBlockCoords(@NotNull Random rand) { // Pad the sides. Never generate on the side of a mega chunk. int x = GenUtils.randInt(rand, lowX, highX); int z = GenUtils.randInt(rand, lowZ, highZ); - return new int[]{x*16+7, z*16+7}; + return new int[] {x * 16 + 7, z * 16 + 7}; } - + public int[] getCenterBlockCoords() { - + int lowX = megaToBlockCoords(this.x); int lowZ = megaToBlockCoords(this.z); // TerraformGeneratorPlugin.logger.info("MC(" + this.x + "," + this.z + "):(" + (lowX + megaChunkBlockWidth/2) + "," + (lowZ + megaChunkBlockWidth/2) + ")"); - return new int[]{lowX + megaChunkBlockWidth/2, lowZ + megaChunkBlockWidth/2}; + return new int[] {lowX + megaChunkBlockWidth / 2, lowZ + megaChunkBlockWidth / 2}; } - + /** * Used for structure spawning. They need the center of biome sections. */ public int[] getCenterBiomeSectionBlockCoords() { - + int lowX = getCenterBlockCoords()[0]; int lowZ = getCenterBlockCoords()[1]; - + int sectionX = lowX >> BiomeSection.bitshifts; int sectionZ = lowZ >> BiomeSection.bitshifts; - - int centerOfSectionX = (sectionX << BiomeSection.bitshifts) + BiomeSection.sectionWidth/2; - int centerOfSectionZ = (sectionZ << BiomeSection.bitshifts) + BiomeSection.sectionWidth/2; - + + int centerOfSectionX = (sectionX << BiomeSection.bitshifts) + BiomeSection.sectionWidth / 2; + int centerOfSectionZ = (sectionZ << BiomeSection.bitshifts) + BiomeSection.sectionWidth / 2; + // TerraformGeneratorPlugin.logger.info("MC(" + this.x + "," + this.z + "):(" + (lowX + megaChunkBlockWidth/2) + "," + (lowZ + megaChunkBlockWidth/2) + ")"); - return new int[]{centerOfSectionX, centerOfSectionZ}; + return new int[] {centerOfSectionX, centerOfSectionZ}; } - public int[] getCenterBiomeSectionChunkCoords() { - int[] coords = getCenterBiomeSectionBlockCoords(); - - return new int[] { coords[0] >> 4, coords[1] >> 4 }; + int[] coords = getCenterBiomeSectionBlockCoords(); + + return new int[] {coords[0] >> 4, coords[1] >> 4}; } public int[] getUpperCornerBlockCoords() { - + int upperX = megaToBlockCoords(this.x) + megaChunkBlockWidth - 1; int upperZ = megaToBlockCoords(this.z) + megaChunkBlockWidth - 1; - return new int[]{upperX, upperZ}; + return new int[] {upperX, upperZ}; } - + public int[] getLowerCornerBlockCoords() { - + int lowX = megaToBlockCoords(this.x); int lowZ = megaToBlockCoords(this.z); - return new int[]{lowX, lowZ}; + return new int[] {lowX, lowZ}; } - + public int[] getCenterChunkCoords() { - int[] coords = getCenterBlockCoords(); - - return new int[] { coords[0] >> 4, coords[1] >> 4 }; + int[] coords = getCenterBlockCoords(); + + return new int[] {coords[0] >> 4, coords[1] >> 4}; } + public int[] getLowerCornerChunkCoords() { - int[] coords = getLowerCornerBlockCoords(); - - return new int[] { coords[0] >> 4, coords[1] >> 4 }; + int[] coords = getLowerCornerBlockCoords(); + + return new int[] {coords[0] >> 4, coords[1] >> 4}; } public int[] getUpperCornerChunkCoords() { - int[] coords = getUpperCornerBlockCoords(); - - return new int[] { coords[0] >> 4, coords[1] >> 4 }; + int[] coords = getUpperCornerBlockCoords(); + + return new int[] {coords[0] >> 4, coords[1] >> 4}; } + public @NotNull BiomeSection getCenterBiomeSection(TerraformWorld tw) { - int[] coords = getCenterBiomeSectionBlockCoords(); - return BiomeBank.getBiomeSectionFromBlockCoords(tw,coords[0],coords[1]); + int[] coords = getCenterBiomeSectionBlockCoords(); + return BiomeBank.getBiomeSectionFromBlockCoords(tw, coords[0], coords[1]); } public boolean containsXZBlockCoords(int x, int z) { @@ -168,24 +186,7 @@ public int getZ() { } @Override - public @NotNull String toString(){ + public @NotNull String toString() { return x + "," + z; } - - private static int blockCoordsToMega(int coord) { - if(coord >= 0) { - return (int) (double) (coord / megaChunkBlockWidth); - } - else - { - return (int) (-1.0*(Math.ceil(((double)Math.abs(coord))/((double)megaChunkBlockWidth)))); - } - } - - /** - * @return lower bounds of block coords within the megachunk. - */ - private static int megaToBlockCoords(int coord) { - return coord*(megaChunkBlockWidth); - } } diff --git a/common/src/main/java/org/terraform/data/SimpleBlock.java b/common/src/main/java/org/terraform/data/SimpleBlock.java index 84b22b37..76191607 100644 --- a/common/src/main/java/org/terraform/data/SimpleBlock.java +++ b/common/src/main/java/org/terraform/data/SimpleBlock.java @@ -1,12 +1,6 @@ package org.terraform.data; import com.google.gson.annotations.SerializedName; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.Objects; -import java.util.Random; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -28,13 +22,16 @@ import org.terraform.utils.GenUtils; import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Objects; +import java.util.Random; public class SimpleBlock { - @SerializedName("w") // wtf is this for - private final int x, y, z; - @NotNull final PopulatorDataAbstract popData; + @SerializedName("w") // wtf is this for + private final int x, y, z; public SimpleBlock(@NotNull Location loc) { this.popData = new PopulatorDataPostGen(loc.getChunk()); @@ -57,37 +54,6 @@ public SimpleBlock(@NotNull PopulatorDataAbstract data, int x, int y, int z) { this.y = y; this.z = z; } - - public void pathTowards(int width, int maxLength, @NotNull SimpleBlock target, Material... types) { - BlockFace dir = BlockFace.NORTH; - int max = -1; - if(target.getX() - this.getX() > max) { - // east - dir = BlockFace.EAST; - }else if(this.getX() - target.getX() > max) { - // west - dir = BlockFace.WEST; - }else if(this.getZ() - target.getZ() > max) { - // north - dir = BlockFace.NORTH; - }else if(target.getZ() - this.getZ() > max) { - // south - dir = BlockFace.SOUTH; - } - - SimpleBlock base = this; - for(int i = 0; i < maxLength; i++) { - if(!base.lsetType(types)) - break; - - for(int w = 0; w < width; w++) - for(BlockFace adj:BlockUtils.getAdjacentFaces(dir)) - base.getRelative(adj).setType(types); - base = base.getRelative(dir); - } - - } - public SimpleBlock(@NotNull PopulatorDataAbstract data, @NotNull SimpleLocation sLoc) { // this.world = world; @@ -98,6 +64,7 @@ public SimpleBlock(@NotNull PopulatorDataAbstract data, @NotNull SimpleLocation } + public SimpleBlock(@NotNull PopulatorDataAbstract data, @NotNull Location loc) { // this.world = loc.getWorld().getName(); this.popData = data; @@ -115,13 +82,49 @@ public SimpleBlock(@NotNull PopulatorDataAbstract data, @NotNull Block b) { this.z = b.getZ(); // this.data = b.getBlockData().getAsString(); } - + + public void pathTowards(int width, int maxLength, @NotNull SimpleBlock target, Material... types) { + BlockFace dir = BlockFace.NORTH; + int max = -1; + if (target.getX() - this.getX() > max) { + // east + dir = BlockFace.EAST; + } + else if (this.getX() - target.getX() > max) { + // west + dir = BlockFace.WEST; + } + else if (this.getZ() - target.getZ() > max) { + // north + dir = BlockFace.NORTH; + } + else if (target.getZ() - this.getZ() > max) { + // south + dir = BlockFace.SOUTH; + } + + SimpleBlock base = this; + for (int i = 0; i < maxLength; i++) { + if (!base.lsetType(types)) { + break; + } + + for (int w = 0; w < width; w++) { + for (BlockFace adj : BlockUtils.getAdjacentFaces(dir)) { + base.getRelative(adj).setType(types); + } + } + base = base.getRelative(dir); + } + + } + public @NotNull SimpleLocation getLoc() { - return new SimpleLocation(x,y,z); + return new SimpleLocation(x, y, z); } - + public @NotNull SimpleBlock getAtY(int y) { - return new SimpleBlock(popData,x,y,z); + return new SimpleBlock(popData, x, y, z); } public double distanceSquared(@NotNull SimpleBlock other) { @@ -134,17 +137,18 @@ public double distanceSquared(@NotNull SimpleBlock other) { return Math.pow(selfX - oX, 2) + Math.pow(selfY - oY, 2) + Math.pow(selfZ - oZ, 2); } - + public boolean isConnected(SimpleBlock other) { - for(BlockFace face:BlockUtils.sixBlockFaces) { - if(this.getRelative(face).equals(other)) - return true; - } - return false; + for (BlockFace face : BlockUtils.sixBlockFaces) { + if (this.getRelative(face).equals(other)) { + return true; + } + } + return false; } - + public double distance(@NotNull SimpleBlock other) { - + return Math.sqrt(distanceSquared(other)); } @@ -158,8 +162,9 @@ public boolean sameLocation(@NotNull SimpleBlock other) { public @NotNull SimpleBlock untilSolid(@NotNull BlockFace face) { SimpleBlock rel = this.getRelative(face); - while (!rel.isSolid()) + while (!rel.isSolid()) { rel = rel.getRelative(face); + } return rel; } @@ -167,6 +172,7 @@ public boolean sameLocation(@NotNull SimpleBlock other) { /** * Lenient set. Only replaces non-solid blocks. + * * @return if the set was a success. */ public boolean lsetType(@NotNull Material type) { @@ -197,8 +203,9 @@ public void setBlockData(BlockData dat) { } public void RSolSetBlockData(BlockData data) { - if (isSolid()) + if (isSolid()) { setBlockData(data); + } } public @NotNull SimpleBlock getRelative(int nx, int ny, int nz) { @@ -209,7 +216,8 @@ public void RSolSetBlockData(BlockData data) { return new SimpleBlock(popData, (int) Math.round(x + v.getX()), (int) Math.round(y + v.getY()), - (int) Math.round(z + v.getZ())); + (int) Math.round(z + v.getZ()) + ); } public @NotNull String getCoords() { @@ -221,46 +229,57 @@ public void RSolSetBlockData(BlockData data) { } public @NotNull SimpleBlock getRelative(@NotNull BlockFace face, int count) { - return new SimpleBlock(popData, x + face.getModX() * count, y + face.getModY() * count, z + face.getModZ() * count); + return new SimpleBlock( + popData, + x + face.getModX() * count, + y + face.getModY() * count, + z + face.getModZ() * count + ); } - + public void addEntity(EntityType type) { - popData.addEntity(x, y, z, type); - } - - - public int countAdjacentsThatMatchType(BlockFace @NotNull [] faces, Material @NotNull ...types) { - int i = 0; - for(BlockFace face:faces) { - for(Material type:types) - if(getRelative(face).getType() == type) - i++; - } - return i; - } - - public boolean doAdjacentsMatchType(BlockFace @NotNull [] faces, Material @NotNull ...types) { - for(BlockFace face:faces) { - for(Material type:types) - if(getRelative(face).getType() == type) - return true; - } - return false; - } - - public void replaceAdjacentNonLiquids(BlockFace @NotNull [] faces, Material liquid, Material...types) { - for(BlockFace face:faces) { - if(!getRelative(face).isSolid() && getRelative(face).getType() != liquid) - getRelative(face).setType(types); - } - } - + popData.addEntity(x, y, z, type); + } + + + public int countAdjacentsThatMatchType(BlockFace @NotNull [] faces, Material @NotNull ... types) { + int i = 0; + for (BlockFace face : faces) { + for (Material type : types) { + if (getRelative(face).getType() == type) { + i++; + } + } + } + return i; + } + + public boolean doAdjacentsMatchType(BlockFace @NotNull [] faces, Material @NotNull ... types) { + for (BlockFace face : faces) { + for (Material type : types) { + if (getRelative(face).getType() == type) { + return true; + } + } + } + return false; + } + + public void replaceAdjacentNonLiquids(BlockFace @NotNull [] faces, Material liquid, Material... types) { + for (BlockFace face : faces) { + if (!getRelative(face).isSolid() && getRelative(face).getType() != liquid) { + getRelative(face).setType(types); + } + } + } + public boolean hasAdjacentSolid(BlockFace @NotNull [] faces) { - for(BlockFace face:faces) { - if(getRelative(face).isSolid()) - return true; - } - return false; + for (BlockFace face : faces) { + if (getRelative(face).isSolid()) { + return true; + } + } + return false; } public int getChunkX() { @@ -290,81 +309,87 @@ public int getZ() { public @Nullable Material getType() { return popData.getType(x, y, z); } - + + public void setType(@NotNull Material type) { + if (popData.getType(x, y, z) == Material.WATER) { + BlockData data = Bukkit.createBlockData(type); + if (data instanceof Waterlogged wl) { + wl.setWaterlogged(true); + } + popData.setBlockData(x, y, z, data); + } + else { + popData.setType(x, y, z, type); + } + + // Setting leaves with setType will be persistent + if (Tag.LEAVES.isTagged(type)) { + // if (type.toString().contains("LEAVES")) { + BlockData l = Bukkit.createBlockData(type); + if (l instanceof Leaves) { + ((Leaves) l).setPersistent(true); + } + + setBlockData(l); + } + } + + public void setType(Material... types) { + setType(GenUtils.randChoice(types)); + } + public boolean isAir() { - return popData.getType(x, y, z) == Material.AIR || popData.getType(x, y, z) == Material.CAVE_AIR; + return popData.getType(x, y, z) == Material.AIR || popData.getType(x, y, z) == Material.CAVE_AIR; } public boolean isSolid() { - return popData.getType(x, y, z).isSolid(); + return popData.getType(x, y, z).isSolid(); } - + public void physicsSetType(@NotNull Material type, boolean updatePhysics) { - if(this.popData instanceof IPopulatorDataPhysicsCapable) - { + if (this.popData instanceof IPopulatorDataPhysicsCapable) { if (popData.getType(x, y, z) == Material.WATER) { BlockData data = Bukkit.createBlockData(type); if (data instanceof Waterlogged wl) { wl.setWaterlogged(true); } ((IPopulatorDataPhysicsCapable) popData).setBlockData(x, y, z, data, updatePhysics); - } else - ((IPopulatorDataPhysicsCapable) popData).setType(x, y, z, type, updatePhysics); + } + else { + ((IPopulatorDataPhysicsCapable) popData).setType(x, y, z, type, updatePhysics); + } // Setting leaves with setType will be persistent if (Tag.LEAVES.isTagged(type)) { // if (type.toString().contains("LEAVES")) { BlockData l = Bukkit.createBlockData(type); - if(l instanceof Leaves) + if (l instanceof Leaves) { ((Leaves) l).setPersistent(true); + } - ((IPopulatorDataPhysicsCapable) popData).setBlockData(x,y,z,l, updatePhysics); + ((IPopulatorDataPhysicsCapable) popData).setBlockData(x, y, z, l, updatePhysics); } - - } - else - setType(type); + + } + else { + setType(type); + } } - + public void physicsSetBlockData(BlockData dat, boolean updatePhysics) { - if(this.popData instanceof IPopulatorDataPhysicsCapable) - { - if (popData.getType(x, y, z) == Material.WATER) { - if (dat instanceof Waterlogged wl) { + if (this.popData instanceof IPopulatorDataPhysicsCapable) { + if (popData.getType(x, y, z) == Material.WATER) { + if (dat instanceof Waterlogged wl) { wl.setWaterlogged(true); - } - } - ((IPopulatorDataPhysicsCapable) popData).setBlockData(x, y, z, dat, updatePhysics); - } - else - setBlockData(dat); - } - - public void setType(@NotNull Material type) { - if (popData.getType(x, y, z) == Material.WATER) { - BlockData data = Bukkit.createBlockData(type); - if (data instanceof Waterlogged wl) { - wl.setWaterlogged(true); + } } - popData.setBlockData(x, y, z, data); - } else - popData.setType(x, y, z, type); - - // Setting leaves with setType will be persistent - if (Tag.LEAVES.isTagged(type)) { - // if (type.toString().contains("LEAVES")) { - BlockData l = Bukkit.createBlockData(type); - if(l instanceof Leaves) - ((Leaves) l).setPersistent(true); - - setBlockData(l); + ((IPopulatorDataPhysicsCapable) popData).setBlockData(x, y, z, dat, updatePhysics); + } + else { + setBlockData(dat); } - } - - public void setType(Material... types) { - setType(GenUtils.randChoice(types)); } public boolean lsetType(Material... types) { @@ -372,8 +397,9 @@ public boolean lsetType(Material... types) { } public void RSolSetType(@NotNull Material type) { - if (isSolid()) + if (isSolid()) { setType(type); + } } /** @@ -396,57 +422,55 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof SimpleBlock other)) return false; + if (this == obj) { + return true; + } + if (!(obj instanceof SimpleBlock other)) { + return false; + } return Objects.equals(popData.getTerraformWorld(), other.getPopData().getTerraformWorld()) - && x == other.x && z == other.z && y == other.y; + && x == other.x + && z == other.z + && y == other.y; } public @NotNull SimpleBlock getGround() { - return new SimpleBlock( - popData, - x, - GenUtils.getHighestGround(popData, x, z), - z); + return new SimpleBlock(popData, x, GenUtils.getHighestGround(popData, x, z), z); } public @NotNull SimpleBlock getGroundOrSeaLevel() { - int y = GenUtils.getHighestGround(popData, x, z); - if(y < TerraformGenerator.seaLevel) y = TerraformGenerator.seaLevel; - return new SimpleBlock( - popData, - x, - y, - z); + int y = GenUtils.getHighestGround(popData, x, z); + if (y < TerraformGenerator.seaLevel) { + y = TerraformGenerator.seaLevel; + } + return new SimpleBlock(popData, x, y, z); } public @NotNull SimpleBlock getGroundOrDry() { - int y = GenUtils.getHighestGround(popData, x, z); - - while(y < TerraformGeneratorPlugin.injector.getMaxY() - && (BlockUtils.isWet(this.getAtY(y+1))|| - Tag.ICE.isTagged(this.getAtY(y+1).getType()))) y++; - return new SimpleBlock( - popData, - x, - y, - z); + int y = GenUtils.getHighestGround(popData, x, z); + + while (y < TerraformGeneratorPlugin.injector.getMaxY() && (BlockUtils.isWet(this.getAtY(y + 1)) + || Tag.ICE.isTagged(this.getAtY(y + 1).getType()))) { + y++; + } + return new SimpleBlock(popData, x, y, z); } - public @NotNull SimpleBlock getUp() { - return this.getRelative(0, 1, 0); - } - public @NotNull SimpleBlock getUp(int i) { + public @NotNull SimpleBlock getUp() { + return this.getRelative(0, 1, 0); + } + + public @NotNull SimpleBlock getUp(int i) { return this.getRelative(0, i, 0); - } + } /** * @param cutoff number of iterations before stopping and returning null * @return first solid block above this one */ public @Nullable SimpleBlock findCeiling(int cutoff) { - SimpleBlock ceil = this.getUp(); + SimpleBlock ceil = this.getUp(); while (cutoff > 0) { if (ceil.isSolid() && ceil.getType() != Material.LANTERN) { return ceil; @@ -462,7 +486,7 @@ public boolean equals(Object obj) { * @return first solid block below this one */ public @Nullable SimpleBlock findFloor(int cutoff) { - SimpleBlock floor = this.getDown(); + SimpleBlock floor = this.getDown(); while (cutoff > 0 && floor.getY() >= TerraformGeneratorPlugin.injector.getMinY()) { if (floor.isSolid() && floor.getType() != Material.LANTERN) { return floor; @@ -476,10 +500,11 @@ public boolean equals(Object obj) { /** * If solid, find nearest air pocket upwards. * If not solid, find nearest floor. + * * @param cutoff number of iterations before stopping and returning null */ public @Nullable SimpleBlock findAirPocket(int cutoff) { - SimpleBlock floor = this.getDown(); + SimpleBlock floor = this.getDown(); while (cutoff > 0 && floor.getY() >= TerraformGeneratorPlugin.injector.getMinY()) { if (!floor.isSolid()) { return floor; @@ -489,15 +514,16 @@ public boolean equals(Object obj) { } return null; } - + /** * If solid, find nearest air pocket upwards. * If not solid, find nearest floor. + * * @param cutoff number of iterations before stopping and returning null */ public @Nullable SimpleBlock findNearestAirPocket(int cutoff) { - if(this.isSolid()) { - SimpleBlock rel = this.getUp(); + if (this.isSolid()) { + SimpleBlock rel = this.getUp(); while (cutoff > 0) { if (!rel.isSolid()) { return rel; @@ -506,23 +532,24 @@ public boolean equals(Object obj) { rel = rel.getUp(); } return null; - } - else - { - SimpleBlock candidate = this.findFloor(cutoff); - if(candidate != null) candidate = candidate.getUp(); - return candidate; - } - } - + } + else { + SimpleBlock candidate = this.findFloor(cutoff); + if (candidate != null) { + candidate = candidate.getUp(); + } + return candidate; + } + } + /** * @param cutoff number of iterations before stopping and returning null * @return first stone-like block below this one */ public @Nullable SimpleBlock findStonelikeFloor(int cutoff) { - SimpleBlock floor = this.getDown(); + SimpleBlock floor = this.getDown(); while (cutoff > 0 && floor.getY() >= TerraformGeneratorPlugin.injector.getMinY()) { - // floor.getUp().setType(Material.CYAN_STAINED_GLASS); + // floor.getUp().setType(Material.CYAN_STAINED_GLASS); if (BlockUtils.isStoneLike(floor.getType())) { return floor; } @@ -531,13 +558,13 @@ public boolean equals(Object obj) { } return null; } - + /** * @param cutoff the number of iterations before stopping and returning null * @return first stone-like block above this one */ public @Nullable SimpleBlock findStonelikeCeiling(int cutoff) { - SimpleBlock ceil = this.getUp(); + SimpleBlock ceil = this.getUp(); while (cutoff > 0) { if (BlockUtils.isStoneLike(ceil.getType())) { return ceil; @@ -547,43 +574,47 @@ public boolean equals(Object obj) { } return null; } - + /** * Replaces everything in its way */ public void Pillar(int height, Material... types) { - Random rand = new Random(); + Random rand = new Random(); for (int i = 0; i < height; i++) { this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); } } - + /** * Replaces the block's material with either air or water or lava depending * on the block's surrounding fluid (same y). */ public void fluidize() { - Material fluid = Material.AIR; - if(!BlockUtils.isWet(this)) - for(BlockFace face:BlockUtils.directBlockFaces) { - if(getRelative(face).getType() == Material.WATER) - fluid = Material.WATER; - else if(getRelative(face).getType() == Material.LAVA) - fluid = Material.LAVA; - } - else - fluid = Material.WATER; - setType(fluid); - } - + Material fluid = Material.AIR; + if (!BlockUtils.isWet(this)) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (getRelative(face).getType() == Material.WATER) { + fluid = Material.WATER; + } + else if (getRelative(face).getType() == Material.LAVA) { + fluid = Material.LAVA; + } + } + } + else { + fluid = Material.WATER; + } + setType(fluid); + } + /** * Replaces everything in its way */ public void Pillar(int height, @NotNull Random rand, Material... types) { for (int i = 0; i < height; i++) { - this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); + this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); } } @@ -592,14 +623,18 @@ public void Pillar(int height, @NotNull Random rand, Material... types) { */ public void Pillar(int height, boolean pattern, @NotNull Random rand, Material @NotNull ... types) { for (int i = 0; i < height; i++) { - if (Arrays.equals(new Material[]{Material.BARRIER}, types)) continue; - if (!pattern) - this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); - else if (types[i % types.length] != Material.BARRIER) - this.getRelative(0, i, 0).setType(types[i % types.length]); + if (Arrays.equals(new Material[] {Material.BARRIER}, types)) { + continue; + } + if (!pattern) { + this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); + } + else if (types[i % types.length] != Material.BARRIER) { + this.getRelative(0, i, 0).setType(types[i % types.length]); + } } } - + /** * Corrects all multiple facing block data in a pillar @@ -620,6 +655,7 @@ public void LPillar(int height, Material... types) { /** * Replaces until a solid block is reached. + * * @return height of pillar created */ public int LPillar(int height, @NotNull Random rand, Material... types) { @@ -628,16 +664,23 @@ public int LPillar(int height, @NotNull Random rand, Material... types) { /** * Replaces until a solid block is reached. + * * @return height of pillar created */ public int LPillar(int height, boolean pattern, @NotNull Random rand, Material @NotNull ... types) { for (int i = 0; i < height; i++) { - if (this.getRelative(0, i, 0).isSolid()) return i; - if (Arrays.equals(new Material[]{Material.BARRIER}, types)) continue; - if (!pattern) + if (this.getRelative(0, i, 0).isSolid()) { + return i; + } + if (Arrays.equals(new Material[] {Material.BARRIER}, types)) { + continue; + } + if (!pattern) { this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); - else + } + else { this.getRelative(0, i, 0).setType(types[i % types.length]); + } } return height; } @@ -647,44 +690,49 @@ public int LPillar(int height, boolean pattern, @NotNull Random rand, Material @ */ public void RPillar(int height, @NotNull Random rand, Material... types) { for (int i = 0; i < height; i++) { - if (!this.getRelative(0, i, 0).isSolid()) + if (!this.getRelative(0, i, 0).isSolid()) { this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); + } } } /** * Replaces solid blocks only + * * @param height pillar height. This height will be reached. - * @param types materials the pillar consists of + * @param types materials the pillar consists of */ public void ReplacePillar(int height, Material... types) { for (int i = 0; i < height; i++) { - if (this.getRelative(0, i, 0).isSolid()) + if (this.getRelative(0, i, 0).isSolid()) { this.getRelative(0, i, 0).setType(GenUtils.randChoice(types)); + } } } /** * Replaces non-cave air only + * * @param height of pillar - * @param rand to use for choosing random material types - * @param types actual materials to use + * @param rand to use for choosing random material types + * @param types actual materials to use */ public void CAPillar(int height, @NotNull Random rand, Material... types) { for (int i = 0; i < height; i++) { - if (this.getRelative(0, i, 0).getType() != Material.CAVE_AIR) + if (this.getRelative(0, i, 0).getType() != Material.CAVE_AIR) { this.getRelative(0, i, 0).setType(GenUtils.randChoice(rand, types)); + } } } - + public void waterlog(int height) { - for (int i = 0; i < height; i++) { - if(this.getRelative(0,i,0).getBlockData() instanceof Waterlogged) { - Waterlogged log = (Waterlogged) (this.getRelative(0,i,0).getBlockData()); - log.setWaterlogged(true); - this.getRelative(0,i,0).setBlockData(log); - } - } + for (int i = 0; i < height; i++) { + if (this.getRelative(0, i, 0).getBlockData() instanceof Waterlogged) { + Waterlogged log = (Waterlogged) (this.getRelative(0, i, 0).getBlockData()); + log.setWaterlogged(true); + this.getRelative(0, i, 0).setBlockData(log); + } + } } public int downUntilSolid(@NotNull Random rand, Material... types) { @@ -692,7 +740,10 @@ public int downUntilSolid(@NotNull Random rand, Material... types) { for (int y = this.y; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { if (!this.getRelative(0, -depth, 0).isSolid()) { this.getRelative(0, -depth, 0).setType(GenUtils.randChoice(rand, types)); - } else break; + } + else { + break; + } depth++; } @@ -704,7 +755,10 @@ public int blockfaceUntilSolid(int maxDepth, @NotNull Random rand, @NotNull Bloc while (depth <= maxDepth) { if (!this.getRelative(face).isSolid()) { this.getRelative(face).setType(GenUtils.randChoice(rand, types)); - } else break; + } + else { + break; + } depth++; } @@ -720,15 +774,17 @@ public int blockface(int maxDepth, @NotNull Random rand, @NotNull BlockFace face return depth; } - + public void downPillar(int h, Material... types) { - downPillar(new Random(),h,types); + downPillar(new Random(), h, types); } public void downPillar(@NotNull Random rand, int h, Material... types) { int depth = 0; for (int y = this.y; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { - if (depth >= h) break; + if (depth >= h) { + break; + } this.getRelative(0, -depth, 0).setType(GenUtils.randChoice(rand, types)); depth++; } @@ -737,10 +793,15 @@ public void downPillar(@NotNull Random rand, int h, Material... types) { public void downLPillar(@NotNull Random rand, int h, Material... types) { int depth = 0; for (int y = this.y; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { - if (depth >= h) break; + if (depth >= h) { + break; + } if (!this.getRelative(0, -depth, 0).isSolid()) { this.getRelative(0, -depth, 0).setType(GenUtils.randChoice(rand, types)); - } else break; + } + else { + break; + } depth++; } } @@ -748,7 +809,9 @@ public void downLPillar(@NotNull Random rand, int h, Material... types) { public void downRPillar(@NotNull Random rand, int h, Material... types) { int depth = 0; for (int y = this.y; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { - if (depth >= h) break; + if (depth >= h) { + break; + } if (!this.getRelative(0, -depth, 0).isSolid()) { this.getRelative(0, -depth, 0).setType(GenUtils.randChoice(rand, types)); } @@ -759,10 +822,15 @@ public void downRPillar(@NotNull Random rand, int h, Material... types) { public void directionalLPillar(@NotNull Random rand, @NotNull BlockFace face, int h, Material... types) { int depth = 0; for (int y = this.y; y > TerraformGeneratorPlugin.injector.getMinY(); y--) { - if (depth >= h) break; + if (depth >= h) { + break; + } if (!this.getRelative(face, depth).isSolid()) { this.getRelative(face, depth).setType(GenUtils.randChoice(rand, types)); - } else break; + } + else { + break; + } depth++; } } @@ -770,19 +838,20 @@ public void directionalLPillar(@NotNull Random rand, @NotNull BlockFace face, in public @NotNull SimpleBlock getDown(int i) { return this.getRelative(0, -i, 0); } - + public @NotNull SimpleBlock getDown() { return this.getRelative(0, -1, 0); } public @NotNull String toString() { - return x + "," + y + "," + z; + return x + "," + y + "," + z; } public void rsetType(@NotNull EnumSet toReplace, Material... type) { - popData.rsetType(this.toVector(),toReplace,type); + popData.rsetType(this.toVector(), toReplace, type); } + public void rsetBlockData(@NotNull EnumSet toReplace, BlockData data) { - popData.rsetBlockData(this.toVector(),toReplace,data); + popData.rsetBlockData(this.toVector(), toReplace, data); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/data/SimpleChunkLocation.java b/common/src/main/java/org/terraform/data/SimpleChunkLocation.java index 29cb9a0c..91d8825a 100644 --- a/common/src/main/java/org/terraform/data/SimpleChunkLocation.java +++ b/common/src/main/java/org/terraform/data/SimpleChunkLocation.java @@ -11,6 +11,7 @@ /** * class represent chunk location in simple form + * * @author wysohn */ public class SimpleChunkLocation implements Cloneable { @@ -46,7 +47,9 @@ public SimpleChunkLocation(@NotNull Chunk chunk) { // world , x, z public static SimpleChunkLocation chunkStrToLoc(@Nullable String chunk) { - if (chunk == null) return null; + if (chunk == null) { + return null; + } String[] split = StringUtils.split(StringUtils.deleteWhitespace(chunk), ','); String world = split[0]; @@ -92,8 +95,12 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof SimpleChunkLocation other)) return false; + if (this == obj) { + return true; + } + if (!(obj instanceof SimpleChunkLocation other)) { + return false; + } return this.x == other.x && this.z == other.z && Objects.equals(world, other.world); } diff --git a/common/src/main/java/org/terraform/data/SimpleLocation.java b/common/src/main/java/org/terraform/data/SimpleLocation.java index 956df97a..359f9c9e 100644 --- a/common/src/main/java/org/terraform/data/SimpleLocation.java +++ b/common/src/main/java/org/terraform/data/SimpleLocation.java @@ -28,8 +28,13 @@ public SimpleLocation(@NotNull SimpleLocation other) { public @NotNull SimpleLocation getRelative(@NotNull BlockFace face) { return new SimpleLocation(this.x + face.getModX(), this.y + face.getModY(), this.z + face.getModZ()); } + public @NotNull SimpleLocation getRelative(@NotNull BlockFace face, int i) { - return new SimpleLocation(this.x + face.getModX()*i, this.y + face.getModY()*i, this.z + face.getModZ()*i); + return new SimpleLocation( + this.x + face.getModX() * i, + this.y + face.getModY() * i, + this.z + face.getModZ() * i + ); } public float distance(@NotNull SimpleLocation o) { @@ -41,43 +46,50 @@ public float distanceSqr(@NotNull SimpleLocation o) { } public float distanceQuad(@NotNull SimpleLocation o) { - return (float) Math.pow(Math.pow(o.x - x, 2) + Math.pow(o.y - y, 2) + Math.pow(o.z - z, 2),4); - } + return (float) Math.pow(Math.pow(o.x - x, 2) + Math.pow(o.y - y, 2) + Math.pow(o.z - z, 2), 4); + } public float distanceSqr(int nx, int ny, int nz) { return (float) (Math.pow(nx - x, 2) + Math.pow(ny - y, 2) + Math.pow(nz - z, 2)); } - + /** * Returns a value between 0 and 2PI to represent a 360 degree angle * offset of the other location "o" compared to this location. */ public float twoDAngleTo(@NotNull SimpleLocation o) { - - // Handle absolute cases first - if(o.x == x && o.z == z) { - return 0.0f; - }else if(o.x == x && o.z > z){ - return 0.0f; - }else if(o.x == x){ - return (float) Math.PI; - }else if(o.x > x && o.z == z){ - return (float) Math.PI/2; - }else if(o.x < x && o.z == z){ - return (float) (3*Math.PI/2); - } - // Handle CAST trigo calculations - else if(o.x > x && o.z > z) { // A segment - return (float) Math.atan((double) (o.x - x) /(o.z-z)); - }else if(o.x > x) { // C segment - return (float) (Math.atan((double) (z - o.z) /(o.x-x)) + Math.PI/2); - }else if(o.z < z) { // T segment - return (float) (Math.atan((double) (x - o.x) /(z-o.z)) + Math.PI); - }else { // S segment - return (float) (Math.atan((double) (o.z - z) /(x-o.x))+3*Math.PI/2); - } - } - + + // Handle absolute cases first + if (o.x == x && o.z == z) { + return 0.0f; + } + else if (o.x == x && o.z > z) { + return 0.0f; + } + else if (o.x == x) { + return (float) Math.PI; + } + else if (o.x > x && o.z == z) { + return (float) Math.PI / 2; + } + else if (o.x < x && o.z == z) { + return (float) (3 * Math.PI / 2); + } + // Handle CAST trigo calculations + else if (o.x > x && o.z > z) { // A segment + return (float) Math.atan((double) (o.x - x) / (o.z - z)); + } + else if (o.x > x) { // C segment + return (float) (Math.atan((double) (z - o.z) / (o.x - x)) + Math.PI / 2); + } + else if (o.z < z) { // T segment + return (float) (Math.atan((double) (x - o.x) / (z - o.z)) + Math.PI); + } + else { // S segment + return (float) (Math.atan((double) (o.z - z) / (x - o.x)) + 3 * Math.PI / 2); + } + } + /** * Returns a value between 0 and PI to represent a 180 degree angle * offset of the other location "o" compared to this location. @@ -85,38 +97,45 @@ else if(o.x > x && o.z > z) { // A segment * Will return the same value for segment CA and ST (mirrored) */ public float twoDAngleWrapTo(@NotNull SimpleLocation o) { - - // Handle absolute cases first - if(o.x == x && o.z == z) { - return 0.0f; - }else if(o.x == x && o.z > z){ - return 0; - }else if(o.x == x){ - return (float) Math.PI; - }else if(o.x > x && o.z == z){ - return (float) Math.PI/2; - }else if(o.x < x && o.z == z){ - return (float) (Math.PI/2); - } - // Handle CAST trigo calculations - else if(o.x > x && o.z > z) { // A segment - return (float) Math.atan((double) (o.x - x) /(o.z-z)); - }else if(o.x > x) { // C segment - return (float) (Math.atan((double) (z - o.z) /(o.x-x)) + Math.PI/2); - }else if(o.z < z) { // T segment - return (float) (Math.atan((double) (z - o.z) /(x-o.x)) + Math.PI/2); - }else { // S segment - return (float) Math.atan((double) (x - o.x) /(o.z-z)); - } + + // Handle absolute cases first + if (o.x == x && o.z == z) { + return 0.0f; + } + else if (o.x == x && o.z > z) { + return 0; + } + else if (o.x == x) { + return (float) Math.PI; + } + else if (o.x > x && o.z == z) { + return (float) Math.PI / 2; + } + else if (o.x < x && o.z == z) { + return (float) (Math.PI / 2); + } + // Handle CAST trigo calculations + else if (o.x > x && o.z > z) { // A segment + return (float) Math.atan((double) (o.x - x) / (o.z - z)); + } + else if (o.x > x) { // C segment + return (float) (Math.atan((double) (z - o.z) / (o.x - x)) + Math.PI / 2); + } + else if (o.z < z) { // T segment + return (float) (Math.atan((double) (z - o.z) / (x - o.x)) + Math.PI / 2); + } + else { // S segment + return (float) Math.atan((double) (x - o.x) / (o.z - z)); + } } @Override public int hashCode() { - int prime = 93929798; + int prime = 93929798; int hash = x * prime; hash = (hash + y) * prime; hash = (hash + z) * prime; - + return hash; } @@ -169,14 +188,14 @@ public int getZ() { public void setZ(int z) { this.z = z; } - + @Override public @NotNull String toString() { - return this.x + "," + this.y + "," + this.z; + return this.x + "," + this.y + "," + this.z; } public @NotNull SimpleLocation getAtY(int newy) { - return new SimpleLocation(x,newy,z); + return new SimpleLocation(x, newy, z); } public @NotNull SimpleLocation getUp(int n) { diff --git a/common/src/main/java/org/terraform/data/TWSimpleLocation.java b/common/src/main/java/org/terraform/data/TWSimpleLocation.java index a363255f..0049d1a1 100644 --- a/common/src/main/java/org/terraform/data/TWSimpleLocation.java +++ b/common/src/main/java/org/terraform/data/TWSimpleLocation.java @@ -6,18 +6,19 @@ public class TWSimpleLocation extends SimpleLocation { - final TerraformWorld tw; - public TWSimpleLocation(TerraformWorld tw, int x, int y, int z) { - super(x, y, z); - this.tw = tw; - // TODO Auto-generated constructor stub - } - - public TWSimpleLocation(TerraformWorld tw, @NotNull SimpleLocation loc) { - super(loc); - this.tw = tw; - } - + final TerraformWorld tw; + + public TWSimpleLocation(TerraformWorld tw, int x, int y, int z) { + super(x, y, z); + this.tw = tw; + // TODO Auto-generated constructor stub + } + + public TWSimpleLocation(TerraformWorld tw, @NotNull SimpleLocation loc) { + super(loc); + this.tw = tw; + } + @Override public int hashCode() { @@ -27,16 +28,13 @@ public int hashCode() { @Override public boolean equals(Object obj) { if (obj instanceof TWSimpleLocation sLoc) { - return sLoc.x == x - && sLoc.y == y - && sLoc.z == z - && tw.getName().equals(sLoc.getTerraformWorld().getName()); + return sLoc.x == x && sLoc.y == y && sLoc.z == z && tw.getName().equals(sLoc.getTerraformWorld().getName()); } return false; } - + public TerraformWorld getTerraformWorld() { - return tw; + return tw; } } diff --git a/common/src/main/java/org/terraform/data/TerraformWorld.java b/common/src/main/java/org/terraform/data/TerraformWorld.java index 1a2ea805..8462d396 100644 --- a/common/src/main/java/org/terraform/data/TerraformWorld.java +++ b/common/src/main/java/org/terraform/data/TerraformWorld.java @@ -13,8 +13,8 @@ import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.main.config.TConfigOption; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Objects; @@ -23,13 +23,13 @@ public class TerraformWorld { private static final ConcurrentHashMap WORLDS = new ConcurrentHashMap<>(); + public final @NotNull NoiseCaveRegistry noiseCaveRegistry; private final String worldName; private final long seed; + private final @NotNull TerraformBukkitBlockPopulator bukkitBlockPopulator; public int minY = 0; public int maxY = 256; - private final @NotNull TerraformBukkitBlockPopulator bukkitBlockPopulator; - public final @NotNull NoiseCaveRegistry noiseCaveRegistry; public TerraformWorld(String name, long seed) { TerraformGeneratorPlugin.logger.info("Creating TW instance: " + name + " - " + seed); this.worldName = name; @@ -66,88 +66,81 @@ private TerraformWorld(@NotNull World world) { public @NotNull FastNoise getTemperatureOctave() { - return NoiseCacheHandler.getNoise( - this, - NoiseCacheEntry.TW_TEMPERATURE, - tw -> { - FastNoise n = new FastNoise((int) (tw.getSeed() * 2)); - n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_TEMPERATURE_FREQUENCY.getFloat()); // Default 0.03f - return n; - }); + return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_TEMPERATURE, tw -> { + FastNoise n = new FastNoise((int) (tw.getSeed() * 2)); + n.SetNoiseType(NoiseType.Simplex); + n.SetFrequency(TConfigOption.BIOME_TEMPERATURE_FREQUENCY.getFloat()); // Default 0.03f + return n; + }); } public @NotNull FastNoise getMoistureOctave() { - return NoiseCacheHandler.getNoise( - this, - NoiseCacheEntry.TW_MOISTURE, - tw -> { - FastNoise n = new FastNoise((int) (tw.getSeed()/4)); - n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_MOISTURE_FREQUENCY.getFloat()); // Default 0.03f - return n; - }); + return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_MOISTURE, tw -> { + FastNoise n = new FastNoise((int) (tw.getSeed() / 4)); + n.SetNoiseType(NoiseType.Simplex); + n.SetFrequency(TConfigOption.BIOME_MOISTURE_FREQUENCY.getFloat()); // Default 0.03f + return n; + }); } public @NotNull FastNoise getOceanicNoise() { - return NoiseCacheHandler.getNoise( - this, - NoiseCacheEntry.TW_OCEANIC, - tw -> { - FastNoise n = new FastNoise((int) tw.getSeed() * 12); - n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_OCEANIC_FREQUENCY.getFloat()); - return n; - }); + return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_OCEANIC, tw -> { + FastNoise n = new FastNoise((int) tw.getSeed() * 12); + n.SetNoiseType(NoiseType.Simplex); + n.SetFrequency(TConfigOption.BIOME_OCEANIC_FREQUENCY.getFloat()); + return n; + }); } public @NotNull FastNoise getMountainousNoise() { - return NoiseCacheHandler.getNoise( - this, - NoiseCacheEntry.TW_MOUNTAINOUS, - tw -> { - FastNoise n = new FastNoise((int) tw.getSeed() * 73); - n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_MOUNTAINOUS_FREQUENCY.getFloat()); - return n; - }); - } - + return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_MOUNTAINOUS, tw -> { + FastNoise n = new FastNoise((int) tw.getSeed() * 73); + n.SetNoiseType(NoiseType.Simplex); + n.SetFrequency(TConfigOption.BIOME_MOUNTAINOUS_FREQUENCY.getFloat()); + return n; + }); + } + public long getSeed() { return seed; } public @NotNull Random getRand(long d) { - return new Random(seed/4 + 25981*d); + return new Random(seed / 4 + 25981 * d); } public @NotNull Random getHashedRand(long a, int b, int c) { - return new Random(11*a + Objects.hash(seed, 127*b, 773*c)); + return new Random(11 * a + Objects.hash(seed, 127 * b, 773 * c)); } public @NotNull Random getHashedRand(int x, int y, int z, long multiplier) { - return new Random(Objects.hash(seed, 11*x, 127*y, 773*z) * multiplier); + return new Random(Objects.hash(seed, 11 * x, 127 * y, 773 * z) * multiplier); } /** * Same as getBiomeBank(x,y,z), except y is autofilled to be HeightMap.getBlockHeight + * * @param x blockX * @param z blockZ */ public BiomeBank getBiomeBank(int x, int z) { ChunkCache cache = TerraformGenerator.getCache(this, x, z); BiomeBank cachedValue = cache.getBiome(x, z); - if (!BiomeBank.debugPrint && cachedValue != null) return cachedValue; - - int y = HeightMap.getBlockHeight(this, x, z); + if (!BiomeBank.debugPrint && cachedValue != null) { + return cachedValue; + } + + int y = HeightMap.getBlockHeight(this, x, z); return cache.cacheBiome(x, z, BiomeBank.calculateBiome(this, x, y, z)); } - + public BiomeBank getBiomeBank(int x, int y, int z) { ChunkCache cache = TerraformGenerator.getCache(this, x, z); BiomeBank cachedValue = cache.getBiome(x, z); - if (cachedValue != null) return cachedValue; + if (cachedValue != null) { + return cachedValue; + } return cache.cacheBiome(x, z, BiomeBank.calculateBiome(this, x, y, z)); } @@ -161,7 +154,7 @@ public String getName() { return Bukkit.getWorld(worldName); } - public @NotNull TerraformBukkitBlockPopulator getBukkitBlockPopulator() { - return bukkitBlockPopulator; - } + public @NotNull TerraformBukkitBlockPopulator getBukkitBlockPopulator() { + return bukkitBlockPopulator; + } } diff --git a/common/src/main/java/org/terraform/data/Wall.java b/common/src/main/java/org/terraform/data/Wall.java index 313d1cb6..e0c0139b 100644 --- a/common/src/main/java/org/terraform/data/Wall.java +++ b/common/src/main/java/org/terraform/data/Wall.java @@ -7,21 +7,21 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.utils.BlockUtils; -public class Wall extends SimpleBlock{ +public class Wall extends SimpleBlock { private final BlockFace direction; public Wall(@NotNull SimpleBlock block, BlockFace dir) { - super(block.getPopData(), block.getX(), block.getY(), block.getZ()); + super(block.getPopData(), block.getX(), block.getY(), block.getZ()); this.direction = dir; } public Wall(@NotNull SimpleBlock block) { - super(block.getPopData(), block.getX(), block.getY(), block.getZ()); + super(block.getPopData(), block.getX(), block.getY(), block.getZ()); this.direction = BlockFace.NORTH; } - + public Wall(@NotNull PopulatorDataAbstract data, int x, int y, int z, BlockFace dir) { - super(data,x,y,z); + super(data, x, y, z); this.direction = dir; } @@ -37,19 +37,19 @@ public Wall(@NotNull PopulatorDataAbstract data, int x, int y, int z, BlockFace public @NotNull Wall getLeft() { return new Wall(this.getRelative(BlockUtils.getAdjacentFaces(direction)[0]), direction); } - + public @NotNull Wall getUp() { - return new Wall(super.getUp(), direction); + return new Wall(super.getUp(), direction); } public @NotNull Wall getUp(int i) { - return new Wall(super.getUp(i), direction); + return new Wall(super.getUp(i), direction); } public @NotNull Wall getGround() { return new Wall(super.getGround(), direction); } - + public @NotNull Wall getGroundOrDry() { return new Wall(super.getGroundOrDry(), direction); } @@ -62,17 +62,21 @@ public Wall(@NotNull PopulatorDataAbstract data, int x, int y, int z, BlockFace * Gets the first solid block above this one */ public Wall findCeiling(int cutoff) { - SimpleBlock sb = super.findCeiling(cutoff); - if(sb == null) return null; - return new Wall(sb, direction); + SimpleBlock sb = super.findCeiling(cutoff); + if (sb == null) { + return null; + } + return new Wall(sb, direction); } /** * Gets the first solid block below this one */ public Wall findFloor(int cutoff) { - SimpleBlock sb = super.findFloor(cutoff); - if(sb == null) return null; + SimpleBlock sb = super.findFloor(cutoff); + if (sb == null) { + return null; + } return new Wall(sb, direction); } @@ -80,8 +84,10 @@ public Wall findFloor(int cutoff) { * Gets the first solid block below this one */ public Wall findNearestAirPocket(int cutoff) { - SimpleBlock sb = super.findNearestAirPocket(cutoff); - if(sb == null) return null; + SimpleBlock sb = super.findNearestAirPocket(cutoff); + if (sb == null) { + return null; + } return new Wall(sb, direction); } @@ -89,17 +95,21 @@ public Wall findNearestAirPocket(int cutoff) { * Gets the first stone-like block below this one */ public Wall findStonelikeFloor(int cutoff) { - SimpleBlock sb = super.findStonelikeFloor(cutoff); - if(sb == null) return null; + SimpleBlock sb = super.findStonelikeFloor(cutoff); + if (sb == null) { + return null; + } return new Wall(sb, direction); } - + /** * Gets the first stone-like block above this one */ public Wall findStonelikeCeiling(int cutoff) { - SimpleBlock sb = super.findStonelikeCeiling(cutoff); - if(sb == null) return null; + SimpleBlock sb = super.findStonelikeCeiling(cutoff); + if (sb == null) { + return null; + } return new Wall(super.findStonelikeCeiling(cutoff), direction); } @@ -117,7 +127,7 @@ public Wall findStonelikeCeiling(int cutoff) { } return null; } - + /** * Gets the first solid block towards that blockface @@ -150,9 +160,13 @@ public Wall findStonelikeCeiling(int cutoff) { } public Wall getLeft(int it) { - if (it < 0) return getRight(-it); + if (it < 0) { + return getRight(-it); + } Wall w = this; - for (int i = 0; i < it; i++) w = w.getLeft(); + for (int i = 0; i < it; i++) { + w = w.getLeft(); + } return w; } @@ -161,9 +175,13 @@ public Wall getLeft(int it) { } public Wall getRight(int it) { - if (it < 0) return getLeft(-it); + if (it < 0) { + return getLeft(-it); + } Wall w = this; - for (int i = 0; i < it; i++) w = w.getRight(); + for (int i = 0; i < it; i++) { + w = w.getRight(); + } return w; } @@ -179,9 +197,13 @@ public Wall getRight(int it) { } public Wall getRear(int it) { - if (it < 0) return getFront(-it); + if (it < 0) { + return getFront(-it); + } Wall w = this.clone(); - for (int i = 0; i < it; i++) w = w.getRear(); + for (int i = 0; i < it; i++) { + w = w.getRear(); + } return w; } @@ -190,20 +212,24 @@ public Wall getRear(int it) { } public Wall getFront(int it) { - if (it < 0) return getRear(-it); + if (it < 0) { + return getRear(-it); + } Wall w = this.clone(); - for (int i = 0; i < it; i++) w = w.getFront(); + for (int i = 0; i < it; i++) { + w = w.getFront(); + } return w; } public BlockFace getDirection() { return direction; } - + public @NotNull Wall getDown(int i) { return new Wall(super.getDown(i), direction); } - + public @NotNull Wall getDown() { return new Wall(super.getDown(), direction); } @@ -223,11 +249,11 @@ public BlockFace getDirection() { @Override public boolean equals(Object obj) { - return super.equals(obj); + return super.equals(obj); } - + public void lootTableChest(TerraLootTable table) { - get().getPopData().lootTableChest(getX(), getY(), getZ(), table); + get().getPopData().lootTableChest(getX(), getY(), getZ(), table); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/event/TerraformStructureSpawnEvent.java b/common/src/main/java/org/terraform/event/TerraformStructureSpawnEvent.java index 479dde5e..1c717e0d 100644 --- a/common/src/main/java/org/terraform/event/TerraformStructureSpawnEvent.java +++ b/common/src/main/java/org/terraform/event/TerraformStructureSpawnEvent.java @@ -15,34 +15,32 @@ public final class TerraformStructureSpawnEvent extends Event { private final String structureName; private final int x; private final int z; - + public TerraformStructureSpawnEvent(int x, int z, String structureName) { - this.structureName = structureName; - this.x = x; - this.z = z; + this.structureName = structureName; + this.x = x; + this.z = z; } - - public @NotNull HandlerList getHandlers() { + public static @NotNull HandlerList getHandlerList() { return handlers; } - public static @NotNull HandlerList getHandlerList() { + public @NotNull HandlerList getHandlers() { return handlers; } - - public String getStructureName() { - return structureName; - } + public String getStructureName() { + return structureName; + } - public int getX() { - return x; - } + public int getX() { + return x; + } - public int getZ() { - return z; - } + public int getZ() { + return z; + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/main/LangOpt.java b/common/src/main/java/org/terraform/main/LangOpt.java index 561e1beb..487361fa 100644 --- a/common/src/main/java/org/terraform/main/LangOpt.java +++ b/common/src/main/java/org/terraform/main/LangOpt.java @@ -60,7 +60,8 @@ public String parse(String @NotNull ... placeholders) { for (int i = 0; i < placeholders.length; i++) { if (i % 2 == 0) { placeholder = placeholders[i]; - } else { + } + else { parsed = parsed.replaceAll(placeholder, placeholders[i]); } } diff --git a/common/src/main/java/org/terraform/main/LanguageManager.java b/common/src/main/java/org/terraform/main/LanguageManager.java index c7d41c28..abfd39c9 100644 --- a/common/src/main/java/org/terraform/main/LanguageManager.java +++ b/common/src/main/java/org/terraform/main/LanguageManager.java @@ -1,70 +1,71 @@ package org.terraform.main; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + public class LanguageManager { - - private FileConfiguration langFile; - private final File file; - - public LanguageManager(@NotNull TerraformGeneratorPlugin plugin){ - this.file = new File(plugin.getDataFolder(),plugin.getConfigLoader().getString("lang")); - reloadLangFile(); - loadDefaults(); - } - - private final @NotNull HashMap cache = new HashMap<>(); - - private void loadDefaults(){ - fetchLang("permissions.insufficient","&cYou don't have enough permissions to perform this action!"); - fetchLang("command.wrong-arg-length","&cToo many or too little arguments provided!"); - fetchLang("command.unknown","&cUnknown subcommand."); - fetchLang("command.help.postive-pages","&cThe page specified must be a positive number!"); - fetchLang("permissions.console-cannot-exec","&cOnly players can execute this command."); - } - - public String fetchLang(@NotNull String langKey){ - return fetchLang(langKey,null); - } - - public String fetchLang(@NotNull String langKey, @Nullable String def){ - if(cache.containsKey(langKey)){ - return cache.get(langKey); - } - if(langFile.isSet(langKey)){ - String value = ChatColor.translateAlternateColorCodes('&', langFile.getString(langKey)); - cache.put(langKey, value); - return value; - }else if(def != null){ - langFile.set(langKey, def); - saveLangFile(); - } - cache.put(langKey, ChatColor.translateAlternateColorCodes('&', def)); - return ChatColor.translateAlternateColorCodes('&', def); - } - + + private final File file; + private final @NotNull HashMap cache = new HashMap<>(); + private FileConfiguration langFile; + + public LanguageManager(@NotNull TerraformGeneratorPlugin plugin) { + this.file = new File(plugin.getDataFolder(), plugin.getConfigLoader().getString("lang")); + reloadLangFile(); + loadDefaults(); + } + + private void loadDefaults() { + fetchLang("permissions.insufficient", "&cYou don't have enough permissions to perform this action!"); + fetchLang("command.wrong-arg-length", "&cToo many or too little arguments provided!"); + fetchLang("command.unknown", "&cUnknown subcommand."); + fetchLang("command.help.postive-pages", "&cThe page specified must be a positive number!"); + fetchLang("permissions.console-cannot-exec", "&cOnly players can execute this command."); + } + + public String fetchLang(@NotNull String langKey) { + return fetchLang(langKey, null); + } + + public String fetchLang(@NotNull String langKey, @Nullable String def) { + if (cache.containsKey(langKey)) { + return cache.get(langKey); + } + if (langFile.isSet(langKey)) { + String value = ChatColor.translateAlternateColorCodes('&', langFile.getString(langKey)); + cache.put(langKey, value); + return value; + } + else if (def != null) { + langFile.set(langKey, def); + saveLangFile(); + } + cache.put(langKey, ChatColor.translateAlternateColorCodes('&', def)); + return ChatColor.translateAlternateColorCodes('&', def); + } + public FileConfiguration getLangFile() { return langFile; } public void saveLangFile() { try { - langFile.save(file); - } catch (IOException e) { + langFile.save(file); + } + catch (IOException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } public void reloadLangFile() { - this.cache.clear(); + this.cache.clear(); this.langFile = YamlConfiguration.loadConfiguration(file); } diff --git a/common/src/main/java/org/terraform/main/TLogger.java b/common/src/main/java/org/terraform/main/TLogger.java index bbf7f59c..90f1bd4e 100644 --- a/common/src/main/java/org/terraform/main/TLogger.java +++ b/common/src/main/java/org/terraform/main/TLogger.java @@ -1,116 +1,127 @@ package org.terraform.main; -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.logging.ConsoleHandler; -import java.util.logging.FileHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; import org.terraform.main.config.TConfigOption; +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.logging.*; + public class TLogger { - - private static final Logger LOGGER = Logger.getLogger("TerraformGenerator-Custom"); + + private static final Logger LOGGER = Logger.getLogger("TerraformGenerator-Custom"); private static boolean suppressConsoleLogs = false; - - public TLogger() { - suppressConsoleLogs = TConfigOption.DEVSTUFF_SUPPRESS_CONSOLE_LOGS.getBoolean(); - if(suppressConsoleLogs) { + + public TLogger() { + suppressConsoleLogs = TConfigOption.DEVSTUFF_SUPPRESS_CONSOLE_LOGS.getBoolean(); + if (suppressConsoleLogs) { Handler consoleHandler; Handler fileHandler; - try{ + try { // Creating consoleHandler and fileHandler consoleHandler = new ConsoleHandler(); - fileHandler = new FileHandler("plugins" + File.separator + "TerraformGenerator" + File.separator + "terraform.log", true); - + fileHandler = new FileHandler("plugins" + + File.separator + + "TerraformGenerator" + + File.separator + + "terraform.log", true); + // Follow bukkit format fileHandler.setFormatter(new SimpleFormatter() { private static final String format = "[%1$tF %1$tT] [%2$-7s] %3$s %n"; @Override public synchronized @NotNull String format(@NotNull LogRecord lr) { - return String.format(format, + return String.format( + format, new Date(lr.getMillis()), lr.getLevel().getLocalizedName(), - ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', lr.getMessage())) ); + ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', lr.getMessage())) + ); } }); - + LOGGER.setUseParentHandlers(false); - + // Assigning handlers to LOGGER object LOGGER.addHandler(consoleHandler); LOGGER.addHandler(fileHandler); - + // No stdout // LOGGER.setLevel(Level.OFF); consoleHandler.setLevel(Level.OFF); fileHandler.setLevel(Level.ALL); - + LOGGER.config("Configuration done."); - + // Console handler removed // LOGGER.removeHandler(consoleHandler); - + this.stdout("Custom Logger Initialized"); - }catch(IOException exception){ - Bukkit.getLogger().severe("Error occur in FileHandler." + exception); - suppressConsoleLogs = false; } - } + catch (IOException exception) { + Bukkit.getLogger().severe("Error occur in FileHandler." + exception); + suppressConsoleLogs = false; + } + } } - + public void stdout(@NotNull String message) { - Bukkit.getConsoleSender().sendMessage("[TerraformGenerator] " - + ChatColor.translateAlternateColorCodes('&', message)); - - if(suppressConsoleLogs) { - LOGGER.log(Level.INFO," " + message); - } + Bukkit.getConsoleSender() + .sendMessage("[TerraformGenerator] " + ChatColor.translateAlternateColorCodes('&', message)); + + if (suppressConsoleLogs) { + LOGGER.log(Level.INFO, " " + message); + } } public void error(@NotNull String message) { - if(suppressConsoleLogs) { - LOGGER.log(Level.SEVERE,"[!] " + message); - }else { - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[TerraformGenerator][!] " - + ChatColor.translateAlternateColorCodes('&', message)); - } + if (suppressConsoleLogs) { + LOGGER.log(Level.SEVERE, "[!] " + message); + } + else { + Bukkit.getConsoleSender() + .sendMessage(ChatColor.RED + "[TerraformGenerator][!] " + ChatColor.translateAlternateColorCodes( + '&', + message + )); + } } public void info(@NotNull String message) { - if(suppressConsoleLogs) { - LOGGER.log(Level.INFO,message); - }else - Bukkit.getConsoleSender().sendMessage("[TerraformGenerator] " - + ChatColor.translateAlternateColorCodes('&', message)); + if (suppressConsoleLogs) { + LOGGER.log(Level.INFO, message); + } + else { + Bukkit.getConsoleSender() + .sendMessage("[TerraformGenerator] " + ChatColor.translateAlternateColorCodes('&', message)); + } } - + public void debug(@NotNull String message) { - if (TConfigOption.DEVSTUFF_DEBUG_MODE.getBoolean()) - if(suppressConsoleLogs) { - LOGGER.log(Level.INFO,"[v] "+message); - }else - Bukkit.getConsoleSender().sendMessage("[TerraformGenerator][v] " - + ChatColor.translateAlternateColorCodes('&', message)); + if (TConfigOption.DEVSTUFF_DEBUG_MODE.getBoolean()) { + if (suppressConsoleLogs) { + LOGGER.log(Level.INFO, "[v] " + message); + } + else { + Bukkit.getConsoleSender() + .sendMessage("[TerraformGenerator][v] " + ChatColor.translateAlternateColorCodes('&', message)); + } + } } public void stackTrace(@NotNull Throwable e) { - for(StackTraceElement stackTraceElement : e.getStackTrace()) { + for (StackTraceElement stackTraceElement : e.getStackTrace()) { final String message = stackTraceElement.toString(); - if(suppressConsoleLogs) { + if (suppressConsoleLogs) { LOGGER.log(Level.SEVERE, "[!] " + message); - } else { + } + else { Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[TerraformGenerator][!] " + message); } } diff --git a/common/src/main/java/org/terraform/main/TerraformCommandManager.java b/common/src/main/java/org/terraform/main/TerraformCommandManager.java index 49bb449f..e9abe3d8 100644 --- a/common/src/main/java/org/terraform/main/TerraformCommandManager.java +++ b/common/src/main/java/org/terraform/main/TerraformCommandManager.java @@ -20,16 +20,20 @@ public class TerraformCommandManager implements TabExecutor { + public final @NotNull ArrayList bases = new ArrayList(); + private final @NotNull ArrayList commands = new ArrayList<>(); + + private final TerraformGeneratorPlugin plugin; public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String @NotNull ... bases) { - - this.plugin = plugin; - for(String base:bases){ - this.bases.add(base); - plugin.getCommand(base).setExecutor(this); - } - registerCommand(new HelpCommand(plugin,this,"help","h","?")); - - if (TConfigOption.DEVSTUFF_EXTENDED_COMMANDS.getBoolean()) { + + this.plugin = plugin; + for (String base : bases) { + this.bases.add(base); + plugin.getCommand(base).setExecutor(this); + } + registerCommand(new HelpCommand(plugin, this, "help", "h", "?")); + + if (TConfigOption.DEVSTUFF_EXTENDED_COMMANDS.getBoolean()) { this.registerCommand(new PreviewCommand(plugin, "preview")); this.registerCommand(new TimingsCommand(plugin, "timings", "lag")); this.registerCommand(new CoconutCommand(plugin, "coconut")); @@ -38,8 +42,8 @@ public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String this.registerCommand(new SphereCommand(plugin, "sphere")); this.registerCommand(new FractalTreeCommand(plugin, "fractal", "fractaltree", "ftree")); this.registerCommand(new CaveCommand(plugin, "cave")); - this.registerCommand(new WarmOceanRuinsCommand(plugin, "warmoceanruins","wor")); - this.registerCommand(new TrailRuinsCommand(plugin, "trailruins","tr")); + this.registerCommand(new WarmOceanRuinsCommand(plugin, "warmoceanruins", "wor")); + this.registerCommand(new TrailRuinsCommand(plugin, "trailruins", "tr")); this.registerCommand(new IceSpikeCommand(plugin, "icespike")); this.registerCommand(new CoralCommand(plugin, "coral")); this.registerCommand(new WitchHutCommand(plugin, "hut")); @@ -70,7 +74,7 @@ public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String this.registerCommand(new RuinedPortalCommand(plugin, "ruinedportal")); this.registerCommand(new MansionCommand(plugin, "mansion")); this.registerCommand(new SchematicSaveCommand(plugin, "save")); - this.registerCommand(new AncientCityCommand(plugin, "ancientcity","ac")); + this.registerCommand(new AncientCityCommand(plugin, "ancientcity", "ac")); this.registerCommand(new SchematicLoadCommand(plugin, "load")); this.registerCommand(new PyramidCommand(plugin, "pyramid")); this.registerCommand(new MazeCommand(plugin, "maze")); @@ -80,7 +84,7 @@ public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String this.registerCommand(new PlainsVillageCommand(plugin, "plainsvillage", "pv")); this.registerCommand(new RibCageCommand(plugin, "ribcage")); this.registerCommand(new OreDitCommand(plugin, "oredit")); - this.registerCommand(new NewTreeCommand(plugin, "newtree","nt")); + this.registerCommand(new NewTreeCommand(plugin, "newtree", "nt")); this.registerCommand(new CrappyDebugStructureCommand(plugin, "cdsc")); this.registerCommand(new SeekCommand(plugin, "seek")); @@ -89,90 +93,97 @@ public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String this.registerCommand(new FixerCacheFlushCommand(plugin, "fixercacheflush", "fcf")); this.registerCommand(new LocateBiomeCommand(plugin, "locatebiome", "lb")); } - - private final @NotNull ArrayList commands = new ArrayList<>(); - private final TerraformGeneratorPlugin plugin; - public final @NotNull ArrayList bases = new ArrayList(); - - public void unregisterCommand(@NotNull Class clazz){ + public void unregisterCommand(@NotNull Class clazz) { commands.removeIf(clazz::isInstance); - } - - public void unregisterCommand(String alias){ + } + + public void unregisterCommand(String alias) { commands.removeIf(cmd -> cmd.matchCommand(alias)); - } - - public @NotNull ArrayList getCommands(){ - return commands; - } - - public void registerCommand(@NotNull TerraCommand cmd){ - this.commands.add(cmd); - plugin.getLang().fetchLang("command." + cmd.aliases.get(0) + ".desc",cmd.getDefaultDescription()); - } - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String arg2, - String @NotNull [] args) { - if(args.length == 0){ - sender.sendMessage(plugin.getLang().fetchLang("command.unknown")); + } + + public @NotNull ArrayList getCommands() { + return commands; + } + + public void registerCommand(@NotNull TerraCommand cmd) { + this.commands.add(cmd); + plugin.getLang().fetchLang("command." + cmd.aliases.get(0) + ".desc", cmd.getDefaultDescription()); + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, + @NotNull Command cmd, + @NotNull String arg2, + String @NotNull [] args) + { + if (args.length == 0) { + sender.sendMessage(plugin.getLang().fetchLang("command.unknown")); new HelpCommand(plugin, this).execute(sender, new Stack<>()); return false; - } - for(TerraCommand command:commands){ - if(command.matchCommand(args[0].toLowerCase(Locale.ENGLISH))){ - Stack stack = new Stack<>(); - // Push arguments from back to front, except the 1st arg - for(int i = args.length -1; i>=1; i--){ - stack.push(args[i]); - } - if(!command.hasPermission(sender)){ - sender.sendMessage(plugin.getLang().fetchLang("permissions.insufficient")); - return false; - } - if(!command.canConsoleExec() && !(sender instanceof Player)){ - sender.sendMessage(plugin.getLang().fetchLang("permissions.console-cannot-exec")); - return false; - } - if(!command.isInAcceptedParamRange(stack)){ - sender.sendMessage(plugin.getLang().fetchLang("command.wrong-arg-length")); - return false; - } - try{ - command.execute(sender, stack); - return true; - }catch(InvalidArgumentException e){ - sender.sendMessage(ChatColor.RED + e.getProblem()); - return false; - } - } - } - sender.sendMessage(plugin.getLang().fetchLang("command.unknown")); - return false; - } + } + for (TerraCommand command : commands) { + if (command.matchCommand(args[0].toLowerCase(Locale.ENGLISH))) { + Stack stack = new Stack<>(); + // Push arguments from back to front, except the 1st arg + for (int i = args.length - 1; i >= 1; i--) { + stack.push(args[i]); + } + if (!command.hasPermission(sender)) { + sender.sendMessage(plugin.getLang().fetchLang("permissions.insufficient")); + return false; + } + if (!command.canConsoleExec() && !(sender instanceof Player)) { + sender.sendMessage(plugin.getLang().fetchLang("permissions.console-cannot-exec")); + return false; + } + if (!command.isInAcceptedParamRange(stack)) { + sender.sendMessage(plugin.getLang().fetchLang("command.wrong-arg-length")); + return false; + } + try { + command.execute(sender, stack); + return true; + } + catch (InvalidArgumentException e) { + sender.sendMessage(ChatColor.RED + e.getProblem()); + return false; + } + } + } + sender.sendMessage(plugin.getLang().fetchLang("command.unknown")); + return false; + } @Nullable @Override - public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String alias, @NotNull String @NotNull [] args) { - List options = new ArrayList<>(); + public List onTabComplete(@NotNull CommandSender commandSender, + @NotNull Command command, + @NotNull String alias, + @NotNull String @NotNull [] args) + { + List options = new ArrayList<>(); if (args.length == 0) { for (TerraCommand terraCommand : commands) { - if (terraCommand.hasPermission(commandSender)) + if (terraCommand.hasPermission(commandSender)) { options.add(terraCommand.aliases.get(0)); + } } - }else if(args.length == 1) { + } + else if (args.length == 1) { for (TerraCommand terraCommand : commands) { - if (terraCommand.hasPermission(commandSender)) - for(String a:terraCommand.aliases) { - if(a.startsWith(args[0].toLowerCase(Locale.ENGLISH))) { - options.add(terraCommand.aliases.get(0)); - break; - } - } + if (terraCommand.hasPermission(commandSender)) { + for (String a : terraCommand.aliases) { + if (a.startsWith(args[0].toLowerCase(Locale.ENGLISH))) { + options.add(terraCommand.aliases.get(0)); + break; + } + } + } } - }else { + } + else { for (TerraCommand terraCommand : commands) { if (terraCommand.matchCommand(args[0].toLowerCase(Locale.ENGLISH))) { for (TerraCommandArgument arg : terraCommand.parameters) { diff --git a/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java b/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java index 9166bfb7..10e8b528 100644 --- a/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java +++ b/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java @@ -12,11 +12,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.biome.BiomeBank; -import org.terraform.coregen.ChunkCache; -import org.terraform.coregen.ChunkCacheLoader; -import org.terraform.coregen.HeightMap; -import org.terraform.coregen.NMSInjectorAbstract; -import org.terraform.coregen.TerraformPopulator; +import org.terraform.coregen.*; import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleChunkLocation; @@ -43,76 +39,81 @@ public class TerraformGeneratorPlugin extends JavaPlugin implements Listener { - public static TLogger logger; public static final Set INJECTED_WORLDS = new HashSet<>(); public static final @NotNull PrivateFieldHandler privateFieldHandler; + public static TLogger logger; public static @Nullable NMSInjectorAbstract injector; - private static TerraformGeneratorPlugin instance; public static TfgWatchdogSuppressant watchdogSuppressant; - - private ConfigLoader config; - private LanguageManager lang; + private static TerraformGeneratorPlugin instance; static { PrivateFieldHandler handler; try { Field.class.getDeclaredField("modifiers"); handler = new Pre14PrivateFieldHandler(); - } catch (NoSuchFieldException | SecurityException ex) { + } + catch (NoSuchFieldException | SecurityException ex) { handler = new Post14PrivateFieldHandler(); } privateFieldHandler = handler; } + private ConfigLoader config; + private LanguageManager lang; + public static TerraformGeneratorPlugin get() { return instance; } - @Override + @Override public void onEnable() { super.onEnable(); - GenUtils.initGenUtils(); - BlockUtils.initBlockUtils(); + GenUtils.initGenUtils(); + BlockUtils.initBlockUtils(); instance = this; - config = new ConfigLoader(this); - lang = new LanguageManager(this); + config = new ConfigLoader(this); + lang = new LanguageManager(this); TConfigOption.loadValues(config); // Initiate the height map flat radius value HeightMap.spawnFlatRadiusSquared = TConfigOption.HEIGHT_MAP_SPAWN_FLAT_RADIUS.getInt(); - if(HeightMap.spawnFlatRadiusSquared > 0) HeightMap.spawnFlatRadiusSquared *= HeightMap.spawnFlatRadiusSquared; + if (HeightMap.spawnFlatRadiusSquared > 0) { + HeightMap.spawnFlatRadiusSquared *= HeightMap.spawnFlatRadiusSquared; + } BiomeBank.initSinglesConfig(); // Initiates single biome modes. - + // Initialize chunk cache based on config size - TerraformGenerator.CHUNK_CACHE = - CacheBuilder.newBuilder() - .maximumSize(TConfigOption.DEVSTUFF_CHUNKCACHE_SIZE.getInt()).build(new ChunkCacheLoader()); - + TerraformGenerator.CHUNK_CACHE = CacheBuilder.newBuilder() + .maximumSize(TConfigOption.DEVSTUFF_CHUNKCACHE_SIZE.getInt()) + .build(new ChunkCacheLoader()); + // Initialize biome query cache based on config size GenUtils.biomeQueryCache = CacheBuilder.newBuilder() - .maximumSize(TConfigOption.DEVSTUFF_CHUNKBIOMES_SIZE.getInt()) - .build(new CacheLoader<>() { - @Override - public @NotNull EnumSet load(@NotNull ChunkCache key) { - EnumSet banks = EnumSet.noneOf(BiomeBank.class); - int gridX = key.chunkX * 16; - int gridZ = key.chunkZ * 16; - for(int x = gridX; x < gridX + 16; x++) { - for(int z = gridZ; z < gridZ + 16; z++) { - BiomeBank bank = key.tw.getBiomeBank(x, z); - if(!banks.contains(bank)) banks.add(bank); - } - } - return banks; - } - }); - + .maximumSize(TConfigOption.DEVSTUFF_CHUNKBIOMES_SIZE.getInt()) + .build(new CacheLoader<>() { + @Override + public @NotNull EnumSet load(@NotNull ChunkCache key) { + EnumSet banks = EnumSet.noneOf(BiomeBank.class); + int gridX = key.chunkX * 16; + int gridZ = key.chunkZ * 16; + for (int x = gridX; x < gridX + 16; x++) { + for (int z = gridZ; z < gridZ + 16; z++) { + BiomeBank bank = key.tw.getBiomeBank(x, z); + if (!banks.contains(bank)) { + banks.add(bank); + } + } + } + return banks; + } + }); + LangOpt.init(this); logger = new TLogger(); watchdogSuppressant = new TfgWatchdogSuppressant(); new TerraformGeneratorMetricsHandler(this); // bStats - + TerraformGenerator.updateSeaLevelFromConfig(); new TerraformCommandManager(this, "terraform", "terra"); Bukkit.getPluginManager().registerEvents(this, this); @@ -120,18 +121,25 @@ public void onEnable() { String version = Version.getVersionPackage(); logger.stdout("Detected version: " + version + ", number: " + Version.DOUBLE); try { - injector = Version.SupportedVersion.getInjector(); - if(injector == null) throw new ClassNotFoundException(); - } catch (ClassNotFoundException e) { + injector = Version.SupportedVersion.getInjector(); + if (injector == null) { + throw new ClassNotFoundException(); + } + } + catch (ClassNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); logger.stdout("&cNo support for this version has been made yet!"); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { + } + catch (InstantiationException | + IllegalAccessException | + IllegalArgumentException | + InvocationTargetException | + NoSuchMethodException | + SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); logger.stdout("&cSomething went wrong initiating the injector!"); } - + injector.startupTasks(); if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_ENABLED.getBoolean()) { @@ -141,15 +149,16 @@ public void onEnable() { StructureRegistry.init(); } - + @Override public void onDisable() { - // This is already done in NativeGeneratorPatcherPopulator World Unload Event. - // NativeGeneratorPatcherPopulator.flushChanges(); + // This is already done in NativeGeneratorPatcherPopulator World Unload Event. + // NativeGeneratorPatcherPopulator.flushChanges(); } - + /** * Legacy thing. Consider removal. + * * @deprecated */ @Deprecated @@ -160,18 +169,20 @@ public void onWorldLoad(@NotNull WorldLoadEvent event) { if (!TerraformGenerator.preWorldInitGen.isEmpty()) { if (!TConfigOption.DEVSTUFF_ATTEMPT_FIXING_PREMATURE.getBoolean()) { logger.stdout("&cIgnoring " - + TerraformGenerator.preWorldInitGen.size() - + " pre-maturely generated chunks." - + " You may see a patch of plain land."); + + TerraformGenerator.preWorldInitGen.size() + + " pre-maturely generated chunks." + + " You may see a patch of plain land."); return; } logger.stdout("&6Trying to decorate " - + TerraformGenerator.preWorldInitGen.size() - + " pre-maturely generated chunks."); + + TerraformGenerator.preWorldInitGen.size() + + " pre-maturely generated chunks."); int fixed = 0; TerraformWorld tw = TerraformWorld.get(event.getWorld()); for (SimpleChunkLocation sc : TerraformGenerator.preWorldInitGen) { - if (!sc.getWorld().equals(event.getWorld().getName())) continue; + if (!sc.getWorld().equals(event.getWorld().getName())) { + continue; + } logger.stdout("Populating " + sc); PopulatorDataPostGen data = new PopulatorDataPostGen(sc.toChunk()); new TerraformPopulator(tw).populate(tw, data); @@ -193,10 +204,11 @@ public void onWorldInit(@NotNull WorldInitEvent event) { INJECTED_WORLDS.add(event.getWorld().getName()); tw.minY = injector.getMinY(); tw.maxY = injector.getMaxY(); - + logger.stdout("&aInjection success! Proceeding with generation."); - } else { + } + else { logger.stdout("&cInjection failed."); } } @@ -207,13 +219,13 @@ public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String return new TerraformGenerator(); } - public ConfigLoader getConfigLoader() { - return config; - } + public ConfigLoader getConfigLoader() { + return config; + } - public LanguageManager getLang() { - // TODO Auto-generated method stub - return lang; - } + public LanguageManager getLang() { + // TODO Auto-generated method stub + return lang; + } } diff --git a/common/src/main/java/org/terraform/main/config/ConfigLoader.java b/common/src/main/java/org/terraform/main/config/ConfigLoader.java index 6a7e9c57..edffc805 100644 --- a/common/src/main/java/org/terraform/main/config/ConfigLoader.java +++ b/common/src/main/java/org/terraform/main/config/ConfigLoader.java @@ -1,108 +1,116 @@ package org.terraform.main.config; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; +import org.terraform.main.TerraformGeneratorPlugin; + import java.io.File; import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import org.terraform.main.TerraformGeneratorPlugin; - public class ConfigLoader { - - private final @NotNull HashMap configOptions = new HashMap<>(); - private final TerraformGeneratorPlugin plugin; - private static final int configVersion = 4; - public ConfigLoader(@NotNull TerraformGeneratorPlugin plugin){ - this.plugin = plugin; - plugin.getConfig().options().copyDefaults(false); - plugin.saveConfig(); - configOptions.put("lang","eng.yml"); - configOptions.put("config-version", configVersion); - } - - public void load(){ - - // If config version is older, overwrite the whole config. - boolean overwrite = false; - if(!plugin.getConfig().isSet("config-version")) - overwrite = true; - else if(plugin.getConfig().getInt("config-version") < configVersion) - overwrite = true; - - // Make backup of old config before overwriting - if(overwrite) { - try { - if(new File("./plugins/TerraformGenerator/config.yml").exists()) { - Bukkit.getLogger().info("New config version detected. Overwriting old config. A backup will be made"); + + private static final int configVersion = 4; + private final @NotNull HashMap configOptions = new HashMap<>(); + private final TerraformGeneratorPlugin plugin; + + public ConfigLoader(@NotNull TerraformGeneratorPlugin plugin) { + this.plugin = plugin; + plugin.getConfig().options().copyDefaults(false); + plugin.saveConfig(); + configOptions.put("lang", "eng.yml"); + configOptions.put("config-version", configVersion); + } + + public void load() { + + // If config version is older, overwrite the whole config. + boolean overwrite = false; + if (!plugin.getConfig().isSet("config-version")) { + overwrite = true; + } + else if (plugin.getConfig().getInt("config-version") < configVersion) { + overwrite = true; + } + + // Make backup of old config before overwriting + if (overwrite) { + try { + if (new File("./plugins/TerraformGenerator/config.yml").exists()) { + Bukkit.getLogger() + .info("New config version detected. Overwriting old config. A backup will be made"); Files.copy( - new File("./plugins/TerraformGenerator/config.yml").toPath(), - new File("./plugins/TerraformGenerator/config.yml-" + System.currentTimeMillis() + ".bak").toPath() + new File("./plugins/TerraformGenerator/config.yml").toPath(), + new File("./plugins/TerraformGenerator/config.yml-" + + System.currentTimeMillis() + + ".bak").toPath() ); - } - }catch(Exception e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - Bukkit.getLogger().info("Failed to backup old config before overwrite."); - } - } - - for(String key: new ArrayList<>(configOptions.keySet())){ - if(!overwrite && plugin.getConfig().isSet(key)){ - configOptions.put(key, plugin.getConfig().get(key)); - }else{ - plugin.getConfig().set(key, configOptions.get(key)); - plugin.saveConfig(); - } - } - } - - public void reload(){ - plugin.reloadConfig(); - load(); - } - - /** - * Registers a new config option - * @param key the key of the new option - * @param defaultValue the default value of the new option - */ - public void reg(String key, Object defaultValue){ - this.configOptions.put(key,defaultValue); - } - - public void save(){ - for(String key:configOptions.keySet()){ - plugin.getConfig().set(key, configOptions.get(key)); - plugin.saveConfig(); - } - } - - public String getString(String key){ - return (String) configOptions.get(key); - } - - public Object get(String key){ - return configOptions.get(key); - } - - public boolean getBoolean(String key){ - return (Boolean) configOptions.get(key); - } - - public int getInt(String key){ - return (Integer) configOptions.get(key); - } - - public double getDouble(String key){ - return (Double) configOptions.get(key); - } - - @SuppressWarnings("unchecked") - public List getStringList(String key){ - return (List) configOptions.get(key); - } - + } + } + catch (Exception e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + Bukkit.getLogger().info("Failed to backup old config before overwrite."); + } + } + + for (String key : new ArrayList<>(configOptions.keySet())) { + if (!overwrite && plugin.getConfig().isSet(key)) { + configOptions.put(key, plugin.getConfig().get(key)); + } + else { + plugin.getConfig().set(key, configOptions.get(key)); + plugin.saveConfig(); + } + } + } + + public void reload() { + plugin.reloadConfig(); + load(); + } + + /** + * Registers a new config option + * + * @param key the key of the new option + * @param defaultValue the default value of the new option + */ + public void reg(String key, Object defaultValue) { + this.configOptions.put(key, defaultValue); + } + + public void save() { + for (String key : configOptions.keySet()) { + plugin.getConfig().set(key, configOptions.get(key)); + plugin.saveConfig(); + } + } + + public String getString(String key) { + return (String) configOptions.get(key); + } + + public Object get(String key) { + return configOptions.get(key); + } + + public boolean getBoolean(String key) { + return (Boolean) configOptions.get(key); + } + + public int getInt(String key) { + return (Integer) configOptions.get(key); + } + + public double getDouble(String key) { + return (Double) configOptions.get(key); + } + + @SuppressWarnings("unchecked") + public List getStringList(String key) { + return (List) configOptions.get(key); + } + } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/main/config/TConfigOption.java b/common/src/main/java/org/terraform/main/config/TConfigOption.java index 5af2635d..1eb2e701 100644 --- a/common/src/main/java/org/terraform/main/config/TConfigOption.java +++ b/common/src/main/java/org/terraform/main/config/TConfigOption.java @@ -498,8 +498,8 @@ public enum TConfigOption { ; private final String path; - private Object value; private final Function map; + private Object value; TConfigOption(String path, Object defaultValue) { this.path = path; @@ -523,6 +523,41 @@ public static void loadValues(@NotNull ConfigLoader conf) { } } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areCavesEnabled() { + return TConfigOption.FEATURE_CAVES_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areTreesEnabled() { + return TConfigOption.FEATURE_TREES_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areTallMushroomsEnabled() { + return TConfigOption.FEATURE_TALL_MUSHROOMS_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean arePlantsEnabled() { + return TConfigOption.FEATURE_PLANTS_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areStructuresEnabled() { + return TConfigOption.FEATURE_STRUCTURES_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areAnimalsEnabled() { + return TConfigOption.FEATURE_ANIMALS_ENABLED.getBoolean(); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areDecorationsEnabled() { + return TConfigOption.FEATURE_DECORATIONS_ENABLED.getBoolean(); + } + public @NotNull String getString() { return ChatColor.translateAlternateColorCodes('&', (String) value); } @@ -587,39 +622,4 @@ public T get(@NotNull Class clazz) { return clazz.cast(value); } - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areCavesEnabled() { - return TConfigOption.FEATURE_CAVES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areTreesEnabled() { - return TConfigOption.FEATURE_TREES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areTallMushroomsEnabled() { - return TConfigOption.FEATURE_TALL_MUSHROOMS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean arePlantsEnabled() { - return TConfigOption.FEATURE_PLANTS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areStructuresEnabled() { - return TConfigOption.FEATURE_STRUCTURES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areAnimalsEnabled() { - return TConfigOption.FEATURE_ANIMALS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areDecorationsEnabled() { - return TConfigOption.FEATURE_DECORATIONS_ENABLED.getBoolean(); - } - } diff --git a/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java b/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java index 920ddb1c..82d41c46 100644 --- a/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java +++ b/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java @@ -17,42 +17,24 @@ import java.util.Random; public class AmethystGeodePopulator { - - private final int geodeRadius; - private final double frequency; - private final int minDepth; - private final int minDepthBelowSurface; - - + + private final int geodeRadius; + private final double frequency; + private final int minDepth; + private final int minDepthBelowSurface; + + public AmethystGeodePopulator(int geodeRadius, double frequency, int minDepth, int minDepthBelowSurface) { - this.geodeRadius = geodeRadius; - this.frequency = TConfigOption.FEATURE_ORES_ENABLED.getBoolean() ? frequency : 0; - this.minDepth = minDepth; - this.minDepthBelowSurface = minDepthBelowSurface; + this.geodeRadius = geodeRadius; + this.frequency = TConfigOption.FEATURE_ORES_ENABLED.getBoolean() ? frequency : 0; + this.minDepth = minDepth; + this.minDepthBelowSurface = minDepthBelowSurface; } - - public void populate(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if(GenUtils.chance(random, (int) (frequency*10000.0), 10000)) { - int x = GenUtils.randInt(random, 0, 15) + data.getChunkX() * 16; - int z = GenUtils.randInt(random, 0, 15) + data.getChunkZ() * 16; - int upperHeightRange = GenUtils.getHighestGround(data, x, z) - minDepthBelowSurface; - if(upperHeightRange > minDepth) - upperHeightRange = minDepth; - - upperHeightRange = Math.min( - world.getBiomeBank(x,z).getHandler().getMaxHeightForCaves(world, x, z), - upperHeightRange); - - if(upperHeightRange < 14) return; - - // Elevate 14 units up. - int y = GenUtils.randInt(random, 14, upperHeightRange); - placeGeode(random.nextInt(9999), geodeRadius, new SimpleBlock(data,x,y,z)); - } - } - + public static void placeGeode(int seed, float r, @NotNull SimpleBlock block) { - if (r <= 1) return; + if (r <= 1) { + return; + } ArrayList amethystBlocks = new ArrayList<>(); FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); @@ -62,59 +44,72 @@ public static void placeGeode(int seed, float r, @NotNull SimpleBlock block) { for (float y = -r; y <= r; y++) { for (float z = -r; z <= r; z++) { SimpleBlock rel = block.getRelative(Math.round(x), Math.round(y), Math.round(z)); - double outerCrust = - (Math.pow(x, 2) - + Math.pow(y, 2) - + Math.pow(z, 2) - )/Math.pow(r, 2); - double innerCrust = - (Math.pow(x, 2) - + Math.pow(y, 2) - + Math.pow(z, 2) - )/Math.pow(r-1.0, 2); - double amethystCrust = - (Math.pow(x, 2) - + Math.pow(y, 2) - + Math.pow(z, 2) - )/Math.pow(r-2.2, 2); - double airHollower = - (Math.pow(x, 2) - + Math.pow(y, 2) - + Math.pow(z, 2) - )/Math.pow(r-3.3, 2); - + double outerCrust = (Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) / Math.pow(r, 2); + double innerCrust = (Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) / Math.pow(r - 1.0, 2); + double amethystCrust = (Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) / Math.pow(r - 2.2, 2); + double airHollower = (Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)) / Math.pow(r - 3.3, 2); + double noiseVal = 1 + 0.4 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); - + if (airHollower <= noiseVal) { - if(BlockUtils.isWet(rel)) - rel.setType(Material.WATER); - else - rel.setType(Material.CAVE_AIR); + if (BlockUtils.isWet(rel)) { + rel.setType(Material.WATER); + } + else { + rel.setType(Material.CAVE_AIR); + } // Only do the other stuff if this isn't air. - }else if(rel.isSolid()) - if (amethystCrust <= noiseVal) { - rel.setType(Material.AMETHYST_BLOCK,Material.BUDDING_AMETHYST); - amethystBlocks.add(rel); - }else if (innerCrust <= noiseVal) { - rel.setType(Material.CALCITE); - }else if (outerCrust <= noiseVal) { - rel.setType(Material.SMOOTH_BASALT); - } + } + else if (rel.isSolid()) { + if (amethystCrust <= noiseVal) { + rel.setType(Material.AMETHYST_BLOCK, Material.BUDDING_AMETHYST); + amethystBlocks.add(rel); + } + else if (innerCrust <= noiseVal) { + rel.setType(Material.CALCITE); + } + else if (outerCrust <= noiseVal) { + rel.setType(Material.SMOOTH_BASALT); + } + } } } } - + // Place crystals - for(SimpleBlock rel:amethystBlocks) { - for(BlockFace face:BlockUtils.sixBlockFaces) { - if(GenUtils.chance(1,6)) continue; - SimpleBlock target = rel.getRelative(face); - if(BlockUtils.isAir(target.getType()) && GenUtils.chance(1,6)) { - new DirectionalBuilder(Material.AMETHYST_CLUSTER) - .setFacing(face) - .apply(target); - } + for (SimpleBlock rel : amethystBlocks) { + for (BlockFace face : BlockUtils.sixBlockFaces) { + if (GenUtils.chance(1, 6)) { + continue; + } + SimpleBlock target = rel.getRelative(face); + if (BlockUtils.isAir(target.getType()) && GenUtils.chance(1, 6)) { + new DirectionalBuilder(Material.AMETHYST_CLUSTER).setFacing(face).apply(target); + } + } + } + } + + public void populate(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { + if (GenUtils.chance(random, (int) (frequency * 10000.0), 10000)) { + int x = GenUtils.randInt(random, 0, 15) + data.getChunkX() * 16; + int z = GenUtils.randInt(random, 0, 15) + data.getChunkZ() * 16; + int upperHeightRange = GenUtils.getHighestGround(data, x, z) - minDepthBelowSurface; + if (upperHeightRange > minDepth) { + upperHeightRange = minDepth; } + + upperHeightRange = Math.min(world.getBiomeBank(x, z).getHandler().getMaxHeightForCaves(world, x, z), + upperHeightRange + ); + + if (upperHeightRange < 14) { + return; + } + + // Elevate 14 units up. + int y = GenUtils.randInt(random, 14, upperHeightRange); + placeGeode(random.nextInt(9999), geodeRadius, new SimpleBlock(data, x, y, z)); } } } diff --git a/common/src/main/java/org/terraform/populators/AnimalPopulator.java b/common/src/main/java/org/terraform/populators/AnimalPopulator.java index 0ffbf70a..26d9e247 100644 --- a/common/src/main/java/org/terraform/populators/AnimalPopulator.java +++ b/common/src/main/java/org/terraform/populators/AnimalPopulator.java @@ -21,12 +21,21 @@ public class AnimalPopulator { private BiomeBank[] blacklistedBiomes; private boolean isAquatic = false; - public AnimalPopulator(EntityType animalType, int minNum, int maxNum, int chance, boolean useWhitelist, BiomeBank... biomes) { + public AnimalPopulator(EntityType animalType, + int minNum, + int maxNum, + int chance, + boolean useWhitelist, + BiomeBank... biomes) + { this.animalType = animalType; this.chance = chance; if (useWhitelist) { this.whitelistedBiomes = biomes; - } else this.blacklistedBiomes = biomes; + } + else { + this.blacklistedBiomes = biomes; + } this.minNum = minNum; this.maxNum = maxNum; @@ -39,19 +48,25 @@ public AnimalPopulator(EntityType animalType, int minNum, int maxNum, int chance public boolean canSpawn(@NotNull Random rand) { return TConfigOption.areAnimalsEnabled() && !GenUtils.chance(rand, 100 - chance, 100); } - + private boolean canSpawnInBiome(BiomeBank b) { - if (!TConfigOption.areAnimalsEnabled()) return false; + if (!TConfigOption.areAnimalsEnabled()) { + return false; + } - if (whitelistedBiomes != null) { + if (whitelistedBiomes != null) { for (BiomeBank entr : whitelistedBiomes) { - if (entr == b) return true; + if (entr == b) { + return true; + } } return false; } if (blacklistedBiomes != null) { for (BiomeBank entr : blacklistedBiomes) { - if (entr == b) return false; + if (entr == b) { + return false; + } } return true; } @@ -59,28 +74,36 @@ private boolean canSpawnInBiome(BiomeBank b) { } public void populate(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if (!TConfigOption.areAnimalsEnabled()) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } for (int i = 0; i < GenUtils.randInt(random, minNum, maxNum); i++) { int x = (data.getChunkX() << 4) + GenUtils.randInt(random, 5, 7); int z = (data.getChunkZ() << 4) + GenUtils.randInt(random, 5, 7); - + // To account for solid ground that spawns above the noisemap (i.e. boulders/black spikes) - int height = GenUtils.getHighestGround(data,x,z)+1;// HeightMap.getBlockHeight(world, x, z) + 2; - - if(canSpawnInBiome(world.getBiomeBank(x, z))) - if(!this.isAquatic && height > TerraformGenerator.seaLevel) { - if(!data.getType(x, height, z).isSolid()) // Don't spawn in blocks - data.addEntity(x, height, z, animalType); - }else if(this.isAquatic && height <= TerraformGenerator.seaLevel) { - if(data.getType(x, height, z) == Material.WATER) // Don't spawn in anything but water - data.addEntity(x, height, z, animalType); - } + int height = GenUtils.getHighestGround(data, x, z) + 1;// HeightMap.getBlockHeight(world, x, z) + 2; + + if (canSpawnInBiome(world.getBiomeBank(x, z))) { + if (!this.isAquatic && height > TerraformGenerator.seaLevel) { + if (!data.getType(x, height, z).isSolid()) // Don't spawn in blocks + { + data.addEntity(x, height, z, animalType); + } + } + else if (this.isAquatic && height <= TerraformGenerator.seaLevel) { + if (data.getType(x, height, z) == Material.WATER) // Don't spawn in anything but water + { + data.addEntity(x, height, z, animalType); + } + } + } } } - public @NotNull AnimalPopulator setAquatic(boolean aquatic) { - this.isAquatic = aquatic; - return this; - } + public @NotNull AnimalPopulator setAquatic(boolean aquatic) { + this.isAquatic = aquatic; + return this; + } } diff --git a/common/src/main/java/org/terraform/populators/OrePopulator.java b/common/src/main/java/org/terraform/populators/OrePopulator.java index befff6d1..28e2f114 100644 --- a/common/src/main/java/org/terraform/populators/OrePopulator.java +++ b/common/src/main/java/org/terraform/populators/OrePopulator.java @@ -25,35 +25,50 @@ public class OrePopulator { private final int maxNumberOfVeins; // Maximum number of veins per chunk private final int peakSpawnChanceHeight; // Optimal height for ore to spawn private final int maxSpawnHeight; // max y height where ore can be rarely found - private int minRange; // min spawn height private final BiomeBank[] requiredBiomes; private final int maxDistance; private final boolean ignorePeakSpawnChance; + private int minRange; // min spawn height - public OrePopulator(Material type, int baseChance, int maxOreSize, - int maxNumberOfVeins, int peakSpawnChanceHeight, int maxSpawnHeight, - boolean ignorePeakSpawnChance, BiomeBank... requiredBiomes) { + public OrePopulator(Material type, + int baseChance, + int maxOreSize, + int maxNumberOfVeins, + int peakSpawnChanceHeight, + int maxSpawnHeight, + boolean ignorePeakSpawnChance, + BiomeBank... requiredBiomes) + { this.type = type; this.baseChance = baseChance; this.maxOreSize = maxOreSize; - this.minOreSize = maxOreSize/2; + this.minOreSize = maxOreSize / 2; this.maxNumberOfVeins = maxNumberOfVeins; this.peakSpawnChanceHeight = peakSpawnChanceHeight; this.maxSpawnHeight = maxSpawnHeight; this.requiredBiomes = requiredBiomes; this.ignorePeakSpawnChance = ignorePeakSpawnChance; - this.minRange = TerraformGeneratorPlugin.injector.getMinY()+1; - this.maxDistance = Math.max(Math.abs(minRange - peakSpawnChanceHeight), Math.abs(maxSpawnHeight - peakSpawnChanceHeight)); + this.minRange = TerraformGeneratorPlugin.injector.getMinY() + 1; + this.maxDistance = Math.max( + Math.abs(minRange - peakSpawnChanceHeight), + Math.abs(maxSpawnHeight - peakSpawnChanceHeight) + ); } - public OrePopulator(Material type, int baseChance, int maxOreSize, - int maxNumberOfVeins, int minRange, int peakSpawnChanceHeight, - int maxSpawnHeight, boolean ignorePeakSpawnChance, - BiomeBank... requiredBiomes) { + public OrePopulator(Material type, + int baseChance, + int maxOreSize, + int maxNumberOfVeins, + int minRange, + int peakSpawnChanceHeight, + int maxSpawnHeight, + boolean ignorePeakSpawnChance, + BiomeBank... requiredBiomes) + { this.type = type; this.baseChance = baseChance; this.maxOreSize = maxOreSize; - this.minOreSize = maxOreSize/2; + this.minOreSize = maxOreSize / 2; this.maxNumberOfVeins = TConfigOption.FEATURE_ORES_ENABLED.getBoolean() ? maxNumberOfVeins : 0; this.minRange = minRange; this.peakSpawnChanceHeight = peakSpawnChanceHeight; @@ -61,77 +76,92 @@ public OrePopulator(Material type, int baseChance, int maxOreSize, this.requiredBiomes = requiredBiomes; this.ignorePeakSpawnChance = ignorePeakSpawnChance; // this.minRange = TerraformGeneratorPlugin.injector.getMinY()+1; - this.maxDistance = Math.max(Math.abs(minRange - peakSpawnChanceHeight), Math.abs(maxSpawnHeight - peakSpawnChanceHeight)); + this.maxDistance = Math.max( + Math.abs(minRange - peakSpawnChanceHeight), + Math.abs(maxSpawnHeight - peakSpawnChanceHeight) + ); } - + public void populate(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if(requiredBiomes.length > 0) { - BiomeBank b = BiomeBank.getBiomeSectionFromChunk(world, data.getChunkX(), data.getChunkZ()).getBiomeBank(); - boolean canPopulate = false; - for(BiomeBank comp:requiredBiomes) - if(comp == b) { + if (requiredBiomes.length > 0) { + BiomeBank b = BiomeBank.getBiomeSectionFromChunk(world, data.getChunkX(), data.getChunkZ()).getBiomeBank(); + boolean canPopulate = false; + for (BiomeBank comp : requiredBiomes) { + if (comp == b) { canPopulate = true; break; } - - if(!canPopulate) return; - } - - // Attempt maxNumberOfVeins number of times - for (int i = 0; i < this.maxNumberOfVeins; i++) { - - // Roll chance to spawn one ore - if (GenUtils.chance(random, this.baseChance, 100)) { - // RNG determined X Y and Z within chunk - int x = GenUtils.randInt(random, 0, 15) + data.getChunkX() * 16; - int z = GenUtils.randInt(random, 0, 15) + data.getChunkZ() * 16; - // int groundHeight = GenUtils.getHighestGround(data, x, z); - int range = maxSpawnHeight; - // Low chance for ores to spawn above max range - // if (GenUtils.chance(random, 1, 5)) range = maxSpawnHeight; - - // Ignore ground height and just spawn - // Range cannot be above ground - // if(range > groundHeight) range = groundHeight; - - // Spawn failed. - if(minRange > range) continue; - if(minRange < world.minY) minRange = world.minY; - - int y = GenUtils.randInt(random, minRange + 64, range + 64) - 64; // The 64 is to make sure no negative numbers are fed in. - - if(!ignorePeakSpawnChance) { - // Calculate chance based on spawnHeight and peakSpawnChanceHeight height. Max chance at peakSpawnChanceHeight. - int distance = Math.abs(y - peakSpawnChanceHeight); - - if(!GenUtils.chance((int) Math.round(100.0*(1.0 - ((float)distance)/((float)maxDistance))), 100)) { + } + + if (!canPopulate) { + return; + } + } + + // Attempt maxNumberOfVeins number of times + for (int i = 0; i < this.maxNumberOfVeins; i++) { + + // Roll chance to spawn one ore + if (GenUtils.chance(random, this.baseChance, 100)) { + // RNG determined X Y and Z within chunk + int x = GenUtils.randInt(random, 0, 15) + data.getChunkX() * 16; + int z = GenUtils.randInt(random, 0, 15) + data.getChunkZ() * 16; + // int groundHeight = GenUtils.getHighestGround(data, x, z); + int range = maxSpawnHeight; + // Low chance for ores to spawn above max range + // if (GenUtils.chance(random, 1, 5)) range = maxSpawnHeight; + + // Ignore ground height and just spawn + // Range cannot be above ground + // if(range > groundHeight) range = groundHeight; + + // Spawn failed. + if (minRange > range) { + continue; + } + if (minRange < world.minY) { + minRange = world.minY; + } + + int y = GenUtils.randInt(random, minRange + 64, range + 64) + - 64; // The 64 is to make sure no negative numbers are fed in. + + if (!ignorePeakSpawnChance) { + // Calculate chance based on spawnHeight and peakSpawnChanceHeight height. Max chance at peakSpawnChanceHeight. + int distance = Math.abs(y - peakSpawnChanceHeight); + + if (!GenUtils.chance( + (int) Math.round(100.0 * (1.0 - ((float) distance) / ((float) maxDistance))), + 100 + )) + { continue; - } - } - - // Generate ore with rough sphere size. - placeOre( - Objects.hash(world.getSeed(),x,y,z), - data, x, y, z); - - } - } + } + } + + // Generate ore with rough sphere size. + placeOre(Objects.hash(world.getSeed(), x, y, z), data, x, y, z); + + } + } } - + // Don't use simpleblock to forcefully compress memory usage and GC invocations by this. public void placeOre(int seed, @NotNull PopulatorDataAbstract data, int coreX, int coreY, int coreZ) { - double size = GenUtils.randDouble(new Random(seed), minOreSize, maxOreSize); - // Size is the volume of the sphere, so radius is: - double radius = Math.pow(((3.0/4.0)*size*(1.0/Math.PI)), 1.0/3.0); - - if (radius <= 0) return; + double size = GenUtils.randDouble(new Random(seed), minOreSize, maxOreSize); + // Size is the volume of the sphere, so radius is: + double radius = Math.pow(((3.0 / 4.0) * size * (1.0 / Math.PI)), 1.0 / 3.0); + + if (radius <= 0) { + return; + } if (radius <= 0.5) { // block.setReplaceType(ReplaceType.ALL); - data.setType(coreX,coreY,coreZ,GenUtils.randChoice(new Random(seed), type)); + data.setType(coreX, coreY, coreZ, GenUtils.randChoice(new Random(seed), type)); return; } - + FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); @@ -142,80 +172,79 @@ public void placeOre(int seed, @NotNull PopulatorDataAbstract data, int coreX, i int relX = (int) Math.round(x) + coreX; int relY = (int) Math.round(y) + coreY; int relZ = (int) Math.round(z) + coreZ; - if(relY > TerraformGeneratorPlugin.injector.getMaxY() - || relY <= TerraformGeneratorPlugin.injector.getMinY()) // do not touch bedrock layer + if (relY > TerraformGeneratorPlugin.injector.getMaxY() + || relY <= TerraformGeneratorPlugin.injector.getMinY()) // do not touch bedrock layer + { continue; - // SimpleBlock rel = block.getRelative((int)Math.round(x), (int)Math.round(y), (int)Math.round(z)); - double equationResult = Math.pow(x, 2) / Math.pow(radius,2) - + Math.pow(y, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - Material oreType = data.getType(relX,relY,relZ); + } + // SimpleBlock rel = block.getRelative((int)Math.round(x), (int)Math.round(y), (int)Math.round(z)); + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + + Math.pow(y, 2) / Math.pow(radius, 2) + + Math.pow(z, 2) / Math.pow(radius, 2); + Material oreType = data.getType(relX, relY, relZ); if (equationResult <= 1 + 0.7 * noise.GetNoise(relX, relY, relZ)) { if (oreType == Material.STONE) { - data.setType(relX,relY,relZ,type); + data.setType(relX, relY, relZ, type); } // 1.17 behaviour - else if(Version.isAtLeast(17)) - { - // Deepslate replacing other ores - if(type == Material.DEEPSLATE - && BlockUtils.ores.contains(oreType)) { - data.setType(relX,relY,relZ,BlockUtils.deepSlateVersion(oreType)); - } - // Normal ores replacing deepslate - else if(oreType == Material.DEEPSLATE) - { - data.setType(relX,relY,relZ,BlockUtils.deepSlateVersion(type)); - } - } - + else if (Version.isAtLeast(17)) { + // Deepslate replacing other ores + if (type == Material.DEEPSLATE && BlockUtils.ores.contains(oreType)) { + data.setType(relX, relY, relZ, BlockUtils.deepSlateVersion(oreType)); + } + // Normal ores replacing deepslate + else if (oreType == Material.DEEPSLATE) { + data.setType(relX, relY, relZ, BlockUtils.deepSlateVersion(type)); + } + } + } } } } } - public Material getType() { - return type; - } + public Material getType() { + return type; + } - public int getBaseChance() { - return baseChance; - } + public int getBaseChance() { + return baseChance; + } - public int getMaxOreSize() { - return maxOreSize; - } + public int getMaxOreSize() { + return maxOreSize; + } - public int getMinOreSize() { - return minOreSize; - } + public int getMinOreSize() { + return minOreSize; + } - public int getMaxNumberOfVeins() { - return maxNumberOfVeins; - } + public int getMaxNumberOfVeins() { + return maxNumberOfVeins; + } - public int getPeakSpawnChanceHeight() { - return peakSpawnChanceHeight; - } + public int getPeakSpawnChanceHeight() { + return peakSpawnChanceHeight; + } - public int getMaxSpawnHeight() { - return maxSpawnHeight; - } + public int getMaxSpawnHeight() { + return maxSpawnHeight; + } - public int getMinRange() { - return minRange; - } + public int getMinRange() { + return minRange; + } - public BiomeBank[] getRequiredBiomes() { - return requiredBiomes; - } + public BiomeBank[] getRequiredBiomes() { + return requiredBiomes; + } - public int getMaxDistance() { - return maxDistance; - } + public int getMaxDistance() { + return maxDistance; + } - public boolean isIgnorePeakSpawnChance() { - return ignorePeakSpawnChance; - } + public boolean isIgnorePeakSpawnChance() { + return ignorePeakSpawnChance; + } } diff --git a/common/src/main/java/org/terraform/reflection/Post14PrivateFieldHandler.java b/common/src/main/java/org/terraform/reflection/Post14PrivateFieldHandler.java index 06715eef..efeca4cb 100644 --- a/common/src/main/java/org/terraform/reflection/Post14PrivateFieldHandler.java +++ b/common/src/main/java/org/terraform/reflection/Post14PrivateFieldHandler.java @@ -23,10 +23,23 @@ public class Post14PrivateFieldHandler extends PrivateFieldHandler { try { Class varHandle = Class.forName("java.lang.invoke.VarHandle"); - lookup = publicLookup.findStatic(MethodHandles.class, "privateLookupIn", MethodType.methodType(MethodHandles.Lookup.class, Class.class, Lookup.class)); - findVarHandle = publicLookup.findVirtual(MethodHandles.Lookup.class, "findVarHandle", MethodType.methodType(varHandle, Class.class, String.class, Class.class)); - varHandleSet = publicLookup.findVirtual(varHandle, "set", MethodType.methodType(void.class, Object[].class)); - } catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { + lookup = publicLookup.findStatic( + MethodHandles.class, + "privateLookupIn", + MethodType.methodType(MethodHandles.Lookup.class, Class.class, Lookup.class) + ); + findVarHandle = publicLookup.findVirtual( + MethodHandles.Lookup.class, + "findVarHandle", + MethodType.methodType(varHandle, Class.class, String.class, Class.class) + ); + varHandleSet = publicLookup.findVirtual( + varHandle, + "set", + MethodType.methodType(void.class, Object[].class) + ); + } + catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } @@ -44,28 +57,32 @@ public void injectField(@NotNull Object obj, @NotNull String field, Object value try { Object lookup = LOOKUP.invoke(null, Field.class, MethodHandles.lookup()); Object varHandleModifiers = FIND_VAR_HANDLE.invoke(lookup, Field.class, "modifiers", int.class); - VAR_HANDLE_SET.invoke(varHandleModifiers, new Object[]{targetField, mds & ~Modifier.FINAL}); - } catch (Throwable throwable) { - // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(throwable); + VAR_HANDLE_SET.invoke(varHandleModifiers, new Object[] {targetField, mds & ~Modifier.FINAL}); + } + catch (Throwable throwable) { + // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(throwable); TerraformGeneratorPlugin.logger.info("Java 14+ detected."); } targetField.set(obj, value); } - + @Override - public void injectField(Object obj, @NotNull Field targetField, Object value) throws IllegalArgumentException, IllegalAccessException { - targetField.setAccessible(true); - int mds = targetField.getModifiers(); - - try { - Object lookup = LOOKUP.invoke(null, Field.class, MethodHandles.lookup()); - Object varHandleModifiers = FIND_VAR_HANDLE.invoke(lookup, Field.class, "modifiers", int.class); - VAR_HANDLE_SET.invoke(varHandleModifiers, new Object[]{targetField, mds & ~Modifier.FINAL}); - } catch (Throwable throwable) { - // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(throwable); - TerraformGeneratorPlugin.logger.info("Java 14+ detected."); - } - targetField.set(obj, value); + public void injectField(Object obj, @NotNull Field targetField, Object value) + throws IllegalArgumentException, IllegalAccessException + { + targetField.setAccessible(true); + int mds = targetField.getModifiers(); + + try { + Object lookup = LOOKUP.invoke(null, Field.class, MethodHandles.lookup()); + Object varHandleModifiers = FIND_VAR_HANDLE.invoke(lookup, Field.class, "modifiers", int.class); + VAR_HANDLE_SET.invoke(varHandleModifiers, new Object[] {targetField, mds & ~Modifier.FINAL}); + } + catch (Throwable throwable) { + // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(throwable); + TerraformGeneratorPlugin.logger.info("Java 14+ detected."); + } + targetField.set(obj, value); } } diff --git a/common/src/main/java/org/terraform/reflection/Pre14PrivateFieldHandler.java b/common/src/main/java/org/terraform/reflection/Pre14PrivateFieldHandler.java index 04905378..5d0ddf34 100644 --- a/common/src/main/java/org/terraform/reflection/Pre14PrivateFieldHandler.java +++ b/common/src/main/java/org/terraform/reflection/Pre14PrivateFieldHandler.java @@ -20,7 +20,8 @@ public class Pre14PrivateFieldHandler extends PrivateFieldHandler { Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); fieldModifiers = lookup.unreflectSetter(modifiersField); - } catch (NoSuchFieldException | IllegalAccessException e) { + } + catch (NoSuchFieldException | IllegalAccessException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } diff --git a/common/src/main/java/org/terraform/reflection/PrivateFieldHandler.java b/common/src/main/java/org/terraform/reflection/PrivateFieldHandler.java index 27a3a9eb..41a9a533 100644 --- a/common/src/main/java/org/terraform/reflection/PrivateFieldHandler.java +++ b/common/src/main/java/org/terraform/reflection/PrivateFieldHandler.java @@ -4,9 +4,11 @@ public abstract class PrivateFieldHandler { public abstract void injectField(Object obj, String field, Object value) throws Throwable; - - - public void injectField(Object obj, Field target, Object value) throws IllegalArgumentException, IllegalAccessException { - throw new UnsupportedOperationException(); + + + public void injectField(Object obj, Field target, Object value) + throws IllegalArgumentException, IllegalAccessException + { + throw new UnsupportedOperationException(); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/schematic/SchematicListener.java b/common/src/main/java/org/terraform/schematic/SchematicListener.java index 5fe5a632..558eb8e9 100644 --- a/common/src/main/java/org/terraform/schematic/SchematicListener.java +++ b/common/src/main/java/org/terraform/schematic/SchematicListener.java @@ -28,17 +28,25 @@ public class SchematicListener implements Listener { add(ChatColor.RED + "-=[Developer's Tool]=-"); }}); wand.setItemMeta(meta); - + return wand; } @EventHandler public void onBlockClick(@NotNull PlayerInteractEvent event) { - if (event.getHand() == EquipmentSlot.OFF_HAND) return; - if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; + if (event.getHand() == EquipmentSlot.OFF_HAND) { + return; + } + if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) { + return; + } ItemStack item = event.getPlayer().getEquipment().getItemInMainHand(); - if (!item.hasItemMeta()) return; - if (!item.getItemMeta().getDisplayName().equals(WAND_NAME)) return; + if (!item.hasItemMeta()) { + return; + } + if (!item.getItemMeta().getDisplayName().equals(WAND_NAME)) { + return; + } event.setCancelled(true); Player player = event.getPlayer(); @@ -47,7 +55,8 @@ public void onBlockClick(@NotNull PlayerInteractEvent event) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) { terraRg.setOne(event.getClickedBlock()); player.sendMessage(ChatColor.GREEN + "Position one set."); - } else { + } + else { terraRg.setTwo(event.getClickedBlock()); player.sendMessage(ChatColor.GREEN + "Position two set."); } diff --git a/common/src/main/java/org/terraform/schematic/SchematicParser.java b/common/src/main/java/org/terraform/schematic/SchematicParser.java index b41bea40..c68d3a0c 100644 --- a/common/src/main/java/org/terraform/schematic/SchematicParser.java +++ b/common/src/main/java/org/terraform/schematic/SchematicParser.java @@ -1,47 +1,47 @@ package org.terraform.schematic; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map.Entry; - import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.jetbrains.annotations.NotNull; import org.terraform.data.SimpleBlock; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map.Entry; + public class SchematicParser { - - private boolean isDelayedApply = false; - private final HashMap delayed = new HashMap<>(); - private static final EnumSet fragile = EnumSet.of( - Material.BROWN_MUSHROOM, - Material.RED_MUSHROOM, - Material.BROWN_CARPET, - Material.RED_CARPET, - Material.WHITE_CARPET, - Material.SOUL_FIRE, - Material.REDSTONE_WIRE, - Material.REDSTONE_TORCH, - Material.REPEATER, - Material.RAIL, - Material.LEVER, - Material.POTATOES, - Material.KELP - ); - + + private static final EnumSet fragile = EnumSet.of( + Material.BROWN_MUSHROOM, + Material.RED_MUSHROOM, + Material.BROWN_CARPET, + Material.RED_CARPET, + Material.WHITE_CARPET, + Material.SOUL_FIRE, + Material.REDSTONE_WIRE, + Material.REDSTONE_TORCH, + Material.REPEATER, + Material.RAIL, + Material.LEVER, + Material.POTATOES, + Material.KELP + ); + private final HashMap delayed = new HashMap<>(); + private boolean isDelayedApply = false; + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if(isDelayedApply || !fragile.contains(data.getMaterial())) - block.setBlockData(data); - else - { - delayed.put(block, data); - } + if (isDelayedApply || !fragile.contains(data.getMaterial())) { + block.setBlockData(data); + } + else { + delayed.put(block, data); + } } - + public void applyDelayedData() { - isDelayedApply = true; - for(Entry entry:delayed.entrySet()) { - applyData(entry.getKey(), entry.getValue()); - } + isDelayedApply = true; + for (Entry entry : delayed.entrySet()) { + applyData(entry.getKey(), entry.getValue()); + } } } diff --git a/common/src/main/java/org/terraform/schematic/TerraSchematic.java b/common/src/main/java/org/terraform/schematic/TerraSchematic.java index 32eab5c6..62ae4585 100644 --- a/common/src/main/java/org/terraform/schematic/TerraSchematic.java +++ b/common/src/main/java/org/terraform/schematic/TerraSchematic.java @@ -6,11 +6,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Directional; -import org.bukkit.block.data.MultipleFacing; -import org.bukkit.block.data.Orientable; -import org.bukkit.block.data.Rotatable; +import org.bukkit.block.data.*; import org.bukkit.block.data.type.RedstoneWire; import org.bukkit.block.data.type.RedstoneWire.Connection; import org.bukkit.util.Vector; @@ -22,27 +18,19 @@ import org.terraform.utils.BlockUtils; import org.terraform.utils.version.Version; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; +import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import java.util.Scanner; public class TerraSchematic { - public static final String SCHEMATIC_FOLDER = File.separator + "schematic"; - public static final @NotNull HashMap> cache = new HashMap<>(); - + public static final String SCHEMATIC_FOLDER = File.separator + "schematic"; + public static final @NotNull HashMap> cache = new HashMap<>(); + final SimpleBlock refPoint; private final @NotNull File schematicFolder; public @NotNull SchematicParser parser = new SchematicParser(); HashMap data = new HashMap<>(); - final SimpleBlock refPoint; BlockFace face = BlockFace.NORTH; private double VERSION_VALUE; @@ -57,36 +45,29 @@ public TerraSchematic(@NotNull Location loc) { this.schematicFolder = new File(TerraformGeneratorPlugin.get().getDataFolder(), SCHEMATIC_FOLDER); this.refPoint = new SimpleBlock(loc); } - - public @NotNull TerraSchematic clone(SimpleBlock refPoint) { - TerraSchematic clone = new TerraSchematic(refPoint); - clone.data = new HashMap<>(); - clone.data.putAll(data); - clone.VERSION_VALUE = VERSION_VALUE; - return clone; - } public static @NotNull TerraSchematic load(String internalPath, SimpleBlock refPoint) throws FileNotFoundException { - // A new object gets created from here. If the path is in the cache, - // this object is NOT the one that gets returned. Instead, a clone is - // returned, with a new hashmap copy and a (broken) version number. - TerraSchematic schem = new TerraSchematic(refPoint); - if(cache.containsKey(internalPath)) { - schem.data = cache.get(internalPath); - return schem.clone(refPoint); + // A new object gets created from here. If the path is in the cache, + // this object is NOT the one that gets returned. Instead, a clone is + // returned, with a new hashmap copy and a (broken) version number. + TerraSchematic schem = new TerraSchematic(refPoint); + if (cache.containsKey(internalPath)) { + schem.data = cache.get(internalPath); + return schem.clone(refPoint); } boolean wasInDataFolder = false; InputStream is = TerraformGeneratorPlugin.get().getClass().getResourceAsStream("/" + internalPath + ".terra"); - if(is == null) { + if (is == null) { // Try to lookup in the schematics folder final File schematicFolder = new File(TerraformGeneratorPlugin.get().getDataFolder(), SCHEMATIC_FOLDER); final File schematicFile = new File(schematicFolder, internalPath + ".terra"); - try{ - if(!schematicFile.getCanonicalPath().startsWith(schematicFolder.getCanonicalPath())) + try { + if (!schematicFile.getCanonicalPath().startsWith(schematicFolder.getCanonicalPath())) { throw new IllegalArgumentException("Schematic name contained illegal characters (i.e. periods)"); + } } - catch(Exception e){ + catch (Exception e) { throw new IllegalArgumentException("Schematic name contained illegal characters (i.e. periods)"); } is = new FileInputStream(schematicFile); @@ -97,10 +78,12 @@ public TerraSchematic(@NotNull Location loc) { String line = sc.nextLine(); // First line is the schematic's version. schem.VERSION_VALUE = Double.parseDouble(line); - + while (sc.hasNextLine()) { line = sc.nextLine(); - if (line.isEmpty()) continue; + if (line.isEmpty()) { + continue; + } String[] cont = line.split(":@:"); String[] v = cont[0].split(","); Vector key = new Vector(Integer.parseInt(v[0]), Integer.parseInt(v[1]), Integer.parseInt(v[2])); @@ -108,12 +91,14 @@ public TerraSchematic(@NotNull Location loc) { try { value = Bukkit.createBlockData(cont[1]); // TerraformGeneratorPlugin.logger.info("loaded: " + value.getAsString()); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { BlockDataFixerAbstract fixer = TerraformGeneratorPlugin.injector.getBlockDataFixer(); if (fixer != null) { - value = Bukkit.createBlockData(fixer.updateSchematic(schem.getVersionValue(),cont[1])); - - } else { + value = Bukkit.createBlockData(fixer.updateSchematic(schem.getVersionValue(), cont[1])); + + } + else { // GG throw e; } @@ -121,13 +106,22 @@ public TerraSchematic(@NotNull Location loc) { schem.data.put(key, value); } sc.close(); - + // Cache all small schematics that are not in the data folder - if(schem.data.size() < 100 && !wasInDataFolder) - cache.put(internalPath, schem.data); + if (schem.data.size() < 100 && !wasInDataFolder) { + cache.put(internalPath, schem.data); + } return schem; } + public @NotNull TerraSchematic clone(SimpleBlock refPoint) { + TerraSchematic clone = new TerraSchematic(refPoint); + clone.data = new HashMap<>(); + clone.data.putAll(data); + clone.VERSION_VALUE = VERSION_VALUE; + return clone; + } + public void registerBlock(@NotNull Block b) { Vector rel = b.getLocation().toVector().subtract(refPoint.toVector()); // String coords = rel.getBlockX() + "," + rel.getBlockY() + "," + rel.getBlockZ(); @@ -137,7 +131,7 @@ public void registerBlock(@NotNull Block b) { public void apply() { BlockDataFixerAbstract bdfa = TerraformGeneratorPlugin.injector.getBlockDataFixer(); ArrayList multiFace = new ArrayList<>(); - + for (Entry entry : data.entrySet()) { Vector pos = entry.getKey().clone(); BlockData bd = entry.getValue().clone(); @@ -145,10 +139,12 @@ public void apply() { int x = pos.getBlockX(); pos.setX(pos.getZ()); pos.setZ(x * -1); - } else if (face == BlockFace.SOUTH) { + } + else if (face == BlockFace.SOUTH) { pos.setX(pos.getX() * -1); pos.setZ(pos.getZ() * -1); - } else if (face == BlockFace.EAST) { + } + else if (face == BlockFace.EAST) { int x = pos.getBlockX(); pos.setX(pos.getZ() * -1); pos.setZ(x); @@ -159,75 +155,88 @@ public void apply() { if (face == BlockFace.EAST || face == BlockFace.WEST) { if (o.getAxis() == Axis.X) { o.setAxis(Axis.Z); - } else if (o.getAxis() == Axis.Z) { + } + else if (o.getAxis() == Axis.Z) { o.setAxis(Axis.X); } } - } else if (bd instanceof Rotatable r) { + } + else if (bd instanceof Rotatable r) { if (face == BlockFace.SOUTH) { r.setRotation(r.getRotation().getOppositeFace()); - } else if (face == BlockFace.EAST) { + } + else if (face == BlockFace.EAST) { r.setRotation(BlockUtils.getAdjacentFaces(r.getRotation())[0]); - } else if (face == BlockFace.WEST) { + } + else if (face == BlockFace.WEST) { r.setRotation(BlockUtils.getAdjacentFaces(r.getRotation())[1]); } - } + } else if (bd instanceof Directional r) { - if (BlockUtils.isDirectBlockFace(r.getFacing())) + if (BlockUtils.isDirectBlockFace(r.getFacing())) { if (face == BlockFace.SOUTH) { - // South means flip it to opposite face - // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + r.getFacing().getOppositeFace()); + // South means flip it to opposite face + // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + r.getFacing().getOppositeFace()); r.setFacing(r.getFacing().getOppositeFace()); - } else if (face == BlockFace.WEST) { - // Turn left - // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + BlockUtils.getAdjacentFaces(r.getFacing())[1]); + } + else if (face == BlockFace.WEST) { + // Turn left + // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + BlockUtils.getAdjacentFaces(r.getFacing())[1]); r.setFacing(BlockUtils.getAdjacentFaces(r.getFacing())[1]); - } else if (face == BlockFace.EAST) { - // Turn right - // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + BlockUtils.getAdjacentFaces(r.getFacing())[0]); + } + else if (face == BlockFace.EAST) { + // Turn right + // TerraformGeneratorPlugin.logger.info(r.getMaterial() + ":" + r.getFacing() + " ->" + BlockUtils.getAdjacentFaces(r.getFacing())[0]); r.setFacing(BlockUtils.getAdjacentFaces(r.getFacing())[0]); } - } + } + } else if (bd instanceof MultipleFacing) { multiFace.add(pos); } else if (bd instanceof RedstoneWire w) { RedstoneWire newData = (RedstoneWire) Bukkit.createBlockData(Material.REDSTONE_WIRE); - newData.setPower(w.getPower()); - for(BlockFace wireFace:w.getAllowedFaces()) - { - if(w.getFace(wireFace) == Connection.NONE) continue; - - if (this.face == BlockFace.SOUTH) { - // South means flip it to opposite face - newData.setFace(wireFace.getOppositeFace(), w.getFace(wireFace)); - } else if (this.face == BlockFace.WEST) { - // Turn left - newData.setFace(BlockUtils.getAdjacentFaces(wireFace)[1], w.getFace(wireFace)); - } else if (this.face == BlockFace.EAST) { - // Turn right - newData.setFace(BlockUtils.getAdjacentFaces(wireFace)[0], w.getFace(wireFace)); + newData.setPower(w.getPower()); + for (BlockFace wireFace : w.getAllowedFaces()) { + if (w.getFace(wireFace) == Connection.NONE) { + continue; + } + + if (this.face == BlockFace.SOUTH) { + // South means flip it to opposite face + newData.setFace(wireFace.getOppositeFace(), w.getFace(wireFace)); } - else - newData.setFace(wireFace, w.getFace(wireFace)); - } - bd = newData; + else if (this.face == BlockFace.WEST) { + // Turn left + newData.setFace(BlockUtils.getAdjacentFaces(wireFace)[1], w.getFace(wireFace)); + } + else if (this.face == BlockFace.EAST) { + // Turn right + newData.setFace(BlockUtils.getAdjacentFaces(wireFace)[0], w.getFace(wireFace)); + } + else { + newData.setFace(wireFace, w.getFace(wireFace)); + } + } + bd = newData; } // Apply version-specific updates - if (bdfa != null) + if (bdfa != null) { bdfa.correctFacing(pos, null, bd, face); + } } parser.applyData(refPoint.getRelative(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), bd); } - + parser.applyDelayedData(); // Multiple-facing blocks are just gonna be painful. for (Vector pos : multiFace) { SimpleBlock b = refPoint.getRelative(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); - if(b.getBlockData() instanceof MultipleFacing) - BlockUtils.correctSurroundingMultifacingData(b); + if (b.getBlockData() instanceof MultipleFacing) { + BlockUtils.correctSurroundingMultifacingData(b); + } } if (bdfa != null && face != BlockFace.NORTH) { for (Vector pos : bdfa.flush()) { @@ -239,29 +248,31 @@ else if (bd instanceof RedstoneWire w) { public void export(@NotNull String path) throws IOException { // Validate it again. - String validation = new FilenameArgument("schem-name", false).validate(null,path); - if(!validation.isEmpty()) + String validation = new FilenameArgument("schem-name", false).validate(null, path); + if (!validation.isEmpty()) { throw new IOException(validation); + } File outputFile = new File(schematicFolder, path); - if(!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } - if(!outputFile.exists()) { + if (!outputFile.exists()) { outputFile.createNewFile(); } FileOutputStream outputStream = new FileOutputStream(outputFile); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream)); - + // Append version header - bufferedWriter.write(Version.DOUBLE+""); + bufferedWriter.write(Version.DOUBLE + ""); bufferedWriter.newLine(); - + for (Entry entry : data.entrySet()) { - String vector = entry.getKey().getBlockX() + "," + entry.getKey().getBlockY() + ',' + entry.getKey().getBlockZ(); + String vector = entry.getKey().getBlockX() + "," + entry.getKey().getBlockY() + ',' + entry.getKey() + .getBlockZ(); bufferedWriter.write(vector + ":@:" + entry.getValue().getAsString()); bufferedWriter.newLine(); } @@ -287,8 +298,8 @@ public void setFace(BlockFace face) { * This doesn't appear to be used at all * lmao. */ - public double getVersionValue() { - return VERSION_VALUE; - } + public double getVersionValue() { + return VERSION_VALUE; + } } diff --git a/common/src/main/java/org/terraform/small_items/DecorationsBuilder.java b/common/src/main/java/org/terraform/small_items/DecorationsBuilder.java index 9398105d..d0c2154d 100644 --- a/common/src/main/java/org/terraform/small_items/DecorationsBuilder.java +++ b/common/src/main/java/org/terraform/small_items/DecorationsBuilder.java @@ -33,18 +33,6 @@ public enum DecorationsBuilder { this.material = material; } - public void build(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - data.setType(x, y, z, material); - } - - /* public void build(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, int minHeight, int maxHeight) { - BlockUtils.spawnPillar(rand, data, x, y, z, material, minHeight, maxHeight); - } - */ - public void build(@NotNull SimpleBlock block) { - build(block.getPopData(), block.getX(), block.getY(), block.getZ()); - } - /* public void build(@NotNull SimpleBlock block, @NotNull Random rand, int minHeight, int maxHeight) { int height = GenUtils.randInt(rand, minHeight, maxHeight); @@ -60,8 +48,25 @@ public static void build(@NotNull Random rand, @NotNull PopulatorDataAbstract da randChoice(rand, options).build(data, x, y, z); } */ - public static void build(@NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull DecorationsBuilder... options) { + public static void build(@NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull DecorationsBuilder... options) + { randChoice(options).build(data, x, y, z); } + public void build(@NotNull PopulatorDataAbstract data, int x, int y, int z) { + data.setType(x, y, z, material); + } + + /* public void build(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, int minHeight, int maxHeight) { + BlockUtils.spawnPillar(rand, data, x, y, z, material, minHeight, maxHeight); + } + */ + public void build(@NotNull SimpleBlock block) { + build(block.getPopData(), block.getX(), block.getY(), block.getZ()); + } + } diff --git a/common/src/main/java/org/terraform/small_items/PlantBuilder.java b/common/src/main/java/org/terraform/small_items/PlantBuilder.java index 9f4a3bca..2319f57e 100644 --- a/common/src/main/java/org/terraform/small_items/PlantBuilder.java +++ b/common/src/main/java/org/terraform/small_items/PlantBuilder.java @@ -84,18 +84,53 @@ public enum PlantBuilder { this(material, false); } + public static void build(@NotNull SimpleBlock block, @NotNull PlantBuilder... options) { + randChoice(options).build(block.getPopData(), block.getX(), block.getY(), block.getZ()); + } + + public static void build(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull PlantBuilder... options) + { + randChoice(rand, options).build(data, x, y, z); + } + + public static void build(@NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull PlantBuilder... options) + { + randChoice(options).build(data, x, y, z); + } + public void build(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if ( !TConfigOption.arePlantsEnabled() ) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } - if(isDoublePlant) { + if (isDoublePlant) { BlockUtils.setDoublePlant(data, x, y, z, material); - } else { + } + else { data.setType(x, y, z, material); } } - public void build(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, int minHeight, int maxHeight) { - if ( !TConfigOption.arePlantsEnabled() ) return; + public void build(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int minHeight, + int maxHeight) + { + if (!TConfigOption.arePlantsEnabled()) { + return; + } BlockUtils.spawnPillar(rand, data, x, y, z, material, minHeight, maxHeight); } @@ -105,21 +140,13 @@ public void build(@NotNull SimpleBlock block) { } public void build(@NotNull SimpleBlock block, @NotNull Random rand, int minHeight, int maxHeight) { - if ( !TConfigOption.arePlantsEnabled() ) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } int height = GenUtils.randInt(rand, minHeight, maxHeight); - for(int i = 0; i < height; i++) block.getRelative(0, i, 0).setType(material); - } - - public static void build(@NotNull SimpleBlock block, @NotNull PlantBuilder... options) { - randChoice(options).build(block.getPopData(), block.getX(), block.getY(), block.getZ()); - } - - public static void build(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull PlantBuilder... options) { - randChoice(rand, options).build(data, x, y, z); - } - - public static void build(@NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull PlantBuilder... options) { - randChoice(options).build(data, x, y, z); + for (int i = 0; i < height; i++) { + block.getRelative(0, i, 0).setType(material); + } } } diff --git a/common/src/main/java/org/terraform/structure/JigsawState.java b/common/src/main/java/org/terraform/structure/JigsawState.java index b57b5d85..18fe669e 100644 --- a/common/src/main/java/org/terraform/structure/JigsawState.java +++ b/common/src/main/java/org/terraform/structure/JigsawState.java @@ -23,30 +23,26 @@ public class JigsawState { /** * Called to check if chunkX,chunkZ will contain a piece */ - public boolean isInRange(int chunkX, int chunkZ){ - if(!calculatedRange) - { + public boolean isInRange(int chunkX, int chunkZ) { + if (!calculatedRange) { calculatedRange = true; - roomPopulatorStates.forEach((gen)->{ - gen.getRooms().forEach((room)->{ + roomPopulatorStates.forEach((gen) -> { + gen.getRooms().forEach((room) -> { int[] lowerCorner = room.getLowerCorner(); int[] upperCorner = room.getUpperCorner(); - minChunkX = Math.min(minChunkX, lowerCorner[0]>>4); - maxChunkX = Math.max(maxChunkX, upperCorner[0]>>4); - minChunkZ = Math.min(minChunkZ, lowerCorner[1]>>4); - maxChunkZ = Math.max(maxChunkZ, upperCorner[1]>>4); + minChunkX = Math.min(minChunkX, lowerCorner[0] >> 4); + maxChunkX = Math.max(maxChunkX, upperCorner[0] >> 4); + minChunkZ = Math.min(minChunkZ, lowerCorner[1] >> 4); + maxChunkZ = Math.max(maxChunkZ, upperCorner[1] >> 4); }); - minChunkX = Math.min(minChunkX, (gen.getCentX()-gen.getRange())>>4); - maxChunkX = Math.max(maxChunkX, (gen.getCentX()+gen.getRange())>>4); - minChunkZ = Math.min(minChunkZ, (gen.getCentZ()-gen.getRange())>>4); - maxChunkZ = Math.max(maxChunkZ, (gen.getCentZ()+gen.getRange())>>4); + minChunkX = Math.min(minChunkX, (gen.getCentX() - gen.getRange()) >> 4); + maxChunkX = Math.max(maxChunkX, (gen.getCentX() + gen.getRange()) >> 4); + minChunkZ = Math.min(minChunkZ, (gen.getCentZ() - gen.getRange()) >> 4); + maxChunkZ = Math.max(maxChunkZ, (gen.getCentZ() + gen.getRange()) >> 4); }); } - return chunkX >= minChunkX - && chunkX <= maxChunkX - && chunkZ >= minChunkZ - && chunkZ <= maxChunkZ; + return chunkX >= minChunkX && chunkX <= maxChunkX && chunkZ >= minChunkZ && chunkZ <= maxChunkZ; } } diff --git a/common/src/main/java/org/terraform/structure/JigsawStructurePopulator.java b/common/src/main/java/org/terraform/structure/JigsawStructurePopulator.java index c282c7d6..af5b60fc 100644 --- a/common/src/main/java/org/terraform/structure/JigsawStructurePopulator.java +++ b/common/src/main/java/org/terraform/structure/JigsawStructurePopulator.java @@ -13,7 +13,7 @@ * The large rooms that exceed 3x3 chunks MUST use the old block populator and * they WILL go last no matter what */ -public abstract class JigsawStructurePopulator extends SingleMegaChunkStructurePopulator{ +public abstract class JigsawStructurePopulator extends SingleMegaChunkStructurePopulator { /** * @return the JigsawState for the structure. This will be used in diff --git a/common/src/main/java/org/terraform/structure/MultiMegaChunkStructurePopulator.java b/common/src/main/java/org/terraform/structure/MultiMegaChunkStructurePopulator.java index 596165ca..d9a541ac 100644 --- a/common/src/main/java/org/terraform/structure/MultiMegaChunkStructurePopulator.java +++ b/common/src/main/java/org/terraform/structure/MultiMegaChunkStructurePopulator.java @@ -8,10 +8,10 @@ * including things like small dungeons and shipwrecks. */ public abstract class MultiMegaChunkStructurePopulator extends StructurePopulator { - - public abstract boolean canSpawn(TerraformWorld tw, int chunkX, int chunkZ); - - public abstract int[][] getCoordsFromMegaChunk(TerraformWorld tw, MegaChunk mc); + + public abstract boolean canSpawn(TerraformWorld tw, int chunkX, int chunkZ); + + public abstract int[][] getCoordsFromMegaChunk(TerraformWorld tw, MegaChunk mc); public abstract int[] getNearestFeature(TerraformWorld world, int rawX, int rawZ); } diff --git a/common/src/main/java/org/terraform/structure/SingleMegaChunkStructurePopulator.java b/common/src/main/java/org/terraform/structure/SingleMegaChunkStructurePopulator.java index c36628b3..17828929 100644 --- a/common/src/main/java/org/terraform/structure/SingleMegaChunkStructurePopulator.java +++ b/common/src/main/java/org/terraform/structure/SingleMegaChunkStructurePopulator.java @@ -5,21 +5,21 @@ /** * Represents larger structures that will only spawn once per megachunk. - * This will ALWAYS spawn structures in the center of the mega chunk, and + * This will ALWAYS spawn structures in the center of the mega chunk, and * query the biome type from the center coord's biomesection. *

    * SingleMegaChunkStructures CANNOT overlap. */ public abstract class SingleMegaChunkStructurePopulator extends StructurePopulator { - /** - * Do special checks here, including biome white/blacklisting and coordinate - * calculations. Also check for config spawnrates here. - *
    - * THIS METHOD IS NO LONGER USED TO CHECK IF THE STRUCTURE WILL SPAWN IN THE - * SPECIFIED CHUNK COORDS. THIS MUST BE HANDLED SEPARATELY. - */ - public abstract boolean canSpawn(TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome); + /** + * Do special checks here, including biome white/blacklisting and coordinate + * calculations. Also check for config spawnrates here. + *
    + * THIS METHOD IS NO LONGER USED TO CHECK IF THE STRUCTURE WILL SPAWN IN THE + * SPECIFIED CHUNK COORDS. THIS MUST BE HANDLED SEPARATELY. + */ + public abstract boolean canSpawn(TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome); + - } diff --git a/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java b/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java index 9ffb9ae0..552ce5d9 100644 --- a/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java +++ b/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java @@ -8,42 +8,48 @@ import org.terraform.main.config.TConfigOption; public class StructureBufferDistanceHandler { - - /** - * Called from decorators to determine whether or not they - * can place large trees and obstructive decorations, or if - * they must make way for structures. - */ - public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + + /** + * Called from decorators to determine whether or not they + * can place large trees and obstructive decorations, or if + * they must make way for structures. + */ + public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { // Within radius - if(Math.pow(chunkX*16,2) + Math.pow(chunkZ*16,2) < HeightMap.spawnFlatRadiusSquared) + if (Math.pow(chunkX * 16, 2) + Math.pow(chunkZ * 16, 2) < HeightMap.spawnFlatRadiusSquared) { return false; + } - MegaChunk mc = new MegaChunk(chunkX, chunkZ); - BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); + MegaChunk mc = new MegaChunk(chunkX, chunkZ); + BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); for (StructurePopulator structPop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { - if (structPop == null) continue; - - if(!(structPop instanceof SingleMegaChunkStructurePopulator spop)) continue; + if (structPop == null) { + continue; + } + + if (!(structPop instanceof SingleMegaChunkStructurePopulator spop)) { + continue; + } int chunkBufferRadius = spop.getChunkBufferDistance(); - if(chunkBufferRadius <= 0) - continue; + if (chunkBufferRadius <= 0) { + continue; + } // No need to account for strongholds, which have a different way of // checking spawn locations. - + // Grab the center chunk, where the structure will spawn - int[] chunkCoords = mc.getCenterBiomeSectionChunkCoords(); + int[] chunkCoords = mc.getCenterBiomeSectionChunkCoords(); if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { - // If the structure will spawn, calculate distance to it. - int dist = (int) (Math.pow(chunkCoords[0] - chunkX,2) + Math.pow(chunkCoords[1] - chunkZ,2)); - if(Math.sqrt(dist) <= chunkBufferRadius) { - return false; - } + // If the structure will spawn, calculate distance to it. + int dist = (int) (Math.pow(chunkCoords[0] - chunkX, 2) + Math.pow(chunkCoords[1] - chunkZ, 2)); + if (Math.sqrt(dist) <= chunkBufferRadius) { + return false; + } } } - + return true; - } + } } diff --git a/common/src/main/java/org/terraform/structure/StructureLocator.java b/common/src/main/java/org/terraform/structure/StructureLocator.java index 12de7519..1ad3bb4c 100644 --- a/common/src/main/java/org/terraform/structure/StructureLocator.java +++ b/common/src/main/java/org/terraform/structure/StructureLocator.java @@ -14,116 +14,169 @@ import org.terraform.main.config.TConfigOption; public class StructureLocator { - - private static final int[] TIMEDOUT = new int[] { -7, 13 }; - private static final LoadingCache STRUCTURELOCATION_CACHE = - CacheBuilder.newBuilder() - .maximumSize(300).build(new StructureLocatorCacheLoader()); - - public static int[] locateMultiMegaChunkStructure(TerraformWorld tw, @NotNull MegaChunk center, @NotNull MultiMegaChunkStructurePopulator populator, int timeoutMillis) { - - if(!populator.isEnabled()) return null; - StructureLocatorKey cacheKey = new StructureLocatorKey(center,tw,populator); - - // Do not use the cache if timeout is -1. - // /terra locate should keep re-running this code for debug purposes. - if(timeoutMillis != -1) { - int[] coords = STRUCTURELOCATION_CACHE.getIfPresent(cacheKey); - if(coords != null) { - // Query timed out before. Don't try again. - if(coords[0] == TIMEDOUT[0] && coords[1] == TIMEDOUT[1]) - return null; - return coords; - } - } - long currentTimeMillis = System.currentTimeMillis(); - - int blockX = -1; + + private static final int[] TIMEDOUT = new int[] {-7, 13}; + private static final LoadingCache STRUCTURELOCATION_CACHE = CacheBuilder.newBuilder() + .maximumSize(300) + .build(new StructureLocatorCacheLoader()); + + public static int[] locateMultiMegaChunkStructure(TerraformWorld tw, + @NotNull MegaChunk center, + @NotNull MultiMegaChunkStructurePopulator populator, + int timeoutMillis) + { + + if (!populator.isEnabled()) { + return null; + } + StructureLocatorKey cacheKey = new StructureLocatorKey(center, tw, populator); + + // Do not use the cache if timeout is -1. + // /terra locate should keep re-running this code for debug purposes. + if (timeoutMillis != -1) { + int[] coords = STRUCTURELOCATION_CACHE.getIfPresent(cacheKey); + if (coords != null) { + // Query timed out before. Don't try again. + if (coords[0] == TIMEDOUT[0] && coords[1] == TIMEDOUT[1]) { + return null; + } + return coords; + } + } + long currentTimeMillis = System.currentTimeMillis(); + + int blockX = -1; int blockZ = -1; int radius = 0; boolean found = false; while (!found) { for (MegaChunk mc : getSurroundingChunks(center, radius)) { - // Timeout catcher - if(timeoutMillis != -1 && System.currentTimeMillis() - currentTimeMillis > timeoutMillis) { - STRUCTURELOCATION_CACHE.put(cacheKey, TIMEDOUT); - break; - } + // Timeout catcher + if (timeoutMillis != -1 && System.currentTimeMillis() - currentTimeMillis > timeoutMillis) { + STRUCTURELOCATION_CACHE.put(cacheKey, TIMEDOUT); + break; + } for (int[] coords : populator.getCoordsFromMegaChunk(tw, mc)) { - if (coords == null) continue; + if (coords == null) { + continue; + } - if (TConfigOption.areStructuresEnabled() && populator.canSpawn(tw, coords[0] >> 4, coords[1] >> 4)) { + if (TConfigOption.areStructuresEnabled() && populator.canSpawn( + tw, + coords[0] >> 4, + coords[1] >> 4 + )) + { found = true; blockX = coords[0]; blockZ = coords[1]; break; } } - if (found) break; + if (found) { + break; + } } radius++; } STRUCTURELOCATION_CACHE.put(cacheKey, new int[] {blockX, blockZ}); return new int[] {blockX, blockZ}; } - - public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, int rawX, int rawZ, @NotNull SingleMegaChunkStructurePopulator populator, int timeoutMillis) { + + public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, + int rawX, + int rawZ, + @NotNull SingleMegaChunkStructurePopulator populator, + int timeoutMillis) + { MegaChunk center = new MegaChunk(rawX, 0, rawZ); return locateSingleMegaChunkStructure(tw, center, populator, timeoutMillis); - } - - public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, @NotNull MegaChunk center, @NotNull SingleMegaChunkStructurePopulator populator, int timeoutMillis) { - - if(!populator.isEnabled()) return null; - - StructureLocatorKey cacheKey = new StructureLocatorKey(center,tw,populator); - - // Do not use the cache if timeout is -1. - // /terra locate should keep re-running this code for debug purposes. - // Also to prevent potential bugs where bad coordinates are cached. - // Caching must be done anyway for vanilla, as it will cause locks when - // players level up villagers. - if(timeoutMillis != -1) { - int[] coords = STRUCTURELOCATION_CACHE.getIfPresent(cacheKey); - if(coords != null) { - // Query timed out before. Don't try again. - if(coords[0] == TIMEDOUT[0] && coords[1] == TIMEDOUT[1]) - return null; - return coords; - } - } - long currentTimeMillis = System.currentTimeMillis(); - MegaChunk lowerBound = null; + } + + public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, + @NotNull MegaChunk center, + @NotNull SingleMegaChunkStructurePopulator populator, + int timeoutMillis) + { + + if (!populator.isEnabled()) { + return null; + } + + StructureLocatorKey cacheKey = new StructureLocatorKey(center, tw, populator); + + // Do not use the cache if timeout is -1. + // /terra locate should keep re-running this code for debug purposes. + // Also to prevent potential bugs where bad coordinates are cached. + // Caching must be done anyway for vanilla, as it will cause locks when + // players level up villagers. + if (timeoutMillis != -1) { + int[] coords = STRUCTURELOCATION_CACHE.getIfPresent(cacheKey); + if (coords != null) { + // Query timed out before. Don't try again. + if (coords[0] == TIMEDOUT[0] && coords[1] == TIMEDOUT[1]) { + return null; + } + return coords; + } + } + long currentTimeMillis = System.currentTimeMillis(); + MegaChunk lowerBound = null; MegaChunk upperBound = null; int blockX = -1; int blockZ = -1; int radius = 0; boolean found = false; - + while (!found) { for (MegaChunk mc : getSurroundingChunks(center, radius)) { - // Timeout catcher - if(timeoutMillis != -1 && System.currentTimeMillis() - currentTimeMillis > timeoutMillis) { - STRUCTURELOCATION_CACHE.put(cacheKey, TIMEDOUT); - break; - } - if (lowerBound == null) lowerBound = mc; - if (upperBound == null) upperBound = mc; - if (mc.getX() < lowerBound.getX() || mc.getZ() < lowerBound.getZ()) + // Timeout catcher + if (timeoutMillis != -1 && System.currentTimeMillis() - currentTimeMillis > timeoutMillis) { + STRUCTURELOCATION_CACHE.put(cacheKey, TIMEDOUT); + break; + } + if (lowerBound == null) { lowerBound = mc; - if (mc.getX() > upperBound.getX() || mc.getZ() > upperBound.getZ()) + } + if (upperBound == null) { upperBound = mc; + } + if (mc.getX() < lowerBound.getX() || mc.getZ() < lowerBound.getZ()) { + lowerBound = mc; + } + if (mc.getX() > upperBound.getX() || mc.getZ() > upperBound.getZ()) { + upperBound = mc; + } int[] coords = mc.getCenterBiomeSectionBlockCoords(); // populator.getCoordsFromMegaChunk(tw, mc); - if (coords == null) continue; + if (coords == null) { + continue; + } BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // Right bitshift of 4 is conversion from block coords to chunk coords. - - if (TConfigOption.areStructuresEnabled() && populator.canSpawn(tw, coords[0] >> 4, coords[1] >> 4, biome)) { - for (SingleMegaChunkStructurePopulator availablePops : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) { - if (availablePops == null) continue; - if(TConfigOption.areStructuresEnabled() && availablePops.canSpawn(tw, coords[0] >> 4, coords[1] >> 4, biome)) { + + if (TConfigOption.areStructuresEnabled() && populator.canSpawn( + tw, + coords[0] >> 4, + coords[1] >> 4, + biome + )) + { + for (SingleMegaChunkStructurePopulator availablePops : StructureRegistry.getLargeStructureForMegaChunk( + tw, + mc + )) { + if (availablePops == null) { + continue; + } + if (TConfigOption.areStructuresEnabled() && availablePops.canSpawn( + tw, + coords[0] >> 4, + coords[1] >> 4, + biome + )) + { if (availablePops.getClass().equals(populator.getClass())) { // Can spawn found = true; @@ -137,79 +190,84 @@ public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, @ break; } } - if (found) break; + if (found) { + break; + } } } radius++; - + } STRUCTURELOCATION_CACHE.put(cacheKey, new int[] {blockX, blockZ}); return new int[] {blockX, blockZ}; } - - private static @NotNull Collection getSurroundingChunks(@NotNull MegaChunk center, int radius) { - if (radius == 0) return new ArrayList<>() {{ - add(center); - }}; + + private static @NotNull Collection getSurroundingChunks(@NotNull MegaChunk center, int radius) { + if (radius == 0) { + return new ArrayList<>() {{ + add(center); + }}; + } // xxxxx // xxx x x // xox x o x // xxx x x // xxxxx ArrayList candidates = new ArrayList<>(); - // Lock rX, iterate rZ - for(int rx:new int[] {-radius,radius}) { - for (int rz = -radius; rz <= radius; rz++) { - candidates.add(center.getRelative(rx, rz)); - } + // Lock rX, iterate rZ + for (int rx : new int[] {-radius, radius}) { + for (int rz = -radius; rz <= radius; rz++) { + candidates.add(center.getRelative(rx, rz)); + } } - + // Lock rZ, iterate rX - for(int rz:new int[] {-radius,radius}) { - for (int rx = 1-radius; rx <= radius-1; rx++) { - candidates.add(center.getRelative(rx, rz)); + for (int rz : new int[] {-radius, radius}) { + for (int rx = 1 - radius; rx <= radius - 1; rx++) { + candidates.add(center.getRelative(rx, rz)); } - } + } return candidates; - } - - public static class StructureLocatorCacheLoader extends CacheLoader { - /** - * Does not do loading. - * If this is null, the caller is responsible for inserting it. - */ - @Override - public int @NotNull [] load(@NotNull StructureLocatorKey key) { - return null; - } - } - - private static class StructureLocatorKey{ - private final MegaChunk mc; - private final TerraformWorld tw; - private final StructurePopulator pop; - public StructureLocatorKey(MegaChunk mc, TerraformWorld tw, StructurePopulator pop) { - super(); - this.mc = mc; - this.tw = tw; - this.pop = pop; - } - - @Override - public boolean equals(Object obj) { - if(obj instanceof StructureLocatorKey other) { - if(other.mc.equals(mc) && other.tw.getName().equals(tw.getName())) { - return pop.getClass().isInstance(other.pop); - } - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(mc,tw,pop.getClass()); - } - } - + } + + public static class StructureLocatorCacheLoader extends CacheLoader { + /** + * Does not do loading. + * If this is null, the caller is responsible for inserting it. + */ + @Override + public int @NotNull [] load(@NotNull StructureLocatorKey key) { + return null; + } + } + + private static class StructureLocatorKey { + private final MegaChunk mc; + private final TerraformWorld tw; + private final StructurePopulator pop; + + public StructureLocatorKey(MegaChunk mc, TerraformWorld tw, StructurePopulator pop) { + super(); + this.mc = mc; + this.tw = tw; + this.pop = pop; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof StructureLocatorKey other) { + if (other.mc.equals(mc) && other.tw.getName().equals(tw.getName())) { + return pop.getClass().isInstance(other.pop); + } + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(mc, tw, pop.getClass()); + } + } + } diff --git a/common/src/main/java/org/terraform/structure/StructurePopulator.java b/common/src/main/java/org/terraform/structure/StructurePopulator.java index 10eefe99..064da509 100644 --- a/common/src/main/java/org/terraform/structure/StructurePopulator.java +++ b/common/src/main/java/org/terraform/structure/StructurePopulator.java @@ -6,25 +6,25 @@ import java.util.Random; public abstract class StructurePopulator { - + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public abstract boolean isEnabled(); public abstract void populate(TerraformWorld world, PopulatorDataAbstract data); public abstract Random getHashedRandom(TerraformWorld world, int chunkX, int chunkZ); - + /** - * Refers to 6x6 chunks as a buffer distance for the structure to spawn + * Refers to 6x6 chunks as a buffer distance for the structure to spawn * with the default value. - * This buffer will force biome populators to stop populating + * This buffer will force biome populators to stop populating * certain things for that chunk radius. *

    * For underground structures, this should be "0" to denote NO buffer *

    * Only works for SingleMegaChunkStructurePopulators - */ + */ public int getChunkBufferDistance() { - return 3; + return 3; } } diff --git a/common/src/main/java/org/terraform/structure/StructureRegistry.java b/common/src/main/java/org/terraform/structure/StructureRegistry.java index 0a70daa9..7aaa05df 100644 --- a/common/src/main/java/org/terraform/structure/StructureRegistry.java +++ b/common/src/main/java/org/terraform/structure/StructureRegistry.java @@ -46,7 +46,8 @@ public class StructureRegistry { * getLargeStructureForMegaChunk contains the populator. Small structure populators * will always attempt to spawn. */ - public static final Map largeStructureRegistry = new EnumMap<>(StructureType.class); + public static final Map largeStructureRegistry = new EnumMap<>( + StructureType.class); public static final Collection smallStructureRegistry = new ArrayList<>(); private static final HashMap queryCache = new HashMap<>(); @@ -61,8 +62,9 @@ public static void init() { registerStructure(StructureType.MEGA_DUNGEON, new StrongholdPopulator()); registerStructure(StructureType.MEGA_DUNGEON, new MansionPopulator()); registerStructure(StructureType.MEGA_DUNGEON, new AncientCityPopulator()); - if(Version.isAtLeast(21)) + if (Version.isAtLeast(21)) { registerStructure(StructureType.MEGA_DUNGEON, new TrialChamberPopulator()); + } registerStructure(StructureType.LARGE_CAVE, new LargeCavePopulator()); @@ -87,8 +89,9 @@ public static void init() { public static @Nullable StructureType getStructureType(@NotNull Class populatorType) { for (Entry entry : largeStructureRegistry.entrySet()) { for (SingleMegaChunkStructurePopulator pops : entry.getValue()) { - if (populatorType.isInstance(pops)) + if (populatorType.isInstance(pops)) { return entry.getKey(); + } } } return null; // Invalid populator Type. @@ -98,14 +101,19 @@ public static void init() { * @return the structure types that can spawn in this mega chunk * Only one is meant to be picked. */ - public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - // TerraformGeneratorPlugin.logger.info("getLargeStructureForMegaChunkQuery: " + mc.getX() + "," + mc.getZ()); + public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk(@NotNull TerraformWorld tw, + @NotNull MegaChunk mc) + { + // TerraformGeneratorPlugin.logger.info("getLargeStructureForMegaChunkQuery: " + mc.getX() + "," + mc.getZ()); // Clear the cache if it gets big. - if (queryCache.size() > 50) queryCache.clear(); - MegaChunkKey key = new MegaChunkKey(tw,mc); + if (queryCache.size() > 50) { + queryCache.clear(); + } + MegaChunkKey key = new MegaChunkKey(tw, mc); // Don't re-calculate - if (queryCache.containsKey(key)) + if (queryCache.containsKey(key)) { return queryCache.get(key); + } Random structRand = tw.getHashedRand(9, mc.getX(), mc.getZ()); int maxStructures = 3; // GenUtils.randInt(structRand, 1, TConfigOption.STRUCTURES_MEGACHUNK_MAXSTRUCTURES.getInt()); @@ -114,14 +122,26 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( // Check if there are any mega dungeons enabled if (largeStructureRegistry.containsKey(StructureType.MEGA_DUNGEON) - && largeStructureRegistry.get(StructureType.MEGA_DUNGEON).length > 0) { + && largeStructureRegistry.get(StructureType.MEGA_DUNGEON).length > 0) + { // First check if the megadungeons can spawn. Shuffle the array first. - SingleMegaChunkStructurePopulator[] available = (SingleMegaChunkStructurePopulator[]) shuffleArray(structRand, largeStructureRegistry.get(StructureType.MEGA_DUNGEON)); + SingleMegaChunkStructurePopulator[] available = (SingleMegaChunkStructurePopulator[]) shuffleArray( + structRand, + largeStructureRegistry.get(StructureType.MEGA_DUNGEON) + ); for (SingleMegaChunkStructurePopulator pop : available) { int[] coords = mc.getCenterBiomeSectionBlockCoords(); // pop.getCoordsFromMegaChunk(tw, mc); - if (coords == null) continue; + if (coords == null) { + continue; + } - if (TConfigOption.areStructuresEnabled() && pop.canSpawn(tw, coords[0] >> 4, coords[1] >> 4, mc.getCenterBiomeSection(tw).getBiomeBank())) { + if (TConfigOption.areStructuresEnabled() && pop.canSpawn( + tw, + coords[0] >> 4, + coords[1] >> 4, + mc.getCenterBiomeSection(tw).getBiomeBank() + )) + { pops[size] = pop; size++; break; // ONLY ONE MEGA DUNGEON. @@ -134,18 +154,26 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( StructureType[] types = {StructureType.LARGE_CAVE, StructureType.VILLAGE, StructureType.LARGE_MISC}; types = (StructureType[]) shuffleArray(structRand, types); for (StructureType type : types) { - if (largeStructureRegistry.containsKey(type)) + if (largeStructureRegistry.containsKey(type)) { for (SingleMegaChunkStructurePopulator pop : largeStructureRegistry.get(type)) { int[] coords = mc.getCenterBiomeSectionBlockCoords(); - if (TConfigOption.areStructuresEnabled() && pop.canSpawn(tw, coords[0] >> 4, coords[1] >> 4, mc.getCenterBiomeSection(tw).getBiomeBank())) { + if (TConfigOption.areStructuresEnabled() && pop.canSpawn(tw, + coords[0] >> 4, + coords[1] >> 4, + mc.getCenterBiomeSection(tw).getBiomeBank() + )) + { pops[size] = pop; size++; break; // ONLY ONE OF EACH TYPE. Do not try to spawn multiple. } } + } // Stop trying if max structures is hit - if (size >= maxStructures) break; + if (size >= maxStructures) { + break; + } } // } @@ -161,7 +189,9 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( // Implementing FisherYates shuffle private static Object @NotNull [] shuffleArray(@NotNull Random rand, Object[] ar) { ar = ar.clone(); - if (ar.length == 0) return ar; + if (ar.length == 0) { + return ar; + } for (int i = ar.length - 1; i > 0; i--) { int index = rand.nextInt(i + 1); // Simple swap @@ -176,7 +206,9 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( * Registers small or large structures. Must implement either SingleMegaChunkStructurePopulator or MultiMegaChunkStructurePopulator. */ public static void registerStructure(StructureType type, @NotNull StructurePopulator pop) { - if (!pop.isEnabled()) return;// Don't register disabled features + if (!pop.isEnabled()) { + return;// Don't register disabled features + } if (pop instanceof SingleMegaChunkStructurePopulator) { SingleMegaChunkStructurePopulator[] pops = {(SingleMegaChunkStructurePopulator) pop}; @@ -187,10 +219,13 @@ public static void registerStructure(StructureType type, @NotNull StructurePopul System.arraycopy(existing, 0, pops, 0, existing.length); System.arraycopy(old, 0, pops, existing.length, 1); } - TerraformGeneratorPlugin.logger.info("[Structure Registry] Registered Large Structure: " + pop.getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("[Structure Registry] Registered Large Structure: " + pop.getClass() + .getSimpleName()); largeStructureRegistry.put(type, pops); - } else if (pop instanceof MultiMegaChunkStructurePopulator) { - TerraformGeneratorPlugin.logger.info("[Structure Registry] Registered Small Structure: " + pop.getClass().getSimpleName()); + } + else if (pop instanceof MultiMegaChunkStructurePopulator) { + TerraformGeneratorPlugin.logger.info("[Structure Registry] Registered Small Structure: " + pop.getClass() + .getSimpleName()); smallStructureRegistry.add((MultiMegaChunkStructurePopulator) pop); } @@ -219,25 +254,28 @@ public static void registerStructure(StructureType type, @NotNull StructurePopul } return pops; } - + private static class MegaChunkKey { - private final TerraformWorld tw; - private final MegaChunk mc; - public MegaChunkKey(TerraformWorld tw, MegaChunk mc) { - super(); - this.tw = tw; - this.mc = mc; - } - - @Override - public int hashCode() { - return Objects.hash(tw.hashCode(),mc.getX(), mc.getZ()); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof MegaChunkKey other)) return false; + private final TerraformWorld tw; + private final MegaChunk mc; + + public MegaChunkKey(TerraformWorld tw, MegaChunk mc) { + super(); + this.tw = tw; + this.mc = mc; + } + + @Override + public int hashCode() { + return Objects.hash(tw.hashCode(), mc.getX(), mc.getZ()); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MegaChunkKey other)) { + return false; + } return this.tw.equals(other.tw) && mc.getX() == other.mc.getX() && mc.getZ() == other.mc.getZ(); - } + } } } diff --git a/common/src/main/java/org/terraform/structure/VanillaStructurePopulator.java b/common/src/main/java/org/terraform/structure/VanillaStructurePopulator.java index 0251ba62..2a151ee3 100644 --- a/common/src/main/java/org/terraform/structure/VanillaStructurePopulator.java +++ b/common/src/main/java/org/terraform/structure/VanillaStructurePopulator.java @@ -3,9 +3,9 @@ /** * Spawns the associated vanilla structure. */ -public abstract class VanillaStructurePopulator extends SingleMegaChunkStructurePopulator -{ +public abstract class VanillaStructurePopulator extends SingleMegaChunkStructurePopulator { public final String structureRegistryKey; + public VanillaStructurePopulator(String structureKey) { structureRegistryKey = structureKey; diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAbstractRoomPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAbstractRoomPopulator.java index 4d33e0c8..5cc2edc0 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAbstractRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAbstractRoomPopulator.java @@ -24,126 +24,128 @@ public abstract class AncientCityAbstractRoomPopulator extends RoomPopulatorAbstract { - final TerraformWorld tw; + protected final RoomLayoutGenerator gen; + final TerraformWorld tw; protected int shrunkenWidth = 0; - protected final RoomLayoutGenerator gen; - public AncientCityAbstractRoomPopulator(TerraformWorld tw, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { + protected @Nullable CubeRoom effectiveRoom = null; + + public AncientCityAbstractRoomPopulator(TerraformWorld tw, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.tw = tw; this.gen = gen; } - protected @Nullable CubeRoom effectiveRoom = null; - @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - - shrunkenWidth = GenUtils.randInt(this.rand, 2,4); - - // This variable is named depression, but can also represent elevation. - int depression = shrunkenWidth; - - // Sometimes the room will be higher than the path's Y. - if(rand.nextBoolean()) { - depression = depression*-1; - } - - this.effectiveRoom = new CarvedRoom(new CubeRoom( - room.getWidthX() - shrunkenWidth*2 - 1, - room.getWidthZ() - shrunkenWidth*2 - 1, - room.getHeight(), - room.getX(), room.getY() + depression, room.getZ())); - + + shrunkenWidth = GenUtils.randInt(this.rand, 2, 4); + + // This variable is named depression, but can also represent elevation. + int depression = shrunkenWidth; + + // Sometimes the room will be higher than the path's Y. + if (rand.nextBoolean()) { + depression = depression * -1; + } + + this.effectiveRoom = new CarvedRoom(new CubeRoom(room.getWidthX() - shrunkenWidth * 2 - 1, + room.getWidthZ() - shrunkenWidth * 2 - 1, + room.getHeight(), + room.getX(), + room.getY() + depression, + room.getZ() + )); + // Clear out space for the room - effectiveRoom.fillRoom(data, Material.CAVE_AIR); - - // Room flooring + effectiveRoom.fillRoom(data, Material.CAVE_AIR); + + // Room flooring int[] lowerCorner = effectiveRoom.getLowerCorner(0); int[] upperCorner = effectiveRoom.getUpperCorner(0); int y = effectiveRoom.getY(); for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { SimpleBlock b = new SimpleBlock(data, x, y, z); - + // Fuzz the sides to give a sense of ruin - if(x == lowerCorner[0] || x == upperCorner[0] || z == lowerCorner[1] || z == upperCorner[1]) - { - if(rand.nextBoolean()) - b.lsetType(AncientCityUtils.deepslateBricks); + if (x == lowerCorner[0] || x == upperCorner[0] || z == lowerCorner[1] || z == upperCorner[1]) { + if (rand.nextBoolean()) { + b.lsetType(AncientCityUtils.deepslateBricks); + } + } + else { + b.lsetType(AncientCityUtils.deepslateBricks); } - else - b.lsetType(AncientCityUtils.deepslateBricks); - + // every few intervals, place a pillar - int relX = effectiveRoom.getX() - x; + int relX = effectiveRoom.getX() - x; int relZ = effectiveRoom.getZ() - z; - if(relX % 5 == 0 && relZ % 5 == 0 && - (effectiveRoom.isPointInside(b.getRelative(BlockFace.NORTH)) - && effectiveRoom.isPointInside(b.getRelative(BlockFace.SOUTH)) - && effectiveRoom.isPointInside(b.getRelative(BlockFace.EAST)) - && effectiveRoom.isPointInside(b.getRelative(BlockFace.WEST)))) - AncientCityUtils.placeSupportPillar(b.getDown()); - + if (relX % 5 == 0 && relZ % 5 == 0 && (effectiveRoom.isPointInside(b.getRelative(BlockFace.NORTH)) + && effectiveRoom.isPointInside(b.getRelative(BlockFace.SOUTH)) + && effectiveRoom.isPointInside(b.getRelative(BlockFace.EAST)) + && effectiveRoom.isPointInside(b.getRelative(BlockFace.WEST)))) + { + AncientCityUtils.placeSupportPillar(b.getDown()); + } + } } - + // Connect the paths to the rooms - for(Entry entry:room.getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey().getDown(); - for(int i = shrunkenWidth; i < entry.getValue()-shrunkenWidth; i++) { - - if(this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) { - // w.getUp(3).setType(Material.RED_WOOL); - w.setType(AncientCityUtils.deepslateBricks); - w.getLeft().setType(AncientCityUtils.deepslateBricks); - w.getRight().setType(AncientCityUtils.deepslateBricks); - - if(depression < 0) { - new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setDownTypes(AncientCityUtils.deepslateBricks) - .setStairwayDirection(BlockFace.DOWN) - .setStopAtY(effectiveRoom.getY()) - .build(w.getFront()) - .build(w.getFront().getLeft()) - .build(w.getFront().getRight()); - } - else - { - new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setDownTypes(AncientCityUtils.deepslateBricks) - .setStairwayDirection(BlockFace.UP) - .setUpwardsCarveUntilNotSolid(false) - .setStopAtY(effectiveRoom.getY()) - .build(w.getUp().getFront()) - .build(w.getUp().getFront().getLeft()) - .build(w.getUp().getFront().getRight()); - } - - } - w = w.getLeft(); - } + for (Entry entry : room.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey().getDown(); + for (int i = shrunkenWidth; i < entry.getValue() - shrunkenWidth; i++) { + + if (this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) { + // w.getUp(3).setType(Material.RED_WOOL); + w.setType(AncientCityUtils.deepslateBricks); + w.getLeft().setType(AncientCityUtils.deepslateBricks); + w.getRight().setType(AncientCityUtils.deepslateBricks); + + if (depression < 0) { + new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS).setDownTypes(AncientCityUtils.deepslateBricks) + .setStairwayDirection(BlockFace.DOWN) + .setStopAtY(effectiveRoom.getY()) + .build(w.getFront()) + .build(w.getFront().getLeft()) + .build(w.getFront().getRight()); + } + else { + new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS).setDownTypes(AncientCityUtils.deepslateBricks) + .setStairwayDirection(BlockFace.UP) + .setUpwardsCarveUntilNotSolid(false) + .setStopAtY(effectiveRoom.getY()) + .build(w.getUp().getFront()) + .build(w.getUp().getFront().getLeft()) + .build(w.getUp().getFront().getRight()); + } + + } + w = w.getLeft(); + } } } - public void sculkUp(TerraformWorld tw, @NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - FastNoise circleNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 11)); - n.SetNoiseType(FastNoise.NoiseType.Simplex); - n.SetFrequency(0.09f); - - return n; - }); - for(int i = 0; i <= ((room.getWidthX()*room.getWidthZ())/150); i++) - { - // Generates 3d coords, but we will discard the y coords. - // We will separately generate y coords later. - int[] coords = room.randomCoords(rand); - int y = rand.nextInt(5); - SimpleBlock target = new SimpleBlock(data, coords[0], room.getY()+y,coords[2]); - AncientCityUtils.spreadSculk(circleNoise, rand, 5, target); - } - } + public void sculkUp(TerraformWorld tw, @NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { + FastNoise circleNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 11)); + n.SetNoiseType(FastNoise.NoiseType.Simplex); + n.SetFrequency(0.09f); + + return n; + }); + for (int i = 0; i <= ((room.getWidthX() * room.getWidthZ()) / 150); i++) { + // Generates 3d coords, but we will discard the y coords. + // We will separately generate y coords later. + int[] coords = room.randomCoords(rand); + int y = rand.nextInt(5); + SimpleBlock target = new SimpleBlock(data, coords[0], room.getY() + y, coords[2]); + AncientCityUtils.spreadSculk(circleNoise, rand, 5, target); + } + } } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAltarPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAltarPopulator.java index e7b840f6..45242050 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAltarPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityAltarPopulator.java @@ -18,69 +18,78 @@ public class AncientCityAltarPopulator extends AncientCityAbstractRoomPopulator { - public AncientCityAltarPopulator(TerraformWorld tw, HashSet occupied, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { + public AncientCityAltarPopulator(TerraformWorld tw, + HashSet occupied, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { super(tw, gen, rand, forceSpawn, unique); } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - // Generates outer walls - for(Entry entry:this.effectiveRoom.getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey(); - Wall center = null; - boolean shouldPlaceAltar = true; - for(int i = 0; i < entry.getValue(); i++) { - if(i == entry.getValue()/2) center = w; - if(this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) - { - shouldPlaceAltar = false; - break; - } - w = w.getLeft(); - } - if(shouldPlaceAltar) { - String altarFile; - if(entry.getValue() < 7) - { - altarFile = "ancient-city/ancient-city-altar-small"; - } - else if(entry.getValue() < 11) - { - altarFile = "ancient-city/ancient-city-altar-medium"; - } - else - { - altarFile = "ancient-city/ancient-city-altar-large"; - } - - try { - TerraSchematic schema = TerraSchematic.load(altarFile, center); - schema.parser = new AncientCitySchematicParser(); - schema.setFace(center.getDirection()); - schema.apply(); - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - // Misc pillars leading up to the altar - int pillarSpacing = entry.getValue() / 3; - for(int i = pillarSpacing; i < Math.min(effectiveRoom.getWidthX(), effectiveRoom.getWidthZ()); i += 3) - { - center.getFront(i).getLeft(pillarSpacing).LPillar(rand.nextInt(room.getHeight()/3), AncientCityUtils.deepslateBricks); - center.getFront(i).getRight(pillarSpacing).LPillar(rand.nextInt(room.getHeight()/3), AncientCityUtils.deepslateBricks); - } - - super.sculkUp(tw, data, this.effectiveRoom); - return; - } - } - super.sculkUp(tw, data, this.effectiveRoom); + super.populate(data, room); + // Generates outer walls + for (Entry entry : this.effectiveRoom.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey(); + Wall center = null; + boolean shouldPlaceAltar = true; + for (int i = 0; i < entry.getValue(); i++) { + if (i == entry.getValue() / 2) { + center = w; + } + if (this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) { + shouldPlaceAltar = false; + break; + } + w = w.getLeft(); + } + if (shouldPlaceAltar) { + String altarFile; + if (entry.getValue() < 7) { + altarFile = "ancient-city/ancient-city-altar-small"; + } + else if (entry.getValue() < 11) { + altarFile = "ancient-city/ancient-city-altar-medium"; + } + else { + altarFile = "ancient-city/ancient-city-altar-large"; + } + + try { + TerraSchematic schema = TerraSchematic.load(altarFile, center); + schema.parser = new AncientCitySchematicParser(); + schema.setFace(center.getDirection()); + schema.apply(); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + // Misc pillars leading up to the altar + int pillarSpacing = entry.getValue() / 3; + for (int i = pillarSpacing; i < Math.min(effectiveRoom.getWidthX(), effectiveRoom.getWidthZ()); i += 3) + { + center.getFront(i) + .getLeft(pillarSpacing) + .LPillar(rand.nextInt(room.getHeight() / 3), AncientCityUtils.deepslateBricks); + center.getFront(i) + .getRight(pillarSpacing) + .LPillar(rand.nextInt(room.getHeight() / 3), AncientCityUtils.deepslateBricks); + } + + super.sculkUp(tw, data, this.effectiveRoom); + return; + } + } + super.sculkUp(tw, data, this.effectiveRoom); } - + @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getWidthX() % 2 ==1 || room.getWidthZ() % 2 == 1; + return room.getWidthX() % 2 == 1 || room.getWidthZ() % 2 == 1; } } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityCenterPlatformPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityCenterPlatformPopulator.java index ce0effab..2ccc7cb1 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityCenterPlatformPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityCenterPlatformPopulator.java @@ -31,316 +31,359 @@ public class AncientCityCenterPlatformPopulator extends AncientCityAbstractRoomPopulator { - public AncientCityCenterPlatformPopulator(TerraformWorld tw, HashSet occupied, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { + public AncientCityCenterPlatformPopulator(TerraformWorld tw, + HashSet occupied, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { super(tw, gen, rand, forceSpawn, unique); } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - - // Generates outer walls - for(Entry entry:this.effectiveRoom.getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - - if(i > 2 && i < entry.getValue() - 3 && i % 3 == 0) { - - if(!this.gen.isPointInPath(w, shrunkenWidth+1, 2)) { - w.lsetType(Material.CHISELED_DEEPSLATE); - w.getUp().CorrectMultipleFacing(2); - w.getUp().LPillar(2, Material.DEEPSLATE_BRICK_WALL); - w.getUp(3).lsetType(Material.CHISELED_DEEPSLATE); - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP).lapply(w.getUp(3).getRear()); - - w.getRear().getUp(4).lsetType(Material.DEEPSLATE_BRICK_WALL); - w.getRear().getUp(4).CorrectMultipleFacing(1); - } - for(BlockFace dir:BlockUtils.getAdjacentFaces(w.getDirection())) - { - Wall rel = w.getRelative(dir); - if(this.gen.isPointInPath(rel, shrunkenWidth+1, 2)) - continue; - - rel.lsetType(Material.DEEPSLATE_BRICKS); - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(rel.getDirection().getOppositeFace()) - .lapply(rel.getFront()) - .setFacing(dir).lapply(rel.getUp()) - .setFacing(dir.getOppositeFace()) - .lapply(rel.getUp(2)) - .lapply(rel.getUp(4).getRear()); - rel.getUp(3).lsetType(Material.DEEPSLATE_BRICKS); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setHalf(Half.TOP) - .setFacing(rel.getDirection()) - .lapply(rel.getUp(3).getRear()) - .setFacing(rel.getDirection().getOppositeFace()) - .lapply(rel.getUp(3).getFront()); - } - } - w = w.getLeft(); - } - } - - // Spawn corner decorations + super.populate(data, room); + + // Generates outer walls + for (Entry entry : this.effectiveRoom.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + + if (i > 2 && i < entry.getValue() - 3 && i % 3 == 0) { + + if (!this.gen.isPointInPath(w, shrunkenWidth + 1, 2)) { + w.lsetType(Material.CHISELED_DEEPSLATE); + w.getUp().CorrectMultipleFacing(2); + w.getUp().LPillar(2, Material.DEEPSLATE_BRICK_WALL); + w.getUp(3).lsetType(Material.CHISELED_DEEPSLATE); + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP).lapply(w.getUp(3).getRear()); + + w.getRear().getUp(4).lsetType(Material.DEEPSLATE_BRICK_WALL); + w.getRear().getUp(4).CorrectMultipleFacing(1); + } + for (BlockFace dir : BlockUtils.getAdjacentFaces(w.getDirection())) { + Wall rel = w.getRelative(dir); + if (this.gen.isPointInPath(rel, shrunkenWidth + 1, 2)) { + continue; + } + + rel.lsetType(Material.DEEPSLATE_BRICKS); + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(rel.getDirection() + .getOppositeFace()) + .lapply(rel.getFront()) + .setFacing(dir) + .lapply(rel.getUp()) + .setFacing(dir.getOppositeFace()) + .lapply(rel.getUp(2)) + .lapply(rel.getUp(4).getRear()); + rel.getUp(3).lsetType(Material.DEEPSLATE_BRICKS); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setHalf(Half.TOP) + .setFacing(rel.getDirection()) + .lapply(rel.getUp(3).getRear()) + .setFacing(rel.getDirection() + .getOppositeFace()) + .lapply(rel.getUp(3).getFront()); + } + } + w = w.getLeft(); + } + } + + // Spawn corner decorations int y = effectiveRoom.getY(); - for (int[] corner:effectiveRoom.getAllCorners(2)) { - int x = corner[0]; - int z = corner[1]; - spawnLargePillar(new SimpleBlock(data,x,y,z),room); + for (int[] corner : effectiveRoom.getAllCorners(2)) { + int x = corner[0]; + int z = corner[1]; + spawnLargePillar(new SimpleBlock(data, x, y, z), room); } // Direction the head faces - BlockFace facing = BlockUtils.getDirectBlockFace(this.getRand()); - - int modX; int modZ; CubeRoom fireBox; - if(BlockUtils.getAxisFromBlockFace(facing) == Axis.X) { - modX = 3; - modZ = 17; - fireBox = effectiveRoom.getCloneSubsetRoom(8, 2); - } - else { - modZ = 3; - modX = 17; - fireBox = effectiveRoom.getCloneSubsetRoom(2, 8); - } + BlockFace facing = BlockUtils.getDirectBlockFace(this.getRand()); + + int modX; + int modZ; + CubeRoom fireBox; + if (BlockUtils.getAxisFromBlockFace(facing) == Axis.X) { + modX = 3; + modZ = 17; + fireBox = effectiveRoom.getCloneSubsetRoom(8, 2); + } + else { + modZ = 3; + modX = 17; + fireBox = effectiveRoom.getCloneSubsetRoom(2, 8); + } // Make box around head area - int[] lowerCorner = fireBox.getLowerCorner(6); - int[] upperCorner = fireBox.getUpperCorner(6); - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - data.setType(nx, fireBox.getY(), nz, Material.SOUL_SAND); - data.setType(nx, fireBox.getY()+1, nz, Material.SOUL_FIRE); - } - - for(Entry entry:fireBox.getFourWalls(data, 5).entrySet()) { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - w.Pillar(GenUtils.randInt(rand, 1, 3), AncientCityUtils.deepslateBricks); - if(BlockUtils.getAxisFromBlockFace(w.getDirection()) == BlockUtils.getAxisFromBlockFace(facing)) { - w.getRear().setType(AncientCityUtils.deepslateBricks); - w.getRear(2).setType(AncientCityUtils.deepslateBricks); - if(GenUtils.chance(rand, 1, 30)) - BlockUtils.placeCandle(w.getRear().getUp(), rand.nextInt(3)+1, true); - if(GenUtils.chance(rand, 1, 30)) - BlockUtils.placeCandle(w.getRear(2).getUp(), rand.nextInt(3)+1, true); - if(rand.nextBoolean()) - { - w.getRear(3).setType(AncientCityUtils.deepslateBricks); - if(GenUtils.chance(rand, 1, 30)) - BlockUtils.placeCandle(w.getRear(3).getUp(), rand.nextInt(3)+1, true); - if(rand.nextBoolean()) - new StairBuilder(Material.COBBLED_DEEPSLATE_STAIRS, - Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getRear(4)); - } - else { - if(rand.nextBoolean()) - new StairBuilder(Material.COBBLED_DEEPSLATE_STAIRS, - Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getRear(3)); - } - } - w = w.getLeft(); - } - } - - + int[] lowerCorner = fireBox.getLowerCorner(6); + int[] upperCorner = fireBox.getUpperCorner(6); + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + data.setType(nx, fireBox.getY(), nz, Material.SOUL_SAND); + data.setType(nx, fireBox.getY() + 1, nz, Material.SOUL_FIRE); + } + } + + for (Entry entry : fireBox.getFourWalls(data, 5).entrySet()) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + w.Pillar(GenUtils.randInt(rand, 1, 3), AncientCityUtils.deepslateBricks); + if (BlockUtils.getAxisFromBlockFace(w.getDirection()) == BlockUtils.getAxisFromBlockFace(facing)) { + w.getRear().setType(AncientCityUtils.deepslateBricks); + w.getRear(2).setType(AncientCityUtils.deepslateBricks); + if (GenUtils.chance(rand, 1, 30)) { + BlockUtils.placeCandle(w.getRear().getUp(), rand.nextInt(3) + 1, true); + } + if (GenUtils.chance(rand, 1, 30)) { + BlockUtils.placeCandle(w.getRear(2).getUp(), rand.nextInt(3) + 1, true); + } + if (rand.nextBoolean()) { + w.getRear(3).setType(AncientCityUtils.deepslateBricks); + if (GenUtils.chance(rand, 1, 30)) { + BlockUtils.placeCandle(w.getRear(3).getUp(), rand.nextInt(3) + 1, true); + } + if (rand.nextBoolean()) { + new StairBuilder(Material.COBBLED_DEEPSLATE_STAIRS, + Material.POLISHED_DEEPSLATE_STAIRS + ).setFacing(w.getDirection()).apply(w.getRear(4)); + } + } + else { + if (rand.nextBoolean()) { + new StairBuilder(Material.COBBLED_DEEPSLATE_STAIRS, + Material.POLISHED_DEEPSLATE_STAIRS + ).setFacing(w.getDirection()).apply(w.getRear(3)); + } + } + } + w = w.getLeft(); + } + } + + // Spawn a rectangular slab of deepslate bricks - new CylinderBuilder(new Random(), room.getCenterSimpleBlock(data).getUp(13), AncientCityUtils.deepslateBricks) - .setRX(modX).setRZ(modZ).setRY(20) - .build(); - + new CylinderBuilder( + new Random(), + room.getCenterSimpleBlock(data).getUp(13), + AncientCityUtils.deepslateBricks + ).setRX(modX).setRZ(modZ).setRY(20).build(); + // Spawn center head spawnCentralHead(room.getCenterSimpleBlock(data).getUp(13), facing); - - + + // Stairs at the front and back - for(BlockFace dir:new BlockFace[] {facing,facing.getOppositeFace()}) - { - Wall targetStair = new Wall(room.getCenterSimpleBlock(data) - .getAtY(effectiveRoom.getY()+1) - .getRelative(dir,5), - dir.getOppositeFace()); - - for(int radius = 0; radius <= 14; radius++) { - for(BlockFace rel:BlockUtils.getAdjacentFaces(facing)) { - new StairwayBuilder(Material.COBBLED_DEEPSLATE_STAIRS, - Material.POLISHED_DEEPSLATE_STAIRS) - .setAngled(false) - .setCarveAirSpace(false) - .setUpwardsCarveUntilSolid(true) - .setUpwardsCarveUntilNotSolid(false) - .setStopAtY(targetStair.getY() + 4) - .setDownTypes(AncientCityUtils.deepslateBricks) - .setStairwayDirection(BlockFace.UP) - .build(targetStair.getRelative(rel, radius)); - } - } + for (BlockFace dir : new BlockFace[] {facing, facing.getOppositeFace()}) { + Wall targetStair = new Wall(room.getCenterSimpleBlock(data) + .getAtY(effectiveRoom.getY() + 1) + .getRelative(dir, 5), + dir.getOppositeFace() + ); + + for (int radius = 0; radius <= 14; radius++) { + for (BlockFace rel : BlockUtils.getAdjacentFaces(facing)) { + new StairwayBuilder(Material.COBBLED_DEEPSLATE_STAIRS, + Material.POLISHED_DEEPSLATE_STAIRS + ).setAngled(false) + .setCarveAirSpace(false) + .setUpwardsCarveUntilSolid(true) + .setUpwardsCarveUntilNotSolid(false) + .setStopAtY(targetStair.getY() + + 4) + .setDownTypes(AncientCityUtils.deepslateBricks) + .setStairwayDirection(BlockFace.UP) + .build(targetStair.getRelative( + rel, + radius + )); + } + } } - - - // Debree and breakage - lowerCorner = effectiveRoom.getLowerCorner(6); - upperCorner = effectiveRoom.getUpperCorner(6); - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - if(GenUtils.chance(rand, 1, 200)) { - new SphereBuilder(new Random(), new SimpleBlock(data,nx,effectiveRoom.getY(),nz), Material.AIR) - .setRadius(2f) - .setSphereFrequency(0.15f) - .setHardReplace(true) - .build(); - } - } - - - CubeRoom basement = new CubeRoom(this.effectiveRoom.getWidthX(), - this.effectiveRoom.getWidthZ(), - 6, - this.effectiveRoom.getX(), this.effectiveRoom.getY()-6, this.effectiveRoom.getZ()); - AncientCityResearchBasementHandler.populate(rand, data, basement, facing); - - super.sculkUp(tw, data, this.effectiveRoom); + + + // Debree and breakage + lowerCorner = effectiveRoom.getLowerCorner(6); + upperCorner = effectiveRoom.getUpperCorner(6); + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + if (GenUtils.chance(rand, 1, 200)) { + new SphereBuilder(new Random(), + new SimpleBlock(data, nx, effectiveRoom.getY(), nz), + Material.AIR + ).setRadius(2f).setSphereFrequency(0.15f).setHardReplace(true).build(); + } + } + } + + + CubeRoom basement = new CubeRoom(this.effectiveRoom.getWidthX(), + this.effectiveRoom.getWidthZ(), + 6, + this.effectiveRoom.getX(), + this.effectiveRoom.getY() - 6, + this.effectiveRoom.getZ() + ); + AncientCityResearchBasementHandler.populate(rand, data, basement, facing); + + super.sculkUp(tw, data, this.effectiveRoom); } - + private void spawnCentralHead(@NotNull SimpleBlock core, @NotNull BlockFace facing) { - - int headHeight = 11; - int headWidth = 15; - int generalFuzzSize = 3; - for(int radius = 0; radius <= headWidth; radius++) { - for(BlockFace rel:BlockUtils.getAdjacentFaces(facing)) { - if(Version.isAtLeast(19)) { - core.getRelative(rel,radius).setType(OneOneNineBlockHandler.REINFORCED_DEEPSLATE); - core.getUp(headHeight).getRelative(rel,radius).setType(OneOneNineBlockHandler.REINFORCED_DEEPSLATE); - } - else - if(radius % 2 == 0) { - core.getRelative(rel,radius).setType(AncientCityUtils.deepslateTiles); - core.getUp(headHeight).getRelative(rel,radius).setType(AncientCityUtils.deepslateTiles); - - } - else - { - core.getRelative(rel,radius).setType(Material.POLISHED_DIORITE,Material.DIORITE); - core.getUp(headHeight).getRelative(rel,radius).setType(Material.POLISHED_DIORITE,Material.DIORITE); - } - - // Air the warden's teeth - if(radius != headWidth) - core.getRelative(rel,radius).getUp() - .Pillar(headHeight-1, Material.AIR); - - airWardenBlocks(core.getRelative(rel,radius),facing); - airWardenBlocks(core.getUp(headHeight).getRelative(rel,radius),facing); - - airWardenBlocks(core.getUp(1).getRelative(rel,radius), headHeight-1, facing); - - - // Fuzz up and down - core.getRelative(rel,radius).getDown().downPillar(GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize+1), AncientCityUtils.deepslateTiles); - airWardenBlocks(core.getRelative(rel,radius).getDown(), facing); - core.getRelative(rel,radius).getUp(headHeight+1).Pillar(GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize+1), AncientCityUtils.deepslateTiles); - - if(radius == headWidth) { - if(Version.isAtLeast(19)) - core.getRelative(rel,radius).Pillar(headHeight, OneOneNineBlockHandler.REINFORCED_DEEPSLATE); - else - core.getRelative(rel,radius).Pillar(headHeight, true, new Random(), Material.DEEPSLATE_TILES, Material.DIORITE); - - // Fuzz left and right - for(int i = -2; i <= headHeight + 2; i++) { - SimpleBlock start = core.getRelative(rel, radius+1).getUp(i); - int maxFuzzSize = GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize+1); - if(i >= headHeight/2 - 1 && i <= headHeight/2 + 2) - maxFuzzSize += 2; - for(int fuzzSize = 0; fuzzSize < maxFuzzSize; fuzzSize++) - { - start.getRelative(rel, fuzzSize).setType(AncientCityUtils.deepslateTiles); - } - } - } - } - } - - + + int headHeight = 11; + int headWidth = 15; + int generalFuzzSize = 3; + for (int radius = 0; radius <= headWidth; radius++) { + for (BlockFace rel : BlockUtils.getAdjacentFaces(facing)) { + if (Version.isAtLeast(19)) { + core.getRelative(rel, radius).setType(OneOneNineBlockHandler.REINFORCED_DEEPSLATE); + core.getUp(headHeight) + .getRelative(rel, radius) + .setType(OneOneNineBlockHandler.REINFORCED_DEEPSLATE); + } + else if (radius % 2 == 0) { + core.getRelative(rel, radius).setType(AncientCityUtils.deepslateTiles); + core.getUp(headHeight).getRelative(rel, radius).setType(AncientCityUtils.deepslateTiles); + + } + else { + core.getRelative(rel, radius).setType(Material.POLISHED_DIORITE, Material.DIORITE); + core.getUp(headHeight) + .getRelative(rel, radius) + .setType(Material.POLISHED_DIORITE, Material.DIORITE); + } + + // Air the warden's teeth + if (radius != headWidth) { + core.getRelative(rel, radius).getUp().Pillar(headHeight - 1, Material.AIR); + } + + airWardenBlocks(core.getRelative(rel, radius), facing); + airWardenBlocks(core.getUp(headHeight).getRelative(rel, radius), facing); + + airWardenBlocks(core.getUp(1).getRelative(rel, radius), headHeight - 1, facing); + + + // Fuzz up and down + core.getRelative(rel, radius) + .getDown() + .downPillar( + GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize + 1), + AncientCityUtils.deepslateTiles + ); + airWardenBlocks(core.getRelative(rel, radius).getDown(), facing); + core.getRelative(rel, radius) + .getUp(headHeight + 1) + .Pillar( + GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize + 1), + AncientCityUtils.deepslateTiles + ); + + if (radius == headWidth) { + if (Version.isAtLeast(19)) { + core.getRelative(rel, radius).Pillar(headHeight, OneOneNineBlockHandler.REINFORCED_DEEPSLATE); + } + else { + core.getRelative(rel, radius) + .Pillar(headHeight, true, new Random(), Material.DEEPSLATE_TILES, Material.DIORITE); + } + + // Fuzz left and right + for (int i = -2; i <= headHeight + 2; i++) { + SimpleBlock start = core.getRelative(rel, radius + 1).getUp(i); + int maxFuzzSize = GenUtils.randInt(rand, generalFuzzSize, generalFuzzSize + 1); + if (i >= headHeight / 2 - 1 && i <= headHeight / 2 + 2) { + maxFuzzSize += 2; + } + for (int fuzzSize = 0; fuzzSize < maxFuzzSize; fuzzSize++) { + start.getRelative(rel, fuzzSize).setType(AncientCityUtils.deepslateTiles); + } + } + } + } + } + + } - + private void airWardenBlocks(@NotNull SimpleBlock b, @NotNull BlockFace dir) { - airWardenBlocks(b, 1, dir); + airWardenBlocks(b, 1, dir); } - + /** * This method will replace rocks near the warden head. */ private void airWardenBlocks(@NotNull SimpleBlock b, int height, @NotNull BlockFace dir) { - for(int i = 0; i < height; i++) { - // b.getUp(i).setType(Material.AIR); - for(int depth = 1; depth <= 3; depth++) - { - b.getUp(i).getRelative(dir,depth).setType(Material.AIR); - b.getUp(i).getRelative(dir,-depth).setType(Material.AIR); - } - } + for (int i = 0; i < height; i++) { + // b.getUp(i).setType(Material.AIR); + for (int depth = 1; depth <= 3; depth++) { + b.getUp(i).getRelative(dir, depth).setType(Material.AIR); + b.getUp(i).getRelative(dir, -depth).setType(Material.AIR); + } + } } - + // Spawns in the corners of the center large platform private void spawnLargePillar(@NotNull SimpleBlock core, @NotNull CubeRoom room) { - - // Hollow square with a pillar in the middle - for(int relX = -2; relX <= 2; relX++) - for(int relZ = -2; relZ <= 2; relZ++) - { - SimpleBlock target = core.getRelative(relX,1,relZ); - if(Math.abs(relX) == 2 || Math.abs(relZ) == 2 || - (relX == 0 && relZ == 0)) - target.RPillar(10, new Random(), - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICK_SLAB); - else - target.Pillar(10, Material.AIR); - } - - // Spiral Stairway upwards + + // Hollow square with a pillar in the middle + for (int relX = -2; relX <= 2; relX++) { + for (int relZ = -2; relZ <= 2; relZ++) { + SimpleBlock target = core.getRelative(relX, 1, relZ); + if (Math.abs(relX) == 2 || Math.abs(relZ) == 2 || (relX == 0 && relZ == 0)) { + target.RPillar(10, + new Random(), + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICK_SLAB + ); + } + else { + target.Pillar(10, Material.AIR); + } + } + } + + // Spiral Stairway upwards int bfIndex = 0; - if(core.getX() < room.getX() && core.getZ() < room.getZ()) - bfIndex = 3; - else if(core.getX() > room.getX() && core.getZ() < room.getZ()) - bfIndex = 5; - else if(core.getX() < room.getX() && core.getZ() > room.getZ()) - bfIndex = 1; - else if(core.getX() > room.getX() && core.getZ() > room.getZ()) - bfIndex = 7; - + if (core.getX() < room.getX() && core.getZ() < room.getZ()) { + bfIndex = 3; + } + else if (core.getX() > room.getX() && core.getZ() < room.getZ()) { + bfIndex = 5; + } + else if (core.getX() < room.getX() && core.getZ() > room.getZ()) { + bfIndex = 1; + } + else if (core.getX() > room.getX() && core.getZ() > room.getZ()) { + bfIndex = 7; + } + for (int i = 1; i <= 10; i++) { // If index is 1, carve an entrance - if(i == 1) { - SimpleBlock target = core.getRelative(BlockUtils.xzPlaneBlockFaces[bfIndex],2); - - for(int relX = -1; relX <= 1; relX++) - for(int relZ = -1; relZ <= 1; relZ++) - target.getRelative(relX,1,relZ).Pillar(3,Material.AIR); - } + if (i == 1) { + SimpleBlock target = core.getRelative(BlockUtils.xzPlaneBlockFaces[bfIndex], 2); + + for (int relX = -1; relX <= 1; relX++) { + for (int relZ = -1; relZ <= 1; relZ++) { + target.getRelative(relX, 1, relZ).Pillar(3, Material.AIR); + } + } + } // Two slab stairs BlockFace face = BlockUtils.xzPlaneBlockFaces[bfIndex]; Slab bottom = (Slab) Bukkit.createBlockData(Material.DEEPSLATE_BRICK_SLAB); bottom.setType(Type.BOTTOM); core.getRelative(face.getModX(), i, face.getModZ()).setBlockData(bottom); - - + + bfIndex = getNextIndex(bfIndex); face = BlockUtils.xzPlaneBlockFaces[bfIndex]; @@ -349,33 +392,31 @@ else if(core.getX() > room.getX() && core.getZ() > room.getZ()) core.getRelative(face.getModX(), i, face.getModZ()).setBlockData(top); bfIndex = getNextIndex(bfIndex); } - - for(BlockFace face:BlockUtils.directBlockFaces) { - Wall target = new Wall(core.getUp(10), face).getFront(2); - target.getFront().getUp().setType(Material.DEEPSLATE_BRICK_WALL); - target.getFront().getDown().getRight().setType(Material.DEEPSLATE_BRICK_WALL); - target.getFront().getDown().getLeft().setType(Material.DEEPSLATE_BRICK_WALL); - target.getFront().getRight().setType(Material.DEEPSLATE_BRICK_SLAB); - target.getFront().getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(face) - .apply(target.getUp().getRight()) - .apply(target.getUp().getLeft()); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(face) - .setHalf(Half.TOP) - .apply(target.getFront()) - .apply(target.getFront().getRight().getDown(2)) - .apply(target.getFront().getLeft().getDown(2)); - - target.getUp().getRight(2).setType(Material.DEEPSLATE_BRICK_WALL); - target.getUp().getLeft(2).setType(Material.DEEPSLATE_BRICK_WALL); - - } + + for (BlockFace face : BlockUtils.directBlockFaces) { + Wall target = new Wall(core.getUp(10), face).getFront(2); + target.getFront().getUp().setType(Material.DEEPSLATE_BRICK_WALL); + target.getFront().getDown().getRight().setType(Material.DEEPSLATE_BRICK_WALL); + target.getFront().getDown().getLeft().setType(Material.DEEPSLATE_BRICK_WALL); + target.getFront().getRight().setType(Material.DEEPSLATE_BRICK_SLAB); + target.getFront().getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(face) + .apply(target.getUp().getRight()) + .apply(target.getUp().getLeft()); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(face) + .setHalf(Half.TOP) + .apply(target.getFront()) + .apply(target.getFront().getRight().getDown(2)) + .apply(target.getFront().getLeft().getDown(2)); + + target.getUp().getRight(2).setType(Material.DEEPSLATE_BRICK_WALL); + target.getUp().getLeft(2).setType(Material.DEEPSLATE_BRICK_WALL); + + } } - + @Override public boolean canPopulate(CubeRoom room) { diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityLargePillarRoomPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityLargePillarRoomPopulator.java index d9d3ca9b..8aad60ed 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityLargePillarRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityLargePillarRoomPopulator.java @@ -20,120 +20,120 @@ public class AncientCityLargePillarRoomPopulator extends AncientCityAbstractRoomPopulator { - public AncientCityLargePillarRoomPopulator(TerraformWorld tw, HashSet occupied, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { + public AncientCityLargePillarRoomPopulator(TerraformWorld tw, + HashSet occupied, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { super(tw, gen, rand, forceSpawn, unique); - - + + } - + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - // super.populate(data, room); - this.effectiveRoom = room; - - // Room flooring + // super.populate(data, room); + this.effectiveRoom = room; + + // Room flooring int[] lowerCorner = effectiveRoom.getLowerCorner(0); int[] upperCorner = effectiveRoom.getUpperCorner(0); int y = effectiveRoom.getY(); for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { SimpleBlock b = new SimpleBlock(data, x, y, z); - + // Fuzz the sides to give a sense of ruin - if(x == lowerCorner[0] || x == upperCorner[0] || z == lowerCorner[1] || z == upperCorner[1]) + if (x == lowerCorner[0] || x == upperCorner[0] || z == lowerCorner[1] || z == upperCorner[1]) { + if (rand.nextBoolean()) { + b.lsetType(AncientCityUtils.deepslateBricks); + } + } + else { + b.lsetType(AncientCityUtils.deepslateBricks); + } + } + } + + FastNoise ruinsNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_ANCIENTCITY_RUINS, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 11)); + n.SetNoiseType(FastNoise.NoiseType.Simplex); + n.SetFrequency(0.09f); + + return n; + }); + + try { + // Place upwards + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + int maxHeight = 70; + + AncientCityPillarSchematicParser lastParser = null; + while (maxHeight > 0) { + TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pillar-segment", center); + lastParser = new AncientCityPillarSchematicParser(); + schema.parser = lastParser; + schema.setFace(BlockUtils.getDirectBlockFace(rand)); + schema.apply(); + + center = center.getUp(3); + + // If around 30% of the pillar fails to place, break out of the loop and + // place ruined versions of the upper pillar + // TerraformGeneratorPlugin.logger.info("FR = " + lastParser.calculateFailRate()); + if (lastParser.calculateFailRate() > 0.3f) { + break; + } + maxHeight--; + } + + // Make the top of the pillar a bit fuzzed. + for (SimpleBlock b : lastParser.getTouchedOffsets()) { + b.getUp() + .LPillar((int) (5 * ruinsNoise.GetNoise(b.getX(), b.getZ())), AncientCityUtils.deepslateBricks); + } + + // Place downwards + center = room.getCenterSimpleBlock(data).getDown(3); + maxHeight = 70; + + lastParser = null; + while (maxHeight > 0) { + TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pillar-segment", center); + lastParser = new AncientCityPillarSchematicParser(); + schema.parser = lastParser; + schema.setFace(BlockUtils.getDirectBlockFace(rand)); + schema.apply(); + + center = center.getDown(3); + + // If around 30% of the pillar fails to place, break out of the loop and + // place ruined versions of the upper pillar + // TerraformGeneratorPlugin.logger.info("FR = " + lastParser.calculateFailRate()); + if (lastParser.calculateFailRate() > 0.3f + || center.getY() <= TerraformGeneratorPlugin.injector.getMinY()) { - if(rand.nextBoolean()) - b.lsetType(AncientCityUtils.deepslateBricks); + break; } - else - b.lsetType(AncientCityUtils.deepslateBricks); + maxHeight--; + } + + // Make the bottom of the pillar a bit fuzzed. + for (SimpleBlock b : lastParser.getTouchedOffsets()) { + b.getDown(3).downLPillar(new Random(), + (int) Math.abs(5 * ruinsNoise.GetNoise(b.getX(), b.getZ())), + AncientCityUtils.deepslateBricks + ); } + + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } - - FastNoise ruinsNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.STRUCTURE_ANCIENTCITY_RUINS, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 11)); - n.SetNoiseType(FastNoise.NoiseType.Simplex); - n.SetFrequency(0.09f); - - return n; - }); - - try { - // Place upwards - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - int maxHeight = 70; - - AncientCityPillarSchematicParser lastParser = null; - while(maxHeight > 0) - { - TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pillar-segment", center); - lastParser = new AncientCityPillarSchematicParser(); - schema.parser = lastParser; - schema.setFace(BlockUtils.getDirectBlockFace(rand)); - schema.apply(); - - center = center.getUp(3); - - // If around 30% of the pillar fails to place, break out of the loop and - // place ruined versions of the upper pillar - // TerraformGeneratorPlugin.logger.info("FR = " + lastParser.calculateFailRate()); - if(lastParser.calculateFailRate() > 0.3f) - { - break; - } - maxHeight--; - } - - // Make the top of the pillar a bit fuzzed. - for(SimpleBlock b:lastParser.getTouchedOffsets()) - { - b.getUp().LPillar( - (int) (5*ruinsNoise.GetNoise(b.getX(), b.getZ())), - AncientCityUtils.deepslateBricks); - } - - // Place downwards - center = room.getCenterSimpleBlock(data).getDown(3); - maxHeight = 70; - - lastParser = null; - while(maxHeight > 0) - { - TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pillar-segment", center); - lastParser = new AncientCityPillarSchematicParser(); - schema.parser = lastParser; - schema.setFace(BlockUtils.getDirectBlockFace(rand)); - schema.apply(); - - center = center.getDown(3); - - // If around 30% of the pillar fails to place, break out of the loop and - // place ruined versions of the upper pillar - // TerraformGeneratorPlugin.logger.info("FR = " + lastParser.calculateFailRate()); - if(lastParser.calculateFailRate() > 0.3f || center.getY() <= TerraformGeneratorPlugin.injector.getMinY()) - { - break; - } - maxHeight--; - } - - // Make the bottom of the pillar a bit fuzzed. - for(SimpleBlock b:lastParser.getTouchedOffsets()) - { - b.getDown(3).downLPillar( - new Random(), - (int) Math.abs(5*ruinsNoise.GetNoise(b.getX(), b.getZ())), - AncientCityUtils.deepslateBricks); - } - - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - super.sculkUp(tw, data, room); + + super.sculkUp(tw, data, room); } @Override diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathMiniRoomPlacer.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathMiniRoomPlacer.java index 64e484e1..97ee78cc 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathMiniRoomPlacer.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathMiniRoomPlacer.java @@ -14,74 +14,70 @@ public class AncientCityPathMiniRoomPlacer { - public static void placeAltar(@NotNull Wall origin) { - Material[] deepSlateBricks = new Material[] {Material.DEEPSLATE_BRICKS, Material.CRACKED_DEEPSLATE_BRICKS}; - // Place cylinder below - cylinderDown(origin, 4, deepSlateBricks); - - cylinderDown(origin.getUp(), 3, deepSlateBricks); - - // Place stairs leading to altar - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(origin.getDirection()) - .apply(origin.getRear(2).getUp()) - .apply(origin.getRear().getLeft().getUp()) - .apply(origin.getRear().getRight().getUp()); - - origin.getRear(3).getUp().fluidize(); - origin.getRear(2).getUp().getLeft().fluidize(); - origin.getRear(2).getUp().getRight().fluidize(); - - // Place the actual altar - Wall altarCore = origin.getFront(2).getUp(2); - altarCore.setType(deepSlateBricks); - altarCore.getLeft().setType(deepSlateBricks); - altarCore.getRight().setType(deepSlateBricks); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(altarCore.getDirection()) - .apply(altarCore.getRear()) - .setFacing(altarCore.getDirection().getOppositeFace()) - .apply(altarCore.getFront()); - - altarCore.getFront().getDown().setType(deepSlateBricks); - altarCore.getRear().getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); - altarCore.getRear().getRight().setType(Material.DEEPSLATE_BRICK_SLAB); - altarCore.getLeft(2).setType(Material.DEEPSLATE_BRICK_SLAB); - altarCore.getRight(2).setType(Material.DEEPSLATE_BRICK_SLAB); - - altarCore.getUp().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); - altarCore.getUp().getLeft().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); - altarCore.getUp().getRight().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); - - altarCore.getUp(3).setType(Material.DEEPSLATE_BRICK_SLAB); - altarCore.getUp(3).getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); - altarCore.getUp(3).getRight().setType(Material.DEEPSLATE_BRICK_SLAB); - - for(BlockFace adj:BlockUtils.getAdjacentFaces(altarCore.getDirection())) { - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(adj.getOppositeFace()) - .apply(altarCore.getRelative(adj,2).getUp(2)) - .setHalf(Half.TOP) - .apply(altarCore.getRelative(adj,2).getUp()); - } - - } - - private static void cylinderDown(@NotNull SimpleBlock core, int radius, Material... mat) { + public static void placeAltar(@NotNull Wall origin) { + Material[] deepSlateBricks = new Material[] {Material.DEEPSLATE_BRICKS, Material.CRACKED_DEEPSLATE_BRICKS}; + // Place cylinder below + cylinderDown(origin, 4, deepSlateBricks); + + cylinderDown(origin.getUp(), 3, deepSlateBricks); + + // Place stairs leading to altar + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(origin.getDirection()) + .apply(origin.getRear(2).getUp()) + .apply(origin.getRear().getLeft().getUp()) + .apply(origin.getRear().getRight().getUp()); + + origin.getRear(3).getUp().fluidize(); + origin.getRear(2).getUp().getLeft().fluidize(); + origin.getRear(2).getUp().getRight().fluidize(); + + // Place the actual altar + Wall altarCore = origin.getFront(2).getUp(2); + altarCore.setType(deepSlateBricks); + altarCore.getLeft().setType(deepSlateBricks); + altarCore.getRight().setType(deepSlateBricks); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(altarCore.getDirection()) + .apply(altarCore.getRear()) + .setFacing(altarCore.getDirection().getOppositeFace()) + .apply(altarCore.getFront()); + + altarCore.getFront().getDown().setType(deepSlateBricks); + altarCore.getRear().getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); + altarCore.getRear().getRight().setType(Material.DEEPSLATE_BRICK_SLAB); + altarCore.getLeft(2).setType(Material.DEEPSLATE_BRICK_SLAB); + altarCore.getRight(2).setType(Material.DEEPSLATE_BRICK_SLAB); + + altarCore.getUp().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); + altarCore.getUp().getLeft().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); + altarCore.getUp().getRight().Pillar(2, Material.COBBLED_DEEPSLATE_WALL); + + altarCore.getUp(3).setType(Material.DEEPSLATE_BRICK_SLAB); + altarCore.getUp(3).getLeft().setType(Material.DEEPSLATE_BRICK_SLAB); + altarCore.getUp(3).getRight().setType(Material.DEEPSLATE_BRICK_SLAB); + + for (BlockFace adj : BlockUtils.getAdjacentFaces(altarCore.getDirection())) { + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(adj.getOppositeFace()) + .apply(altarCore.getRelative(adj, 2).getUp(2)) + .setHalf(Half.TOP) + .apply(altarCore.getRelative(adj, 2).getUp()); + } + + } + + private static void cylinderDown(@NotNull SimpleBlock core, int radius, Material... mat) { for (float x = -radius; x <= radius; x++) { for (float z = -radius; z <= radius; z++) { SimpleBlock rel = core.getRelative(Math.round(x), 0, Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - + + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); + if (equationResult <= 1.0) { - rel.downUntilSolid(new Random(), mat); + rel.downUntilSolid(new Random(), mat); } } } - } - + } + } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathPopulator.java index 3fb4da24..a4638332 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPathPopulator.java @@ -26,6 +26,7 @@ public class AncientCityPathPopulator extends PathPopulatorAbstract { private final RoomLayoutGenerator gen; private final HashSet occupied; + public AncientCityPathPopulator(Random rand, RoomLayoutGenerator gen, HashSet occupied) { // private int state = 0; this.gen = gen; @@ -34,208 +35,207 @@ public AncientCityPathPopulator(Random rand, RoomLayoutGenerator gen, HashSet 4) pathFacing = core.getDirection().getOppositeFace(); - - // 0 is center - // 1, 8 is the segment closest to center - // 2, 7 is next closest - // 3, 6 is the next - // 4, 5 is the sides (highest point in the arc) - switch(state) { - case 0: - // Debug arrow -// core.getUp().setType(Material.RED_WOOL); -// core.getUp().getRear().getLeft().setType(Material.RED_WOOL); -// core.getUp().getRear().getRight().setType(Material.RED_WOOL); - // Middle of the arc. - core.getUp(6).lsetType(Material.DEEPSLATE_BRICK_WALL); - core.getUp(5).lsetType(Material.DEEPSLATE_BRICKS); - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.SOUL_LANTERN); - lantern.setHanging(true); - core.getUp(4).lsetBlockData(lantern); - - // Support pillar - AncientCityUtils.placeSupportPillar(core.getDown()); - - // Mirror the sides to create the arc in the middle - for(BlockFace leftRight:BlockUtils.getAdjacentFaces(core.getDirection())) { - - new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS) - .setHalf(Half.TOP).setFacing(leftRight.getOppositeFace()) - .apply(core.getRelative(leftRight,2).getDown()); - - core.getRelative(leftRight,2).setType(Material.CHISELED_DEEPSLATE); - core.getRelative(leftRight,2).getUp().lsetType(Material.DEEPSLATE_TILES); - core.getRelative(leftRight,2).getUp(2).LPillar(2, Material.POLISHED_DEEPSLATE); - core.getRelative(leftRight,2).getUp(4).lsetType(Material.CHISELED_DEEPSLATE); - - new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(leftRight.getOppositeFace()) - .lapply(core.getUp(5).getRelative(leftRight,2)); - - new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(leftRight) - .setHalf(Half.TOP) - .lapply(core.getUp(4).getRelative(leftRight)); - - core.getRelative(leftRight).getUp(5).lsetType(Material.DEEPSLATE_BRICKS); - - } - break; - case 1, 8: - - // Upper stair - new StairBuilder(Material.DEEPSLATE_TILE_STAIRS) - .setHalf(Half.TOP) - .setFacing(pathFacing.getOppositeFace()) - .lapply(core.getUp(5)); - - for(BlockFace leftRight:BlockUtils.getAdjacentFaces(core.getDirection())) { - // Slab - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP) - .lapply(core.getRelative(leftRight,2).getDown()); - -// if(pathFacing == core.getDirection()) -// core.getUp().setType(Material.BLUE_WOOL); -// else -// core.getUp().setType(Material.GREEN_WOOL); - - // Stairs that complete the arc - new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(pathFacing.getOppositeFace()) - .lapply(core.getRelative(leftRight,2).getUp()); - new StairBuilder(Material.DEEPSLATE_TILE_STAIRS) - .setHalf(Half.TOP) - .setFacing(pathFacing.getOppositeFace()) - .lapply(core.getRelative(leftRight,2).getUp(4)); - - core.getRelative(leftRight,2).getUp(5).lsetType(Material.DEEPSLATE_TILES); - core.getRelative(leftRight).getUp(5).lsetType(Material.DEEPSLATE_BRICK_WALL); - core.getRelative(leftRight).getUp(6).lsetType(Material.DEEPSLATE_BRICK_SLAB); - - } - break; - case 2, 7: - for(BlockFace leftRight:BlockUtils.getAdjacentFaces(core.getDirection())) { - // Slab - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP) - .lapply(core.getRelative(leftRight,2).getDown()) - .lapply(core.getRelative(leftRight).getUp(5)); - - core.getRelative(leftRight,2).getUp(5).lsetType(Material.DEEPSLATE_TILES); - core.getRelative(leftRight,2).getUp(6).lsetType(Material.DEEPSLATE_BRICK_SLAB); - - } - break; - case 3, 6: - // Center slab - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP) - .lapply(core.getUp(5)); - - for(BlockFace leftRight:BlockUtils.getAdjacentFaces(core.getDirection())) { - // Slab - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP) - .lapply(core.getRelative(leftRight, 2).getUp(5)); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(pathFacing.getOppositeFace()) - .lapply(core.getRelative(leftRight, 2).getUp(6)); - } - break; - case 4, 5: - // Center slab - new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB) - .setType(Type.TOP) - .lapply(core.getUp(5)); - - for(BlockFace leftRight:BlockUtils.getAdjacentFaces(core.getDirection())) { - // Slab - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(leftRight) - .setHalf(Half.TOP) - .lapply(core.getRelative(leftRight, 2).getUp(5)); - - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(pathFacing.getOppositeFace()) - .lapply(core.getRelative(leftRight, 2).getUp(6)); - } - break; - default: - TerraformGeneratorPlugin.logger.info("Ancient City Populator: Irregular path state: " + state); - break; - } + if (occupied.contains(core.getLoc()) + || occupied.contains(core.getRight().getLoc()) + || occupied.contains(core.getLeft().getLoc())) + { + return; + } + + occupied.add(core.getLoc()); + occupied.add(core.getRight().getLoc()); + occupied.add(core.getLeft().getLoc()); + + BlockFace pathFacing = core.getDirection(); + if (state > 4) { + pathFacing = core.getDirection().getOppositeFace(); + } + + // 0 is center + // 1, 8 is the segment closest to center + // 2, 7 is next closest + // 3, 6 is the next + // 4, 5 is the sides (highest point in the arc) + switch (state) { + case 0: + // Debug arrow + // core.getUp().setType(Material.RED_WOOL); + // core.getUp().getRear().getLeft().setType(Material.RED_WOOL); + // core.getUp().getRear().getRight().setType(Material.RED_WOOL); + // Middle of the arc. + core.getUp(6).lsetType(Material.DEEPSLATE_BRICK_WALL); + core.getUp(5).lsetType(Material.DEEPSLATE_BRICKS); + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.SOUL_LANTERN); + lantern.setHanging(true); + core.getUp(4).lsetBlockData(lantern); + + // Support pillar + AncientCityUtils.placeSupportPillar(core.getDown()); + + // Mirror the sides to create the arc in the middle + for (BlockFace leftRight : BlockUtils.getAdjacentFaces(core.getDirection())) { + + new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS).setHalf(Half.TOP) + .setFacing(leftRight.getOppositeFace()) + .apply(core.getRelative(leftRight, 2) + .getDown()); + + core.getRelative(leftRight, 2).setType(Material.CHISELED_DEEPSLATE); + core.getRelative(leftRight, 2).getUp().lsetType(Material.DEEPSLATE_TILES); + core.getRelative(leftRight, 2).getUp(2).LPillar(2, Material.POLISHED_DEEPSLATE); + core.getRelative(leftRight, 2).getUp(4).lsetType(Material.CHISELED_DEEPSLATE); + + new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS).setFacing(leftRight.getOppositeFace()) + .lapply(core.getUp(5) + .getRelative(leftRight, 2)); + + new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS).setFacing(leftRight) + .setHalf(Half.TOP) + .lapply(core.getUp(4).getRelative(leftRight)); + + core.getRelative(leftRight).getUp(5).lsetType(Material.DEEPSLATE_BRICKS); + + } + break; + case 1, 8: + + // Upper stair + new StairBuilder(Material.DEEPSLATE_TILE_STAIRS).setHalf(Half.TOP) + .setFacing(pathFacing.getOppositeFace()) + .lapply(core.getUp(5)); + + for (BlockFace leftRight : BlockUtils.getAdjacentFaces(core.getDirection())) { + // Slab + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP) + .lapply(core.getRelative(leftRight, 2).getDown()); + + // if(pathFacing == core.getDirection()) + // core.getUp().setType(Material.BLUE_WOOL); + // else + // core.getUp().setType(Material.GREEN_WOOL); + + // Stairs that complete the arc + new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS).setFacing(pathFacing.getOppositeFace()) + .lapply(core.getRelative(leftRight, 2).getUp()); + new StairBuilder(Material.DEEPSLATE_TILE_STAIRS).setHalf(Half.TOP) + .setFacing(pathFacing.getOppositeFace()) + .lapply(core.getRelative(leftRight, 2).getUp(4)); + + core.getRelative(leftRight, 2).getUp(5).lsetType(Material.DEEPSLATE_TILES); + core.getRelative(leftRight).getUp(5).lsetType(Material.DEEPSLATE_BRICK_WALL); + core.getRelative(leftRight).getUp(6).lsetType(Material.DEEPSLATE_BRICK_SLAB); + + } + break; + case 2, 7: + for (BlockFace leftRight : BlockUtils.getAdjacentFaces(core.getDirection())) { + // Slab + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP) + .lapply(core.getRelative(leftRight, 2).getDown()) + .lapply(core.getRelative(leftRight).getUp(5)); + + core.getRelative(leftRight, 2).getUp(5).lsetType(Material.DEEPSLATE_TILES); + core.getRelative(leftRight, 2).getUp(6).lsetType(Material.DEEPSLATE_BRICK_SLAB); + + } + break; + case 3, 6: + // Center slab + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP).lapply(core.getUp(5)); + + for (BlockFace leftRight : BlockUtils.getAdjacentFaces(core.getDirection())) { + // Slab + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP) + .lapply(core.getRelative(leftRight, 2).getUp(5)); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(pathFacing.getOppositeFace()) + .lapply(core.getRelative(leftRight, 2).getUp(6)); + } + break; + case 4, 5: + // Center slab + new SlabBuilder(Material.DEEPSLATE_BRICK_SLAB).setType(Type.TOP).lapply(core.getUp(5)); + + for (BlockFace leftRight : BlockUtils.getAdjacentFaces(core.getDirection())) { + // Slab + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(leftRight) + .setHalf(Half.TOP) + .lapply(core.getRelative(leftRight, 2).getUp(5)); + + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(pathFacing.getOppositeFace()) + .lapply(core.getRelative(leftRight, 2).getUp(6)); + } + break; + default: + TerraformGeneratorPlugin.logger.info("Ancient City Populator: Irregular path state: " + state); + break; + } } @Override @@ -245,12 +245,16 @@ public boolean customCarve(@NotNull SimpleBlock base, BlockFace dir, int pathWid EnumSet carveMaterials = BlockUtils.stoneLike.clone(); carveMaterials.addAll(BlockUtils.caveDecoratorMaterials); BlockUtils.carveCaveAir(seed, - pathWidth + 3, pathWidth + 3, pathWidth + 3, + pathWidth + 3, + pathWidth + 3, + pathWidth + 3, 0.09f, - core.get(), - true, true, - carveMaterials); - + core.get(), + true, + true, + carveMaterials + ); + return true; } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPillarSchematicParser.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPillarSchematicParser.java index e635dd2b..2e729fa6 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPillarSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPillarSchematicParser.java @@ -12,48 +12,46 @@ import org.terraform.utils.version.OneOneNineBlockHandler; public class AncientCityPillarSchematicParser extends SchematicParser { - - private int failCount = 0; - private int totalCount = 0; - @NotNull - final - ArrayList touchedOffsets = new ArrayList<>(); - - public @NotNull ArrayList getTouchedOffsets() { - return touchedOffsets; - } - - public float calculateFailRate() { - return ((float) failCount)/((float) totalCount); - } - + + @NotNull + final ArrayList touchedOffsets = new ArrayList<>(); + private int failCount = 0; + private int totalCount = 0; + + public @NotNull ArrayList getTouchedOffsets() { + return touchedOffsets; + } + + public float calculateFailRate() { + return ((float) failCount) / ((float) totalCount); + } + @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - Random rand = new Random(); - totalCount += 1; - if(block.isSolid() && block.getType() != OneOneNineBlockHandler.SCULK_VEIN) { - failCount += 1; - return; - } - else if(touchedOffsets.isEmpty() || touchedOffsets.get(0).getY() == block.getY()) - { - touchedOffsets.add(block); - } - else if(touchedOffsets.get(0).getY() < block.getY()) { - touchedOffsets.clear(); - touchedOffsets.add(block); - } - - if(data.getMaterial() == Material.DEEPSLATE_TILES) - { // Crack deepslate tiles - if(rand.nextBoolean()) - data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_TILES); - } - else if(data.getMaterial() == Material.DEEPSLATE_BRICKS) - { // Crack deepslate bricks - if(rand.nextBoolean()) - data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_BRICKS); - } - super.applyData(block, data); + Random rand = new Random(); + totalCount += 1; + if (block.isSolid() && block.getType() != OneOneNineBlockHandler.SCULK_VEIN) { + failCount += 1; + return; + } + else if (touchedOffsets.isEmpty() || touchedOffsets.get(0).getY() == block.getY()) { + touchedOffsets.add(block); + } + else if (touchedOffsets.get(0).getY() < block.getY()) { + touchedOffsets.clear(); + touchedOffsets.add(block); + } + + if (data.getMaterial() == Material.DEEPSLATE_TILES) { // Crack deepslate tiles + if (rand.nextBoolean()) { + data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_TILES); + } + } + else if (data.getMaterial() == Material.DEEPSLATE_BRICKS) { // Crack deepslate bricks + if (rand.nextBoolean()) { + data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_BRICKS); + } + } + super.applyData(block, data); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java index 5a827b82..7bcdc7f3 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java @@ -34,29 +34,36 @@ public class AncientCityPopulator extends SingleMegaChunkStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if ( !isEnabled()) return false; + if (!isEnabled()) { + return false; + } // MegaChunk mc = new MegaChunk(chunkX, chunkZ); // int[] coords = mc.getCenterBiomeSectionBlockCoords(); - // Do not spawn ancient cities in non-mountains, like vanilla - if(biome.getType() != BiomeType.MOUNTAINOUS - && biome.getType() != BiomeType.HIGH_MOUNTAINOUS) - return false; - - if(!Version.isAtLeast(19)) return false; - - return rollSpawnRatio(tw,chunkX,chunkZ); + // Do not spawn ancient cities in non-mountains, like vanilla + if (biome.getType() != BiomeType.MOUNTAINOUS && biome.getType() != BiomeType.HIGH_MOUNTAINOUS) { + return false; + } + + if (!Version.isAtLeast(19)) { + return false; + } + + return rollSpawnRatio(tw, chunkX, chunkZ); } + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 123122), - (int) (TConfigOption.STRUCTURES_ANCIENTCITY_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_ANCIENTCITY_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); @@ -67,17 +74,21 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // if(!Version.isAtLeast(18) && minY < 0) minY = 8; int y = GenUtils.randInt(minY, TConfigOption.STRUCTURES_ANCIENTCITY_MAX_Y.getInt()); - - spawnAncientCity(tw, - tw.getHashedRand(x, y, z, 23412222), - data, x, y + 1, z); + + spawnAncientCity(tw, tw.getHashedRand(x, y, z, 23412222), data, x, y + 1, z); } - public void spawnAncientCity(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - TerraformGeneratorPlugin.logger.info("Spawning ancient city at: " + x + "," + y + "," + z); - + public void spawnAncientCity(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + TerraformGeneratorPlugin.logger.info("Spawning ancient city at: " + x + "," + y + "," + z); + // Level One - HashSet occupied = new HashSet<>(); + HashSet occupied = new HashSet<>(); Random hashedRand = tw.getHashedRand(x, y, z); RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, 40, x, y, z, 120); gen.setPathPopulator(new AncientCityPathPopulator(tw.getHashedRand(x, y, z, 2), gen, occupied)); @@ -87,103 +98,108 @@ public void spawnAncientCity(@NotNull TerraformWorld tw, @NotNull Random random, gen.setRoomMinHeight(20); gen.setRoomMinX(16); gen.setRoomMinZ(16); - + gen.registerRoomPopulator(new AncientCityRuinsPlatform(tw, occupied, gen, random, false, false)); gen.registerRoomPopulator(new AncientCitySchematicPlatform(tw, occupied, gen, random, false, false)); gen.registerRoomPopulator(new AncientCityAltarPopulator(tw, occupied, gen, random, false, false)); gen.registerRoomPopulator(new AncientCityLargePillarRoomPopulator(tw, occupied, gen, random, false, false)); - + // Forcefully place the center platform in the middle - CubeRoom room = new CubeRoom(50, 50, 40, x,y,z); + CubeRoom room = new CubeRoom(50, 50, 40, x, y, z); room.setRoomPopulator(new AncientCityCenterPlatformPopulator(tw, occupied, gen, random, true, true)); gen.getRooms().add(room); - + gen.setCarveRooms(true); gen.setCarveRoomsMultiplier(1.5f, 2f, 1.5f); gen.calculateRoomPlacement(); // gen.fill(data, tw, Material.CAVE_AIR); gen.carvePathsOnly(data, tw, Material.CAVE_AIR); gen.carveRoomsOnly(data, tw, Material.CAVE_AIR); - + // Creep up the whole place. float radius = 80; - FastNoise circleNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 11)); - n.SetNoiseType(FastNoise.NoiseType.Simplex); - n.SetFrequency(0.09f); - - return n; - }); - + FastNoise circleNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.BIOME_CAVECLUSTER_CIRCLENOISE, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 11)); + n.SetNoiseType(FastNoise.NoiseType.Simplex); + n.SetFrequency(0.09f); + + return n; + }); + SimpleBlock center = new SimpleBlock(data, x, y, z); TerraformGeneratorPlugin.logger.info("Spawning sculk..."); - + PopulatorDataICABiomeWriterAbstract ica = null; - if(center.getPopData() instanceof PopulatorDataICABiomeWriterAbstract) { - ica = (PopulatorDataICABiomeWriterAbstract) center.getPopData(); + if (center.getPopData() instanceof PopulatorDataICABiomeWriterAbstract) { + ica = (PopulatorDataICABiomeWriterAbstract) center.getPopData(); } - + for (float nx = -radius; nx <= radius; nx++) { for (float nz = -radius; nz <= radius; nz++) { for (float ny = -50; ny <= 50; ny++) { - SimpleBlock rel = center.getRelative(Math.round(nx), Math.round(ny), Math.round(nz)); - - if(ica != null) - ica.setBiome(rel.getX(), rel.getY(), rel.getZ(), OneOneNineBlockHandler.DEEP_DARK); - - - if(!BlockUtils.isStoneLike(rel.getType())) continue; - // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(nx, 2) / Math.pow(radius, 2) - + Math.pow(nz, 2) / Math.pow(radius, 2) + Math.pow(ny, 2) / Math.pow(50, 2); - float noiseVal = circleNoise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); - if (equationResult <= 1 + 0.7 * noiseVal) { - if(BlockUtils.isExposedToNonSolid(rel) || !rel.getDown().isSolid() || !rel.getUp().isSolid()) - { - // Inner area of the circle is sculk - if(equationResult <= 0.7*(1 + 0.7 * noiseVal)) - { - rel.setType(OneOneNineBlockHandler.SCULK); - - // If the above is not solid, place some decorations - if(!rel.getUp().isSolid()) - if(GenUtils.chance(random, 1, 230)) - rel.getUp().setType(OneOneNineBlockHandler.SCULK_CATALYST); - else if(GenUtils.chance(random, 1, 150)) - rel.getUp().setType(OneOneNineBlockHandler.SCULK_SENSOR); - else if(GenUtils.chance(random, 1, 600)) - rel.getUp().setBlockData(OneOneNineBlockHandler.getActiveSculkShrieker()); - } - else // Outer area are sculk veins - { - for(BlockFace face:BlockUtils.sixBlockFaces) { - SimpleBlock adj = rel.getRelative(face); - if(adj.isAir()) - { - new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN) - .setFace(face.getOppositeFace(), true) - .apply(adj); - } - else if(adj.getBlockData() instanceof MultipleFacing mf) - { - if(mf.getAllowedFaces().contains(face.getOppositeFace())) - mf.setFace(face.getOppositeFace(), true); - adj.setBlockData(mf); - } - } - } - } - else if(rel.getType() == Material.WATER) - rel.setType(Material.CAVE_AIR); - } + SimpleBlock rel = center.getRelative(Math.round(nx), Math.round(ny), Math.round(nz)); + + if (ica != null) { + ica.setBiome(rel.getX(), rel.getY(), rel.getZ(), OneOneNineBlockHandler.DEEP_DARK); + } + + + if (!BlockUtils.isStoneLike(rel.getType())) { + continue; + } + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); + double equationResult = Math.pow(nx, 2) / Math.pow(radius, 2) + Math.pow(nz, 2) / Math.pow( + radius, + 2 + ) + Math.pow(ny, 2) / Math.pow(50, 2); + float noiseVal = circleNoise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); + if (equationResult <= 1 + 0.7 * noiseVal) { + if (BlockUtils.isExposedToNonSolid(rel) || !rel.getDown().isSolid() || !rel.getUp().isSolid()) { + // Inner area of the circle is sculk + if (equationResult <= 0.7 * (1 + 0.7 * noiseVal)) { + rel.setType(OneOneNineBlockHandler.SCULK); + + // If the above is not solid, place some decorations + if (!rel.getUp().isSolid()) { + if (GenUtils.chance(random, 1, 230)) { + rel.getUp().setType(OneOneNineBlockHandler.SCULK_CATALYST); + } + else if (GenUtils.chance(random, 1, 150)) { + rel.getUp().setType(OneOneNineBlockHandler.SCULK_SENSOR); + } + else if (GenUtils.chance(random, 1, 600)) { + rel.getUp().setBlockData(OneOneNineBlockHandler.getActiveSculkShrieker()); + } + } + } + else // Outer area are sculk veins + { + for (BlockFace face : BlockUtils.sixBlockFaces) { + SimpleBlock adj = rel.getRelative(face); + if (adj.isAir()) { + new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN).setFace( + face.getOppositeFace(), + true + ).apply(adj); + } + else if (adj.getBlockData() instanceof MultipleFacing mf) { + if (mf.getAllowedFaces().contains(face.getOppositeFace())) { + mf.setFace(face.getOppositeFace(), true); + } + adj.setBlockData(mf); + } + } + } + } + else if (rel.getType() == Material.WATER) { + rel.setType(Material.CAVE_AIR); + } + } } } } - + gen.populatePathsOnly(); gen.runRoomPopulators(data, tw); } @@ -197,10 +213,10 @@ else if(rel.getType() == Material.WATER) public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_ANCIENTCITY_ENABLED.getBoolean(); } - + // Underground structures don't need a decorative buffer @Override public int getChunkBufferDistance() { - return 0; + return 0; } } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityResearchBasementHandler.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityResearchBasementHandler.java index d69810ac..284d4f2f 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityResearchBasementHandler.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityResearchBasementHandler.java @@ -23,258 +23,268 @@ public class AncientCityResearchBasementHandler { - public static void populate(@NotNull Random random, @NotNull PopulatorDataAbstract data, @NotNull CubeRoom room, @NotNull BlockFace headFacing) { - - // Clear out the room and place floor - int[] lowerCorner = room.getLowerCorner(); - int[] upperCorner = room.getUpperCorner(); - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) - for(int y = room.getY(); y < room.getY() + room.getHeight(); y++) - { - if(y == room.getY() || y == room.getY() + room.getHeight()-1) - { - if(y == room.getY() && x > lowerCorner[0] && x < upperCorner[0] - && z > lowerCorner[1] && z < upperCorner[1]) { - data.setType(x, y, z, Material.GRAY_WOOL); - data.setType(x, y-1, z, AncientCityUtils.deepslateBricks); - } - else - data.setType(x, y, z, AncientCityUtils.deepslateBricks); - } - else - data.setType(x, y, z, Material.AIR); - - } - - // Place walls - for(Entry entry:room.getFourWalls(data, 0).entrySet()) - { - Wall w = entry.getKey().getLeft(3); - for(int i = 3; i < entry.getValue()-3; i+=3) - { - w.getUp(4).setType(Material.CHISELED_DEEPSLATE); - w.setType(Material.CHISELED_DEEPSLATE); - new StairBuilder(Material.DEEPSLATE_TILE_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getUp(3)) - .setHalf(Half.TOP) - .apply(w.getUp()); - new OrientableBuilder(Material.POLISHED_BASALT) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp(2)) - .apply(w.getUp(2).getFront()); - - // Back of wall - w.getUp().getFront().setType(Material.CHISELED_DEEPSLATE); - w.getUp(3).getFront().setType(Material.CHISELED_DEEPSLATE); - w.getFront().setType(Material.DEEPSLATE_TILES); - w.getUp(4).getFront().setType(Material.DEEPSLATE_TILES); - - - // Left and right sides - for(BlockFace face:BlockUtils.getAdjacentFaces(w.getDirection())) - { - Wall temp = w.getRelative(face); - - temp.getUp(2).setType(Material.POLISHED_BASALT); - - new StairBuilder(Material.DEEPSLATE_TILE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(temp) - .setHalf(Half.TOP) - .apply(temp.getUp(4)); - - new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(temp.getUp(3)) - .setHalf(Half.TOP) - .apply(temp.getUp()); - - // rear - w.getFront().getRelative(face).Pillar(2, Material.POLISHED_BASALT); - w.getFront().getRelative(face).getUp(2).setType(Material.DEEPSLATE_TILES); - w.getFront().getRelative(face).getUp(3).Pillar(2, Material.POLISHED_BASALT); - } - - w = w.getLeft(3); - } - } - - // Place 4 solid cubes of deepslate at the corners - // Decorate the sides - for(int[] corner:room.getAllCorners(2)) - { - - SimpleBlock core = new SimpleBlock(data,corner[0],room.getY(),corner[1]); - - // Solid rectangle - for(int relX = -2; relX <= 2; relX++) - for(int relZ = -2; relZ <= 2; relZ++) - { - SimpleBlock target = core.getRelative(relX,1,relZ); - target.RPillar(4, new Random(), - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS, - Material.DEEPSLATE_BRICK_SLAB); - } - - // Stairs at the top and bottom - for(BlockFace side:BlockUtils.directBlockFaces) - { - Wall w = new Wall(core,side).getFront(3).getUp(); - if(!w.getDown().isSolid() || w.isSolid()) continue; - // w.setType(Material.RED_WOOL); - for(BlockFace adj:BlockUtils.getAdjacentFaces(side)) - { - if(w.getRelative(adj).isSolid()) continue; - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w) - .apply(w.getRelative(adj,1)) - .apply(w.getRelative(adj,2)) - .apply(w.getRelative(adj,3)) - .setHalf(Half.TOP) - .apply(w.getUp(3)) - .apply(w.getRelative(adj,1).getUp(3)) - .apply(w.getRelative(adj,2).getUp(3)) - .apply(w.getRelative(adj,3).getUp(3)); - - // Make these corners - BlockUtils.correctStairData(w.getRelative(adj,3)); - BlockUtils.correctStairData(w.getRelative(adj,3).getUp(3)); - w.getRelative(adj,2).getRear().Pillar(4, Material.POLISHED_BASALT); - } - } - } - - // Build stairs leading out of the room - int roomBreadth = BlockUtils.getAxisFromBlockFace(headFacing) == Axis.X ? room.getWidthX() : room.getWidthZ(); - SimpleBlock base = room.getCenterSimpleBlock(data).getRelative(headFacing, roomBreadth / 3); - - for(int depth = 0; depth < 10; depth++) - { - boolean breakOut = false; - for(BlockFace adj:BlockUtils.getAdjacentFaces(headFacing)) - { - Wall core = new Wall(base.getUp(), adj).getFront(2) - .getRelative(headFacing,depth); - if(core.isSolid()) {breakOut=true; break;} - if(depth == 0) - { - core.Pillar(4, Material.POLISHED_BASALT); - for(int i = 1; i < 4; i++) - core.getFront(i).Pillar(6, AncientCityUtils.deepslateBricks); - } - else - new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setDownTypes(AncientCityUtils.deepslateBricks) - .setStairwayDirection(BlockFace.UP) - .setStopAtY(room.getY()+6) - .setUpwardsCarveUntilNotSolid(false) - .build(core); - } - if(breakOut) break; - } - - // Place a center light pillar and partition the room with 8 walls - SimpleBlock pillarCent = room.getCenterSimpleBlock(data).getUp(); - for(int nx = -1; nx <= 1; nx++) - for(int nz = -1; nz <= 1; nz++) - { - pillarCent.getRelative(nx,0,nz).setType(AncientCityUtils.deepslateTiles); - pillarCent.getRelative(nx,3,nz).setType(AncientCityUtils.deepslateTiles); - } - pillarCent.getUp().Pillar(2, OneOneNineBlockHandler.SCULK_SENSOR); - for(BlockFace face:BlockUtils.directBlockFaces) - { - new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(pillarCent.getRelative(face,2)) - .setHalf(Half.TOP) - .apply(pillarCent.getRelative(face,2).getUp(3)); - - pillarCent.getRelative(face).getUp().Pillar(2, Material.REDSTONE_LAMP); - - pillarCent.getRelative(face).getRelative(BlockUtils.getLeft(face)) - .getUp().Pillar(2, Material.DEEPSLATE_BRICK_WALL); - pillarCent.getRelative(face).getRelative(BlockUtils.getLeft(face)) - .getUp().CorrectMultipleFacing(2); - } - - // Glass wall up - for(BlockFace[] faces:BlockUtils.cornerBlockFaces) - { - SimpleBlock rel = pillarCent.getRelative(faces[0], 3).getRelative(faces[1], 3); - rel.Pillar(4, Material.POLISHED_BASALT); - - for(BlockFace face:faces) { - int v = face.getModX() != 0 ? room.getWidthX()/2 - 6 : room.getWidthZ()/2 - 6; - SimpleBlock relrel = rel; - for(int i = 1; i < v; i++) - { - relrel = relrel.getRelative(face); - if(relrel.isSolid()) break; - relrel.getUp().Pillar(2, Material.GLASS_PANE); - relrel.CorrectMultipleFacing(3); - relrel.setType(AncientCityUtils.deepslateBricks); - relrel.getUp(3).setType(AncientCityUtils.deepslateBricks); - } - relrel.Pillar(4, Material.POLISHED_BASALT); - } - } - - // Place piston doors at the entrance - try { - TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pistondoor", - base.getUp().getRelative(headFacing.getOppositeFace(),2)); - schema.parser = new AncientCitySchematicParser(); - schema.setFace(headFacing); - schema.apply(); - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - // Decorate the 4 redstone research rooms - for(BlockFace face:BlockUtils.directBlockFaces) { - // room.getCenterSimpleBlock(data).getUp().setType(Material.RED_WOOL); - SimpleBlock pasteCent = room.getCenterSimpleBlock(data).getUp() - .getRelative(face, 2) - .getRelative(BlockUtils.getLeft(face), 2); - - try { - String schematic; - - // This aligns the rooms with the head's piston entrance, as the - // rooms are of an unequal size. - if(BlockUtils.getAxisFromBlockFace(face) == BlockUtils.getAxisFromBlockFace(headFacing)) - schematic = northSouthResearchSchematics[random.nextInt(northSouthResearchSchematics.length)]; - else - schematic = eastWestResearchSchematics[random.nextInt(eastWestResearchSchematics.length)]; - - TerraSchematic schema = - TerraSchematic.load(schematic, - pasteCent); - schema.parser = new AncientCitySchematicParser(); - schema.setFace(face); - schema.apply(); - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - } - - private static final String[] northSouthResearchSchematics = new String[] { - "ancient-city/ancient-city-basement-sculkresearch", - "ancient-city/ancient-city-basement-redstoneresearch", - "ancient-city/ancient-city-basement-sleepingchamber", - }; - private static final String[] eastWestResearchSchematics = new String[] { - "ancient-city/ancient-city-basement-farm", - "ancient-city/ancient-city-basement-cage", - }; + private static final String[] northSouthResearchSchematics = new String[] { + "ancient-city/ancient-city-basement-sculkresearch", + "ancient-city/ancient-city-basement-redstoneresearch", + "ancient-city/ancient-city-basement-sleepingchamber", + }; + private static final String[] eastWestResearchSchematics = new String[] { + "ancient-city/ancient-city-basement-farm", "ancient-city/ancient-city-basement-cage", + }; + + public static void populate(@NotNull Random random, + @NotNull PopulatorDataAbstract data, + @NotNull CubeRoom room, + @NotNull BlockFace headFacing) + { + + // Clear out the room and place floor + int[] lowerCorner = room.getLowerCorner(); + int[] upperCorner = room.getUpperCorner(); + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + for (int y = room.getY(); y < room.getY() + room.getHeight(); y++) { + if (y == room.getY() || y == room.getY() + room.getHeight() - 1) { + if (y == room.getY() + && x > lowerCorner[0] + && x < upperCorner[0] + && z > lowerCorner[1] + && z < upperCorner[1]) + { + data.setType(x, y, z, Material.GRAY_WOOL); + data.setType(x, y - 1, z, AncientCityUtils.deepslateBricks); + } + else { + data.setType(x, y, z, AncientCityUtils.deepslateBricks); + } + } + else { + data.setType(x, y, z, Material.AIR); + } + + } + } + } + + // Place walls + for (Entry entry : room.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey().getLeft(3); + for (int i = 3; i < entry.getValue() - 3; i += 3) { + w.getUp(4).setType(Material.CHISELED_DEEPSLATE); + w.setType(Material.CHISELED_DEEPSLATE); + new StairBuilder(Material.DEEPSLATE_TILE_STAIRS).setFacing(w.getDirection()) + .apply(w.getUp(3)) + .setHalf(Half.TOP) + .apply(w.getUp()); + new OrientableBuilder(Material.POLISHED_BASALT).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp(2)) + .apply(w.getUp(2).getFront()); + + // Back of wall + w.getUp().getFront().setType(Material.CHISELED_DEEPSLATE); + w.getUp(3).getFront().setType(Material.CHISELED_DEEPSLATE); + w.getFront().setType(Material.DEEPSLATE_TILES); + w.getUp(4).getFront().setType(Material.DEEPSLATE_TILES); + + + // Left and right sides + for (BlockFace face : BlockUtils.getAdjacentFaces(w.getDirection())) { + Wall temp = w.getRelative(face); + + temp.getUp(2).setType(Material.POLISHED_BASALT); + + new StairBuilder(Material.DEEPSLATE_TILE_STAIRS).setFacing(face.getOppositeFace()) + .apply(temp) + .setHalf(Half.TOP) + .apply(temp.getUp(4)); + + new StairBuilder(Material.POLISHED_DEEPSLATE_STAIRS).setFacing(face.getOppositeFace()) + .apply(temp.getUp(3)) + .setHalf(Half.TOP) + .apply(temp.getUp()); + + // rear + w.getFront().getRelative(face).Pillar(2, Material.POLISHED_BASALT); + w.getFront().getRelative(face).getUp(2).setType(Material.DEEPSLATE_TILES); + w.getFront().getRelative(face).getUp(3).Pillar(2, Material.POLISHED_BASALT); + } + + w = w.getLeft(3); + } + } + + // Place 4 solid cubes of deepslate at the corners + // Decorate the sides + for (int[] corner : room.getAllCorners(2)) { + + SimpleBlock core = new SimpleBlock(data, corner[0], room.getY(), corner[1]); + + // Solid rectangle + for (int relX = -2; relX <= 2; relX++) { + for (int relZ = -2; relZ <= 2; relZ++) { + SimpleBlock target = core.getRelative(relX, 1, relZ); + target.RPillar( + 4, + new Random(), + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICKS, + Material.CRACKED_DEEPSLATE_BRICKS, + Material.DEEPSLATE_BRICK_SLAB + ); + } + } + + // Stairs at the top and bottom + for (BlockFace side : BlockUtils.directBlockFaces) { + Wall w = new Wall(core, side).getFront(3).getUp(); + if (!w.getDown().isSolid() || w.isSolid()) { + continue; + } + // w.setType(Material.RED_WOOL); + for (BlockFace adj : BlockUtils.getAdjacentFaces(side)) { + if (w.getRelative(adj).isSolid()) { + continue; + } + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w) + .apply(w.getRelative(adj, 1)) + .apply(w.getRelative(adj, 2)) + .apply(w.getRelative(adj, 3)) + .setHalf(Half.TOP) + .apply(w.getUp(3)) + .apply(w.getRelative(adj, 1).getUp(3)) + .apply(w.getRelative(adj, 2).getUp(3)) + .apply(w.getRelative(adj, 3).getUp(3)); + + // Make these corners + BlockUtils.correctStairData(w.getRelative(adj, 3)); + BlockUtils.correctStairData(w.getRelative(adj, 3).getUp(3)); + w.getRelative(adj, 2).getRear().Pillar(4, Material.POLISHED_BASALT); + } + } + } + + // Build stairs leading out of the room + int roomBreadth = BlockUtils.getAxisFromBlockFace(headFacing) == Axis.X ? room.getWidthX() : room.getWidthZ(); + SimpleBlock base = room.getCenterSimpleBlock(data).getRelative(headFacing, roomBreadth / 3); + + for (int depth = 0; depth < 10; depth++) { + boolean breakOut = false; + for (BlockFace adj : BlockUtils.getAdjacentFaces(headFacing)) { + Wall core = new Wall(base.getUp(), adj).getFront(2).getRelative(headFacing, depth); + if (core.isSolid()) { + breakOut = true; + break; + } + if (depth == 0) { + core.Pillar(4, Material.POLISHED_BASALT); + for (int i = 1; i < 4; i++) { + core.getFront(i).Pillar(6, AncientCityUtils.deepslateBricks); + } + } + else { + new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS).setDownTypes(AncientCityUtils.deepslateBricks) + .setStairwayDirection(BlockFace.UP) + .setStopAtY(room.getY() + 6) + .setUpwardsCarveUntilNotSolid(false) + .build(core); + } + } + if (breakOut) { + break; + } + } + + // Place a center light pillar and partition the room with 8 walls + SimpleBlock pillarCent = room.getCenterSimpleBlock(data).getUp(); + for (int nx = -1; nx <= 1; nx++) { + for (int nz = -1; nz <= 1; nz++) { + pillarCent.getRelative(nx, 0, nz).setType(AncientCityUtils.deepslateTiles); + pillarCent.getRelative(nx, 3, nz).setType(AncientCityUtils.deepslateTiles); + } + } + pillarCent.getUp().Pillar(2, OneOneNineBlockHandler.SCULK_SENSOR); + for (BlockFace face : BlockUtils.directBlockFaces) { + new StairBuilder(Material.DEEPSLATE_BRICK_STAIRS).setFacing(face.getOppositeFace()) + .apply(pillarCent.getRelative(face, 2)) + .setHalf(Half.TOP) + .apply(pillarCent.getRelative(face, 2).getUp(3)); + + pillarCent.getRelative(face).getUp().Pillar(2, Material.REDSTONE_LAMP); + + pillarCent.getRelative(face) + .getRelative(BlockUtils.getLeft(face)) + .getUp() + .Pillar(2, Material.DEEPSLATE_BRICK_WALL); + pillarCent.getRelative(face).getRelative(BlockUtils.getLeft(face)).getUp().CorrectMultipleFacing(2); + } + + // Glass wall up + for (BlockFace[] faces : BlockUtils.cornerBlockFaces) { + SimpleBlock rel = pillarCent.getRelative(faces[0], 3).getRelative(faces[1], 3); + rel.Pillar(4, Material.POLISHED_BASALT); + + for (BlockFace face : faces) { + int v = face.getModX() != 0 ? room.getWidthX() / 2 - 6 : room.getWidthZ() / 2 - 6; + SimpleBlock relrel = rel; + for (int i = 1; i < v; i++) { + relrel = relrel.getRelative(face); + if (relrel.isSolid()) { + break; + } + relrel.getUp().Pillar(2, Material.GLASS_PANE); + relrel.CorrectMultipleFacing(3); + relrel.setType(AncientCityUtils.deepslateBricks); + relrel.getUp(3).setType(AncientCityUtils.deepslateBricks); + } + relrel.Pillar(4, Material.POLISHED_BASALT); + } + } + + // Place piston doors at the entrance + try { + TerraSchematic schema = TerraSchematic.load("ancient-city/ancient-city-pistondoor", + base.getUp().getRelative(headFacing.getOppositeFace(), 2) + ); + schema.parser = new AncientCitySchematicParser(); + schema.setFace(headFacing); + schema.apply(); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + // Decorate the 4 redstone research rooms + for (BlockFace face : BlockUtils.directBlockFaces) { + // room.getCenterSimpleBlock(data).getUp().setType(Material.RED_WOOL); + SimpleBlock pasteCent = room.getCenterSimpleBlock(data) + .getUp() + .getRelative(face, 2) + .getRelative(BlockUtils.getLeft(face), 2); + + try { + String schematic; + + // This aligns the rooms with the head's piston entrance, as the + // rooms are of an unequal size. + if (BlockUtils.getAxisFromBlockFace(face) == BlockUtils.getAxisFromBlockFace(headFacing)) { + schematic = northSouthResearchSchematics[random.nextInt(northSouthResearchSchematics.length)]; + } + else { + schematic = eastWestResearchSchematics[random.nextInt(eastWestResearchSchematics.length)]; + } + + TerraSchematic schema = TerraSchematic.load(schematic, pasteCent); + schema.parser = new AncientCitySchematicParser(); + schema.setFace(face); + schema.apply(); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityRuinsPlatform.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityRuinsPlatform.java index a0946e33..afc2457f 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityRuinsPlatform.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityRuinsPlatform.java @@ -17,39 +17,44 @@ public class AncientCityRuinsPlatform extends AncientCityAbstractRoomPopulator { - public AncientCityRuinsPlatform(TerraformWorld tw, HashSet occupied, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { + public AncientCityRuinsPlatform(TerraformWorld tw, + HashSet occupied, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { super(tw, gen, rand, forceSpawn, unique); } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - - FastNoise ruinsNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.STRUCTURE_ANCIENTCITY_RUINS, - world -> { - FastNoise n = new FastNoise((int) (world.getSeed() * 11)); - n.SetNoiseType(FastNoise.NoiseType.Simplex); - n.SetFrequency(0.09f); - - return n; - }); - - int totalPillars = 0; - for(Entry entry:this.effectiveRoom.getFourWalls(data, 2).entrySet()) - { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - - w.LPillar(Math.round(Math.abs(5*ruinsNoise.GetNoise(totalPillars,0))), AncientCityUtils.deepslateBricks); - - w = w.getLeft(); - totalPillars++; - } - } - - super.sculkUp(tw, data, this.effectiveRoom); + super.populate(data, room); + + FastNoise ruinsNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_ANCIENTCITY_RUINS, world -> { + FastNoise n = new FastNoise((int) (world.getSeed() * 11)); + n.SetNoiseType(FastNoise.NoiseType.Simplex); + n.SetFrequency(0.09f); + + return n; + }); + + int totalPillars = 0; + for (Entry entry : this.effectiveRoom.getFourWalls(data, 2).entrySet()) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + + w.LPillar( + Math.round(Math.abs(5 * ruinsNoise.GetNoise(totalPillars, 0))), + AncientCityUtils.deepslateBricks + ); + + w = w.getLeft(); + totalPillars++; + } + } + + super.sculkUp(tw, data, this.effectiveRoom); } @Override diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicParser.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicParser.java index 632b026b..199eb341 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicParser.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicParser.java @@ -15,40 +15,40 @@ public class AncientCitySchematicParser extends SchematicParser { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - Random rand = new Random(); - if(data.getMaterial() == Material.DEEPSLATE_TILES) - { // Crack deepslate tiles - if(rand.nextBoolean()) - data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_TILES); - } - else if(data.getMaterial() == Material.DEEPSLATE_BRICKS) - { // Crack deepslate bricks - if(rand.nextBoolean()) - data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_BRICKS); - } - else if(data.getMaterial() == Material.DARK_OAK_PLANKS || data.getMaterial() == Material.DARK_OAK_SLAB) - { // Rot some wood away - if(rand.nextBoolean()) - data = Bukkit.createBlockData(Material.AIR); - } - else if(data.getMaterial() == Material.CANDLE) - { + Random rand = new Random(); + if (data.getMaterial() == Material.DEEPSLATE_TILES) { // Crack deepslate tiles + if (rand.nextBoolean()) { + data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_TILES); + } + } + else if (data.getMaterial() == Material.DEEPSLATE_BRICKS) { // Crack deepslate bricks + if (rand.nextBoolean()) { + data = Bukkit.createBlockData(Material.CRACKED_DEEPSLATE_BRICKS); + } + } + else if (data.getMaterial() == Material.DARK_OAK_PLANKS + || data.getMaterial() == Material.DARK_OAK_SLAB) + { // Rot some wood away + if (rand.nextBoolean()) { + data = Bukkit.createBlockData(Material.AIR); + } + } + else if (data.getMaterial() == Material.CANDLE) { Candle candle = (Candle) Bukkit.createBlockData(Material.CANDLE); candle.setLit(true); - candle.setCandles(1+rand.nextInt(4)); + candle.setCandles(1 + rand.nextInt(4)); data = candle; } - else if(data.getMaterial() == Material.CHEST) - { // Populate chests - if (GenUtils.chance(rand, 2, 5)) { - block.setType(Material.AIR); - return; // 2 fifths of chests are not placed. - } - super.applyData(block, data); - block.getPopData().lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.ANCIENT_CITY); - return; // do not apply data again. - } - super.applyData(block, data); + else if (data.getMaterial() == Material.CHEST) { // Populate chests + if (GenUtils.chance(rand, 2, 5)) { + block.setType(Material.AIR); + return; // 2 fifths of chests are not placed. + } + super.applyData(block, data); + block.getPopData().lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.ANCIENT_CITY); + return; // do not apply data again. + } + super.applyData(block, data); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicPlatform.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicPlatform.java index 1cf43ee7..98c37ef7 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicPlatform.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCitySchematicPlatform.java @@ -21,40 +21,45 @@ /** * This used to be for just towers, but since the formula for paste-schematic, then * delete a random corner works well, this will be used for any schematic. - * @author Leonard * + * @author Leonard */ public class AncientCitySchematicPlatform extends AncientCityAbstractRoomPopulator { - public AncientCitySchematicPlatform(TerraformWorld tw, HashSet occupied, RoomLayoutGenerator gen, Random rand, boolean forceSpawn, boolean unique) { - super(tw, gen, rand, forceSpawn, unique); - } - private final String @NotNull [] smallSchematics = new String[] { - "ancient-city/ancient-city-wood-tower-1", - "ancient-city/ancient-city-rock-tower-1", - "ancient-city/ancient-city-lamp", - }; + "ancient-city/ancient-city-wood-tower-1", + "ancient-city/ancient-city-rock-tower-1", + "ancient-city/ancient-city-lamp", + }; private final String @NotNull [] mediumSchematics = new String[] { - "ancient-city/ancient-city-hot-tub", - "ancient-city/ancient-city-warehouse", - }; + "ancient-city/ancient-city-hot-tub", "ancient-city/ancient-city-warehouse", + }; private final String @NotNull [] largeSchematics = new String[] { - "ancient-city/ancient-city-pantheon", - }; + "ancient-city/ancient-city-pantheon", + }; + public AncientCitySchematicPlatform(TerraformWorld tw, + HashSet occupied, + RoomLayoutGenerator gen, + Random rand, + boolean forceSpawn, + boolean unique) + { + super(tw, gen, rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - - int platformSize = 0; // 0 - small, 1 - medium, 2 - large - if(this.effectiveRoom.getWidthX() >= 10 - && this.effectiveRoom.getWidthZ() >= 10) - platformSize = 1; - if(this.effectiveRoom.getWidthX() >= 16 - && this.effectiveRoom.getWidthZ() >= 16) - platformSize = 2; - - String chosenSchema = switch(platformSize) { + super.populate(data, room); + + int platformSize = 0; // 0 - small, 1 - medium, 2 - large + if (this.effectiveRoom.getWidthX() >= 10 && this.effectiveRoom.getWidthZ() >= 10) { + platformSize = 1; + } + if (this.effectiveRoom.getWidthX() >= 16 && this.effectiveRoom.getWidthZ() >= 16) { + platformSize = 2; + } + + String chosenSchema = switch (platformSize) { case 0 -> { TerraformGeneratorPlugin.logger.info("Small Schematic"); yield smallSchematics[rand.nextInt(smallSchematics.length)]; @@ -71,25 +76,25 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room }; try { - SimpleBlock center = this.effectiveRoom.getCenterSimpleBlock(data).getUp(); - TerraSchematic schema = TerraSchematic.load(chosenSchema, center); + SimpleBlock center = this.effectiveRoom.getCenterSimpleBlock(data).getUp(); + TerraSchematic schema = TerraSchematic.load(chosenSchema, center); schema.parser = new AncientCitySchematicParser(); schema.setFace(BlockUtils.getDirectBlockFace(rand)); schema.apply(); - + // 12 blocks up, possibly spawn an air sphere to make the thing broken. - if(GenUtils.chance(rand, 1, 2)){ - new SphereBuilder(new Random(), - center.getRelative(BlockUtils.getXZPlaneBlockFace(rand), 4).getUp(11), - Material.CAVE_AIR) - .setHardReplace(true) - .setRadius((float) GenUtils.randDouble(rand, 3, 5)) - .build(); + if (GenUtils.chance(rand, 1, 2)) { + new SphereBuilder( + new Random(), + center.getRelative(BlockUtils.getXZPlaneBlockFace(rand), 4).getUp(11), + Material.CAVE_AIR + ).setHardReplace(true).setRadius((float) GenUtils.randDouble(rand, 3, 5)).build(); } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - super.sculkUp(tw, data, this.effectiveRoom); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + super.sculkUp(tw, data, this.effectiveRoom); } @Override diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityUtils.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityUtils.java index f003f75e..1412c1c6 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityUtils.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityUtils.java @@ -19,85 +19,96 @@ public class AncientCityUtils { public static final Material[] deepslateBricks = new Material[] { - Material.DEEPSLATE_BRICKS, - Material.CRACKED_DEEPSLATE_BRICKS + Material.DEEPSLATE_BRICKS, Material.CRACKED_DEEPSLATE_BRICKS }; public static final Material[] deepslateTiles = new Material[] { - Material.DEEPSLATE_TILES, - Material.CRACKED_DEEPSLATE_TILES + Material.DEEPSLATE_TILES, Material.CRACKED_DEEPSLATE_TILES }; + private static @Nullable Tag t = null; public static void placeSupportPillar(@NotNull SimpleBlock w) { Random dud = new Random(); // w.getUp().lsetType(Material.GRAY_WOOL); w.downUntilSolid(dud, Material.DEEPSLATE_BRICKS); - for(BlockFace face : BlockUtils.directBlockFaces) + for (BlockFace face : BlockUtils.directBlockFaces) { w.getRelative(face).downUntilSolid(dud, Material.DEEPSLATE_BRICKS); + } - for(BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { int height = w.getRelative(face).downUntilSolid(dud, Material.COBBLED_DEEPSLATE_WALL); // w.getRelative(face).getUp().lsetType(Material.GRAY_WOOL); w.getRelative(face).getDown(height - 1).CorrectMultipleFacing(height); } } - private static @Nullable Tag t = null; - @SuppressWarnings("unchecked") - public static void spreadSculk(@NotNull FastNoise circleNoise, @NotNull Random random, float radius, @NotNull SimpleBlock center) { - if(t == null) { + public static void spreadSculk(@NotNull FastNoise circleNoise, + @NotNull Random random, + float radius, + @NotNull SimpleBlock center) + { + if (t == null) { try { t = (Tag) Tag.class.getDeclaredField("SCULK_REPLACEABLE_WORLD_GEN").get(null); - } catch(Exception e) { + } + catch (Exception e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } boolean placedShrieker = false; boolean placedSensor = false; boolean placedCatalyst = false; - for(float nx = -radius; nx <= radius; nx++) { - for(float nz = -radius; nz <= radius; nz++) { - for(float ny = -radius; ny <= radius; ny++) { + for (float nx = -radius; nx <= radius; nx++) { + for (float nz = -radius; nz <= radius; nz++) { + for (float ny = -radius; ny <= radius; ny++) { SimpleBlock rel = center.getRelative(Math.round(nx), Math.round(ny), Math.round(nz)); - if(!rel.isSolid() - || rel.getType() == OneOneNineBlockHandler.SCULK_VEIN) + if (!rel.isSolid() || rel.getType() == OneOneNineBlockHandler.SCULK_VEIN) { continue; + } // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(nx, 2) / Math.pow(radius, 2) - + Math.pow(nz, 2) / Math.pow(radius, 2) + Math.pow(ny, 2) / Math.pow(radius, 2); + double equationResult = Math.pow(nx, 2) / Math.pow(radius, 2) + Math.pow(nz, 2) / Math.pow( + radius, + 2 + ) + Math.pow(ny, 2) / Math.pow(radius, 2); float noiseVal = circleNoise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); - if(equationResult <= 1 + 0.7 * noiseVal) { - if(BlockUtils.isExposedToNonSolid(rel) || !rel.getDown().isSolid() || !rel.getUp().isSolid()) { + if (equationResult <= 1 + 0.7 * noiseVal) { + if (BlockUtils.isExposedToNonSolid(rel) || !rel.getDown().isSolid() || !rel.getUp().isSolid()) { // Inner area of the circle is sculk - if(t.isTagged(rel.getType()) && equationResult <= 0.7 * (1 + 0.7 * noiseVal)) { + if (t.isTagged(rel.getType()) && equationResult <= 0.7 * (1 + 0.7 * noiseVal)) { rel.setType(OneOneNineBlockHandler.SCULK); // If the above is not solid, place some decorations - if(!rel.getUp().isSolid()) - if(!placedCatalyst && GenUtils.chance(random, 1, 40)) { + if (!rel.getUp().isSolid()) { + if (!placedCatalyst && GenUtils.chance(random, 1, 40)) { placedCatalyst = true; rel.getUp().setType(OneOneNineBlockHandler.SCULK_CATALYST); - } else if(!placedSensor && GenUtils.chance(random, 1, 20)) { + } + else if (!placedSensor && GenUtils.chance(random, 1, 20)) { placedSensor = true; rel.getUp().setType(OneOneNineBlockHandler.SCULK_SENSOR); - } else if(!placedShrieker && GenUtils.chance(random, 1, 90)) { + } + else if (!placedShrieker && GenUtils.chance(random, 1, 90)) { placedShrieker = true; rel.getUp().setBlockData(OneOneNineBlockHandler.getActiveSculkShrieker()); } - } else if(rel.getType() != OneOneNineBlockHandler.SCULK_SHRIEKER - && rel.getType() != OneOneNineBlockHandler.SCULK_SENSOR - && !Tag.STAIRS.isTagged(rel.getType()) - && !Tag.SLABS.isTagged(rel.getType()))// Outer area are sculk veins + } + } + else if (rel.getType() != OneOneNineBlockHandler.SCULK_SHRIEKER + && rel.getType() != OneOneNineBlockHandler.SCULK_SENSOR + && !Tag.STAIRS.isTagged(rel.getType()) + && !Tag.SLABS.isTagged(rel.getType()))// Outer area are sculk veins { - for(BlockFace face : BlockUtils.sixBlockFaces) { + for (BlockFace face : BlockUtils.sixBlockFaces) { SimpleBlock adj = rel.getRelative(face); - if(adj.isAir()) { - new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN) - .setFace(face.getOppositeFace(), true) - .apply(adj); - } else if(adj.getType() == OneOneNineBlockHandler.SCULK_VEIN) { + if (adj.isAir()) { + new MultipleFacingBuilder(OneOneNineBlockHandler.SCULK_VEIN).setFace( + face.getOppositeFace(), + true + ).apply(adj); + } + else if (adj.getType() == OneOneNineBlockHandler.SCULK_VEIN) { MultipleFacing mf = (MultipleFacing) adj.getBlockData(); mf.setFace(face.getOppositeFace(), true); adj.setBlockData(mf); diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java index 4d1d01cd..fd46a370 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java @@ -19,71 +19,72 @@ public class CatacombsCasketRoomPopulator extends CatacombsStandardPopulator { - public CatacombsCasketRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsCasketRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - - spawnCasket(new Wall(center, BlockUtils.getDirectBlockFace(rand)),rand); - - super.spawnHangingChains(data, room); + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + + spawnCasket(new Wall(center, BlockUtils.getDirectBlockFace(rand)), rand); + + super.spawnHangingChains(data, room); } - - private void spawnCasket(@NotNull Wall target, @NotNull Random rand) { - for(BlockFace face:BlockUtils.directBlockFaces) { - if(face == target.getDirection()) continue; - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setOpen(true) - .setFacing(face) - .apply(target.getRelative(face)); - } - for(BlockFace face:BlockUtils.directBlockFaces) { - if(face == target.getDirection().getOppositeFace()) continue; - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setOpen(true) - .setFacing(face) - .apply(target.getFront().getRelative(face)); - } - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(BlockUtils.getLeft(target.getDirection())) - .apply(target.getUp()) - .apply(target.getFront().getUp()); - - switch(rand.nextInt(3)) { - case 0: - // Chest inside the casket. - if ( TConfigOption.areDecorationsEnabled() ) { - new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getLeft(target.getDirection())) - .setLootTable(TerraLootTable.SIMPLE_DUNGEON) - .apply(target) - .extend(target, target.getFront(), false); - } - break; - case 1: - // Skull and redstone - if ( TConfigOption.areDecorationsEnabled() ) { - new RotatableBuilder(Material.SKELETON_SKULL).setRotation(BlockUtils.getXZPlaneBlockFace(rand)) - .apply(target); - target.getFront().setType(Material.REDSTONE_WIRE); + private void spawnCasket(@NotNull Wall target, @NotNull Random rand) { + for (BlockFace face : BlockUtils.directBlockFaces) { + if (face == target.getDirection()) { + continue; } - break; - default: - // spiders - if ( TConfigOption.areAnimalsEnabled() ) { - target.addEntity(EntityType.CAVE_SPIDER); - target.getFront().addEntity(EntityType.CAVE_SPIDER); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setOpen(true) + .setFacing(face) + .apply(target.getRelative(face)); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + if (face == target.getDirection().getOppositeFace()) { + continue; } - break; - } + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setOpen(true) + .setFacing(face) + .apply(target.getFront().getRelative(face)); + } + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(BlockUtils.getLeft(target.getDirection())) + .apply(target.getUp()) + .apply(target.getFront().getUp()); + + switch (rand.nextInt(3)) { + case 0: + // Chest inside the casket. + if (TConfigOption.areDecorationsEnabled()) { + new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getLeft(target.getDirection())) + .setLootTable(TerraLootTable.SIMPLE_DUNGEON) + .apply(target) + .extend(target, target.getFront(), false); + } + break; + case 1: + // Skull and redstone + if (TConfigOption.areDecorationsEnabled()) { + new RotatableBuilder(Material.SKELETON_SKULL).setRotation(BlockUtils.getXZPlaneBlockFace(rand)) + .apply(target); + target.getFront().setType(Material.REDSTONE_WIRE); + } + break; + default: + // spiders + if (TConfigOption.areAnimalsEnabled()) { + target.addEntity(EntityType.CAVE_SPIDER); + target.getFront().addEntity(EntityType.CAVE_SPIDER); + } + break; + } } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneBasinPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneBasinPopulator.java index 813b21a2..7fb268a9 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneBasinPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneBasinPopulator.java @@ -16,39 +16,38 @@ public class CatacombsDripstoneBasinPopulator extends CatacombsStandardPopulator { - public CatacombsDripstoneBasinPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsDripstoneBasinPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - - new SphereBuilder(new Random(), center.getDown(), Material.WATER) - .setRadius(3f) - .setSphereType(SphereType.LOWER_SEMISPHERE) - .setDoLiquidContainment(true) - .setHardReplace(true) - .build(); - - new CylinderBuilder(new Random(), center.getUp(10), Material.CAVE_AIR) - .setRadius(2.5f) - .setRY(6f) - .setHardReplace(true) - .build(); - - // Sea pickles - for(int i = 2; i <= GenUtils.randInt(2, 5); i++) - { - int[] coords = room.randomCoords(rand, 2); - SimpleBlock target = new SimpleBlock(data, coords[0], room.getY()+1, coords[2]); - target = target.findFloor(room.getHeight()); - if(target == null || !BlockUtils.isWet(target.getUp())) continue; - - CoralGenerator.generateSeaPickles(data, target.getX(), target.getY()+1, target.getZ()); - } + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + + new SphereBuilder(new Random(), center.getDown(), Material.WATER).setRadius(3f) + .setSphereType(SphereType.LOWER_SEMISPHERE) + .setDoLiquidContainment(true) + .setHardReplace(true) + .build(); + + new CylinderBuilder(new Random(), center.getUp(10), Material.CAVE_AIR).setRadius(2.5f) + .setRY(6f) + .setHardReplace(true) + .build(); + + // Sea pickles + for (int i = 2; i <= GenUtils.randInt(2, 5); i++) { + int[] coords = room.randomCoords(rand, 2); + SimpleBlock target = new SimpleBlock(data, coords[0], room.getY() + 1, coords[2]); + target = target.findFloor(room.getHeight()); + if (target == null || !BlockUtils.isWet(target.getUp())) { + continue; + } + + CoralGenerator.generateSeaPickles(data, target.getX(), target.getY() + 1, target.getZ()); + } } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneCavern.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneCavern.java index 0de48815..7477132e 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneCavern.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsDripstoneCavern.java @@ -13,30 +13,28 @@ public class CatacombsDripstoneCavern extends CatacombsStandardPopulator { - public CatacombsDripstoneCavern(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsDripstoneCavern(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - new SphereBuilder(new Random(), center.getDown(), Material.CAVE_AIR) - .setRadius(3f) - .setHardReplace(true) - .build(); - - for(int i = 3; i <= GenUtils.randInt(3, 7); i++) - { - int[] coords = room.randomCoords(rand, 3); - SimpleBlock target = new SimpleBlock(data, coords[0], room.getY()+1, coords[2]); - target = target.findCeiling(room.getHeight()); - if(target == null || target.getY() - room.getY() < 4) continue; - - target.setType(Material.DRIPSTONE_BLOCK); - BlockUtils.downLPointedDripstone(GenUtils.randInt(rand, 1, 3), target.getDown()); - } + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + new SphereBuilder(new Random(), center.getDown(), Material.CAVE_AIR).setRadius(3f).setHardReplace(true).build(); + + for (int i = 3; i <= GenUtils.randInt(3, 7); i++) { + int[] coords = room.randomCoords(rand, 3); + SimpleBlock target = new SimpleBlock(data, coords[0], room.getY() + 1, coords[2]); + target = target.findCeiling(room.getHeight()); + if (target == null || target.getY() - room.getY() < 4) { + continue; + } + + target.setType(Material.DRIPSTONE_BLOCK); + BlockUtils.downLPointedDripstone(GenUtils.randInt(rand, 1, 3), target.getDown()); + } } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java index 2b9fd946..64648e1d 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java @@ -19,132 +19,147 @@ import java.util.Random; public class CatacombsPathPopulator extends PathPopulatorAbstract { + public static final Material[] pathMaterial = new Material[] { + Material.DIRT, Material.COARSE_DIRT, Material.ROOTED_DIRT, Material.DRIPSTONE_BLOCK + }; private final Random rand; - public CatacombsPathPopulator(Random rand) { this.rand = rand; } - + @Override public int getPathMaxBend() { - return 15; + return 15; } @Override public void populate(@NotNull PathPopulatorData ppd) { Wall core = new Wall(ppd.base, ppd.dir); - + // Was populated before. - if (core.getType() != Material.CAVE_AIR) + if (core.getType() != Material.CAVE_AIR) { return; + } Wall ceiling = core.findCeiling(10); if (ceiling != null) { ceiling = ceiling.getDown(); } Wall floor = core.getDown(); - if(!floor.isSolid()) return; // Don't populate a path if there's no floor - + if (!floor.isSolid()) { + return; // Don't populate a path if there's no floor + } + // Set the base path material to a brownish-dirt texture core.setType(pathMaterial); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) - if(rand.nextBoolean()) - core.getRelative(face).setType(pathMaterial); - + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + if (rand.nextBoolean()) { + core.getRelative(face).setType(pathMaterial); + } + } + // Spawn supports boolean spawnSupports = true; - for(BlockFace dir:BlockUtils.getAdjacentFaces(core.getDirection())) { - Wall relPillar = core.getUp().findDir(dir, 2); - if(relPillar == null || !relPillar.getDown().isSolid() || !relPillar.getUp().isSolid() || !relPillar.getUp(3).getRelative(dir.getOppositeFace()).isSolid()) { - spawnSupports = false; + for (BlockFace dir : BlockUtils.getAdjacentFaces(core.getDirection())) { + Wall relPillar = core.getUp().findDir(dir, 2); + if (relPillar == null || !relPillar.getDown().isSolid() || !relPillar.getUp().isSolid() || !relPillar.getUp( + 3).getRelative(dir.getOppositeFace()).isSolid()) + { + spawnSupports = false; + } + else if (core.getDirection().getModX() != 0) { + if (core.getX() % 5 != 0) { + spawnSupports = false; + } } - else - if (core.getDirection().getModX() != 0) { - if (core.getX() % 5 != 0) spawnSupports = false; - } else if (core.getDirection().getModZ() != 0) { - if (core.getZ() % 5 != 0) spawnSupports = false; - } - - if(spawnSupports) { // All supports can be a same-ish width - relPillar.Pillar(3, BlockUtils.stoneBricks); - - relPillar.getUp().setType(Material.CHISELED_STONE_BRICKS); - - // Tiny arch - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(dir) - .setHalf(Half.TOP) - .apply(relPillar.getUp(2).getRelative(dir.getOppositeFace())); - - // Small bases at the sides - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(core.getDirection().getOppositeFace()) - .apply(relPillar.getFront()) - .setFacing(core.getDirection()) - .apply(relPillar.getRear()); + else if (core.getDirection().getModZ() != 0) { + if (core.getZ() % 5 != 0) { + spawnSupports = false; + } + } + + if (spawnSupports) { // All supports can be a same-ish width + relPillar.Pillar(3, BlockUtils.stoneBricks); + + relPillar.getUp().setType(Material.CHISELED_STONE_BRICKS); + + // Tiny arch + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(dir) + .setHalf(Half.TOP) + .apply(relPillar.getUp(2) + .getRelative(dir.getOppositeFace())); + + // Small bases at the sides + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(core.getDirection().getOppositeFace()) + .apply(relPillar.getFront()) + .setFacing(core.getDirection()) + .apply(relPillar.getRear()); } - } - - + } + + // Apply wall decorations (skulls, andesite and chests) - for(int i = 1; i <= 3; i++) { - for(BlockFace dir:BlockUtils.getAdjacentFaces(core.getDirection())) { - Wall rel = core.getUp(i).findDir(dir, 3); - - if(rel != null) { - // wall texturing - if(rand.nextBoolean() && rel.getType() == Material.STONE) { - rel.setType(Material.ANDESITE,Material.COBBLESTONE); - } - - // Skulls - if(rel.getAtY(core.getY()).distance(core) > 1 - && BlockUtils.isStoneLike(rel.getType()) - && rand.nextBoolean()) { - new DirectionalBuilder(Material.SKELETON_WALL_SKULL) - .setFacing(dir.getOppositeFace()) - .apply(rel.getRelative(dir.getOppositeFace())); - } - - // Ground side decorations - if(i == 1) { - if(GenUtils.chance(rand, 1, 60)) { - // Chests - if ( TConfigOption.areDecorationsEnabled() ) { + for (int i = 1; i <= 3; i++) { + for (BlockFace dir : BlockUtils.getAdjacentFaces(core.getDirection())) { + Wall rel = core.getUp(i).findDir(dir, 3); + + if (rel != null) { + // wall texturing + if (rand.nextBoolean() && rel.getType() == Material.STONE) { + rel.setType(Material.ANDESITE, Material.COBBLESTONE); + } + + // Skulls + if (rel.getAtY(core.getY()).distance(core) > 1 + && BlockUtils.isStoneLike(rel.getType()) + && rand.nextBoolean()) + { + new DirectionalBuilder(Material.SKELETON_WALL_SKULL).setFacing(dir.getOppositeFace()) + .apply(rel.getRelative(dir.getOppositeFace())); + } + + // Ground side decorations + if (i == 1) { + if (GenUtils.chance(rand, 1, 60)) { + // Chests + if (TConfigOption.areDecorationsEnabled()) { new ChestBuilder(Material.CHEST).setFacing(dir.getOppositeFace()) .setLootTable(TerraLootTable.SIMPLE_DUNGEON) .apply(rel.getRelative(dir.getOppositeFace())); } - } - else if(GenUtils.chance(rand, 1, 20)) { - // Candles - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(dir) - .apply(rel.getRelative(dir.getOppositeFace())); - - BlockUtils.placeCandle(rel.getRelative(dir.getOppositeFace()).getUp(), GenUtils.randInt(1, 4),true); - } - }else if(rel.getRelative(dir.getOppositeFace()).getUp().isSolid() - && GenUtils.chance(rand, 1, 10)) { - // Cobwebs - if ( TConfigOption.areDecorationsEnabled() ) { + } + else if (GenUtils.chance(rand, 1, 20)) { + // Candles + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS + ).setHalf(Half.TOP).setFacing(dir).apply(rel.getRelative(dir.getOppositeFace())); + + BlockUtils.placeCandle( + rel.getRelative(dir.getOppositeFace()).getUp(), + GenUtils.randInt(1, 4), + true + ); + } + } + else if (rel.getRelative(dir.getOppositeFace()).getUp().isSolid() && GenUtils.chance(rand, 1, 10)) { + // Cobwebs + if (TConfigOption.areDecorationsEnabled()) { rel.getRelative(dir.getOppositeFace()).setType(Material.COBWEB); } - } - } - } + } + } + } } } - + @Override public boolean customCarve(@NotNull SimpleBlock base, BlockFace dir, int pathWidth) { Wall core = new Wall(base.getUp(2), dir); - int seed = 2293 + 5471*core.getX() + 9817*core.getY() ^ 2 + 1049*core.getZ() ^ 3; - BlockUtils.carveCaveAir(seed, - pathWidth, pathWidth, pathWidth, core.get(), false, - BlockUtils.badlandsStoneLike); + int seed = 2293 + 5471 * core.getX() + 9817 * core.getY() ^ 2 + 1049 * core.getZ() ^ 3; + BlockUtils.carveCaveAir(seed, pathWidth, pathWidth, pathWidth, core.get(), false, BlockUtils.badlandsStoneLike); return true; } @@ -154,20 +169,13 @@ public int getPathWidth() { return 2; } - public static final Material[] pathMaterial = new Material[] { - Material.DIRT, - Material.COARSE_DIRT, - Material.ROOTED_DIRT, - Material.DRIPSTONE_BLOCK - }; - public @NotNull Material getFenceMaterial() { return Material.OAK_FENCE; } - + public @NotNull Material getSupportMaterial() { return Material.OAK_LOG; } - - + + } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPillarRoomPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPillarRoomPopulator.java index 5a818137..47089c17 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPillarRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPillarRoomPopulator.java @@ -14,37 +14,37 @@ public class CatacombsPillarRoomPopulator extends CatacombsStandardPopulator { - public CatacombsPillarRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsPillarRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - center.LPillar(room.getHeight(), new Random(), Material.BONE_BLOCK); - - if(rand.nextBoolean()) - center.getUp(2).setType(Material.GOLD_BLOCK); - - for(BlockFace face:BlockUtils.directBlockFaces) { - Wall target = new Wall(center.getRelative(face),face); - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(target); - - target.getUp(2).setType(Material.ANDESITE_WALL); - target.getUp(2).CorrectMultipleFacing(1); - target.getUp(3).getFront().setType(Material.ANDESITE_WALL); - target.getUp(3).getFront().CorrectMultipleFacing(1); - - target.getUp(3).setType(Material.BONE_BLOCK); - target.getUp(4).getFront().LPillar(room.getHeight() - 4, new Random(), Material.BONE_BLOCK); - - } - - super.spawnHangingChains(data, room); + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + center.LPillar(room.getHeight(), new Random(), Material.BONE_BLOCK); + + if (rand.nextBoolean()) { + center.getUp(2).setType(Material.GOLD_BLOCK); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + Wall target = new Wall(center.getRelative(face), face); + new StairBuilder(Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS).setFacing(face.getOppositeFace()) + .apply(target); + + target.getUp(2).setType(Material.ANDESITE_WALL); + target.getUp(2).CorrectMultipleFacing(1); + target.getUp(3).getFront().setType(Material.ANDESITE_WALL); + target.getUp(3).getFront().CorrectMultipleFacing(1); + + target.getUp(3).setType(Material.BONE_BLOCK); + target.getUp(4).getFront().LPillar(room.getHeight() - 4, new Random(), Material.BONE_BLOCK); + + } + + super.spawnHangingChains(data, room); } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java index 381c2497..21ad8005 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java @@ -23,48 +23,57 @@ public class CatacombsPopulator extends SingleMegaChunkStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if ( !isEnabled()) return false; + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); int[] coords = mc.getCenterBiomeSectionBlockCoords(); - - // Do not spawn catacombs under deep oceans, there's no space. - if(biome.getType() == BiomeType.DEEP_OCEANIC) - return false; - - // Don't compete with badlandsmine for space - if(biome == BiomeBank.BADLANDS_CANYON) - return false; - - // Don't compete with villages for space. In future, this may be changed - // to allow multiple structures per megachunk - if(biome == (BiomeBank.PLAINS) - || biome == (BiomeBank.FOREST) - || biome == (BiomeBank.SAVANNA) - || biome == (BiomeBank.TAIGA) - || biome == (BiomeBank.SCARLET_FOREST) - || biome == (BiomeBank.CHERRY_GROVE)) - return false; - - // Do height and space checks + + // Do not spawn catacombs under deep oceans, there's no space. + if (biome.getType() == BiomeType.DEEP_OCEANIC) { + return false; + } + + // Don't compete with badlandsmine for space + if (biome == BiomeBank.BADLANDS_CANYON) { + return false; + } + + // Don't compete with villages for space. In future, this may be changed + // to allow multiple structures per megachunk + if (biome == (BiomeBank.PLAINS) + || biome == (BiomeBank.FOREST) + || biome == (BiomeBank.SAVANNA) + || biome == (BiomeBank.TAIGA) + || biome == (BiomeBank.SCARLET_FOREST) + || biome == (BiomeBank.CHERRY_GROVE)) + { + return false; + } + + // Do height and space checks int height = HeightMap.getBlockHeight(tw, coords[0], coords[1]); if (height < TConfigOption.STRUCTURES_CATACOMBS_MAX_Y.getInt() + 15) { // Way too little space. Abort generation. return false; } - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 17261), - (int) (TConfigOption.STRUCTURES_CATACOMBS_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_CATACOMBS_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); @@ -72,41 +81,73 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int z = coords[1]; int height = HeightMap.getBlockHeight(tw, x, z); int minY = TConfigOption.STRUCTURES_CATACOMBS_MIN_Y.getInt(); - if(!Version.isAtLeast(18) && minY < 0) minY = 8; + if (!Version.isAtLeast(18) && minY < 0) { + minY = 8; + } int y = GenUtils.randInt(minY, TConfigOption.STRUCTURES_CATACOMBS_MAX_Y.getInt()); - - spawnCatacombs(tw, - tw.getHashedRand(x, y, z, 1928374), - data, x, y + 1, z, - height - y > 25); + + spawnCatacombs(tw, tw.getHashedRand(x, y, z, 1928374), data, x, y + 1, z, height - y > 25); } - public void spawnCatacombs(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - spawnCatacombs(tw, random, data, x, y, z, true); + public void spawnCatacombs(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + spawnCatacombs(tw, random, data, x, y, z, true); } - public void spawnCatacombs(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, boolean doubleLevel) { - spawnCatacombs(tw, random, data, x, y, z, doubleLevel, 10, 50); + public void spawnCatacombs(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + boolean doubleLevel) + { + spawnCatacombs(tw, random, data, x, y, z, doubleLevel, 10, 50); } - + private boolean canGoDeeper(@NotNull TerraformWorld tw, int y, @NotNull Random random) { - TerraformGeneratorPlugin.logger.info("TW MinY: " + tw.minY + ", Rolling chance: " + ((int)(TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble()*10000d))); - return y > tw.minY + 10 - && GenUtils.chance( - random, - (int) (TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble()*10000d), - 10000); + TerraformGeneratorPlugin.logger.info("TW MinY: " + + tw.minY + + ", Rolling chance: " + + ((int) (TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble() + * 10000d))); + return y > tw.minY + 10 && GenUtils.chance(random, + (int) (TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble() * 10000d), + 10000 + ); } - public void spawnCatacombs(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, boolean doubleLevel, int numRooms, int range) { - TerraformGeneratorPlugin.logger.info("Spawning catacombs at: " + x + "," + z); + public void spawnCatacombs(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + boolean doubleLevel, + int numRooms, + int range) + { + TerraformGeneratorPlugin.logger.info("Spawning catacombs at: " + x + "," + z); + - // Level One Random hashedRand = tw.getHashedRand(x, y, z); - boolean canGoDeeper = canGoDeeper(tw,y,hashedRand); - RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); + boolean canGoDeeper = canGoDeeper(tw, y, hashedRand); + RoomLayoutGenerator gen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + ); gen.setPathPopulator(new CatacombsPathPopulator(tw.getHashedRand(x, y, z, 2))); gen.setRoomMaxX(10); gen.setRoomMaxZ(10); @@ -119,74 +160,82 @@ public void spawnCatacombs(@NotNull TerraformWorld tw, Random random, @NotNull P gen.registerRoomPopulator(new CatacombsSkeletonDungeonPopulator(random, false, false)); gen.registerRoomPopulator(new CatacombsPillarRoomPopulator(random, false, false)); gen.registerRoomPopulator(new CatacombsCasketRoomPopulator(random, false, false)); - + if (canGoDeeper) { gen.registerRoomPopulator(new CatacombsStairwayPopulator(random, true, false)); gen.registerRoomPopulator(new CatacombsDripstoneCavern(random, true, false)); } gen.calculateRoomPlacement(); gen.fill(data, tw, Material.CAVE_AIR); - + int catacombLevels = 1; RoomLayoutGenerator previousGen; while (canGoDeeper) { - if(catacombLevels >= TConfigOption.STRUCTURES_CATACOMBS_MAX_LEVELS.getInt()) - break; - y -= 15; + if (catacombLevels >= TConfigOption.STRUCTURES_CATACOMBS_MAX_LEVELS.getInt()) { + break; + } + y -= 15; // Level Two - hashedRand = tw.getHashedRand(x, y, z); - canGoDeeper = canGoDeeper(tw,y,hashedRand); - previousGen = gen; + hashedRand = tw.getHashedRand(x, y, z); + canGoDeeper = canGoDeeper(tw, y, hashedRand); + previousGen = gen; gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); gen.setPathPopulator(new CatacombsPathPopulator(tw.getHashedRand(x, y, z, 2))); int stairways = 0; - + for (CubeRoom room : previousGen.getRooms()) { if (room.getPop() instanceof CatacombsStairwayPopulator) { - CubeRoom stairwayBase = new CubeRoom( - room.getWidthX(), + CubeRoom stairwayBase = new CubeRoom(room.getWidthX(), room.getHeight(), room.getWidthZ(), - room.getX(), room.getY() - 15, room.getZ()); + room.getX(), + room.getY() - 15, + room.getZ() + ); stairwayBase.setRoomPopulator(new CatacombsStairwayBasePopulator(hashedRand, true, false)); gen.getRooms().add(stairwayBase); stairways++; - }else if (room.getPop() instanceof CatacombsDripstoneCavern) { - CubeRoom stairwayBase = new CubeRoom( - room.getWidthX(), + } + else if (room.getPop() instanceof CatacombsDripstoneCavern) { + CubeRoom stairwayBase = new CubeRoom(room.getWidthX(), room.getHeight(), room.getWidthZ(), - room.getX(), room.getY() - 15, room.getZ()); + room.getX(), + room.getY() - 15, + room.getZ() + ); stairwayBase.setRoomPopulator(new CatacombsDripstoneBasinPopulator(hashedRand, true, false)); gen.getRooms().add(stairwayBase); stairways++; } } - gen.setRoomMaxX(10); - gen.setRoomMaxZ(10); - gen.setRoomMinX(7); - gen.setRoomMinZ(7); - gen.setRoomMinHeight(7); - gen.setRoomMaxHeight(10); - gen.registerRoomPopulator(new CatacombsStandardPopulator(random, false, false)); - gen.registerRoomPopulator(new CatacombsSkeletonDungeonPopulator(random, false, false)); - gen.registerRoomPopulator(new CatacombsPillarRoomPopulator(random, false, false)); - gen.registerRoomPopulator(new CatacombsCasketRoomPopulator(random, false, false)); - - if (canGoDeeper) { - gen.registerRoomPopulator(new CatacombsStairwayPopulator(random, true, false)); - gen.registerRoomPopulator(new CatacombsDripstoneCavern(random, true, false)); - } - if(stairways <= 0) break; // no more stairways. Don't generate. - - TerraformGeneratorPlugin.logger.info("Additional Catacombs Level at: " + x + "," + z); - - gen.calculateRoomPlacement(); - gen.fill(data, tw, Material.CAVE_AIR); + gen.setRoomMaxX(10); + gen.setRoomMaxZ(10); + gen.setRoomMinX(7); + gen.setRoomMinZ(7); + gen.setRoomMinHeight(7); + gen.setRoomMaxHeight(10); + gen.registerRoomPopulator(new CatacombsStandardPopulator(random, false, false)); + gen.registerRoomPopulator(new CatacombsSkeletonDungeonPopulator(random, false, false)); + gen.registerRoomPopulator(new CatacombsPillarRoomPopulator(random, false, false)); + gen.registerRoomPopulator(new CatacombsCasketRoomPopulator(random, false, false)); + + if (canGoDeeper) { + gen.registerRoomPopulator(new CatacombsStairwayPopulator(random, true, false)); + gen.registerRoomPopulator(new CatacombsDripstoneCavern(random, true, false)); + } + if (stairways <= 0) { + break; // no more stairways. Don't generate. + } + + TerraformGeneratorPlugin.logger.info("Additional Catacombs Level at: " + x + "," + z); + + gen.calculateRoomPlacement(); + gen.fill(data, tw, Material.CAVE_AIR); } - } + } @Override public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { @@ -197,10 +246,10 @@ public void spawnCatacombs(@NotNull TerraformWorld tw, Random random, @NotNull P public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_CATACOMBS_ENABLED.getBoolean(); } - + // Underground structures don't need a decorative buffer @Override public int getChunkBufferDistance() { - return 0; + return 0; } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java index 0d64fb12..99b6c76a 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java @@ -17,43 +17,46 @@ public class CatacombsSkeletonDungeonPopulator extends CatacombsStandardPopulator { - public CatacombsSkeletonDungeonPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsSkeletonDungeonPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - - data.setSpawner(center.getX(), center.getY(), center.getZ(), EntityType.SKELETON); - - int chests = 0; - + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + + data.setSpawner(center.getX(), center.getY(), center.getZ(), EntityType.SKELETON); + + int chests = 0; + // Chests - for(Entry entry:room.getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey(); - if(chests >= 2) break; - for(int i = 0; i < entry.getValue(); i++) { - if(TConfigOption.areDecorationsEnabled() && GenUtils.chance(rand, 1, 40)) { - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.SIMPLE_DUNGEON) - .apply(w); - chests++; - } - if(chests >= 2) break; - w = w.getLeft(); - } + for (Entry entry : room.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey(); + if (chests >= 2) { + break; + } + for (int i = 0; i < entry.getValue(); i++) { + if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(rand, 1, 40)) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.SIMPLE_DUNGEON) + .apply(w); + chests++; + } + if (chests >= 2) { + break; + } + w = w.getLeft(); + } } - - super.spawnHangingChains(data, room); + + super.spawnHangingChains(data, room); } - + @Override protected boolean lightCandles() { - return false; + return false; } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayBasePopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayBasePopulator.java index 6169d2ba..2c77ae73 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayBasePopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayBasePopulator.java @@ -12,33 +12,37 @@ public class CatacombsStairwayBasePopulator extends CatacombsStandardPopulator { - public CatacombsStairwayBasePopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsStairwayBasePopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - - BlockFace stairFace = BlockFace.NORTH; - for(int relY = 0; relY <= 14; relY++) { - SimpleBlock target = center.getUp(relY); - for(BlockFace face:BlockUtils.flatBlockFaces3x3) { - target.getRelative(face).setType(Material.AIR); - if(face == stairFace) { - if(relY < 8) - target.getRelative(face).downUntilSolid(new Random(), Material.ANDESITE, Material.COBBLESTONE, Material.STONE); - else if(target.hasAdjacentSolid(BlockUtils.directBlockFaces)) - target.getRelative(face).setType(Material.ANDESITE, Material.COBBLESTONE, Material.STONE); - else - break; - } - } - - stairFace = BlockUtils.rotateXZPlaneBlockFace(stairFace, 1); - } + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + + BlockFace stairFace = BlockFace.NORTH; + for (int relY = 0; relY <= 14; relY++) { + SimpleBlock target = center.getUp(relY); + for (BlockFace face : BlockUtils.flatBlockFaces3x3) { + target.getRelative(face).setType(Material.AIR); + if (face == stairFace) { + if (relY < 8) { + target.getRelative(face) + .downUntilSolid(new Random(), Material.ANDESITE, Material.COBBLESTONE, Material.STONE); + } + else if (target.hasAdjacentSolid(BlockUtils.directBlockFaces)) { + target.getRelative(face).setType(Material.ANDESITE, Material.COBBLESTONE, Material.STONE); + } + else { + break; + } + } + } + + stairFace = BlockUtils.rotateXZPlaneBlockFace(stairFace, 1); + } } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayPopulator.java index aaf8b6d4..2eadfc4e 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStairwayPopulator.java @@ -11,22 +11,19 @@ public class CatacombsStairwayPopulator extends CatacombsStandardPopulator { - public CatacombsStairwayPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public CatacombsStairwayPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); - SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - new SphereBuilder(new Random(), center.getDown(), Material.CAVE_AIR) - .setRadius(3f) - .setHardReplace(true) - .build(); - - - super.spawnHangingChains(data, room); + super.populate(data, room); + SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); + new SphereBuilder(new Random(), center.getDown(), Material.CAVE_AIR).setRadius(3f).setHardReplace(true).build(); + + + super.spawnHangingChains(data, room); } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java index 113013e1..9d303c76 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java @@ -33,117 +33,142 @@ public CatacombsStandardPopulator(Random rand, boolean forceSpawn, boolean uniqu public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { int[] lowerCorner = room.getLowerCorner(0); int[] upperCorner = room.getUpperCorner(0); - float maxTotalDiff = room.getWidthX()/2f + room.getWidthZ()/2f; + float maxTotalDiff = room.getWidthX() / 2f + room.getWidthZ() / 2f; // Flooring and ceiling decor int y = room.getY(); - + // Flooring - new SphereBuilder(this.rand, room.getCenterSimpleBlock(data), CatacombsPathPopulator.pathMaterial) - .setRX(room.getWidthX()/2f) - .setRZ(room.getWidthZ()/2f) - .setRY(room.getWidthX()/3f) - .setHardReplace(true) - .setSphereType(SphereType.LOWER_SEMISPHERE) - .build(); - + new SphereBuilder( + this.rand, + room.getCenterSimpleBlock(data), + CatacombsPathPopulator.pathMaterial + ).setRX(room.getWidthX() / 2f) + .setRZ(room.getWidthZ() / 2f) + .setRY(room.getWidthX() / 3f) + .setHardReplace(true) + .setSphereType(SphereType.LOWER_SEMISPHERE) + .build(); + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { -// // Flooring - if(rand.nextInt(5) < 4) - data.setType(x,y,z,GenUtils.randChoice(CatacombsPathPopulator.pathMaterial)); - else if(!data.getType(x, y, z).isSolid()) { - data.setType(x,y,z,GenUtils.randChoice(Material.STONE, Material.ANDESITE, Material.CRACKED_STONE_BRICKS)); - } - - // Ceiling is a fuzzed dome. - SimpleBlock ceiling = new SimpleBlock(data, x,y+1,z).findCeiling(room.getHeight()+1); - if(ceiling != null) { - float maxDownExtend = room.getHeight()-4; - int xDiffFromCent = Math.abs(x-room.getX()) + rand.nextInt(2); - int zDiffFromCent = Math.abs(z-room.getZ()) + rand.nextInt(2); - int extend = Math.round(((xDiffFromCent+zDiffFromCent)/(maxTotalDiff)) - *maxDownExtend); - ceiling.getDown().downLPillar(new Random(), extend, Material.STONE, Material.ANDESITE, Material.CRACKED_STONE_BRICKS); - - // Cobwebs - if(TConfigOption.areDecorationsEnabled() && rand.nextInt(10) == 0) - ceiling.getDown(extend+1).getRelative(BlockUtils.getDirectBlockFace(rand)) - .lsetType(Material.COBWEB); - } + // // Flooring + if (rand.nextInt(5) < 4) { + data.setType(x, y, z, GenUtils.randChoice(CatacombsPathPopulator.pathMaterial)); + } + else if (!data.getType(x, y, z).isSolid()) { + data.setType( + x, + y, + z, + GenUtils.randChoice(Material.STONE, Material.ANDESITE, Material.CRACKED_STONE_BRICKS) + ); + } + + // Ceiling is a fuzzed dome. + SimpleBlock ceiling = new SimpleBlock(data, x, y + 1, z).findCeiling(room.getHeight() + 1); + if (ceiling != null) { + float maxDownExtend = room.getHeight() - 4; + int xDiffFromCent = Math.abs(x - room.getX()) + rand.nextInt(2); + int zDiffFromCent = Math.abs(z - room.getZ()) + rand.nextInt(2); + int extend = Math.round(((xDiffFromCent + zDiffFromCent) / (maxTotalDiff)) * maxDownExtend); + ceiling.getDown() + .downLPillar(new Random(), + extend, + Material.STONE, + Material.ANDESITE, + Material.CRACKED_STONE_BRICKS + ); + + // Cobwebs + if (TConfigOption.areDecorationsEnabled() && rand.nextInt(10) == 0) { + ceiling.getDown(extend + 1) + .getRelative(BlockUtils.getDirectBlockFace(rand)) + .lsetType(Material.COBWEB); + } + } } } - + // Walling - for(Entry entry:room.getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - - // Texture walls - w.getRear().ReplacePillar(room.getHeight(), Material.STONE, Material.ANDESITE); - if(rand.nextInt(8) == 4) { - Wall target = w.getUp(rand.nextInt(room.getHeight())+1).getRear(); - if(target.isSolid()) { - target.ReplacePillar(1,Material.POLISHED_ANDESITE); - target.getRight().ReplacePillar(1,Material.POLISHED_ANDESITE); - } - } - - // Candles on room entrances - if((w.getUp(2).getLeft().getRear().isAir()||w.getUp(2).getRight().getRear().isAir()) - && w.getUp(2).getRear().isSolid()){ - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp(2)); - - BlockUtils.placeCandle(w.getUp(3), GenUtils.randInt(1, 4),lightCandles()); - } - - w = w.getLeft(); - } + for (Entry entry : room.getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + + // Texture walls + w.getRear().ReplacePillar(room.getHeight(), Material.STONE, Material.ANDESITE); + if (rand.nextInt(8) == 4) { + Wall target = w.getUp(rand.nextInt(room.getHeight()) + 1).getRear(); + if (target.isSolid()) { + target.ReplacePillar(1, Material.POLISHED_ANDESITE); + target.getRight().ReplacePillar(1, Material.POLISHED_ANDESITE); + } + } + + // Candles on room entrances + if ((w.getUp(2).getLeft().getRear().isAir() || w.getUp(2).getRight().getRear().isAir()) && w.getUp(2) + .getRear() + .isSolid()) + { + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS + ).setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()).apply(w.getUp(2)); + + BlockUtils.placeCandle(w.getUp(3), GenUtils.randInt(1, 4), lightCandles()); + } + + w = w.getLeft(); + } } - + // Skeleton Warriors - for(int i = 0; i < 1+rand.nextInt(3); i++) - { - int[] coords = room.randomCoords(rand, 1); - SimpleBlock target = new SimpleBlock(data, coords[0], room.getY()+1, coords[2]); - target = target.getAtY(room.getY()+1); - - if(data instanceof PopulatorDataPostGen) { - Skeleton e = (Skeleton) ((PopulatorDataPostGen) data).getChunk().getWorld() - .spawnEntity(new Location(((PopulatorDataPostGen) data).getChunk().getWorld(),target.getX()+0.5,target.getY()+0.3,target.getZ()+0.5), - EntityType.SKELETON); - e.getEquipment().setItemInMainHand(new ItemStack(Material.IRON_SWORD)); - e.setPersistent(true); - } - } + for (int i = 0; i < 1 + rand.nextInt(3); i++) { + int[] coords = room.randomCoords(rand, 1); + SimpleBlock target = new SimpleBlock(data, coords[0], room.getY() + 1, coords[2]); + target = target.getAtY(room.getY() + 1); + + if (data instanceof PopulatorDataPostGen) { + Skeleton e = (Skeleton) ((PopulatorDataPostGen) data).getChunk() + .getWorld() + .spawnEntity(new Location(((PopulatorDataPostGen) data).getChunk() + .getWorld(), + target.getX() + 0.5, + target.getY() + 0.3, + target.getZ() + 0.5), EntityType.SKELETON); + e.getEquipment().setItemInMainHand(new ItemStack(Material.IRON_SWORD)); + e.setPersistent(true); + } + } } - + // This has to be isolated into another method because // the chains interfere with lPillar by being solid. // Child classes are responsible for calling this. protected void spawnHangingChains(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - if ( !TConfigOption.areDecorationsEnabled() ) return; - - for(int i = 3; i <= 10; i++) - { - int[] coords = room.randomCoords(rand, 1); - SimpleBlock target = new SimpleBlock(data, coords[0], room.getY()+1, coords[2]); - target = target.findCeiling(room.getHeight()); - if(target == null || target.getY() - room.getY() < 4) continue; - - target.getDown().downLPillar(new Random(), GenUtils.randInt(3, 5), Material.CHAIN); - } + if (!TConfigOption.areDecorationsEnabled()) { + return; + } + + for (int i = 3; i <= 10; i++) { + int[] coords = room.randomCoords(rand, 1); + SimpleBlock target = new SimpleBlock(data, coords[0], room.getY() + 1, coords[2]); + target = target.findCeiling(room.getHeight()); + if (target == null || target.getY() - room.getY() < 4) { + continue; + } + + target.getDown().downLPillar(new Random(), GenUtils.randInt(3, 5), Material.CHAIN); + } } - + protected boolean lightCandles() { - return true; + return true; } - @Override - public boolean canPopulate(CubeRoom room) { - return true; - } + @Override + public boolean canPopulate(CubeRoom room) { + return true; + } } diff --git a/common/src/main/java/org/terraform/structure/caves/GenericLargeCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/GenericLargeCavePopulator.java index c41c3182..3fb43c6a 100644 --- a/common/src/main/java/org/terraform/structure/caves/GenericLargeCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/GenericLargeCavePopulator.java @@ -21,33 +21,28 @@ public GenericLargeCavePopulator(Random rand, boolean forceSpawn, boolean unique super(rand, forceSpawn, unique); } - protected void populateFloor(SimpleBlock floor, int waterLevel){} + protected void populateFloor(SimpleBlock floor, int waterLevel) { + } - protected void populateCeilFloorPair(@NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, int height){ + protected void populateCeilFloorPair(@NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, int height) { // Stalactites - if(GenUtils.chance(rand, 1, 200)) - { + if (GenUtils.chance(rand, 1, 200)) { int r = 2; - int h = GenUtils.randInt(rand, height/4, (int) ((3f / 2f) * (height/2f))); - new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())) - .setSolidBlockType(BlockUtils.stoneOrSlate(ceil.getY())) - .makeSpike(ceil, r, h, false); + int h = GenUtils.randInt(rand, height / 4, (int) ((3f / 2f) * (height / 2f))); + new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())).setSolidBlockType(BlockUtils.stoneOrSlate( + ceil.getY())).makeSpike(ceil, r, h, false); } // Stalagmites - if(GenUtils.chance(rand, 1, 200)) - { + if (GenUtils.chance(rand, 1, 200)) { int r = 2; - int h = GenUtils.randInt(rand, height/4, (int) ((3f / 2f) * (height/2f))); - new StalactiteBuilder(BlockUtils.stoneOrSlateWall(floor.getY())) - .setSolidBlockType(BlockUtils.stoneOrSlate(floor.getY())) - .makeSpike(floor, r, h, true); + int h = GenUtils.randInt(rand, height / 4, (int) ((3f / 2f) * (height / 2f))); + new StalactiteBuilder(BlockUtils.stoneOrSlateWall(floor.getY())).setSolidBlockType(BlockUtils.stoneOrSlate( + floor.getY())).makeSpike(floor, r, h, true); } // Sea pickles - if(BlockUtils.isWet(floor.getUp()) - && GenUtils.chance(rand, 4, 100)) - { + if (BlockUtils.isWet(floor.getUp()) && GenUtils.chance(rand, 4, 100)) { SeaPickle sp = (SeaPickle) Bukkit.createBlockData(Material.SEA_PICKLE); sp.setPickles(GenUtils.randInt(1, 2)); floor.getUp().setBlockData(sp); @@ -56,20 +51,22 @@ protected void populateCeilFloorPair(@NotNull SimpleBlock ceil, @NotNull SimpleB @Override public void populate(@NotNull PopulatorDataAbstract data, CubeRoom room) { - if(!(room instanceof LargeCaveRoomPiece caveRoom)) + if (!(room instanceof LargeCaveRoomPiece caveRoom)) { throw new NotImplementedException("room for LargeCavePopulator was not a LargeCaveRoomPiece"); - assert data.getChunkX() == room.getX()>>4; - assert data.getChunkZ() == room.getZ()>>4; + } + assert data.getChunkX() == room.getX() >> 4; + assert data.getChunkZ() == room.getZ() >> 4; - caveRoom.ceilFloorPairs.forEach((l, pair)->{ - if(pair[1] != null) populateFloor(new SimpleBlock(data, pair[1]), caveRoom.waterLevel); - if(pair[0] != null && pair[1] != null) - { + caveRoom.ceilFloorPairs.forEach((l, pair) -> { + if (pair[1] != null) { + populateFloor(new SimpleBlock(data, pair[1]), caveRoom.waterLevel); + } + if (pair[0] != null && pair[1] != null) { SimpleBlock ceil = new SimpleBlock(data, pair[0]); SimpleBlock floor = new SimpleBlock(data, pair[1]); - int height = ceil.getY()-floor.getY(); + int height = ceil.getY() - floor.getY(); - populateCeilFloorPair(ceil,floor,height); + populateCeilFloorPair(ceil, floor, height); } }); } diff --git a/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java index 6a5c3293..47f9ca16 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java @@ -20,11 +20,7 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.NoiseCacheHandler; -import java.util.ArrayDeque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Objects; -import java.util.Random; +import java.util.*; public class LargeCavePopulator extends JigsawStructurePopulator { /** @@ -50,16 +46,16 @@ public class LargeCavePopulator extends JigsawStructurePopulator { int z = spawnCoords[1]; Random rand = tw.getHashedRand(x, z, 79810139); - FastNoise noise = NoiseCacheHandler.getNoise( - tw, + FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheHandler.NoiseCacheEntry.STRUCTURE_LARGECAVE_CARVER, world -> { - FastNoise n = new FastNoise((int) (world.getSeed()*8726)); + FastNoise n = new FastNoise((int) (world.getSeed() * 8726)); n.SetNoiseType(FastNoise.NoiseType.Simplex); n.SetFrequency(0.04f); return n; - }); + } + ); // Max Y: TransformedHeight // Min Y: -32 @@ -73,17 +69,23 @@ public class LargeCavePopulator extends JigsawStructurePopulator { // Random will be unused // All the arguments in gen are going to be unused too, as it won't be generating rooms GenericLargeCavePopulator cavePopulator = Objects.requireNonNull(GenUtils.choice(rand, - new GenericLargeCavePopulator[] { - new MushroomCavePopulator(tw.getHashedRand(x, 13729804, z), false, false), - new GenericLargeCavePopulator(tw.getHashedRand(x, 13729804, z), false, false), - new LargeLushCavePopulator(tw.getHashedRand(x, 13729804, z), false, false) - })); + new GenericLargeCavePopulator[] { + new MushroomCavePopulator(tw.getHashedRand(x, 13729804, z), false, false), + new GenericLargeCavePopulator(tw.getHashedRand(x, 13729804, z), false, false), + new LargeLushCavePopulator(tw.getHashedRand(x, 13729804, z), false, false) + } + )); RoomLayoutGenerator gen = new RoomLayoutGenerator(new Random(), RoomLayout.RANDOM_BRUTEFORCE, 10, x, y, z, 150); gen.setGenPaths(false); gen.roomCarver = new LargeCaveRoomCarver(GenUtils.randChoice(rand, Material.LAVA, Material.WATER)); SimpleLocation center = new SimpleLocation(x, y, z); - TerraformGeneratorPlugin.logger.info("Large Cave at " + center + " has water level > " + minY + " with populator " +cavePopulator.getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("Large Cave at " + + center + + " has water level > " + + minY + + " with populator " + + cavePopulator.getClass().getSimpleName()); HashMap chunkToRoom = new HashMap<>(); // BFS against center with "edges" as the noise equation @@ -93,43 +95,43 @@ public class LargeCavePopulator extends JigsawStructurePopulator { seen.add(center); queue.add(center); - while(!queue.isEmpty()) - { + while (!queue.isEmpty()) { SimpleLocation v = queue.remove(); // Process v - LargeCaveRoomPiece caveRoom = chunkToRoom.computeIfAbsent( - new SimpleChunkLocation(tw.getName(), - GenUtils.getTripleChunk(v.getX()>>4), - GenUtils.getTripleChunk(v.getZ()>>4)), - (loc)->{ - // Each room is 48x48 blocks wide to ensure that rooms do not carve over - // one another when writing outside their bounds. - LargeCaveRoomPiece newRoom = new LargeCaveRoomPiece( - 41, 41, 15, - GenUtils.getTripleChunk(v.getX()>>4)*16+7, - y, - GenUtils.getTripleChunk(v.getZ()>>4)*16+7); - newRoom.setRoomPopulator(cavePopulator); - gen.getRooms().add(newRoom); - return newRoom; - } - ); + LargeCaveRoomPiece caveRoom = chunkToRoom.computeIfAbsent(new SimpleChunkLocation(tw.getName(), + GenUtils.getTripleChunk(v.getX() >> 4), + GenUtils.getTripleChunk(v.getZ() >> 4) + ), (loc) -> { + // Each room is 48x48 blocks wide to ensure that rooms do not carve over + // one another when writing outside their bounds. + LargeCaveRoomPiece newRoom = new LargeCaveRoomPiece(41, + 41, + 15, + GenUtils.getTripleChunk(v.getX() >> 4) * 16 + 7, + y, + GenUtils.getTripleChunk(v.getZ() >> 4) * 16 + 7 + ); + newRoom.setRoomPopulator(cavePopulator); + gen.getRooms().add(newRoom); + return newRoom; + }); actualMinY = Math.min(actualMinY, v.getY()); boolean nextToBoundary = false; - for(BlockFace face: BlockUtils.sixBlockFaces) - { + for (BlockFace face : BlockUtils.sixBlockFaces) { SimpleLocation neighbour = v.getRelative(face); - if(seen.contains(neighbour)) continue; + if (seen.contains(neighbour)) { + continue; + } // "Edges" are whether the neighbour satisfies the equation - double equationResult = Math.pow(neighbour.getX()-center.getX(), 2) / Math.pow(rX, 2) - + Math.pow(neighbour.getY()-center.getY(), 2) / Math.pow(rY, 2) - + Math.pow(neighbour.getZ()-center.getZ(), 2) / Math.pow(rZ, 2); + double equationResult = Math.pow(neighbour.getX() - center.getX(), 2) / Math.pow(rX, 2) + + Math.pow(neighbour.getY() - center.getY(), 2) / Math.pow(rY, 2) + + Math.pow(neighbour.getZ() - center.getZ(), 2) / Math.pow(rZ, 2); double n = 0.7 * noise.GetNoise(neighbour.getX(), neighbour.getY(), neighbour.getZ()); - if (equationResult > 1 + Math.max(0,n)){ + if (equationResult > 1 + Math.max(0, n)) { nextToBoundary = true; continue; } @@ -143,8 +145,9 @@ public class LargeCavePopulator extends JigsawStructurePopulator { } // Set water levels - ((LargeCaveRoomCarver) gen.roomCarver).waterLevel = actualMinY + GenUtils.randInt(rand, 4,7); - gen.getRooms().forEach((room)->((LargeCaveRoomPiece)room).waterLevel = ((LargeCaveRoomCarver) gen.roomCarver).waterLevel); + ((LargeCaveRoomCarver) gen.roomCarver).waterLevel = actualMinY + GenUtils.randInt(rand, 4, 7); + gen.getRooms() + .forEach((room) -> ((LargeCaveRoomPiece) room).waterLevel = ((LargeCaveRoomCarver) gen.roomCarver).waterLevel); state.roomPopulatorStates.add(gen); return state; @@ -152,18 +155,21 @@ public class LargeCavePopulator extends JigsawStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12345), - (int) (TConfigOption.STRUCTURES_LARGECAVE_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_LARGECAVE_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if ( !isEnabled()) return false; + if (!isEnabled()) { + return false; + } - if(biome.getType() == BiomeType.DEEP_OCEANIC) - return false; - return rollSpawnRatio(tw,chunkX,chunkZ); + if (biome.getType() == BiomeType.DEEP_OCEANIC) { + return false; + } + return rollSpawnRatio(tw, chunkX, chunkZ); } @Override @@ -178,6 +184,6 @@ public boolean isEnabled() { @Override public int getChunkBufferDistance() { - return 0; + return 0; } } diff --git a/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomCarver.java b/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomCarver.java index 944f176d..d1ef0808 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomCarver.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomCarver.java @@ -19,30 +19,33 @@ public LargeCaveRoomCarver(Material fluid) { @Override public void carveRoom(@NotNull PopulatorDataAbstract data, CubeRoom room, Material... wallMaterial) { - if(!(room instanceof LargeCaveRoomPiece caveRoom)) + if (!(room instanceof LargeCaveRoomPiece caveRoom)) { throw new NotImplementedException("room for LargeCaveRoomCarver was not a LargeCaveRoomPiece"); + } - caveRoom.toCarve.forEach((loc, boundary)->{ - if(!boundary) { - data.setType(loc.getX(), loc.getY(), loc.getZ(), - loc.getY() > waterLevel ? Material.CAVE_AIR : fluid); + caveRoom.toCarve.forEach((loc, boundary) -> { + if (!boundary) { + data.setType(loc.getX(), loc.getY(), loc.getZ(), loc.getY() > waterLevel ? Material.CAVE_AIR : fluid); } - else - { + else { // Ensure no fluid flows out - if(loc.getY() <= waterLevel) - data.setType(loc.getX(),loc.getY(),loc.getZ(), BlockUtils.stoneOrSlate(loc.getY())); + if (loc.getY() <= waterLevel) { + data.setType(loc.getX(), loc.getY(), loc.getZ(), BlockUtils.stoneOrSlate(loc.getY())); + } // find the floors and ceilings for the populator. // Only add them to the list if the thing is solid - if(data.getType(loc.getX(),loc.getY(),loc.getZ()).isSolid()) - { - if(!caveRoom.toCarve.containsKey(loc.getDown())) + if (data.getType(loc.getX(), loc.getY(), loc.getZ()).isSolid()) { + if (!caveRoom.toCarve.containsKey(loc.getDown())) { caveRoom.ceilFloorPairs.computeIfAbsent(loc.getAtY(0), - newLoc->new SimpleLocation[2])[1] = loc; - else if(!caveRoom.toCarve.containsKey(loc.getUp())) + newLoc -> new SimpleLocation[2] + )[1] = loc; + } + else if (!caveRoom.toCarve.containsKey(loc.getUp())) { caveRoom.ceilFloorPairs.computeIfAbsent(loc.getAtY(0), - newLoc->new SimpleLocation[2])[0] = loc; + newLoc -> new SimpleLocation[2] + )[0] = loc; + } } } }); diff --git a/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomPiece.java b/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomPiece.java index 16999d73..9538d0c2 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomPiece.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeCaveRoomPiece.java @@ -7,11 +7,10 @@ public class LargeCaveRoomPiece extends CubeRoom { - protected int waterLevel = -64; - // Boolean is true if the location is a boundary. protected final HashMap toCarve = new HashMap<>(); protected final HashMap ceilFloorPairs = new HashMap<>(); + protected int waterLevel = -64; public LargeCaveRoomPiece(int widthX, int widthZ, int height, int x, int y, int z) { super(widthX, widthZ, height, x, y, z); diff --git a/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java index fa220b2b..3293d4b5 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java @@ -16,13 +16,13 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.StalactiteBuilder; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Random; -public class LargeLushCavePopulator extends GenericLargeCavePopulator{ +public class LargeLushCavePopulator extends GenericLargeCavePopulator { public LargeLushCavePopulator(Random rand, boolean forceSpawn, boolean unique) { super(rand, forceSpawn, unique); @@ -33,12 +33,13 @@ public LargeLushCavePopulator(Random rand, boolean forceSpawn, boolean unique) { */ @Override protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { - if(floor.getY() > waterLevel) return; + if (floor.getY() > waterLevel) { + return; + } int waterDepth = waterLevel - floor.getY(); TerraformWorld tw = floor.getPopData().getTerraformWorld(); - FastNoise raisedGroundNoise = NoiseCacheHandler.getNoise( - tw, + FastNoise raisedGroundNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_LARGECAVE_RAISEDGROUNDNOISE, world -> { FastNoise n = new FastNoise((int) (world.getSeed() * 5)); @@ -46,19 +47,24 @@ protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { n.SetFractalOctaves(3); n.SetFrequency(0.06f); return n; - }); + } + ); // Raise some ground up double noise = raisedGroundNoise.GetNoise(floor.getX(), floor.getZ()); - if (noise > 0){ - int h = (int) Math.round(4.3f*waterDepth*noise); - if(h > waterDepth) h = (int) Math.round(waterDepth + Math.sqrt(h-waterDepth)); + if (noise > 0) { + int h = (int) Math.round(4.3f * waterDepth * noise); + if (h > waterDepth) { + h = (int) Math.round(waterDepth + Math.sqrt(h - waterDepth)); + } floor.getUp().RPillar(h, new Random(), Material.CLAY); - floor = floor.getUp(h-1); + floor = floor.getUp(h - 1); } // Place pickles - if(floor.getY() > waterLevel) return; + if (floor.getY() > waterLevel) { + return; + } // sea pickle if (TConfigOption.arePlantsEnabled() && BlockUtils.isWet(floor.getUp()) && GenUtils.chance(rand, 7, 100)) { @@ -68,53 +74,52 @@ protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { } // Lilypads - if(GenUtils.chance(rand, 1, 200) - && BlockUtils.isWet(floor.getAtY(waterLevel)) - && floor.getAtY(waterLevel+1).isAir()) + if (GenUtils.chance(rand, 1, 200) && BlockUtils.isWet(floor.getAtY(waterLevel)) && floor.getAtY(waterLevel + 1) + .isAir()) { - PlantBuilder.LILY_PAD.build(floor.getAtY(waterLevel+1)); + PlantBuilder.LILY_PAD.build(floor.getAtY(waterLevel + 1)); } // Stalagmites - if(GenUtils.chance(rand, 1, 130)) - { + if (GenUtils.chance(rand, 1, 130)) { int r = 2; - int h = GenUtils.randInt(rand, 6*waterDepth, (int) ((3f / 2f) * (6*waterDepth))); - new StalactiteBuilder(BlockUtils.stoneOrSlateWall(floor.getY())) - .setSolidBlockType(BlockUtils.stoneOrSlate(floor.getY())) - .makeSpike(floor, r, h, true); + int h = GenUtils.randInt(rand, 6 * waterDepth, (int) ((3f / 2f) * (6 * waterDepth))); + new StalactiteBuilder(BlockUtils.stoneOrSlateWall(floor.getY())).setSolidBlockType(BlockUtils.stoneOrSlate( + floor.getY())).makeSpike(floor, r, h, true); } } + @Override protected void populateCeilFloorPair(@NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, int height) { TerraformWorld tw = ceil.getPopData().getTerraformWorld(); // Correct for clay ground raise int cutoff = height; - while(cutoff > 0 && floor.getUp().isSolid()){ + while (cutoff > 0 && floor.getUp().isSolid()) { floor = floor.getUp(); cutoff--; } - if(cutoff <= 0) return; // give up. + if (cutoff <= 0) { + return; // give up. + } // Invoke OneUnit from the lush cave populator - new LushClusterCavePopulator(10, true) - .oneUnit(tw, new Random(), ceil, floor, false); + new LushClusterCavePopulator(10, true).oneUnit(tw, new Random(), ceil, floor, false); // Spawn potential stalactites and stalagmites - if(GenUtils.chance(rand, 1, 150)) - { + if (GenUtils.chance(rand, 1, 150)) { int r = 2; - int h = GenUtils.randInt(rand, (int) (height/2.5f), (int) ((3f / 2f) * (height/2.5f))); - new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())) - .setSolidBlockType(BlockUtils.stoneOrSlate(ceil.getY())) - .makeSpike(ceil, r, h, false); + int h = GenUtils.randInt(rand, (int) (height / 2.5f), (int) ((3f / 2f) * (height / 2.5f))); + new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())).setSolidBlockType(BlockUtils.stoneOrSlate( + ceil.getY())).makeSpike(ceil, r, h, false); } // set biome - PopulatorDataICABiomeWriterAbstract biomeWriter = (PopulatorDataICABiomeWriterAbstract) TerraformGeneratorPlugin.injector.getICAData(ceil.getPopData()); - for(int ny = floor.getY(); ny <= ceil.getY(); ny++) + PopulatorDataICABiomeWriterAbstract biomeWriter = (PopulatorDataICABiomeWriterAbstract) TerraformGeneratorPlugin.injector.getICAData( + ceil.getPopData()); + for (int ny = floor.getY(); ny <= ceil.getY(); ny++) { biomeWriter.setBiome(floor.getX(), ny, floor.getZ(), Biome.LUSH_CAVES); + } } } diff --git a/common/src/main/java/org/terraform/structure/caves/MushroomCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/MushroomCavePopulator.java index 00262f72..722066d5 100644 --- a/common/src/main/java/org/terraform/structure/caves/MushroomCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/MushroomCavePopulator.java @@ -13,8 +13,8 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.StalactiteBuilder; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.Objects; @@ -33,12 +33,10 @@ public MushroomCavePopulator(Random rand, boolean forceSpawn, boolean unique) { @Override protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { TerraformWorld tw = floor.getPopData().getTerraformWorld(); - if(floor.getY() <= waterLevel) - { + if (floor.getY() <= waterLevel) { int waterDepth = waterLevel - floor.getY(); - FastNoise raisedGroundNoise = NoiseCacheHandler.getNoise( - tw, + FastNoise raisedGroundNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_LARGECAVE_RAISEDGROUNDNOISE, world -> { FastNoise n = new FastNoise((int) (world.getSeed() * 5)); @@ -46,28 +44,32 @@ protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { n.SetFractalOctaves(3); n.SetFrequency(0.06f); return n; - }); + } + ); // Raise some ground up double noise = raisedGroundNoise.GetNoise(floor.getX(), floor.getZ()); - if (noise > 0){ - int h = (int) Math.round(4.3f*waterDepth*noise); - if(h > waterDepth) h = (int) Math.round(waterDepth + Math.sqrt(h-waterDepth)); + if (noise > 0) { + int h = (int) Math.round(4.3f * waterDepth * noise); + if (h > waterDepth) { + h = (int) Math.round(waterDepth + Math.sqrt(h - waterDepth)); + } floor.getUp().RPillar(h, new Random(), Material.DIRT); floor = floor.getUp(h); // ???? } } // Water decorations come after this - if(floor.getY() >= waterLevel){ + if (floor.getY() >= waterLevel) { // Set mycelium if not underwater floor.setType(Material.MYCELIUM); // chance to set small mushshrooms - if(GenUtils.chance(rand, 7, 100)) { + if (GenUtils.chance(rand, 7, 100)) { SimpleBlock up = floor.getUp(); - if (!up.isSolid()) + if (!up.isSolid()) { PlantBuilder.build(up, PlantBuilder.RED_MUSHROOM, PlantBuilder.BROWN_MUSHROOM); + } } return; @@ -80,39 +82,46 @@ protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { floor.getUp().setBlockData(sp); } } + @Override protected void populateCeilFloorPair(@NotNull SimpleBlock ceil, @NotNull SimpleBlock floor, int height) { TerraformWorld tw = ceil.getPopData().getTerraformWorld(); // Correct for mycelium ground raise int newHeight = height; - while(newHeight > 0 && floor.getUp().isSolid()){ + while (newHeight > 0 && floor.getUp().isSolid()) { floor = floor.getUp(); newHeight--; } - if(newHeight <= 0) return; // give up. + if (newHeight <= 0) { + return; // give up. + } // Only stalactites - if(GenUtils.chance(rand, 1, 150)) - { + if (GenUtils.chance(rand, 1, 150)) { int r = 2; - int h = GenUtils.randInt(rand, (int) (height/2.5f), (int) ((3f / 2f) * (height/2.5f))); - new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())) - .setSolidBlockType(BlockUtils.stoneOrSlate(ceil.getY())) - .makeSpike(ceil, r, h, false); + int h = GenUtils.randInt(rand, (int) (height / 2.5f), (int) ((3f / 2f) * (height / 2.5f))); + new StalactiteBuilder(BlockUtils.stoneOrSlateWall(ceil.getY())).setSolidBlockType(BlockUtils.stoneOrSlate( + ceil.getY())).makeSpike(ceil, r, h, false); } // Check boundaries - the mushrooms are huge and will cut into bordering areas // and unlike stalactites, look especially fucking bad doing so - else if(floor.getChunkX() == floor.getPopData().getChunkX() - && floor.getChunkZ() == floor.getPopData().getChunkZ() - && floor.getType() == Material.MYCELIUM - && newHeight >= 15 && GenUtils.chance(rand, 1, 110)) + else if (floor.getChunkX() == floor.getPopData().getChunkX() + && floor.getChunkZ() == floor.getPopData() + .getChunkZ() + && floor.getType() == Material.MYCELIUM + && newHeight >= 15 + && GenUtils.chance(rand, 1, 110)) { // Big Mushrooms - new MushroomBuilder(Objects.requireNonNull( - GenUtils.choice(rand, FractalTypes.Mushroom.values()))) - .build(tw, floor.getPopData(), floor.getX(), floor.getY(), floor.getZ()); + new MushroomBuilder(Objects.requireNonNull(GenUtils.choice(rand, FractalTypes.Mushroom.values()))).build( + tw, + floor.getPopData(), + floor.getX(), + floor.getY(), + floor.getZ() + ); } } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMineEntranceParser.java b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMineEntranceParser.java index 5f9dbf5a..0c0e139a 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMineEntranceParser.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMineEntranceParser.java @@ -17,7 +17,7 @@ public class BadlandsMineEntranceParser extends SchematicParser { static @Nullable FastNoise noise = null; private boolean didPlaceLantern = false; - + // Don't cache, as it does not change based on terraformworld. static double getNoise(int x, int y, int z) { if (noise == null) { @@ -34,11 +34,12 @@ static double getNoise(int x, int y, int z) { public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { double noiseValue = getNoise(block.getX(), block.getY(), block.getZ()); - switch(data.getMaterial()) { + switch (data.getMaterial()) { case RED_CONCRETE: { if (noiseValue > 0) { super.applyData(block, Bukkit.createBlockData(Material.DARK_OAK_FENCE)); - } else { + } + else { Slab s = (Slab) Bukkit.createBlockData(Material.DARK_OAK_SLAB); s.setType(Slab.Type.TOP); super.applyData(block, s); @@ -63,8 +64,8 @@ public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { case DARK_OAK_FENCE: { if (willPlaceFence(block)) { block.lsetBlockData(data); - } else if (willPlaceFence(block.getUp()) - && !didPlaceLantern) { + } + else if (willPlaceFence(block.getUp()) && !didPlaceLantern) { Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); l.setHanging(true); super.applyData(block, l); @@ -85,16 +86,20 @@ public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { } case DARK_OAK_SLAB: { Slab s = (Slab) data; - if (s.getType() == Slab.Type.BOTTOM) + if (s.getType() == Slab.Type.BOTTOM) { block.lsetBlockData(data); - else super.applyData(block, data); + } + else { + super.applyData(block, data); + } break; } case OAK_STAIRS: { block.lsetBlockData(data); break; } - default: super.applyData(block, data); + default: + super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java index 627024b0..497e7e83 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java @@ -24,6 +24,7 @@ import org.terraform.structure.room.LegacyPathGenerator; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; @@ -35,28 +36,32 @@ public class BadlandsMinePopulator extends JigsawStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } - if (biome != BiomeBank.BADLANDS_CANYON) return false; + if (biome != BiomeBank.BADLANDS_CANYON) { + return false; + } // what the fuck is this - /* - * // randomObjectPositions returns chunk positions here for (Vector2f pos : - * GenUtils.vectorRandomObjectPositions(tw, chunkX >> 4, chunkZ >> 4, - * mineDistance, mineDistance * 0.3f)) { if ((int) pos.x == chunkX && (int) - * pos.y == chunkZ) { SimpleBlock s = getSpawnPosition(data, tw, chunkX, - * chunkZ); return s != null && getSpawnDirection(tw, s.getX(), s.getZ()) != - * null; } } - */ - - return rollSpawnRatio(tw,chunkX,chunkZ); + /* + * // randomObjectPositions returns chunk positions here for (Vector2f pos : + * GenUtils.vectorRandomObjectPositions(tw, chunkX >> 4, chunkZ >> 4, + * mineDistance, mineDistance * 0.3f)) { if ((int) pos.x == chunkX && (int) + * pos.y == chunkZ) { SimpleBlock s = getSpawnPosition(data, tw, chunkX, + * chunkZ); return s != null && getSpawnDirection(tw, s.getX(), s.getZ()) != + * null; } } + */ + + return rollSpawnRatio(tw, chunkX, chunkZ); } - + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override @@ -75,75 +80,92 @@ public boolean isEnabled() { public @NotNull JigsawState calculateRoomPopulators(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { return new MineshaftPopulator().calculateRoomPopulators(tw, mc, true); } + @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } BlockFace outDir, inDir; SimpleBlock entrance, shaft; // Find a suitable spawn direction - MegaChunk mc = new MegaChunk(data.getChunkX(),data.getChunkZ()); - int[] spawnCoords = mc.getCenterBiomeSectionBlockCoords(); - - // This is in the middle of a plateau. - // This must extend out until the entrance is found. - SimpleBlock spawnSpot = new SimpleBlock(data, spawnCoords[0],0,spawnCoords[1]).getGround(); + MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); + int[] spawnCoords = mc.getCenterBiomeSectionBlockCoords(); + + // This is in the middle of a plateau. + // This must extend out until the entrance is found. + SimpleBlock spawnSpot = new SimpleBlock(data, spawnCoords[0], 0, spawnCoords[1]).getGround(); // The plateau (by right,) should generate as a distorted circle. // As such, the direction can be random. - inDir = BlockUtils.getDirectBlockFace(getHashedRandom(tw,data.getChunkX(),data.getChunkZ())); + inDir = BlockUtils.getDirectBlockFace(getHashedRandom(tw, data.getChunkX(), data.getChunkZ())); outDir = inDir.getOppositeFace(); - + entrance = getSpawnEntrance(tw, spawnSpot, outDir); - + // The shaft will spawn directly at the center of the plateau, deep within // the terracotta. shaft = spawnSpot.getAtY(entrance.getY()); // entrance.getRelative(inDir, hallwayLen + sandRadius - 1); - - + + int hallwayLength; - if(BlockUtils.getAxisFromBlockFace(inDir) == Axis.X) { - hallwayLength = Math.abs(shaft.getX() - entrance.getX()); - }else { - hallwayLength = Math.abs(shaft.getZ() - entrance.getZ()); + if (BlockUtils.getAxisFromBlockFace(inDir) == Axis.X) { + hallwayLength = Math.abs(shaft.getX() - entrance.getX()); + } + else { + hallwayLength = Math.abs(shaft.getZ() - entrance.getZ()); } hallwayLength -= 6; // Don't cover the shaft entrance - + TerraformGeneratorPlugin.logger.info("Badlands Mineshaft Entrance: " + entrance); TerraformGeneratorPlugin.logger.info("Badlands Mineshaft Shaft: " + shaft); TerraformGeneratorPlugin.logger.info("Badlands Mineshaft Hallway Length: " + hallwayLength); - + Random random = tw.getHashedRand(entrance.getX(), entrance.getY(), entrance.getZ(), 4); // Spawning stuff - + // Standard mineshaft below the badlands entrance // Comment this out, the new populator will handle this // new MineshaftPopulator().spawnMineshaft(tw, random, data, shaft.getX(), shaft.getY() - shaftDepth - 5, shaft.getZ(), false, 3, 60, true); // Carve downwards hole into the mineshaft below spawnShaft(random, shaft, inDir); - + // Carve entrance out - LegacyPathGenerator g = new LegacyPathGenerator(entrance.getRelative(inDir.getModX() * 3, -1, inDir.getModZ() * 3), - new Material[] {Material.CAVE_AIR}, new Random(), new int[]{0,0}, new int[]{0,0}, -1); + LegacyPathGenerator g = new LegacyPathGenerator(entrance.getRelative( + inDir.getModX() * 3, + -1, + inDir.getModZ() * 3 + ), + new Material[] {Material.CAVE_AIR}, + new Random(), + new int[] {0, 0}, + new int[] {0, 0}, + -1 + ); g.setPopulator(new BadlandsMineshaftPathPopulator(random)); g.generateStraightPath(null, inDir, hallwayLength); - + // Create the entrance - spawnEntrance(entrance.getRelative(inDir,5), outDir); + spawnEntrance(entrance.getRelative(inDir, 5), outDir); patchEntrance(entrance, inDir); // Spawn an ore lift if (GenUtils.chance(random, 4, 5)) { try { - // Ore lift schematic. Constructor has true to replace oak with dark oak - TerraSchematic schema = TerraSchematic.load("ore-lift", new SimpleBlock(data, shaft.getX() - 1, shaft.getY() - shaftDepth, shaft.getZ() - 1)); + // Ore lift schematic. Constructor has true to replace oak with dark oak + TerraSchematic schema = TerraSchematic.load( + "ore-lift", + new SimpleBlock(data, shaft.getX() - 1, shaft.getY() - shaftDepth, shaft.getZ() - 1) + ); schema.parser = new OreLiftSchematicParser(true); schema.setFace(BlockFace.NORTH); schema.apply(); - } catch(FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } @@ -151,23 +173,23 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract /** - * Keeps searching in the provided direction until the height of the block is roughly + * Keeps searching in the provided direction until the height of the block is roughly * at the ground level outside the plateau's raised height. */ @NotNull SimpleBlock getSpawnEntrance(TerraformWorld tw, @NotNull SimpleBlock query, @NotNull BlockFace dir) { - while(query.getGround().getY() >= 100) { - query = query.getRelative(dir); - } - - double riverHeight = HeightMap.getRawRiverDepth(tw, query.getX(), query.getZ()); + while (query.getGround().getY() >= 100) { + query = query.getRelative(dir); + } + + double riverHeight = HeightMap.getRawRiverDepth(tw, query.getX(), query.getZ()); double baseHeight = HeightMap.CORE.getHeight(tw, query.getX(), query.getZ()) + riverHeight; - while(query.getGround().getY() > baseHeight + 3) { // 3 block leeway to account for random blurring - query = query.getRelative(dir); - riverHeight = HeightMap.getRawRiverDepth(tw, query.getX(), query.getZ()); + while (query.getGround().getY() > baseHeight + 3) { // 3 block leeway to account for random blurring + query = query.getRelative(dir); + riverHeight = HeightMap.getRawRiverDepth(tw, query.getX(), query.getZ()); baseHeight = HeightMap.CORE.getHeight(tw, query.getX(), query.getZ()) + riverHeight; } - + return query.getGround(); } @@ -177,26 +199,37 @@ void spawnEntrance(SimpleBlock entrance, @NotNull BlockFace direction) { // Place support frame try { SimpleBlock framePos = entrance.getRelative(BlockUtils.getRight(direction), 1).getRelative(direction); - TerraSchematic entranceSchematic = TerraSchematic.load("badlands-mineshaft/badlands-mine-entrance", framePos); + TerraSchematic entranceSchematic = TerraSchematic.load( + "badlands-mineshaft/badlands-mine-entrance", + framePos + ); entranceSchematic.parser = new BadlandsMineEntranceParser(); entranceSchematic.setFace(direction); entranceSchematic.apply(); - } catch(Exception e) { + } + catch (Exception e) { TerraformGeneratorPlugin.logger.error("An error occurred reading Badlands Mine Entrance schematic file."); - TerraformGeneratorPlugin.logger.stackTrace(e); + TerraformGeneratorPlugin.logger.stackTrace(e); } } void patchEntrance(@NotNull SimpleBlock entrance, @NotNull BlockFace direction) { BlockFace nextDir = BlockUtils.getRight(direction); fillWithBlock(entrance.getRelative(nextDir.getModX() * 2, -1, nextDir.getModZ() * 2), - entrance.getRelative(-nextDir.getModX() * 2, -4, -nextDir.getModZ() * 2).getRelative(direction, 3)); + entrance.getRelative(-nextDir.getModX() * 2, -4, -nextDir.getModZ() * 2).getRelative(direction, 3) + ); } void fillWithBlock(@NotNull SimpleBlock start, @NotNull SimpleBlock end) { - for(int x = Math.min(start.getX(), end.getX()); x <= Math.min(start.getX(), end.getX()) + Math.abs(start.getX() - end.getX()); x++) { - for(int z = Math.min(start.getZ(), end.getZ()); z <= Math.min(start.getZ(), end.getZ()) + Math.abs(start.getZ() - end.getZ()); z++) { - for(int y = Math.min(start.getY(), end.getY()); y <= Math.min(start.getY(), end.getY()) + Math.abs(start.getY() - end.getY()); y++) { + for (int x = Math.min(start.getX(), end.getX()); + x <= Math.min(start.getX(), end.getX()) + Math.abs(start.getX() - end.getX()); + x++) { + for (int z = Math.min(start.getZ(), end.getZ()); + z <= Math.min(start.getZ(), end.getZ()) + Math.abs(start.getZ() - end.getZ()); + z++) { + for (int y = Math.min(start.getY(), end.getY()); + y <= Math.min(start.getY(), end.getY()) + Math.abs(start.getY() - end.getY()); + y++) { new SimpleBlock(start.getPopData(), x, y, z).lsetType(Material.RED_SAND); } } @@ -205,28 +238,34 @@ void fillWithBlock(@NotNull SimpleBlock start, @NotNull SimpleBlock end) { private void spawnShaft(@NotNull Random random, @NotNull SimpleBlock shaft, @NotNull BlockFace inDir) { BlockFace outDir = inDir.getOppositeFace(); - int mineshaftY = (int) (HeightMap.CORE.getHeight(shaft.getPopData().getTerraformWorld(), shaft.getX(), shaft.getZ()) - BadlandsMinePopulator.shaftDepth); + int mineshaftY = (int) (HeightMap.CORE.getHeight( + shaft.getPopData().getTerraformWorld(), + shaft.getX(), + shaft.getZ() + ) - BadlandsMinePopulator.shaftDepth); int shaftStart = -5; int supportR = 3; EnumSet toReplace = EnumSet.copyOf(BlockUtils.badlandsStoneLike); - toReplace.addAll(Arrays.asList(Material.STONE_SLAB, Material.MOSSY_COBBLESTONE_WALL, Material.COBBLESTONE_WALL, - Material.MOSSY_COBBLESTONE, Material.COBWEB, Material.MOSSY_COBBLESTONE_SLAB, Material.COBBLESTONE_SLAB)); + toReplace.addAll(Arrays.asList(Material.STONE_SLAB, + Material.MOSSY_COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE, + Material.COBWEB, + Material.MOSSY_COBBLESTONE_SLAB, + Material.COBBLESTONE_SLAB + )); // Carving at ground level - BlockUtils.carveCaveAir(random.nextInt(777123), - 5.5f / 2f, - 4.5f, - 5.5f / 2f, - shaft, - true, - toReplace); + BlockUtils.carveCaveAir(random.nextInt(777123), 5.5f / 2f, 4.5f, 5.5f / 2f, shaft, true, toReplace); ArrayList platforms = new ArrayList<>(); - for (double i = 0; i < shaft.getY()-mineshaftY; i ++) { // Carve shaft + for (double i = 0; i < shaft.getY() - mineshaftY; i++) { // Carve shaft double width = 6 + Math.pow((i % 6) * 0.2, 2); SimpleBlock centerBlock = shaft.getRelative(GenUtils.randInt(random, -1, 1), - (int) Math.round(- i + shaftStart), GenUtils.randInt(random, -1, 1)); + (int) Math.round(-i + shaftStart), + GenUtils.randInt(random, -1, 1) + ); BlockUtils.carveCaveAir(random.nextInt(777123), (float) width / 2f, @@ -234,9 +273,10 @@ private void spawnShaft(@NotNull Random random, @NotNull SimpleBlock shaft, @Not (float) width / 2f, centerBlock, true, - toReplace); + toReplace + ); - if (i % 6 > 4 && i < shaft.getY()-mineshaftY - 6) { // Add mineshaft platform positions + if (i % 6 > 4 && i < shaft.getY() - mineshaftY - 6) { // Add mineshaft platform positions for (int b = 0; b < 1; b++) { double angle = GenUtils.randDouble(random, 0, 2 * Math.PI); int xAdd = (int) Math.round(Math.sin(angle) * 3); @@ -252,8 +292,9 @@ private void spawnShaft(@NotNull Random random, @NotNull SimpleBlock shaft, @Not // Spawn platforms with loot for (SimpleBlock platform : platforms) { - if (GenUtils.chance(random, 3, 4)) + if (GenUtils.chance(random, 3, 4)) { spawnShaftPlatform(platform); + } } // Vertical support structure @@ -261,31 +302,35 @@ private void spawnShaft(@NotNull Random random, @NotNull SimpleBlock shaft, @Not BlockFace left = BlockUtils.getLeft(inDir); ArrayList mainPillars = new ArrayList<>(); // Order does matter here mainPillars.add( // Front right - shaft.getRelative(inDir.getModX() * supportR, shaftStart, inDir.getModZ() * supportR).getRelative(right, supportR)); + shaft.getRelative(inDir.getModX() * supportR, shaftStart, inDir.getModZ() * supportR) + .getRelative(right, supportR)); mainPillars.add( // Front left - shaft.getRelative(inDir.getModX() * supportR, shaftStart, inDir.getModZ() * supportR).getRelative(left, supportR)); + shaft.getRelative(inDir.getModX() * supportR, shaftStart, inDir.getModZ() * supportR) + .getRelative(left, supportR)); mainPillars.add( // Rear left - shaft.getRelative(outDir.getModX() * supportR, shaftStart, outDir.getModZ() * supportR).getRelative(left, supportR)); + shaft.getRelative(outDir.getModX() * supportR, shaftStart, outDir.getModZ() * supportR) + .getRelative(left, supportR)); mainPillars.add( // Rear right - shaft.getRelative(outDir.getModX() * supportR, shaftStart, outDir.getModZ() * supportR).getRelative(right, supportR)); + shaft.getRelative(outDir.getModX() * supportR, shaftStart, outDir.getModZ() * supportR) + .getRelative(right, supportR)); // Two random pillars ArrayList supportPillars = new ArrayList<>(mainPillars); int xAdd = GenUtils.randInt(random, -supportR, supportR); int zAdd = (supportR - Math.abs(xAdd)) * (random.nextBoolean() ? 1 : -1); - supportPillars.add( - shaft.getRelative(outDir.getModX() * xAdd, shaftStart, outDir.getModZ() * xAdd).getRelative(left, zAdd)); + supportPillars.add(shaft.getRelative(outDir.getModX() * xAdd, shaftStart, outDir.getModZ() * xAdd) + .getRelative(left, zAdd)); xAdd = GenUtils.randInt(random, -supportR, supportR); zAdd = (supportR - Math.abs(xAdd)) * (random.nextBoolean() ? 1 : -1); - supportPillars.add( - shaft.getRelative(outDir.getModX() * xAdd, shaftStart, outDir.getModZ() * xAdd).getRelative(left, zAdd)); + supportPillars.add(shaft.getRelative(outDir.getModX() * xAdd, shaftStart, outDir.getModZ() * xAdd) + .getRelative(left, zAdd)); supportPillars.removeIf(n -> GenUtils.chance(random, 1, 5)); // Place vertical support structure for (SimpleBlock pillar : supportPillars) { - for (int y = -4; y < shaft.getY()-mineshaftY + 5; y++) { + for (int y = -4; y < shaft.getY() - mineshaftY + 5; y++) { pillar.getRelative(0, -y, 0).lsetType(Material.DARK_OAK_FENCE); } } @@ -296,19 +341,25 @@ private void spawnShaft(@NotNull Random random, @NotNull SimpleBlock shaft, @Not BlockFace face = BlockUtils.getLeft(inDir); for (int i = 0; i < mainPillars.size(); i++) { - if (supportPillars.contains(mainPillars.get(i)) && - supportPillars.contains(mainPillars.get(i + 1 >= mainPillars.size() ? 0 : i + 1)) - && GenUtils.chance(random, 2, 3)) { + if (supportPillars.contains(mainPillars.get(i)) + && supportPillars.contains(mainPillars.get(i + 1 + >= mainPillars.size() + ? 0 + : i + 1)) + && GenUtils.chance(random, 2, 3)) + { SimpleBlock mainPillar = mainPillars.get(i); for (int add = 1; add < 2 * supportR; add++) { - SimpleBlock b = new SimpleBlock(platform.getPopData(), mainPillar.getX(), y, - mainPillar.getZ()).getRelative(face, add); + SimpleBlock b = new SimpleBlock(platform.getPopData(), + mainPillar.getX(), + y, + mainPillar.getZ() + ).getRelative(face, add); if (b.getType() == Material.STONE || BlockUtils.isAir(b.getType())) { b.setType(Material.DARK_OAK_FENCE); BlockUtils.correctSurroundingMultifacingData(b); - if (GenUtils.chance(random, 1, 12) && - !b.getDown().isSolid()) { + if (GenUtils.chance(random, 1, 12) && !b.getDown().isSolid()) { Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); l.setHanging(true); b.getDown().setBlockData(l); @@ -329,7 +380,8 @@ private void spawnShaftPlatform(@NotNull SimpleBlock center) { 2.5f, center.getUp(2), true, - BlockUtils.badlandsStoneLike); + BlockUtils.badlandsStoneLike + ); center.setType(Material.DARK_OAK_PLANKS); ArrayList lootBlocks = new ArrayList<>(); @@ -345,8 +397,9 @@ private void spawnShaftPlatform(@NotNull SimpleBlock center) { center.getRelative(face, 2).setBlockData(stairs); SimpleBlock lantern = center.getRelative(face, 2).getUp(); - if (BlockUtils.isAir(lantern.getType()) && GenUtils.chance(1, 4)) + if (BlockUtils.isAir(lantern.getType()) && GenUtils.chance(1, 4)) { lantern.setType(Material.LANTERN); + } Slab slab = (Slab) Bukkit.createBlockData(Material.DARK_OAK_SLAB); slab.setType(Slab.Type.TOP); @@ -369,8 +422,14 @@ private void setLootBlock(@NotNull SimpleBlock lootBlock) { if (GenUtils.chance(1, 25) && !lootBlock.isSolid()) { lootBlock.setType(Material.BARREL); lootBlock.setBlockData(BlockUtils.getRandomBarrel()); - lootBlock.getPopData().lootTableChest(lootBlock.getX(), lootBlock.getY(), lootBlock.getZ(), TerraLootTable.ABANDONED_MINESHAFT); - } else { + lootBlock.getPopData() + .lootTableChest(lootBlock.getX(), + lootBlock.getY(), + lootBlock.getZ(), + TerraLootTable.ABANDONED_MINESHAFT + ); + } + else { lootBlock.lsetType(GenUtils.randChoice(BlockUtils.ores)); } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/BrokenShaftPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/BrokenShaftPopulator.java index a63f451c..51ee1d4d 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/BrokenShaftPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/BrokenShaftPopulator.java @@ -26,16 +26,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { SimpleBlock b = new SimpleBlock(data, x, y, z); if (b.getType() == Material.CAVE_AIR - || b.getType() == Material.OAK_PLANKS - || b.getType() == Material.OAK_SLAB - || b.getType() == Material.GRAVEL) { + || b.getType() == Material.OAK_PLANKS + || b.getType() == Material.OAK_SLAB + || b.getType() == Material.GRAVEL) + { b.setType(GenUtils.randChoice( Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE, - Material.CAVE_AIR)); + Material.CAVE_AIR + )); } } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/CaveSpiderDenPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/CaveSpiderDenPopulator.java index a21341c6..a2877f1b 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/CaveSpiderDenPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/CaveSpiderDenPopulator.java @@ -27,10 +27,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // If the room has any sunlight or water, don't build this. SimpleBlock center = room.getCenterSimpleBlock(data).getUp(); - if(BlockUtils.isWet(center) - || GenUtils.getHighestGround(data, center.getX(), center.getZ()) <= center.getY()) - return; - + if (BlockUtils.isWet(center) + || GenUtils.getHighestGround(data, center.getX(), center.getZ()) <= center.getY()) + { + return; + } + // Flooring - Have a stone brick platform. int y = room.getY(); for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { @@ -44,7 +46,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Material.OAK_SLAB, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE, - Material.COBBLESTONE_SLAB)); + Material.COBBLESTONE_SLAB + )); } } } @@ -58,10 +61,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room b = b.getUp(); limit--; } - if (limit < 0) continue; // No space above. + if (limit < 0) { + continue; // No space above. + } if (x == room.getX() && z == room.getZ()) { data.setSpawner(x, b.getY(), z, EntityType.CAVE_SPIDER); - } else { + } + else { Wall w = new Wall(b, BlockFace.NORTH); w.LPillar(GenUtils.randInt(0, 2), rand, Material.COBWEB); } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java index 2c8ec063..551086e5 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java @@ -45,8 +45,13 @@ public boolean customCarve(@NotNull SimpleBlock base, BlockFace dir, int pathWid Wall core = new Wall(base.getUp(), dir); int seed = 55 + core.getX() + core.getY() ^ 2 + core.getZ() ^ 3; BlockUtils.carveCaveAir(seed, - pathWidth, pathWidth + 1, pathWidth, core.get(), false, - BlockUtils.caveCarveReplace); + pathWidth, + pathWidth + 1, + pathWidth, + core.get(), + false, + BlockUtils.caveCarveReplace + ); return true; } @@ -55,12 +60,13 @@ public boolean customCarve(@NotNull SimpleBlock base, BlockFace dir, int pathWid public void populate(@NotNull PathPopulatorData ppd) { Wall core = new Wall(ppd.base, ppd.dir); - if(ppd.dir == BlockFace.UP) - { + if (ppd.dir == BlockFace.UP) { // Make a platform - for(int nx = -1; nx <= 1; nx++) - for(int nz = -1; nz <= 1; nz++) - core.getRelative(nx,0,nz).setType(getPathMaterial()); + for (int nx = -1; nx <= 1; nx++) { + for (int nz = -1; nz <= 1; nz++) { + core.getRelative(nx, 0, nz).setType(getPathMaterial()); + } + } return; } // God this sucks @@ -68,12 +74,14 @@ public void populate(@NotNull PathPopulatorData ppd) { legacyPopulate(core); legacyPopulate(core.getFront()); } + public void legacyPopulate(@NotNull Wall core) { // what the fuck is wrong with you // Was populated before. - if (core.getType() != Material.CAVE_AIR) + if (core.getType() != Material.CAVE_AIR) { return; + } Wall ceiling = core.findCeiling(10); if (ceiling != null) { @@ -83,13 +91,13 @@ public void legacyPopulate(@NotNull Wall core) { Wall right = core.findRight(10); // Central Pathway - core.setType(GenUtils.randChoice( - Material.COBBLESTONE, + core.setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.ANDESITE, Material.DIORITE, - Material.MOSSY_COBBLESTONE)); + Material.MOSSY_COBBLESTONE + )); core.getRight().setType(GenUtils.randChoice(getPathMaterial())); core.getLeft().setType(GenUtils.randChoice(getPathMaterial())); @@ -100,25 +108,31 @@ public void legacyPopulate(@NotNull Wall core) { } // Broken feel - if (rand.nextBoolean()) core.getRight(2) - .setType(GenUtils.randChoice(getPathMaterial())); - if (rand.nextBoolean()) core.getLeft(2) - .setType(GenUtils.randChoice(getPathMaterial())); + if (rand.nextBoolean()) { + core.getRight(2).setType(GenUtils.randChoice(getPathMaterial())); + } + if (rand.nextBoolean()) { + core.getLeft(2).setType(GenUtils.randChoice(getPathMaterial())); + } // Decorate with pebbles n shit lol for (int i = -2; i <= 2; i++) { - if (i == 0) continue; + if (i == 0) { + continue; + } Wall target = core.getLeft(i); // Checks if there's space on the ground if (!Tag.SLABS.isTagged(target.getType()) - && target.isSolid() - && target.getType() != Material.GRAVEL - && target.getUp().getType() == Material.CAVE_AIR) { + && target.isSolid() + && target.getType() != Material.GRAVEL + && target.getUp().getType() == Material.CAVE_AIR) + { if (GenUtils.chance(1, 10)) { // Pebble Directional pebble = (Directional) Material.STONE_BUTTON.createBlockData("[face=floor]"); pebble.setFacing(BlockUtils.getDirectBlockFace(rand)); target.getUp().setBlockData(pebble); - } else if (GenUtils.chance(1, 10)) { // Mushroom + } + else if (GenUtils.chance(1, 10)) { // Mushroom PlantBuilder.build(target.getUp(), PlantBuilder.BROWN_MUSHROOM, PlantBuilder.RED_MUSHROOM); } } @@ -127,30 +141,40 @@ public void legacyPopulate(@NotNull Wall core) { // Rails if (TConfigOption.areDecorationsEnabled() && core.isSolid() && rand.nextBoolean()) { Rail rail = (Rail) Bukkit.createBlockData(Material.RAIL); - switch(core.getDirection()) { + switch (core.getDirection()) { case NORTH, SOUTH -> rail.setShape(Shape.NORTH_SOUTH); case EAST, WEST -> rail.setShape(Shape.EAST_WEST); } - + // Check if rails are wet. - if(BlockUtils.isWet(core.getUp().get())) - rail.setWaterlogged(true); - + if (BlockUtils.isWet(core.getUp().get())) { + rail.setWaterlogged(true); + } + core.getUp().setBlockData(rail); // BlockUtils.correctSurroundingRails(core.getUp().get()); if (GenUtils.chance(rand, 1, 100)) { - TerraformGeneratorPlugin.logger.info("Minecart with chest at: " + core.getX() + ", " + core.getY() + ", " + core.getZ()); + TerraformGeneratorPlugin.logger.info("Minecart with chest at: " + + core.getX() + + ", " + + core.getY() + + ", " + + core.getZ()); IPopulatorDataMinecartSpawner ms = (IPopulatorDataMinecartSpawner) core.get().getPopData(); - ms.spawnMinecartWithChest( - core.getX(), core.getY() + 1, core.getZ(), - TerraLootTable.ABANDONED_MINESHAFT, rand + ms.spawnMinecartWithChest(core.getX(), + core.getY() + 1, + core.getZ(), + TerraLootTable.ABANDONED_MINESHAFT, + rand ); } } boolean hasSupports = setMineshaftSupport(left, right, ceiling); - if (hasSupports) return; + if (hasSupports) { + return; + } // Now for the stuff that we've put in normal caves for (int i = -2; i <= 2; i++) { @@ -158,18 +182,16 @@ public void legacyPopulate(@NotNull Wall core) { Wall floor = core.getLeft(i).findFloor(10); // Decorations on the wall - if (ceil != null && floor != null) + if (ceil != null && floor != null) { for (int ny = 0; ny <= ceil.getY() - floor.getY(); ny++) { Wall[] walls = { - floor.getRelative(0, ny, 0).findLeft(10), - floor.getRelative(0, ny, 0).findRight(10) + floor.getRelative(0, ny, 0).findLeft(10), floor.getRelative(0, ny, 0).findRight(10) }; for (Wall target : walls) { if (target != null) { if (target.getType() == Material.STONE) { if (GenUtils.chance(1, 10)) { - target.setType(GenUtils.randChoice( - Material.COBBLESTONE, + target.setType(GenUtils.randChoice(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE )); } @@ -180,6 +202,7 @@ public void legacyPopulate(@NotNull Wall core) { } } } + } // Vertical decorations if (ceil != null && !Tag.SLABS.isTagged(ceil.getType()) && !Tag.LOGS.isTagged(ceil.getType())) { @@ -193,19 +216,28 @@ public void legacyPopulate(@NotNull Wall core) { break; } } - if (canSpawn) - ceil.downLPillar(rand, GenUtils.randInt(rand, 1, 3), + if (canSpawn) { + ceil.downLPillar(rand, + GenUtils.randInt(rand, 1, 3), Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL ); + } - } else if (GenUtils.chance(rand, 1, 6)) { + } + else if (GenUtils.chance(rand, 1, 6)) { // Cobweb - if (TConfigOption.areDecorationsEnabled()) + if (TConfigOption.areDecorationsEnabled()) { ceil.setType(Material.COBWEB); - } else if (GenUtils.chance(rand, 1, 10)) { + } + } + else if (GenUtils.chance(rand, 1, 10)) { // Slabbing - Slab slab = (Slab) Bukkit.createBlockData(GenUtils.randChoice(Material.COBBLESTONE_SLAB, Material.STONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB)); + Slab slab = (Slab) Bukkit.createBlockData(GenUtils.randChoice( + Material.COBBLESTONE_SLAB, + Material.STONE_SLAB, + Material.MOSSY_COBBLESTONE_SLAB + )); slab.setType(Type.TOP); ceil.setBlockData(slab); } @@ -221,24 +253,33 @@ public void legacyPopulate(@NotNull Wall core) { break; } } - if (canSpawn) - floor.LPillar(GenUtils.randInt(rand, 1, 3), false, rand, + if (canSpawn) { + floor.LPillar(GenUtils.randInt(rand, 1, 3), + false, + rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL ); + } - } else if (GenUtils.chance(rand, 1, 10)) { + } + else if (GenUtils.chance(rand, 1, 10)) { // Slabbing for (BlockFace face : BlockUtils.directBlockFaces) { if (floor.getRelative(face).isSolid()) { - Slab slab = (Slab) Bukkit.createBlockData(GenUtils.randChoice(Material.COBBLESTONE_SLAB, Material.STONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB)); + Slab slab = (Slab) Bukkit.createBlockData(GenUtils.randChoice( + Material.COBBLESTONE_SLAB, + Material.STONE_SLAB, + Material.MOSSY_COBBLESTONE_SLAB + )); slab.setType(Type.BOTTOM); floor.setBlockData(slab); break; } } - } else if (GenUtils.chance(1, 15)) { // Mushroom + } + else if (GenUtils.chance(1, 15)) { // Mushroom PlantBuilder.build(floor, PlantBuilder.BROWN_MUSHROOM, PlantBuilder.RED_MUSHROOM); } @@ -247,7 +288,9 @@ public void legacyPopulate(@NotNull Wall core) { } public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @Nullable Wall ceil) { - if (!TConfigOption.areDecorationsEnabled()) return true; + if (!TConfigOption.areDecorationsEnabled()) { + return true; + } if (left == null || right == null) { return false; // Lol wtf is this situation even @@ -255,9 +298,14 @@ public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @N // Check interval if (left.getDirection().getModX() != 0) { - if (left.getX() % 5 != 0) return false; - } else if (left.getDirection().getModZ() != 0) { - if (left.getZ() % 5 != 0) return false; + if (left.getX() % 5 != 0) { + return false; + } + } + else if (left.getDirection().getModZ() != 0) { + if (left.getZ() % 5 != 0) { + return false; + } } // Check if the support distance is too small @@ -280,10 +328,12 @@ public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @N // Support if (ceil != null) { Orientable log = (Orientable) Bukkit.createBlockData(getSupportMaterial()); - if (left.getDirection().getModX() != 0) + if (left.getDirection().getModX() != 0) { log.setAxis(Axis.Z); - if (left.getDirection().getModZ() != 0) + } + if (left.getDirection().getModZ() != 0) { log.setAxis(Axis.X); + } ceil = left.clone().getRelative(0, ceil.getY() - left.getY(), 0).getLeft(); Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); @@ -291,16 +341,15 @@ public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @N for (int i = 0; i < dist + 2; i++) { Wall support = ceil.getRight(i); - if (!support.isSolid() || - support.getType() == getFenceMaterial()) { + if (!support.isSolid() || support.getType() == getFenceMaterial()) { if (support.getUp().getType() != getSupportMaterial() - && support.getDown().getType() != getSupportMaterial()) { + && support.getDown().getType() != getSupportMaterial()) + { support.setBlockData(log); // L A M P if (GenUtils.chance(rand, 1, 100)) { - support.getDown().get() - .lsetBlockData(lantern); + support.getDown().get().lsetBlockData(lantern); } // Vine @@ -316,31 +365,29 @@ public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @N } return true; } - + private void placeSupportFences(@NotNull Wall w) { - while(!w.isSolid()) { - if(w.getType() == Material.LAVA) - w.setType(Material.COBBLESTONE); - else - w.setType(getFenceMaterial()); - w = w.getDown(); - } + while (!w.isSolid()) { + if (w.getType() == Material.LAVA) { + w.setType(Material.COBBLESTONE); + } + else { + w.setType(getFenceMaterial()); + } + w = w.getDown(); + } } public Material @NotNull [] getPathMaterial() { return new Material[] { - Material.OAK_PLANKS, - Material.OAK_SLAB, - Material.OAK_PLANKS, - Material.OAK_SLAB, - Material.GRAVEL + Material.OAK_PLANKS, Material.OAK_SLAB, Material.OAK_PLANKS, Material.OAK_SLAB, Material.GRAVEL }; } public @NotNull Material getFenceMaterial() { return Material.OAK_FENCE; } - + public @NotNull Material getSupportMaterial() { return Material.OAK_LOG; } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java index dd10f476..13f7f5f3 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java @@ -25,36 +25,45 @@ public class MineshaftPopulator extends JigsawStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } // MegaChunk mc = new MegaChunk(chunkX, chunkZ); // int[] coords = mc.getCenterBiomeSectionBlockCoords(); - // Do not spawn mineshafts under deep oceans, there's no space. - if(biome.getType() == BiomeType.DEEP_OCEANIC) - return false; + // Do not spawn mineshafts under deep oceans, there's no space. + if (biome.getType() == BiomeType.DEEP_OCEANIC) { + return false; + } - // Don't compete with badlandsmine for space - if(biome == BiomeBank.BADLANDS_CANYON) - return false; + // Don't compete with badlandsmine for space + if (biome == BiomeBank.BADLANDS_CANYON) { + return false; + } - // Do height and space checks - // In the interest of optimisation, this check will not be performed. + // Do height and space checks + // In the interest of optimisation, this check will not be performed. - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public @NotNull JigsawState calculateRoomPopulators(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { return calculateRoomPopulators(tw, mc, false); } - public @NotNull JigsawState calculateRoomPopulators(@NotNull TerraformWorld tw, @NotNull MegaChunk mc, boolean badlandsMineshaft) { + + public @NotNull JigsawState calculateRoomPopulators(@NotNull TerraformWorld tw, + @NotNull MegaChunk mc, + boolean badlandsMineshaft) + { JigsawState state = new JigsawState(); int[] coords = mc.getCenterBiomeSectionBlockCoords(); @@ -62,17 +71,19 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk int z = coords[1]; int y; - if(!badlandsMineshaft) - { - y = GenUtils.randInt(TConfigOption.STRUCTURES_MINESHAFT_MIN_Y.getInt(), TConfigOption.STRUCTURES_MINESHAFT_MAX_Y.getInt()); - if(y < TerraformGeneratorPlugin.injector.getMinY()) + if (!badlandsMineshaft) { + y = GenUtils.randInt( + TConfigOption.STRUCTURES_MINESHAFT_MIN_Y.getInt(), + TConfigOption.STRUCTURES_MINESHAFT_MAX_Y.getInt() + ); + if (y < TerraformGeneratorPlugin.injector.getMinY()) { y = TerraformGeneratorPlugin.injector.getMinY() + 15; + } } - else - { + else { // Badlands mines want to spawn an entrance shaft. Because of this, // they will spawn closer to the surface. - y = (int) (HeightMap.CORE.getHeight(tw,x,z) - BadlandsMinePopulator.shaftDepth); + y = (int) (HeightMap.CORE.getHeight(tw, x, z) - BadlandsMinePopulator.shaftDepth); } // Level One @@ -81,43 +92,63 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, 10, x, y, z, 150); Random pathRand = tw.getHashedRand(x, y, z, 2); - gen.setPathPopulator(badlandsMineshaft ? new BadlandsMineshaftPathPopulator(pathRand) : new MineshaftPathPopulator(pathRand)); + gen.setPathPopulator(badlandsMineshaft + ? new BadlandsMineshaftPathPopulator(pathRand) + : new MineshaftPathPopulator(pathRand)); gen.setRoomMaxX(15); gen.setRoomMaxZ(15); gen.setRoomMinX(13); gen.setRoomMinZ(13); - gen.registerRoomPopulator(new SmeltingHallPopulator(tw.getHashedRand(mc.getX(), mc.getZ(),198034143), false, false)); - gen.registerRoomPopulator(new CaveSpiderDenPopulator(tw.getHashedRand(mc.getX(), mc.getZ(),1829731), false, false)); + gen.registerRoomPopulator(new SmeltingHallPopulator( + tw.getHashedRand(mc.getX(), mc.getZ(), 198034143), + false, + false + )); + gen.registerRoomPopulator(new CaveSpiderDenPopulator( + tw.getHashedRand(mc.getX(), mc.getZ(), 1829731), + false, + false + )); - if (doubleLevel) - gen.registerRoomPopulator(new ShaftRoomPopulator(tw.getHashedRand(mc.getX(), mc.getZ(),213098), true, false)); + if (doubleLevel) { + gen.registerRoomPopulator(new ShaftRoomPopulator(tw.getHashedRand(mc.getX(), mc.getZ(), 213098), + true, + false + )); + } // To connect the mineshaft to the surface entrance if (badlandsMineshaft) { - CubeRoom brokenShaft = new CubeRoom( - 15, - 15, - 7, - gen.getCentX(), gen.getCentY(), gen.getCentZ()); + CubeRoom brokenShaft = new CubeRoom(15, 15, 7, gen.getCentX(), gen.getCentY(), gen.getCentZ()); brokenShaft.setRoomPopulator(new BrokenShaftPopulator(hashedRand, true, false)); gen.getRooms().add(brokenShaft); } - gen.wallMaterials = new Material[]{Material.CAVE_AIR}; + gen.wallMaterials = new Material[] {Material.CAVE_AIR}; gen.roomCarver = new CaveRoomCarver(); gen.calculateRoomPlacement(); PathState ps = gen.getOrCalculatePathState(tw); - ps.writer = new CavePathWriter(0f, 1f, 0f, 0,1,0); + ps.writer = new CavePathWriter(0f, 1f, 0f, 0, 1, 0); gen.calculateRoomPopulators(tw); state.roomPopulatorStates.add(gen); // gen.fill(data, tw, Material.CAVE_AIR); if (doubleLevel) { // Level Two - RoomLayoutGenerator secondGen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, 10, x, y + 15, z, 150); + RoomLayoutGenerator secondGen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + 10, + x, + y + 15, + z, + 150 + ); pathRand = tw.getHashedRand(x, y + 15, z, 2); - secondGen.setPathPopulator(badlandsMineshaft ? new BadlandsMineshaftPathPopulator(pathRand) : new MineshaftPathPopulator(pathRand)); + secondGen.setPathPopulator(badlandsMineshaft + ? new BadlandsMineshaftPathPopulator(pathRand) + : new MineshaftPathPopulator(pathRand)); secondGen.setRoomMaxX(15); secondGen.setRoomMaxZ(15); secondGen.setRoomMinX(13); @@ -126,24 +157,34 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk for (CubeRoom room : gen.getRooms()) { if (room.getPop() instanceof ShaftRoomPopulator) { - CubeRoom topShaft = new CubeRoom( - room.getWidthX(), + CubeRoom topShaft = new CubeRoom(room.getWidthX(), room.getHeight(), room.getWidthZ(), - room.getX(), room.getY() + 15, room.getZ()); + room.getX(), + room.getY() + 15, + room.getZ() + ); topShaft.setRoomPopulator(new ShaftTopPopulator(hashedRand, true, false)); secondGen.getRooms().add(topShaft); } } - secondGen.registerRoomPopulator(new SmeltingHallPopulator(tw.getHashedRand(mc.getX(), mc.getZ(),9870312), false, false)); - secondGen.registerRoomPopulator(new CaveSpiderDenPopulator(tw.getHashedRand(mc.getX(), mc.getZ(),46783129), false, false)); - - secondGen.wallMaterials = new Material[]{Material.CAVE_AIR}; + secondGen.registerRoomPopulator(new SmeltingHallPopulator( + tw.getHashedRand(mc.getX(), mc.getZ(), 9870312), + false, + false + )); + secondGen.registerRoomPopulator(new CaveSpiderDenPopulator( + tw.getHashedRand(mc.getX(), mc.getZ(), 46783129), + false, + false + )); + + secondGen.wallMaterials = new Material[] {Material.CAVE_AIR}; secondGen.roomCarver = new CaveRoomCarver(); secondGen.calculateRoomPlacement(); ps = secondGen.getOrCalculatePathState(tw); - ps.writer = new CavePathWriter(0f, 1f, 0f, 0,1,0); + ps.writer = new CavePathWriter(0f, 1f, 0f, 0, 1, 0); secondGen.calculateRoomPopulators(tw); state.roomPopulatorStates.add(secondGen); // secondGen.fill(data, tw, Material.CAVE_AIR); @@ -164,6 +205,6 @@ public boolean isEnabled() { @Override public int getChunkBufferDistance() { - return 0; + return 0; } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/OreLiftSchematicParser.java b/common/src/main/java/org/terraform/structure/mineshaft/OreLiftSchematicParser.java index 8e74a7c6..b1c54e74 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/OreLiftSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/OreLiftSchematicParser.java @@ -9,14 +9,16 @@ import org.terraform.utils.GenUtils; public class OreLiftSchematicParser extends SchematicParser { - - boolean isBadlands = false; - public OreLiftSchematicParser() {} - - public OreLiftSchematicParser(boolean isBadlands) { - this.isBadlands = isBadlands; - } - + + boolean isBadlands = false; + + public OreLiftSchematicParser() { + } + + public OreLiftSchematicParser(boolean isBadlands) { + this.isBadlands = isBadlands; + } + @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (BlockUtils.ores.contains(data.getMaterial())) { @@ -25,16 +27,14 @@ public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { // super.applyData(block, data); // Override the normal way as it updates physics. // Don't update physics because rails are cancer. - - if(this.isBadlands) { - if (data.getMaterial().toString().contains("OAK")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll("oak_","dark_oak_") - ); - super.applyData(block, data); - } + + if (this.isBadlands) { + if (data.getMaterial().toString().contains("OAK")) { + data = Bukkit.createBlockData(data.getAsString().replaceAll("oak_", "dark_oak_")); + super.applyData(block, data); + } } - + super.applyData(block, data); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/structure/mineshaft/ShaftRoomPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/ShaftRoomPopulator.java index e3301e88..8956f40f 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/ShaftRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/ShaftRoomPopulator.java @@ -23,13 +23,15 @@ public ShaftRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { // Carve upward shaft. Replace stone-like objects and cave decorations. for (int i = 8; i < 20; i++) { - BlockUtils.carveCaveAir(new Random().nextInt(777123), + BlockUtils.carveCaveAir( + new Random().nextInt(777123), (room.getWidthX() - 4) / 2f, 5, (room.getWidthZ() - 4) / 2f, new SimpleBlock(data, room.getX(), room.getY() + i, room.getZ()), false, - EnumSet.of(Material.BARRIER)); + EnumSet.of(Material.BARRIER) + ); } int[] lowerCorner = room.getLowerCorner(3); @@ -41,16 +43,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { SimpleBlock b = new SimpleBlock(data, x, y, z); if (b.getType() == Material.CAVE_AIR - || b.getType() == Material.OAK_PLANKS - || b.getType() == Material.OAK_SLAB - || b.getType() == Material.GRAVEL) { + || b.getType() == Material.OAK_PLANKS + || b.getType() == Material.OAK_SLAB + || b.getType() == Material.GRAVEL) + { b.setType(GenUtils.randChoice( Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE, - Material.CAVE_AIR)); + Material.CAVE_AIR + )); } } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/ShaftTopPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/ShaftTopPopulator.java index 0224ab53..1155bebe 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/ShaftTopPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/ShaftTopPopulator.java @@ -56,20 +56,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall target = w.getRelative(0, -GenUtils.randInt(rand, 8, 10), 0); // Clear a space - BlockUtils.carveCaveAir(new Random().nextInt(777123), + BlockUtils.carveCaveAir( + new Random().nextInt(777123), 3, 5, 3, new SimpleBlock(data, target.getX(), room.getY(), target.getZ()), false, - EnumSet.of(Material.BARRIER)); + EnumSet.of(Material.BARRIER) + ); schema = TerraSchematic.load("ore-lift", target.get().getRelative(-1, 0, -1)); schema.parser = new OreLiftSchematicParser(); schema.setFace(BlockFace.NORTH); schema.apply(); target.LPillar(w.getY() - target.getY(), rand, Material.OAK_FENCE); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java index cfdb7075..80c1ca58 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java @@ -35,16 +35,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { SimpleBlock b = new SimpleBlock(data, x, y, z); if (b.getType() == Material.CAVE_AIR - || b.getType() == Material.OAK_PLANKS - || b.getType() == Material.OAK_SLAB - || b.getType() == Material.GRAVEL) { + || b.getType() == Material.OAK_PLANKS + || b.getType() == Material.OAK_SLAB + || b.getType() == Material.GRAVEL) + { b.setType(GenUtils.randChoice( Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE, - Material.CAVE_AIR)); + Material.CAVE_AIR + )); // Small chance to set a lantern if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(rand, 1, 150)) { b.getUp().setType(Material.COBBLESTONE); @@ -72,7 +74,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Furnaces & Chests for (Entry walls : room.getFourWalls(data, 4).entrySet()) { int type = rand.nextInt(3); - if (type == 0) continue; + if (type == 0) { + continue; + } Wall w = walls.getKey(); int l = walls.getValue(); for (int i = 0; i < l; i++) { @@ -84,7 +88,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int ny = 0; ny < room.getHeight() / 3; ny++) { w.getRelative(0, ny, 0).setBlockData(furnace); } - } else if (GenUtils.chance(rand, 1, 5)) { // Chests + } + else if (GenUtils.chance(rand, 1, 5)) { // Chests Chest chest = (Chest) Bukkit.createBlockData(Material.CHEST); chest.setFacing(w.getDirection()); w.setBlockData(chest); diff --git a/common/src/main/java/org/terraform/structure/monument/CageRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/CageRoomPopulator.java index 2c26978c..716d33b3 100644 --- a/common/src/main/java/org/terraform/structure/monument/CageRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/CageRoomPopulator.java @@ -17,8 +17,7 @@ public class CageRoomPopulator extends MonumentRoomPopulator { - public CageRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, - boolean unique) { + public CageRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -32,7 +31,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room super.populate(data, room); // Not always a cage room - if (GenUtils.chance(rand, 3, 5)) return; + if (GenUtils.chance(rand, 3, 5)) { + return; + } for (Entry entry : room.getFourWalls(data, 0).entrySet()) { Wall w = entry.getKey().getUp(7); @@ -45,8 +46,15 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.getRelative(0, j, 0).setBlockData(wall); } // w.Pillar(room.getHeight()-9, rand, Material.PRISMARINE_WALL); - } else { - w.Pillar(room.getHeight() - 9, rand, Material.DARK_PRISMARINE_SLAB, Material.PRISMARINE_SLAB, Material.PRISMARINE_BRICK_SLAB); + } + else { + w.Pillar( + room.getHeight() - 9, + rand, + Material.DARK_PRISMARINE_SLAB, + Material.PRISMARINE_SLAB, + Material.PRISMARINE_BRICK_SLAB + ); Stairs s = (Stairs) Bukkit.createBlockData(design.stairs()); s.setFacing(w.getDirection()); s.setWaterlogged(w.get().getY() <= TerraformGenerator.seaLevel); diff --git a/common/src/main/java/org/terraform/structure/monument/CoralRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/CoralRoomPopulator.java index 4b590551..4ea9d95c 100644 --- a/common/src/main/java/org/terraform/structure/monument/CoralRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/CoralRoomPopulator.java @@ -12,8 +12,7 @@ public class CoralRoomPopulator extends LevelledRoomPopulator { - public CoralRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public CoralRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -28,11 +27,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int y = w.get().getY() + GenUtils.randInt(rand, 0, room.getHeight() - 6); int z = w.get().getZ(); - if (GenUtils.chance(rand, 1, 15)) + if (GenUtils.chance(rand, 1, 15)) { CoralGenerator.generateCoral(data, x, y, z); + } - if (GenUtils.chance(rand, 1, 5)) + if (GenUtils.chance(rand, 1, 5)) { CoralGenerator.generateSponge(data, x, y, z); + } w = w.getLeft(); } diff --git a/common/src/main/java/org/terraform/structure/monument/DecoratedSidesElderRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/DecoratedSidesElderRoomPopulator.java index cab661cb..1ad9513a 100644 --- a/common/src/main/java/org/terraform/structure/monument/DecoratedSidesElderRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/DecoratedSidesElderRoomPopulator.java @@ -16,8 +16,7 @@ public class DecoratedSidesElderRoomPopulator extends MonumentRoomPopulator { - public DecoratedSidesElderRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public DecoratedSidesElderRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -49,9 +48,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (!w.getRear().isSolid()) { Wall wall = w.getUp(4); wall.LPillar(room.getHeight() - 4, true, rand, Material.SEA_LANTERN, Material.DARK_PRISMARINE); - } else { - if (j % 2 == 0) + } + else { + if (j % 2 == 0) { w.LPillar(room.getHeight() - 1, rand, Material.PRISMARINE_BRICKS); + } else { w.LPillar(room.getHeight() - 1, rand, Material.PRISMARINE); w.getUp(3).Pillar(4, rand, Material.SEA_LANTERN); @@ -64,10 +65,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Elder - data.addEntity(room.getX(), - room.getY() + room.getHeight() / 2, - room.getZ(), - EntityType.ELDER_GUARDIAN); + data.addEntity(room.getX(), room.getY() + room.getHeight() / 2, room.getZ(), EntityType.ELDER_GUARDIAN); // Corners are sea lanterns Waterlogged wall = (Waterlogged) Bukkit.createBlockData(Material.PRISMARINE_WALL); diff --git a/common/src/main/java/org/terraform/structure/monument/FishCageRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/FishCageRoomPopulator.java index acbad643..050b496c 100644 --- a/common/src/main/java/org/terraform/structure/monument/FishCageRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/FishCageRoomPopulator.java @@ -17,8 +17,7 @@ public class FishCageRoomPopulator extends LevelledRoomPopulator { - public FishCageRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public FishCageRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -26,17 +25,24 @@ public FishCageRoomPopulator(Random rand, MonumentDesign design, public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { super.populate(data, room); // Fish Cage - CubeRoom cage = new CubeRoom(room.getWidthX() - 6, room.getWidthZ() - 6, room.getHeight() - 11, room.getX(), room.getY() + 7, room.getZ()); + CubeRoom cage = new CubeRoom( + room.getWidthX() - 6, + room.getWidthZ() - 6, + room.getHeight() - 11, + room.getX(), + room.getY() + 7, + room.getZ() + ); for (Entry entry : cage.getFourWalls(data, 0).entrySet()) { Wall w = entry.getKey(); int length = entry.getValue(); for (int i = 0; i < length; i++) { if (i % 2 == 0) { - w.Pillar(cage.getHeight(), - rand, Material.PRISMARINE_WALL); - } else - w.getFront().Pillar(cage.getHeight(), - rand, Material.PRISMARINE_WALL); + w.Pillar(cage.getHeight(), rand, Material.PRISMARINE_WALL); + } + else { + w.getFront().Pillar(cage.getHeight(), rand, Material.PRISMARINE_WALL); + } Stairs stair = (Stairs) Bukkit.createBlockData(design.stairs()); stair.setFacing(w.getDirection()); w.getRelative(0, cage.getHeight(), 0).setBlockData(stair); @@ -56,13 +62,16 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Attach to the ceiling for (int[] corner : cage.getAllCorners()) { - new Wall(new SimpleBlock(data, corner[0], cage.getY() + cage.getHeight() + 1, corner[1]), BlockFace.NORTH) - .Pillar(room.getHeight() - 8 - cage.getHeight(), rand, Material.PRISMARINE_WALL); + new Wall( + new SimpleBlock(data, corner[0], cage.getY() + cage.getHeight() + 1, corner[1]), + BlockFace.NORTH + ).Pillar(room.getHeight() - 8 - cage.getHeight(), rand, Material.PRISMARINE_WALL); } // Dolphins - for (int i = 0; i < GenUtils.randInt(3, 6); i++) + for (int i = 0; i < GenUtils.randInt(3, 6); i++) { data.addEntity(cage.getX(), cage.getY() + 1, cage.getZ(), EntityType.DOLPHIN); + } } @Override diff --git a/common/src/main/java/org/terraform/structure/monument/HollowPillarRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/HollowPillarRoomPopulator.java index be82689a..f76779ad 100644 --- a/common/src/main/java/org/terraform/structure/monument/HollowPillarRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/HollowPillarRoomPopulator.java @@ -13,8 +13,7 @@ public class HollowPillarRoomPopulator extends CageRoomPopulator { - public HollowPillarRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public HollowPillarRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -27,7 +26,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room room.getHeight() - 9, room.getX(), room.getY() + (room.getHeight() / 2) - ((room.getHeight() - 9) / 2), - room.getZ()); + room.getZ() + ); // Attach to the ceiling for (int[] corner : cage.getAllCorners()) { diff --git a/common/src/main/java/org/terraform/structure/monument/LanternPillarRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/LanternPillarRoomPopulator.java index 49cba11b..f7a19a3a 100644 --- a/common/src/main/java/org/terraform/structure/monument/LanternPillarRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/LanternPillarRoomPopulator.java @@ -13,8 +13,7 @@ public class LanternPillarRoomPopulator extends MonumentRoomPopulator { - public LanternPillarRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public LanternPillarRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); // TODO Auto-generated constructor stub } @@ -54,8 +53,10 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.LPillar(room.getHeight(), rand, Material.SEA_LANTERN); // Diagonals - for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) - w.getRelative(face).LPillar(room.getHeight(), true, rand, Material.DARK_PRISMARINE, Material.PRISMARINE_WALL); + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + w.getRelative(face) + .LPillar(room.getHeight(), true, rand, Material.DARK_PRISMARINE, Material.PRISMARINE_WALL); + } // Direct faces for (BlockFace face : BlockUtils.directBlockFaces) { diff --git a/common/src/main/java/org/terraform/structure/monument/LevelledElderRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/LevelledElderRoomPopulator.java index addf7943..57a0d3ef 100644 --- a/common/src/main/java/org/terraform/structure/monument/LevelledElderRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/LevelledElderRoomPopulator.java @@ -15,8 +15,7 @@ public class LevelledElderRoomPopulator extends LevelledRoomPopulator { - public LevelledElderRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public LevelledElderRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -34,8 +33,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = walls.getKey().getUp(4); int length = walls.getValue(); for (int j = 0; j < length; j++) { - if (j % 2 == 0) + if (j % 2 == 0) { w.LPillar(room.getHeight() - 1, rand, Material.PRISMARINE_BRICKS); + } else { w.LPillar(room.getHeight() - 1, rand, Material.PRISMARINE); w.getUp(3).Pillar(4, rand, Material.SEA_LANTERN); @@ -64,9 +64,6 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Elder - data.addEntity(room.getX() + 3, - room.getY() + 8, - room.getZ() - 3, - EntityType.ELDER_GUARDIAN); + data.addEntity(room.getX() + 3, room.getY() + 8, room.getZ() - 3, EntityType.ELDER_GUARDIAN); } } diff --git a/common/src/main/java/org/terraform/structure/monument/LevelledRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/LevelledRoomPopulator.java index 71686cb9..afdc8f10 100644 --- a/common/src/main/java/org/terraform/structure/monument/LevelledRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/LevelledRoomPopulator.java @@ -16,8 +16,7 @@ public class LevelledRoomPopulator extends CageRoomPopulator { - public LevelledRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, - boolean unique) { + public LevelledRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -47,8 +46,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Some prismarine at the bottom Wall cent = new Wall(new SimpleBlock(data, room.getX(), room.getY() + 1, room.getZ()), BlockFace.NORTH); for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { - cent.getUp().getRelative(face).getRelative(face) - .Pillar(2, rand, Material.DARK_PRISMARINE); + cent.getUp().getRelative(face).getRelative(face).Pillar(2, rand, Material.DARK_PRISMARINE); cent.getRelative(face).setType(Material.DARK_PRISMARINE); } @@ -57,11 +55,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int y = room.getY() + 5; y < room.getY() + room.getHeight(); y++) { if (y == room.getY() + 5 || y == room.getY() + room.getHeight() - 1) { data.setType(corner[0], y, corner[1], Material.DARK_PRISMARINE); - } else if (y % 2 == 0) { + } + else if (y % 2 == 0) { Waterlogged wall = (Waterlogged) Bukkit.createBlockData(Material.PRISMARINE_WALL); wall.setWaterlogged(y <= TerraformGenerator.seaLevel); data.setBlockData(corner[0], y, corner[1], wall); - } else { + } + else { data.setType(corner[0], y, corner[1], Material.SEA_LANTERN); } } diff --git a/common/src/main/java/org/terraform/structure/monument/MiniRoomNetworkPopulator.java b/common/src/main/java/org/terraform/structure/monument/MiniRoomNetworkPopulator.java index 37a7c64f..5ed2af81 100644 --- a/common/src/main/java/org/terraform/structure/monument/MiniRoomNetworkPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/MiniRoomNetworkPopulator.java @@ -13,8 +13,7 @@ public class MiniRoomNetworkPopulator extends MonumentRoomPopulator { - public MiniRoomNetworkPopulator(Random rand, MonumentDesign design, boolean forceSpawn, - boolean unique) { + public MiniRoomNetworkPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); } @@ -35,8 +34,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.RPillar(room.getHeight() - 1, rand, design.tileSet()); // Lighting - if (i % 2 == 0) + if (i % 2 == 0) { w.setType(Material.SEA_LANTERN); + } // Center hole if (i == l / 2) { @@ -60,7 +60,8 @@ public void tetrapod(@NotNull Wall w) { if (width % 2 == 1) { w.getLeft(width).RPillar(5, rand, design.tileSet()); w.getRight(width).RPillar(5, rand, design.tileSet()); - } else { + } + else { w.getLeft(width).getUp(2).setType(design.mat(rand)); w.getRight(width).getUp(2).setType(design.mat(rand)); } diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentDesign.java b/common/src/main/java/org/terraform/structure/monument/MonumentDesign.java index d69e9854..a6b7db33 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentDesign.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentDesign.java @@ -36,7 +36,7 @@ public Material[] tileSet() { } public @Nullable Material slab() { - return switch(this) { + return switch (this) { case DARK_LIGHTLESS -> Material.DARK_PRISMARINE_SLAB; case DARK_PRISMARINE_CORNERS -> GenUtils.randChoice(Material.DARK_PRISMARINE_SLAB, Material.PRISMARINE_BRICK_SLAB); @@ -58,11 +58,15 @@ public void spawnLargeLight(@NotNull PopulatorDataAbstract data, int x, int y, i z++; y++; // World w = ((PopulatorDataPostGen) data).getWorld(); - TerraSchematic schema = TerraSchematic.load(this.toString().toLowerCase(Locale.ENGLISH) + "-largelight", new SimpleBlock(data,x,y,z)); + TerraSchematic schema = TerraSchematic.load( + this.toString().toLowerCase(Locale.ENGLISH) + "-largelight", + new SimpleBlock(data, x, y, z) + ); schema.parser = new MonumentSchematicParser(); schema.setFace(BlockFace.NORTH); schema.apply(); - } catch (Throwable e) { + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } @@ -70,8 +74,9 @@ public void spawnLargeLight(@NotNull PopulatorDataAbstract data, int x, int y, i public void upSpire(@NotNull SimpleBlock base, @NotNull Random rand) { while (base.isSolid() || base.getUp().isSolid()) { base = base.getUp(); - if (base.getY() > TerraformGenerator.seaLevel) + if (base.getY() > TerraformGenerator.seaLevel) { return; + } } spire(new Wall(base, BlockFace.NORTH), rand); } @@ -84,8 +89,12 @@ public void spire(@NotNull Wall w, @NotNull Random rand, int height) { switch (this) { case DARK_LIGHTLESS: for (int i = 0; i < height; i++) { - if (i == 0) w.setType(Material.DARK_PRISMARINE); - else if (i > height - 3) w.setType(Material.PRISMARINE_WALL); + if (i == 0) { + w.setType(Material.DARK_PRISMARINE); + } + else if (i > height - 3) { + w.setType(Material.PRISMARINE_WALL); + } else { w.setType(GenUtils.randChoice(Material.DARK_PRISMARINE, Material.PRISMARINE_WALL)); if (rand.nextBoolean()) { @@ -101,8 +110,12 @@ public void spire(@NotNull Wall w, @NotNull Random rand, int height) { break; case DARK_PRISMARINE_CORNERS: for (int i = 0; i < height; i++) { - if (i == 0) w.setType(Material.DARK_PRISMARINE); - else if (i == 3) w.setType(Material.SEA_LANTERN); + if (i == 0) { + w.setType(Material.DARK_PRISMARINE); + } + else if (i == 3) { + w.setType(Material.SEA_LANTERN); + } else { w.setType(GenUtils.randChoice(Material.DARK_PRISMARINE, Material.PRISMARINE_WALL)); if (rand.nextBoolean()) { @@ -117,9 +130,15 @@ public void spire(@NotNull Wall w, @NotNull Random rand, int height) { break; case PRISMARINE_LANTERNS: for (int i = 0; i < height; i++) { - if (i == 0) w.setType(Material.PRISMARINE_BRICKS); - else if (i > height - 2) w.setType(Material.PRISMARINE_WALL); - else if (i == height - 2) w.setType(Material.PRISMARINE_BRICKS); + if (i == 0) { + w.setType(Material.PRISMARINE_BRICKS); + } + else if (i > height - 2) { + w.setType(Material.PRISMARINE_WALL); + } + else if (i == height - 2) { + w.setType(Material.PRISMARINE_BRICKS); + } else { w.setType(Material.PRISMARINE_WALL); if (i == 3) { diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentPathPopulator.java b/common/src/main/java/org/terraform/structure/monument/MonumentPathPopulator.java index 53ad2cd3..62a0167f 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentPathPopulator.java @@ -32,10 +32,12 @@ public void populate(@NotNull PathPopulatorData ppd) { // Floor is Prismarine >:V for (int i = 0; i <= 1; i++) { - if (w.getLeft(i).getType() != Material.SEA_LANTERN) + if (w.getLeft(i).getType() != Material.SEA_LANTERN) { w.getLeft(i).setType(Material.PRISMARINE); - if (w.getRight(i).getType() != Material.SEA_LANTERN) + } + if (w.getRight(i).getType() != Material.SEA_LANTERN) { w.getRight(i).setType(Material.PRISMARINE); + } } // Lantern corridor lights @@ -46,11 +48,11 @@ public void populate(@NotNull PathPopulatorData ppd) { // Pillars if (GenUtils.chance(rand, 1, 20)) { - w.RPillar(5, rand, GenUtils.mergeArr(design.tileSet, new Material[]{Material.SEA_LANTERN})); + w.RPillar(5, rand, GenUtils.mergeArr(design.tileSet, new Material[] {Material.SEA_LANTERN})); } -// else if(GenUtils.chance(rand, 1, 50)){ -// MonumentRoomPopulator.setThickPillar(rand, design, w.get().getUp(3)); -// } + // else if(GenUtils.chance(rand, 1, 50)){ + // MonumentRoomPopulator.setThickPillar(rand, design, w.get().getUp(3)); + // } // Thick pillars if (GenUtils.chance(rand, 1, 50)) { @@ -59,9 +61,9 @@ public void populate(@NotNull PathPopulatorData ppd) { // Small spires on the top if (GenUtils.chance(rand, 1, 50)) { - if (w.getUp(6).isSolid() - && !w.getUp(7).isSolid()) + if (w.getUp(6).isSolid() && !w.getUp(7).isSolid()) { design.spire(w.getUp(7), rand); + } } } diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java b/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java index d16efa30..98236090 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java @@ -31,7 +31,12 @@ import java.util.Random; public class MonumentPopulator extends SingleMegaChunkStructurePopulator { - public static void arch(@NotNull Wall w, @NotNull MonumentDesign design, @NotNull Random random, int archHalfLength, int height) { + public static void arch(@NotNull Wall w, + @NotNull MonumentDesign design, + @NotNull Random random, + int archHalfLength, + int height) + { Wall arch = w.getRelative(0, height, 0); BlockFace left = BlockUtils.getAdjacentFaces(w.getDirection())[1]; BlockFace right = BlockUtils.getAdjacentFaces(w.getDirection())[0]; @@ -91,22 +96,33 @@ private static void lightPlatform(@NotNull PopulatorDataAbstract data, int x, in } } - private static void vegetateNearby(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int range, int x, int z) { + private static void vegetateNearby(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int range, + int x, + int z) + { int i = 25; for (int nx = x - range / 2 - i; nx <= x + range / 2 + i; nx++) { for (int nz = z - range / 2 - i; nz <= z + range / 2 + i; nz++) { if (GenUtils.chance(rand, 2, 5)) { int y = GenUtils.getTrueHighestBlock(data, nx, nz); // Don't place on weird blocks - if (data.getType(nx, y, nz).toString().contains("SLAB") || - data.getType(nx, y, nz).toString().contains("STAIR") || - data.getType(nx, y, nz).toString().contains("WALL")) + if (data.getType(nx, y, nz).toString().contains("SLAB") + || data.getType(nx, y, nz) + .toString() + .contains("STAIR") + || data.getType(nx, y, nz).toString().contains("WALL")) + { continue; + } if (y < TerraformGenerator.seaLevel) { - if (GenUtils.chance(rand, 9, 10)) + if (GenUtils.chance(rand, 9, 10)) { CoralGenerator.generateKelpGrowth(data, nx, y + 1, nz); - else + } + else { CoralGenerator.generateSeaPickles(data, nx, y + 1, nz); + } } } } @@ -122,13 +138,21 @@ private static void setupGuardianSpawns(@NotNull PopulatorDataAbstract data, int int chunkZ = nz >> 4; int hash = Objects.hash(chunkX, chunkZ); - if (done.contains(hash)) + if (done.contains(hash)) { continue; + } done.add(hash); - TerraformGeneratorPlugin.injector.getICAData(((PopulatorDataPostGen) data).getWorld().getChunkAt(chunkX, chunkZ)) - .registerNaturalSpawns(NaturalSpawnType.GUARDIAN, x - range / 2, y, z - range / 2, - x + range / 2, TerraformGenerator.seaLevel, z + range / 2); + TerraformGeneratorPlugin.injector.getICAData(((PopulatorDataPostGen) data).getWorld() + .getChunkAt(chunkX, chunkZ)) + .registerNaturalSpawns(NaturalSpawnType.GUARDIAN, + x - range / 2, + y, + z - range / 2, + x + range / 2, + TerraformGenerator.seaLevel, + z + range / 2 + ); } } @@ -136,26 +160,30 @@ private static void setupGuardianSpawns(@NotNull PopulatorDataAbstract data, int @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } - if (biome.getType() != BiomeType.DEEP_OCEANIC || - biome == BiomeBank.MUSHROOM_ISLANDS) + if (biome.getType() != BiomeType.DEEP_OCEANIC || biome == BiomeBank.MUSHROOM_ISLANDS) { return false; + } return rollSpawnRatio(tw, chunkX, chunkZ); } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 92992), - (int) (TConfigOption.STRUCTURES_MONUMENT_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_MONUMENT_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } - int[] coords = new MegaChunk(data.getChunkX(),data.getChunkZ()).getCenterBiomeSectionBlockCoords(); + int[] coords = new MegaChunk(data.getChunkX(), data.getChunkZ()).getCenterBiomeSectionBlockCoords(); int x = coords[0]; int z = coords[1]; int y = GenUtils.getHighestGround(data, x, z); @@ -163,7 +191,13 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract spawnMonument(tw, tw.getHashedRand(x, y, z, 9299724), data, x, y, z); } - public void spawnMonument(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnMonument(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { TerraformGeneratorPlugin.logger.info("Spawning Monument at: " + x + "," + z); MonumentDesign design = MonumentDesign.values()[random.nextInt(MonumentDesign.values().length)]; int numRooms = 1000; @@ -172,7 +206,15 @@ public void spawnMonument(@NotNull TerraformWorld tw, @NotNull Random random, @N Random hashedRand = tw.getHashedRand(x, y, z); - RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); + RoomLayoutGenerator gen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + ); gen.setPathPopulator(new MonumentPathPopulator(design, tw.getHashedRand(x, y, z, 77))); gen.setRoomMaxX(15); gen.setRoomMaxZ(15); @@ -213,12 +255,21 @@ private void entranceSegment(@NotNull Wall w, @NotNull Random random, MonumentDe /** * Carve a monument entrance. */ - public void spawnMonumentEntrance(TerraformWorld tw, @NotNull MonumentDesign design, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, int range) { + public void spawnMonumentEntrance(TerraformWorld tw, + @NotNull MonumentDesign design, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int range) + { range += 38; BlockFace dir = BlockUtils.getDirectBlockFace(random); SimpleBlock base = new SimpleBlock(data, x, y + 1, z); - for (int i = 0; i < range / 2; i++) + for (int i = 0; i < range / 2; i++) { base = base.getRelative(dir); + } Wall w = new Wall(base, dir); Wall leftClone = w.clone(); Wall rightClone = w.clone(); @@ -241,21 +292,42 @@ public void spawnMonumentEntrance(TerraformWorld tw, @NotNull MonumentDesign des /** * Spawns a pyramid-ish base */ - public void spawnMonumentBase(TerraformWorld tw, @NotNull MonumentDesign design, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, int range) { + public void spawnMonumentBase(TerraformWorld tw, + @NotNull MonumentDesign design, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int range) + { range += 30; for (int i = 6; i >= 0; i--) { for (int nx = x - range / 2 - i; nx <= x + range / 2 + i; nx++) { for (int nz = z - range / 2 - i; nz <= z + range / 2 + i; nz++) { // Spires on the corners - if (i % 2 == 0) + if (i % 2 == 0) { if (nx == x - range / 2 - i || nx == x + range / 2 + i) { if (nz == z - range / 2 - i || nz == z + range / 2 + i) { - design.spire(new Wall(new SimpleBlock(data, nx, y + (6 - i) + 1, nz), BlockFace.NORTH), random); + design.spire( + new Wall(new SimpleBlock(data, nx, y + (6 - i) + 1, nz), BlockFace.NORTH), + random + ); } } + } - data.setType(nx, y + (6 - i), nz, GenUtils.randChoice(random, Material.PRISMARINE_BRICKS, Material.PRISMARINE_BRICKS, Material.PRISMARINE)); + data.setType( + nx, + y + (6 - i), + nz, + GenUtils.randChoice(random, + Material.PRISMARINE_BRICKS, + Material.PRISMARINE_BRICKS, + Material.PRISMARINE + ) + ); } } } @@ -278,7 +350,14 @@ public void spawnMonumentBase(TerraformWorld tw, @NotNull MonumentDesign design, /** * Carves a main hallway in the monument */ - public void carveBaseHallways(TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z, int range) { + public void carveBaseHallways(TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int range) + { range += 29; for (int ny = y + 1; ny <= y + 4; ny++) { for (int nx = x - range / 2; nx <= x + range / 2; nx++) { @@ -286,10 +365,12 @@ public void carveBaseHallways(TerraformWorld tw, Random random, @NotNull Populat // Don't touch the middle if (nx > x + 5 - range / 2 - && nx < x - 5 + range / 2 - && nz > z + 5 - range / 2 - && nz < z - 5 + range / 2) + && nx < x - 5 + range / 2 + && nz > z + 5 - range / 2 + && nz < z - 5 + range / 2) + { continue; + } data.setType(nx, ny, nz, Material.WATER); } } @@ -311,10 +392,10 @@ public void carveBaseHallways(TerraformWorld tw, Random random, @NotNull Populat public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { return world.getHashedRand(888271981, chunkX, chunkZ); } - + @Override public int getChunkBufferDistance() { - return 4; + return 4; } @Override diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/MonumentRoomPopulator.java index 306702a7..bd9a07a8 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentRoomPopulator.java @@ -25,7 +25,10 @@ public MonumentRoomPopulator(Random rand, MonumentDesign design, boolean forceSp this.design = design; } - protected static void setThickPillar(@NotNull Random rand, @NotNull MonumentDesign design, @NotNull SimpleBlock base) { + protected static void setThickPillar(@NotNull Random rand, + @NotNull MonumentDesign design, + @NotNull SimpleBlock base) + { Wall w = new Wall(base, BlockFace.NORTH); w.downUntilSolid(rand, Material.PRISMARINE); for (BlockFace face : BlockUtils.directBlockFaces) { @@ -67,7 +70,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Don't bother with tiny rooms - if (room.getHeight() < 7) return; + if (room.getHeight() < 7) { + return; + } // Corners are dark prismarine for (int[] corner : room.getAllCorners()) { @@ -86,16 +91,17 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (!w.getUp().isSolid()) { Stairs stair = (Stairs) Bukkit.createBlockData(design.stairs()); stair.setFacing(w.getDirection()); - if (w.get().getY() < TerraformGenerator.seaLevel) + if (w.get().getY() < TerraformGenerator.seaLevel) { stair.setWaterlogged(true); + } w.setBlockData(stair); } // Wall decor if (j == length / 2) { if (room.getHeight() >= 16 && room.getWidthX() >= 10 && room.getWidthZ() >= 10) { - MonumentWallPattern.values()[rand.nextInt(MonumentWallPattern.values().length)] - .apply(w.getDown(4)); + MonumentWallPattern.values()[rand.nextInt(MonumentWallPattern.values().length)].apply(w.getDown( + 4)); } } w = w.getLeft(); @@ -104,8 +110,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Sea lanterns for (int[] corner : room.getAllCorners()) { - if (!data.getType(corner[0], room.getY() + room.getHeight() + 1, corner[1]).isSolid()) + if (!data.getType(corner[0], room.getY() + room.getHeight() + 1, corner[1]).isSolid()) { data.setType(corner[0], room.getY() + room.getHeight(), corner[1], Material.SEA_LANTERN); + } } @@ -117,15 +124,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int[] pos : room.getAllCorners(1)) { int x = pos[0]; int z = pos[1]; - design.spire(new Wall(new SimpleBlock(data, x, room.getY() + room.getHeight() + 1, z), BlockFace.NORTH), rand); + design.spire(new Wall( + new SimpleBlock(data, x, room.getY() + room.getHeight() + 1, z), + BlockFace.NORTH + ), rand); } - MonumentPopulator.arch(new Wall(new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()), BlockFace.NORTH), - design, rand, (room.getWidthX() - 4) / 2, 6); - MonumentPopulator.arch(new Wall(new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()), BlockFace.EAST), - design, rand, (room.getWidthX() - 4) / 2, 6); + MonumentPopulator.arch(new Wall( + new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()), + BlockFace.NORTH + ), design, rand, (room.getWidthX() - 4) / 2, 6); + MonumentPopulator.arch(new Wall( + new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()), + BlockFace.EAST + ), design, rand, (room.getWidthX() - 4) / 2, 6); - } else if (i == 2) { + } + else if (i == 2) { // Some abraham lincoln architecture thingy for (Entry walls : room.getFourWalls(data, 1).entrySet()) { Wall w = walls.getKey().getRelative(0, room.getHeight(), 0); @@ -143,7 +158,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room data.setType(x, room.getY() + room.getHeight() + 5, z, design.mat(rand)); } } - } else if (i == 3) { + } + else if (i == 3) { // Large Lamp for (Entry walls : room.getFourWalls(data, 1).entrySet()) { Wall w = walls.getKey().getRelative(0, room.getHeight(), 0); @@ -153,7 +169,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.setType(design.mat(rand)); w.getUp().setType(Material.PRISMARINE_WALL); w.getUp(2).setType(design.slab()); - } else { + } + else { w.setType(design.slab()); } w = w.getLeft(); diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentSchematicParser.java b/common/src/main/java/org/terraform/structure/monument/MonumentSchematicParser.java index 74adff78..95df4b23 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentSchematicParser.java @@ -10,8 +10,7 @@ public class MonumentSchematicParser extends SchematicParser { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (data instanceof Waterlogged - && block.getY() <= TerraformGenerator.seaLevel) { + if (data instanceof Waterlogged && block.getY() <= TerraformGenerator.seaLevel) { ((Waterlogged) data).setWaterlogged(true); } super.applyData(block, data); diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentWallPattern.java b/common/src/main/java/org/terraform/structure/monument/MonumentWallPattern.java index 9b1ec3d3..671da2d3 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentWallPattern.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentWallPattern.java @@ -5,8 +5,7 @@ import org.terraform.data.Wall; public enum MonumentWallPattern { - EYE, - CROSS; + EYE, CROSS; public void apply(@NotNull Wall w) { if (this == EYE) { @@ -40,7 +39,8 @@ public void apply(@NotNull Wall w) { // Pupil w.setType(Material.DARK_PRISMARINE); w.getUp().setType(Material.DARK_PRISMARINE); - } else if (this == CROSS) { + } + else if (this == CROSS) { // Sea lanterns w.setType(Material.SEA_LANTERN); w.getUp(2).setType(Material.SEA_LANTERN); diff --git a/common/src/main/java/org/terraform/structure/monument/TreasureRoomPopulator.java b/common/src/main/java/org/terraform/structure/monument/TreasureRoomPopulator.java index bf8d8963..38f42141 100644 --- a/common/src/main/java/org/terraform/structure/monument/TreasureRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/TreasureRoomPopulator.java @@ -19,8 +19,7 @@ public class TreasureRoomPopulator extends DecoratedSidesElderRoomPopulator { - public TreasureRoomPopulator(Random rand, MonumentDesign design, - boolean forceSpawn, boolean unique) { + public TreasureRoomPopulator(Random rand, MonumentDesign design, boolean forceSpawn, boolean unique) { super(rand, design, forceSpawn, unique); // TODO Auto-generated constructor stub } @@ -35,13 +34,11 @@ private static void spawnLowerClaw(@NotNull PopulatorDataAbstract data, int x, i stair.setFacing(face); block.getUp().getRelative(face).setBlockData(stair); - block.getUp(2).getRelative(face).getRelative(face) - .setBlockData(stair); + block.getUp(2).getRelative(face).getRelative(face).setBlockData(stair); stair.setFacing(face.getOppositeFace()); stair.setHalf(Half.TOP); - block.getUp().getRelative(face).getRelative(face) - .setBlockData(stair); + block.getUp().getRelative(face).getRelative(face).setBlockData(stair); } block.getRelative(-1, 1, -1).setType(Material.PRISMARINE_BRICK_SLAB); @@ -61,13 +58,11 @@ private static void spawnUpperClaw(@NotNull PopulatorDataAbstract data, int x, i stair.setFacing(face); block.getDown().getRelative(face).setBlockData(stair); - block.getDown(2).getRelative(face).getRelative(face) - .setBlockData(stair); + block.getDown(2).getRelative(face).getRelative(face).setBlockData(stair); stair.setFacing(face.getOppositeFace()); stair.setHalf(Half.BOTTOM); - block.getDown().getRelative(face).getRelative(face) - .setBlockData(stair); + block.getDown().getRelative(face).getRelative(face).setBlockData(stair); } Waterlogged slab = (Waterlogged) Bukkit.createBlockData(Material.PRISMARINE_BRICK_SLAB); @@ -91,11 +86,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room try { // World w = ((PopulatorDataPostGen) data).getWorld(); // Add one to all to correct some weird aligning shit. - schema = TerraSchematic.load("monument-gold", new SimpleBlock(data,x+1,y-5,z+1)); + schema = TerraSchematic.load("monument-gold", new SimpleBlock(data, x + 1, y - 5, z + 1)); schema.parser = new MonumentSchematicParser(); schema.setFace(BlockFace.NORTH); schema.apply(); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionCompoundRoomDistributor.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionCompoundRoomDistributor.java index 4c91774f..d714f7a8 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionCompoundRoomDistributor.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionCompoundRoomDistributor.java @@ -28,70 +28,87 @@ * and 2x1 (or 1x2) rooms. */ public class MansionCompoundRoomDistributor { - - // A map of populators and their respective room areas - public static final @NotNull HashMap> groundFloorPopulators = - new HashMap<>() {{ - put(new MansionRoomSize(3,3), MansionRoomPopulatorRegistry.GROUND_3_3.getPopulators()); - put(new MansionRoomSize(2,2), MansionRoomPopulatorRegistry.GROUND_2_2.getPopulators()); - put(new MansionRoomSize(1,2), MansionRoomPopulatorRegistry.GROUND_1_2.getPopulators()); - put(new MansionRoomSize(2,1), MansionRoomPopulatorRegistry.GROUND_2_1.getPopulators()); - put(new MansionRoomSize(1,1), MansionRoomPopulatorRegistry.GROUND_1_1.getPopulators()); - }}; - - public static final @NotNull HashMap> secondFloorPopulators = - new HashMap<>() {{ - put(new MansionRoomSize(3,3), MansionRoomPopulatorRegistry.SECOND_3_3.getPopulators()); - put(new MansionRoomSize(2,2), MansionRoomPopulatorRegistry.SECOND_2_2.getPopulators()); - put(new MansionRoomSize(1,2), MansionRoomPopulatorRegistry.SECOND_1_2.getPopulators()); - put(new MansionRoomSize(2,1), MansionRoomPopulatorRegistry.SECOND_2_1.getPopulators()); - put(new MansionRoomSize(1,1), MansionRoomPopulatorRegistry.SECOND_1_1.getPopulators()); - }}; - - public static void distributeRooms(@NotNull Collection pieces, @NotNull Random random, boolean isGround) { - - HashMap> activeRoomPool; + + // A map of populators and their respective room areas + public static final @NotNull HashMap> groundFloorPopulators = new HashMap<>() {{ + put(new MansionRoomSize(3, 3), MansionRoomPopulatorRegistry.GROUND_3_3.getPopulators()); + put(new MansionRoomSize(2, 2), MansionRoomPopulatorRegistry.GROUND_2_2.getPopulators()); + put(new MansionRoomSize(1, 2), MansionRoomPopulatorRegistry.GROUND_1_2.getPopulators()); + put(new MansionRoomSize(2, 1), MansionRoomPopulatorRegistry.GROUND_2_1.getPopulators()); + put(new MansionRoomSize(1, 1), MansionRoomPopulatorRegistry.GROUND_1_1.getPopulators()); + }}; + + public static final @NotNull HashMap> secondFloorPopulators = new HashMap<>() {{ + put(new MansionRoomSize(3, 3), MansionRoomPopulatorRegistry.SECOND_3_3.getPopulators()); + put(new MansionRoomSize(2, 2), MansionRoomPopulatorRegistry.SECOND_2_2.getPopulators()); + put(new MansionRoomSize(1, 2), MansionRoomPopulatorRegistry.SECOND_1_2.getPopulators()); + put(new MansionRoomSize(2, 1), MansionRoomPopulatorRegistry.SECOND_2_1.getPopulators()); + put(new MansionRoomSize(1, 1), MansionRoomPopulatorRegistry.SECOND_1_1.getPopulators()); + }}; + + public static void distributeRooms(@NotNull Collection pieces, + @NotNull Random random, + boolean isGround) + { + + HashMap> activeRoomPool; ArrayList shuffledList = new ArrayList<>(pieces); - - ArrayList potentialRoomSizes = new ArrayList<>(); - int occupiedCells = 13; - if(isGround) { - activeRoomPool = groundFloorPopulators; - potentialRoomSizes.add(new MansionRoomSize(3,3)); // Stairway Room - }else { - activeRoomPool = secondFloorPopulators; - } - potentialRoomSizes.add(new MansionRoomSize(2,2)); // At least one 2x2 room - - while((double) occupiedCells /pieces.size() < 0.7 || - GenUtils.chance(random, pieces.size()-occupiedCells/4, pieces.size())) { - if((double) occupiedCells /pieces.size() < 0.5 && GenUtils.chance(random, 1, 3)) { - occupiedCells += 4; - potentialRoomSizes.add(new MansionRoomSize(2,2)); - } else { - occupiedCells += 2; - if(random.nextBoolean()) - potentialRoomSizes.add(new MansionRoomSize(2,1)); - else - potentialRoomSizes.add(new MansionRoomSize(1,2)); - } - } - - // Iterate this way because index 0 is the 3x3 room which we want. - for(MansionRoomSize roomSize : potentialRoomSizes) { + + ArrayList potentialRoomSizes = new ArrayList<>(); + int occupiedCells = 13; + if (isGround) { + activeRoomPool = groundFloorPopulators; + potentialRoomSizes.add(new MansionRoomSize(3, 3)); // Stairway Room + } + else { + activeRoomPool = secondFloorPopulators; + } + potentialRoomSizes.add(new MansionRoomSize(2, 2)); // At least one 2x2 room + + while ((double) occupiedCells / pieces.size() < 0.7 || GenUtils.chance( + random, + pieces.size() - occupiedCells / 4, + pieces.size() + )) { + if ((double) occupiedCells / pieces.size() < 0.5 && GenUtils.chance(random, 1, 3)) { + occupiedCells += 4; + potentialRoomSizes.add(new MansionRoomSize(2, 2)); + } + else { + occupiedCells += 2; + if (random.nextBoolean()) { + potentialRoomSizes.add(new MansionRoomSize(2, 1)); + } + else { + potentialRoomSizes.add(new MansionRoomSize(1, 2)); + } + } + } + + // Iterate this way because index 0 is the 3x3 room which we want. + for (MansionRoomSize roomSize : potentialRoomSizes) { Collections.shuffle(shuffledList); - for(JigsawStructurePiece piece : shuffledList) { + for (JigsawStructurePiece piece : shuffledList) { // Force every room to generate at least once before generating duplicate types Collections.shuffle(activeRoomPool.get(roomSize), random); ArrayList populators = activeRoomPool.get(roomSize); - if(populators.size() <= 0) { - activeRoomPool.put(roomSize, MansionRoomPopulatorRegistry.getByRoomSize(roomSize, isGround).getPopulators()); + if (populators.size() <= 0) { + activeRoomPool.put( + roomSize, + MansionRoomPopulatorRegistry.getByRoomSize(roomSize, isGround).getPopulators() + ); populators = activeRoomPool.get(roomSize); } - MansionRoomPopulator populator = populators.get(0).getInstance(piece.getRoom(), ((MansionStandardRoomPiece) piece).internalWalls); - if(canRoomSizeFitWithCenter((MansionStandardRoomPiece) piece, pieces, roomSize, populator, false)) { + MansionRoomPopulator populator = populators.get(0) + .getInstance( + piece.getRoom(), + ((MansionStandardRoomPiece) piece).internalWalls + ); + if (canRoomSizeFitWithCenter((MansionStandardRoomPiece) piece, pieces, roomSize, populator, false)) { // Shuffle and distribute populator - TerraformGeneratorPlugin.logger.info(populator.getClass().getSimpleName() + " generating at " + piece.getRoom().getSimpleLocation()); + TerraformGeneratorPlugin.logger.info(populator.getClass().getSimpleName() + + " generating at " + + piece.getRoom().getSimpleLocation()); ((MansionStandardRoomPiece) piece).setRoomPopulator(populator); // set the populator; // If successful, remove the populator from the active pool. @@ -100,86 +117,101 @@ public static void distributeRooms(@NotNull Collection pie } } } - - // Fill the rest of the rooms with 1x1 rooms - for(JigsawStructurePiece piece:pieces) { - MansionRoomSize roomSize = new MansionRoomSize(1,1); - if(((MansionStandardRoomPiece) piece).getRoomPopulator() == null) { - Collections.shuffle(activeRoomPool.get(roomSize), random); - MansionRoomPopulator populator = activeRoomPool.get(roomSize).get(0).getInstance(piece.getRoom(), ((MansionStandardRoomPiece) piece).internalWalls); - TerraformGeneratorPlugin.logger.info(populator.getClass().getSimpleName() + " generating at " + piece.getRoom().getSimpleLocation()); - ((MansionStandardRoomPiece) piece).setRoomPopulator(populator); // set the populator; - } - - } - } - - - /** - * Also sets the needed rooms to empty room populator and knocks down relevant walls - * if the return value is true. - * @param pieces NOT TO BE MODIFIED + + // Fill the rest of the rooms with 1x1 rooms + for (JigsawStructurePiece piece : pieces) { + MansionRoomSize roomSize = new MansionRoomSize(1, 1); + if (((MansionStandardRoomPiece) piece).getRoomPopulator() == null) { + Collections.shuffle(activeRoomPool.get(roomSize), random); + MansionRoomPopulator populator = activeRoomPool.get(roomSize) + .get(0) + .getInstance( + piece.getRoom(), + ((MansionStandardRoomPiece) piece).internalWalls + ); + TerraformGeneratorPlugin.logger.info(populator.getClass().getSimpleName() + + " generating at " + + piece.getRoom().getSimpleLocation()); + ((MansionStandardRoomPiece) piece).setRoomPopulator(populator); // set the populator; + } + + } + } + + + /** + * Also sets the needed rooms to empty room populator and knocks down relevant walls + * if the return value is true. + * + * @param pieces NOT TO BE MODIFIED */ - public static boolean canRoomSizeFitWithCenter(@NotNull MansionStandardRoomPiece piece, @NotNull Collection pieces, @NotNull MansionRoomSize roomSize, @NotNull MansionRoomPopulator defaultPopulator, boolean force) { - - SimpleLocation center = piece.getRoom().getSimpleLocation(); - - ArrayList relevantLocations = new ArrayList<>(); - relevantLocations.add(center); - // Positive X - if(roomSize.getWidthX() == 2) { - relevantLocations.add(center.getRelative(BlockFace.EAST, MansionJigsawBuilder.groundFloorRoomWidth)); - } - - // Positive Z - if(roomSize.getWidthZ() == 2) { - relevantLocations.add(center.getRelative(BlockFace.SOUTH, MansionJigsawBuilder.groundFloorRoomWidth)); - } - - // Corner for 2x2 rooms - if(roomSize.getWidthZ() == 2 && roomSize.getWidthX() == 2) { - relevantLocations.add(center.getRelative(BlockFace.SOUTH_EAST, MansionJigsawBuilder.groundFloorRoomWidth)); - } - - // 3x3 room - if(roomSize.getWidthX() == 3 && roomSize.getWidthZ() == 3) { - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - relevantLocations.add(center.getRelative(face, MansionJigsawBuilder.groundFloorRoomWidth)); - } - } - - int hits = 0; - // First pass, if any rooms are occupied, return false. - for(JigsawStructurePiece p:pieces) { - if(relevantLocations.contains(p.getRoom().getSimpleLocation())) { - // If force is on, only care if the piece exists in pieces, not if the - // piece is occupied. - if(!force && ((MansionStandardRoomPiece) p).getRoomPopulator() != null) - return false; - hits++; - } - } - - // Should not return false when force is true - // Caller should ensure that. - if(hits < relevantLocations.size()) return false; - - // Second pass, knock down walls and set all rooms to occupied. - // Center room will be set by calling code. - for(JigsawStructurePiece p:pieces) { - if(relevantLocations.contains(p.getRoom().getSimpleLocation())) { - MansionStandardRoomPiece spiece = ((MansionStandardRoomPiece) p); - spiece.setRoomPopulator(defaultPopulator.getInstance(p.getRoom(), spiece.internalWalls),false); - for(BlockFace face:spiece.adjacentPieces.keySet()) { - if(relevantLocations.contains(spiece.adjacentPieces.get(face).getRoom().getSimpleLocation())) - { - spiece.internalWalls.remove(face); // Knock down walls to join rooms - spiece.adjacentPieces.get(face).internalWalls.remove(face.getOppositeFace()); - } - } - } - } - - return true; - } + public static boolean canRoomSizeFitWithCenter(@NotNull MansionStandardRoomPiece piece, + @NotNull Collection pieces, + @NotNull MansionRoomSize roomSize, + @NotNull MansionRoomPopulator defaultPopulator, + boolean force) + { + + SimpleLocation center = piece.getRoom().getSimpleLocation(); + + ArrayList relevantLocations = new ArrayList<>(); + relevantLocations.add(center); + // Positive X + if (roomSize.getWidthX() == 2) { + relevantLocations.add(center.getRelative(BlockFace.EAST, MansionJigsawBuilder.groundFloorRoomWidth)); + } + + // Positive Z + if (roomSize.getWidthZ() == 2) { + relevantLocations.add(center.getRelative(BlockFace.SOUTH, MansionJigsawBuilder.groundFloorRoomWidth)); + } + + // Corner for 2x2 rooms + if (roomSize.getWidthZ() == 2 && roomSize.getWidthX() == 2) { + relevantLocations.add(center.getRelative(BlockFace.SOUTH_EAST, MansionJigsawBuilder.groundFloorRoomWidth)); + } + + // 3x3 room + if (roomSize.getWidthX() == 3 && roomSize.getWidthZ() == 3) { + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + relevantLocations.add(center.getRelative(face, MansionJigsawBuilder.groundFloorRoomWidth)); + } + } + + int hits = 0; + // First pass, if any rooms are occupied, return false. + for (JigsawStructurePiece p : pieces) { + if (relevantLocations.contains(p.getRoom().getSimpleLocation())) { + // If force is on, only care if the piece exists in pieces, not if the + // piece is occupied. + if (!force && ((MansionStandardRoomPiece) p).getRoomPopulator() != null) { + return false; + } + hits++; + } + } + + // Should not return false when force is true + // Caller should ensure that. + if (hits < relevantLocations.size()) { + return false; + } + + // Second pass, knock down walls and set all rooms to occupied. + // Center room will be set by calling code. + for (JigsawStructurePiece p : pieces) { + if (relevantLocations.contains(p.getRoom().getSimpleLocation())) { + MansionStandardRoomPiece spiece = ((MansionStandardRoomPiece) p); + spiece.setRoomPopulator(defaultPopulator.getInstance(p.getRoom(), spiece.internalWalls), false); + for (BlockFace face : spiece.adjacentPieces.keySet()) { + if (relevantLocations.contains(spiece.adjacentPieces.get(face).getRoom().getSimpleLocation())) { + spiece.internalWalls.remove(face); // Knock down walls to join rooms + spiece.adjacentPieces.get(face).internalWalls.remove(face.getOppositeFace()); + } + } + } + } + + return true; + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionEmptyRoomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionEmptyRoomPopulator.java index b4804a1b..b0a8b5cb 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionEmptyRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionEmptyRoomPopulator.java @@ -12,23 +12,21 @@ * Used to mark that a room was considered, but does not need to generate anything. * In contrast to roomPopulator = null, the compound room distributor will not * overwrite emptyroompopulator. - * */ public class MansionEmptyRoomPopulator extends MansionRoomPopulator { - - public MansionEmptyRoomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - @Override - public void decorateRoom(PopulatorDataAbstract data, Random random) { - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,1); - } - - + + public MansionEmptyRoomPopulator(CubeRoom room, HashMap internalWalls) { + super(room, internalWalls); + } + + @Override + public void decorateRoom(PopulatorDataAbstract data, Random random) { + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 1); + } + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionInternalWallState.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionInternalWallState.java index ff7eff48..06acf085 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionInternalWallState.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionInternalWallState.java @@ -1,10 +1,7 @@ package org.terraform.structure.pillager.mansion; public enum MansionInternalWallState { - - WINDOW, - SOLID, - ROOM_ENTRANCE, - EXIT + + WINDOW, SOLID, ROOM_ENTRANCE, EXIT } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionJigsawBuilder.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionJigsawBuilder.java index 41e12fae..91ef6c74 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionJigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionJigsawBuilder.java @@ -32,23 +32,41 @@ import java.util.Random; public class MansionJigsawBuilder extends JigsawBuilder { - - public static final int roomHeight = 7; - public static final int groundFloorRoomWidth = 9; - private final @NotNull ArrayList roofedLocations = new ArrayList<>(); - - private final MansionTowerPieceHandler towerPieceHandler; - private final MansionSecondFloorHandler secondFloorHandler; - + + public static final int roomHeight = 7; + public static final int groundFloorRoomWidth = 9; + private final @NotNull ArrayList roofedLocations = new ArrayList<>(); + + private final MansionTowerPieceHandler towerPieceHandler; + private final MansionSecondFloorHandler secondFloorHandler; + public MansionJigsawBuilder(int widthX, int widthZ, @NotNull PopulatorDataAbstract data, int x, int y, int z) { super(widthX, widthZ, data, x, y, z); towerPieceHandler = new MansionTowerPieceHandler(this, data); secondFloorHandler = new MansionSecondFloorHandler(this); this.pieceWidth = groundFloorRoomWidth; - this.pieceRegistry = new JigsawStructurePiece[]{ - new MansionGroundRoomPiece(groundFloorRoomWidth, roomHeight, groundFloorRoomWidth, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new MansionGroundWallPiece(this, groundFloorRoomWidth, roomHeight, groundFloorRoomWidth, JigsawType.END, BlockUtils.directBlockFaces), - new MansionEntrancePiece(this, groundFloorRoomWidth, roomHeight, groundFloorRoomWidth, JigsawType.ENTRANCE, BlockUtils.directBlockFaces) + this.pieceRegistry = new JigsawStructurePiece[] { + new MansionGroundRoomPiece( + groundFloorRoomWidth, + roomHeight, + groundFloorRoomWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new MansionGroundWallPiece(this, + groundFloorRoomWidth, + roomHeight, + groundFloorRoomWidth, + JigsawType.END, + BlockUtils.directBlockFaces + ), + new MansionEntrancePiece(this, + groundFloorRoomWidth, + roomHeight, + groundFloorRoomWidth, + JigsawType.ENTRANCE, + BlockUtils.directBlockFaces + ) }; this.chanceToAddNewPiece = 90; this.minimumPieces = 15; @@ -56,9 +74,15 @@ public MansionJigsawBuilder(int widthX, int widthZ, @NotNull PopulatorDataAbstra @Override public JigsawStructurePiece getFirstPiece(@NotNull Random random) { - return new MansionGroundRoomPiece(groundFloorRoomWidth, roomHeight, groundFloorRoomWidth, JigsawType.STANDARD, BlockUtils.directBlockFaces); + return new MansionGroundRoomPiece( + groundFloorRoomWidth, + roomHeight, + groundFloorRoomWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ); } - + @Override public void build(@NotNull Random random) { @@ -69,333 +93,403 @@ public void build(@NotNull Random random) { // Make sure awkward corners are fixed for (JigsawStructurePiece piece : this.pieces.values()) { - SimpleBlock core = new SimpleBlock( - this.core.getPopData(), + SimpleBlock core = new SimpleBlock(this.core.getPopData(), piece.getRoom().getX(), piece.getRoom().getY(), - piece.getRoom().getZ()); + piece.getRoom().getZ() + ); Wall target; - - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // nw + + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // nw target = new Wall(core.getRelative(-5, 1, -5)); - decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST, - areOtherWallsOverlapping(piece, BlockFace.NORTH) - || areOtherWallsOverlapping(piece, BlockFace.WEST)); + decorateAwkwardCorner(target, + random, + BlockFace.NORTH, + BlockFace.WEST, + areOtherWallsOverlapping(piece, BlockFace.NORTH) || areOtherWallsOverlapping( + piece, + BlockFace.WEST + ) + ); } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // ne + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // ne target = new Wall(core.getRelative(5, 1, -5)); - decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST, - areOtherWallsOverlapping(piece, BlockFace.NORTH) - || areOtherWallsOverlapping(piece, BlockFace.EAST)); + decorateAwkwardCorner(target, + random, + BlockFace.NORTH, + BlockFace.EAST, + areOtherWallsOverlapping(piece, BlockFace.NORTH) || areOtherWallsOverlapping( + piece, + BlockFace.EAST + ) + ); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // sw + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // sw target = new Wall(core.getRelative(-5, 1, 5)); - decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST, - areOtherWallsOverlapping(piece, BlockFace.SOUTH) - || areOtherWallsOverlapping(piece, BlockFace.WEST)); + decorateAwkwardCorner(target, + random, + BlockFace.SOUTH, + BlockFace.WEST, + areOtherWallsOverlapping(piece, BlockFace.SOUTH) || areOtherWallsOverlapping( + piece, + BlockFace.WEST + ) + ); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // se + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // se target = new Wall(core.getRelative(5, 1, 5)); - decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST, - areOtherWallsOverlapping(piece, BlockFace.SOUTH) - || areOtherWallsOverlapping(piece, BlockFace.EAST)); + decorateAwkwardCorner(target, + random, + BlockFace.SOUTH, + BlockFace.EAST, + areOtherWallsOverlapping(piece, BlockFace.SOUTH) || areOtherWallsOverlapping( + piece, + BlockFace.EAST + ) + ); } } - + // Decorate rooms and walls for (JigsawStructurePiece piece : this.overlapperPieces) { piece.postBuildDecoration(random, this.core.getPopData()); } - + for (JigsawStructurePiece piece : this.pieces.values()) { piece.postBuildDecoration(random, this.core.getPopData()); } for (JigsawStructurePiece piece : this.pieces.values()) { - MansionStandardGroundRoomPiece mansionPiece = (MansionStandardGroundRoomPiece) piece; - mansionPiece.thirdStageDecoration(random, this.core.getPopData()); + MansionStandardGroundRoomPiece mansionPiece = (MansionStandardGroundRoomPiece) piece; + mansionPiece.thirdStageDecoration(random, this.core.getPopData()); } - + // Begin populating second story (place room walls) secondFloorHandler.setRandom(random); secondFloorHandler.populateSecondFloorRoomLayout(); secondFloorHandler.buildSecondFloor(random); secondFloorHandler.decorateAwkwardCorners(); - + // Build the roof int[][] bounds = MansionRoofHandler.getLargestRectangle(this); - + // Shrink to change behaviour of rectangles at the roof. - int[] lowerBounds = new int[] {bounds[0][0],bounds[0][1]}; - int[] upperBounds = new int[] {bounds[1][0],bounds[1][1]}; - + int[] lowerBounds = new int[] {bounds[0][0], bounds[0][1]}; + int[] upperBounds = new int[] {bounds[1][0], bounds[1][1]}; + // Extend the bounds in the shorter axis. - if(MansionRoofHandler.getDominantAxis(lowerBounds, upperBounds) == Axis.X) { - lowerBounds[0] -= 7; - upperBounds[0] += 7; - lowerBounds[1] -= 4; - upperBounds[1] += 4; - }else { - lowerBounds[1] -= 7; - upperBounds[1] += 7; - lowerBounds[0] -= 4; - upperBounds[0] += 4; + if (MansionRoofHandler.getDominantAxis(lowerBounds, upperBounds) == Axis.X) { + lowerBounds[0] -= 7; + upperBounds[0] += 7; + lowerBounds[1] -= 4; + upperBounds[1] += 4; + } + else { + lowerBounds[1] -= 7; + upperBounds[1] += 7; + lowerBounds[0] -= 4; + upperBounds[0] += 4; } - + // Debug code for showing roof bounds. for (JigsawStructurePiece piece : secondFloorHandler.secondFloorOverlapperPieces) { - if(piece instanceof MansionSecondFloorWallPiece) { - ((MansionSecondFloorWallPiece) piece).buildIndividualRoofs(random, this.core.getPopData(), lowerBounds, upperBounds); + if (piece instanceof MansionSecondFloorWallPiece) { + ((MansionSecondFloorWallPiece) piece).buildIndividualRoofs( + random, + this.core.getPopData(), + lowerBounds, + upperBounds + ); } } - + MansionRoofHandler.placeTentRoof(random, this, bounds); for (JigsawStructurePiece piece : secondFloorHandler.secondFloorOverlapperPieces) { piece.postBuildDecoration(random, this.core.getPopData()); } - + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { piece.postBuildDecoration(random, this.core.getPopData()); } - - for(JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { - if(!getRoofedLocations().contains(piece.getRoom().getSimpleLocation())) { - SimpleLocation loc = piece.getRoom().getSimpleLocation().getUp(13); - if(this.core.getPopData().getType(loc.getX(),loc.getY(),loc.getZ()) - != Material.COBBLESTONE_SLAB) { - int towerHeight = towerPieceHandler.registerTowerPiece(random, piece); - ((MansionStandardRoomPiece) piece).setRoomPopulator(new MansionTowerStairwayPopulator(piece.getRoom(), ((MansionStandardRoomPiece) piece).internalWalls, towerHeight)); - } - } + + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + if (!getRoofedLocations().contains(piece.getRoom().getSimpleLocation())) { + SimpleLocation loc = piece.getRoom().getSimpleLocation().getUp(13); + if (this.core.getPopData().getType(loc.getX(), loc.getY(), loc.getZ()) != Material.COBBLESTONE_SLAB) { + int towerHeight = towerPieceHandler.registerTowerPiece(random, piece); + ((MansionStandardRoomPiece) piece).setRoomPopulator(new MansionTowerStairwayPopulator( + piece.getRoom(), + ((MansionStandardRoomPiece) piece).internalWalls, + towerHeight + )); + } + } } - + towerPieceHandler.setupWalls(); towerPieceHandler.buildPieces(random); towerPieceHandler.buildOverlapperPieces(random); - + for (JigsawStructurePiece piece : towerPieceHandler.overlapperPieces) { piece.postBuildDecoration(random, this.core.getPopData()); } - + for (JigsawStructurePiece piece : towerPieceHandler.pieces.values()) { piece.postBuildDecoration(random, this.core.getPopData()); } - + towerPieceHandler.buildRoofs(MansionRoofHandler.getDominantBlockFace(lowerBounds, upperBounds), random); - + // Begin decorating internal rooms - + // GROUND FLOOR - for (JigsawStructurePiece piece : pieces.values()){ - ((MansionStandardRoomPiece) piece).setupInternalAttributes(core.getPopData(), this.getPieces()); + for (JigsawStructurePiece piece : pieces.values()) { + ((MansionStandardRoomPiece) piece).setupInternalAttributes(core.getPopData(), this.getPieces()); } - + // Carves out pathways with a maze algorithm // and open random walls to make the maze less strict. MansionMazeAlgoUtil.setupPathways(this.pieces.values(), random); MansionMazeAlgoUtil.knockdownRandomWalls(this.pieces.values(), random); MansionCompoundRoomDistributor.distributeRooms(this.pieces.values(), random, true); - - for (JigsawStructurePiece piece : pieces.values()){ - ((MansionStandardRoomPiece) piece).buildWalls(random, this.core.getPopData()); + + for (JigsawStructurePiece piece : pieces.values()) { + ((MansionStandardRoomPiece) piece).buildWalls(random, this.core.getPopData()); } - + // Second floor walling - for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()){ - ((MansionStandardRoomPiece) piece).setupInternalAttributes(core.getPopData(),secondFloorHandler.secondFloorPieces); + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + ((MansionStandardRoomPiece) piece).setupInternalAttributes(core.getPopData(), + secondFloorHandler.secondFloorPieces); } - + MansionMazeAlgoUtil.setupPathways(secondFloorHandler.secondFloorPieces.values(), random); MansionMazeAlgoUtil.knockdownRandomWalls(secondFloorHandler.secondFloorPieces.values(), random); - - + + MansionStandardRoomPiece secondFloorStairwayCenter; // Find the Stairway piece and (it extends to the second floor.) - for (JigsawStructurePiece piece : pieces.values()){ - if(((MansionStandardRoomPiece) piece).getRoomPopulator() instanceof MansionGrandStairwayPopulator && ((MansionStandardRoomPiece) piece).isPopulating()) { - secondFloorStairwayCenter = (MansionStandardRoomPiece) secondFloorHandler.secondFloorPieces.get(piece.getRoom().getSimpleLocation().getRelative(0,MansionJigsawBuilder.roomHeight+1,0)); - MansionRoomPopulator secondFloorGrandStairwayPopulator = new MansionSecondFloorGrandStairwayPopulator(null,null).getInstance(secondFloorStairwayCenter.getRoom(), secondFloorStairwayCenter.internalWalls); - if(!MansionCompoundRoomDistributor.canRoomSizeFitWithCenter(secondFloorStairwayCenter, secondFloorHandler.secondFloorPieces.values(), new MansionRoomSize(3,3), secondFloorGrandStairwayPopulator, true)) - { - TerraformGeneratorPlugin.logger.info("[!] Failed to allocate second floor grand stairway space!"); - } - secondFloorStairwayCenter.setRoomPopulator(secondFloorGrandStairwayPopulator); - } + for (JigsawStructurePiece piece : pieces.values()) { + if (((MansionStandardRoomPiece) piece).getRoomPopulator() instanceof MansionGrandStairwayPopulator + && ((MansionStandardRoomPiece) piece).isPopulating()) + { + secondFloorStairwayCenter = (MansionStandardRoomPiece) secondFloorHandler.secondFloorPieces.get(piece.getRoom() + .getSimpleLocation() + .getRelative( + 0, + MansionJigsawBuilder.roomHeight + + 1, + 0)); + MansionRoomPopulator secondFloorGrandStairwayPopulator = new MansionSecondFloorGrandStairwayPopulator( + null, + null).getInstance(secondFloorStairwayCenter.getRoom(), secondFloorStairwayCenter.internalWalls); + if (!MansionCompoundRoomDistributor.canRoomSizeFitWithCenter( + secondFloorStairwayCenter, + secondFloorHandler.secondFloorPieces.values(), + new MansionRoomSize(3, 3), + secondFloorGrandStairwayPopulator, + true + )) + { + TerraformGeneratorPlugin.logger.info("[!] Failed to allocate second floor grand stairway space!"); + } + secondFloorStairwayCenter.setRoomPopulator(secondFloorGrandStairwayPopulator); + } } - + // SECOND FLOOR WALLING MansionCompoundRoomDistributor.distributeRooms(secondFloorHandler.secondFloorPieces.values(), random, false); - for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()){ - ((MansionStandardRoomPiece) piece).buildWalls(random, this.core.getPopData()); + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + ((MansionStandardRoomPiece) piece).buildWalls(random, this.core.getPopData()); } - + // Decorate both floors after all allocations are done. // Always re-loop for each one to prevent weird race condition overlaps. - for (JigsawStructurePiece piece : pieces.values()){ - ((MansionStandardRoomPiece) piece).decorateInternalRoom(random, this.core.getPopData()); + for (JigsawStructurePiece piece : pieces.values()) { + ((MansionStandardRoomPiece) piece).decorateInternalRoom(random, this.core.getPopData()); } - for (JigsawStructurePiece piece : pieces.values()){ - ((MansionStandardRoomPiece) piece).decorateWalls(random, core.getPopData()); + for (JigsawStructurePiece piece : pieces.values()) { + ((MansionStandardRoomPiece) piece).decorateWalls(random, core.getPopData()); } - for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()){ - ((MansionStandardRoomPiece) piece).decorateInternalRoom(random, this.core.getPopData()); + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + ((MansionStandardRoomPiece) piece).decorateInternalRoom(random, this.core.getPopData()); MansionRoofHandler.atticDecorations(random, this.core.getPopData(), piece); } - for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()){ - ((MansionStandardRoomPiece) piece).decorateWalls(random, core.getPopData()); + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + ((MansionStandardRoomPiece) piece).decorateWalls(random, core.getPopData()); } - + // Spawn guards MansionStandardRoomPiece.spawnedGuards = 0; - for (JigsawStructurePiece piece : pieces.values()){ - ((MansionStandardRoomPiece) piece).spawnGuards(random, core.getPopData()); + for (JigsawStructurePiece piece : pieces.values()) { + ((MansionStandardRoomPiece) piece).spawnGuards(random, core.getPopData()); } - for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()){ - ((MansionStandardRoomPiece) piece).spawnGuards(random, core.getPopData()); + for (JigsawStructurePiece piece : secondFloorHandler.secondFloorPieces.values()) { + ((MansionStandardRoomPiece) piece).spawnGuards(random, core.getPopData()); } - TerraformGeneratorPlugin.logger.info("Mansion spawned " + MansionStandardRoomPiece.spawnedGuards + " vindicators and evokers"); + TerraformGeneratorPlugin.logger.info("Mansion spawned " + + MansionStandardRoomPiece.spawnedGuards + + " vindicators and evokers"); } - + /** * Used to check if there's a wall with an opposite facing within the same location */ private boolean areOtherWallsOverlapping(@NotNull JigsawStructurePiece piece, @NotNull BlockFace face) { - SimpleLocation other = new SimpleLocation( - piece.getRoom().getSimpleLocation().getX() + face.getModX() * pieceWidth, + SimpleLocation other = new SimpleLocation(piece.getRoom().getSimpleLocation().getX() + + face.getModX() * pieceWidth, piece.getRoom().getSimpleLocation().getY() + face.getModY() * pieceWidth, - piece.getRoom().getSimpleLocation().getZ() + face.getModZ() * pieceWidth); - for(JigsawStructurePiece wall:this.overlapperPieces) { - if(wall.getRoom().getSimpleLocation().equals(other)) { - if(wall.getRotation() == face.getOppositeFace()) - return true; - } - } - - return false; + piece.getRoom().getSimpleLocation().getZ() + face.getModZ() * pieceWidth + ); + for (JigsawStructurePiece wall : this.overlapperPieces) { + if (wall.getRoom().getSimpleLocation().equals(other)) { + if (wall.getRotation() == face.getOppositeFace()) { + return true; + } + } + } + + return false; } - public void decorateAwkwardCorner(@NotNull Wall target, @NotNull Random random, @NotNull BlockFace one, @NotNull BlockFace two, boolean isSinkIn) { - - // Build a large pillar (supports second floor and provides more depth - if(!isSinkIn) { - Wall largePillar = target.getRelative(one, 4).getRelative(two, 4); - largePillar.Pillar(roomHeight, Material.STONE_BRICKS); - largePillar.getDown().downUntilSolid(new Random(),Material.COBBLESTONE); - largePillar.getRelative(one).downUntilSolid(new Random(),Material.COBBLESTONE); - largePillar.getRelative(two).downUntilSolid(new Random(),Material.COBBLESTONE); - - // Side stone walls - largePillar.getRelative(one).getUp().Pillar(roomHeight-2, Material.COBBLESTONE_WALL); - largePillar.getRelative(one).getUp().CorrectMultipleFacing(roomHeight-2); - largePillar.getRelative(two).getUp().Pillar(roomHeight-2, Material.COBBLESTONE_WALL); - largePillar.getRelative(two).getUp().CorrectMultipleFacing(roomHeight-2); - - // Cobblestone at the top - largePillar.getRelative(one).getRelative(0,roomHeight-1,0).Pillar(3, Material.COBBLESTONE); - largePillar.getRelative(two).getRelative(0,roomHeight-1,0).Pillar(3, Material.COBBLESTONE); - - // Decorative upsidedown stairs - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(one) - .setHalf(Half.TOP) - .apply(largePillar.getRelative(0,roomHeight-2,0).getRelative(one.getOppositeFace())) - .apply(largePillar.getRelative(0,roomHeight-1,0).getRelative(one.getOppositeFace())) - .apply(largePillar.getRelative(0,roomHeight-1,0).getRelative(one.getOppositeFace(),2)); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(two) - .setHalf(Half.TOP) - .apply(largePillar.getRelative(0,roomHeight-2,0).getRelative(two.getOppositeFace())) - .apply(largePillar.getRelative(0,roomHeight-1,0).getRelative(two.getOppositeFace())) - .apply(largePillar.getRelative(0,roomHeight-1,0).getRelative(two.getOppositeFace(),2)); - } - - // Fill in gap in the corner - target.Pillar(roomHeight, Material.POLISHED_ANDESITE); - - target.getUp(2).setType(Material.STONE_BRICK_WALL); - target.getUp(3).setType(Material.POLISHED_DIORITE); - target.getUp(4).setType(Material.STONE_BRICK_WALL); - target.getUp(2).CorrectMultipleFacing(3); - - target.getDown().downUntilSolid(random, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - - // Small stair base - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(one.getOppositeFace()) - .apply(target.getRelative(one)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(two.getOppositeFace()) - .apply(target.getRelative(two)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(two.getOppositeFace()) - .apply(target.getRelative(two).getRelative(one)) - .correct(); - - // Two more slabs at the corner - new SlabBuilder(Material.COBBLESTONE_SLAB) - .lapply(target.getRelative(one).getRelative(BlockUtils.getRight(one))) - .lapply(target.getRelative(one).getRelative(BlockUtils.getLeft(one))); - - new SlabBuilder(Material.COBBLESTONE_SLAB) - .lapply(target.getRelative(two).getRelative(BlockUtils.getRight(two))) - .lapply(target.getRelative(two).getRelative(BlockUtils.getLeft(two))); - - - // Small stair base - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(one.getOppositeFace()) - .setHalf(Half.TOP) - .apply(target.getUp(6).getRelative(one)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(two.getOppositeFace()) - .setHalf(Half.TOP) - .apply(target.getUp(6).getRelative(two)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(two.getOppositeFace()) - .setHalf(Half.TOP) - .apply(target.getUp(6).getRelative(two).getRelative(one)) - .correct(); - - // Two more slabs at the corner - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .lapply(target.getUp(6).getRelative(one).getRelative(BlockUtils.getRight(one))) - .lapply(target.getUp(6).getRelative(one).getRelative(BlockUtils.getLeft(one))); - - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .lapply(target.getUp(6).getRelative(two).getRelative(BlockUtils.getRight(two))) - .lapply(target.getUp(6).getRelative(two).getRelative(BlockUtils.getLeft(two))); + public void decorateAwkwardCorner(@NotNull Wall target, + @NotNull Random random, + @NotNull BlockFace one, + @NotNull BlockFace two, + boolean isSinkIn) + { + + // Build a large pillar (supports second floor and provides more depth + if (!isSinkIn) { + Wall largePillar = target.getRelative(one, 4).getRelative(two, 4); + largePillar.Pillar(roomHeight, Material.STONE_BRICKS); + largePillar.getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + largePillar.getRelative(one).downUntilSolid(new Random(), Material.COBBLESTONE); + largePillar.getRelative(two).downUntilSolid(new Random(), Material.COBBLESTONE); + + // Side stone walls + largePillar.getRelative(one).getUp().Pillar(roomHeight - 2, Material.COBBLESTONE_WALL); + largePillar.getRelative(one).getUp().CorrectMultipleFacing(roomHeight - 2); + largePillar.getRelative(two).getUp().Pillar(roomHeight - 2, Material.COBBLESTONE_WALL); + largePillar.getRelative(two).getUp().CorrectMultipleFacing(roomHeight - 2); + + // Cobblestone at the top + largePillar.getRelative(one).getRelative(0, roomHeight - 1, 0).Pillar(3, Material.COBBLESTONE); + largePillar.getRelative(two).getRelative(0, roomHeight - 1, 0).Pillar(3, Material.COBBLESTONE); + + // Decorative upsidedown stairs + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(one) + .setHalf(Half.TOP) + .apply(largePillar.getRelative(0, roomHeight - 2, 0) + .getRelative(one.getOppositeFace())) + .apply(largePillar.getRelative(0, roomHeight - 1, 0) + .getRelative(one.getOppositeFace())) + .apply(largePillar.getRelative(0, roomHeight - 1, 0) + .getRelative(one.getOppositeFace(), 2)); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(two) + .setHalf(Half.TOP) + .apply(largePillar.getRelative(0, roomHeight - 2, 0) + .getRelative(two.getOppositeFace())) + .apply(largePillar.getRelative(0, roomHeight - 1, 0) + .getRelative(two.getOppositeFace())) + .apply(largePillar.getRelative(0, roomHeight - 1, 0) + .getRelative(two.getOppositeFace(), 2)); + } + + // Fill in gap in the corner + target.Pillar(roomHeight, Material.POLISHED_ANDESITE); + + target.getUp(2).setType(Material.STONE_BRICK_WALL); + target.getUp(3).setType(Material.POLISHED_DIORITE); + target.getUp(4).setType(Material.STONE_BRICK_WALL); + target.getUp(2).CorrectMultipleFacing(3); + + target.getDown() + .downUntilSolid(random, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ); + + // Small stair base + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(one.getOppositeFace()).apply(target.getRelative(one)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(two.getOppositeFace()).apply(target.getRelative(two)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(two.getOppositeFace()) + .apply(target.getRelative(two).getRelative(one)) + .correct(); + + // Two more slabs at the corner + new SlabBuilder(Material.COBBLESTONE_SLAB).lapply(target.getRelative(one).getRelative(BlockUtils.getRight(one))) + .lapply(target.getRelative(one).getRelative(BlockUtils.getLeft(one))); + + new SlabBuilder(Material.COBBLESTONE_SLAB).lapply(target.getRelative(two).getRelative(BlockUtils.getRight(two))) + .lapply(target.getRelative(two).getRelative(BlockUtils.getLeft(two))); + + + // Small stair base + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(one.getOppositeFace()) + .setHalf(Half.TOP) + .apply(target.getUp(6).getRelative(one)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(two.getOppositeFace()) + .setHalf(Half.TOP) + .apply(target.getUp(6).getRelative(two)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(two.getOppositeFace()) + .setHalf(Half.TOP) + .apply(target.getUp(6).getRelative(two).getRelative(one)) + .correct(); + + // Two more slabs at the corner + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .lapply(target.getUp(6) + .getRelative(one) + .getRelative(BlockUtils.getRight(one))) + .lapply(target.getUp(6) + .getRelative(one) + .getRelative(BlockUtils.getLeft(one))); + + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .lapply(target.getUp(6) + .getRelative(two) + .getRelative(BlockUtils.getRight(two))) + .lapply(target.getUp(6) + .getRelative(two) + .getRelative(BlockUtils.getLeft(two))); } - + @Override public boolean canPlaceEntrance(SimpleLocation pieceLoc) { - // Also disallow 2, as it implies a corner doorway, which is diagonal. - // I don't want to deal with a diagonal staircase, so fuck that. - return this.countOverlappingPiecesAtLocation(pieceLoc) != 4 - && this.countOverlappingPiecesAtLocation(pieceLoc) != 2; - } - - public @NotNull ArrayList getRoofedLocations() { - return roofedLocations; - } - - public MansionTowerPieceHandler getTowerPieceHandler() { - return towerPieceHandler; - } - + // Also disallow 2, as it implies a corner doorway, which is diagonal. + // I don't want to deal with a diagonal staircase, so fuck that. + return this.countOverlappingPiecesAtLocation(pieceLoc) != 4 + && this.countOverlappingPiecesAtLocation(pieceLoc) != 2; + } + + public @NotNull ArrayList getRoofedLocations() { + return roofedLocations; + } + + public MansionTowerPieceHandler getTowerPieceHandler() { + return towerPieceHandler; + } + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionMazeAlgoUtil.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionMazeAlgoUtil.java index 6a70c147..7e7bb6e1 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionMazeAlgoUtil.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionMazeAlgoUtil.java @@ -16,13 +16,14 @@ public class MansionMazeAlgoUtil { - private static @Nullable MansionStandardRoomPiece getStartingPiece(@NotNull Collection pieces) { - for(JigsawStructurePiece p:pieces) - return (MansionStandardRoomPiece) p; - return null; - } - - public static void setupPathways(@NotNull Collection pieces, @NotNull Random rand) { + private static @Nullable MansionStandardRoomPiece getStartingPiece(@NotNull Collection pieces) { + for (JigsawStructurePiece p : pieces) { + return (MansionStandardRoomPiece) p; + } + return null; + } + + public static void setupPathways(@NotNull Collection pieces, @NotNull Random rand) { // Total number of cells int n = pieces.size(); @@ -40,63 +41,74 @@ public static void setupPathways(@NotNull Collection piece // Dead end. Go backwards. // No items in stack, break out. - if (cellStack.isEmpty()) break; + if (cellStack.isEmpty()) { + break; + } currentCell = cellStack.pop(); continue; } // choose a random neighbouring cell and move into it. - @SuppressWarnings("unchecked") - Entry entry = (Entry) - neighbours.entrySet().toArray()[ - rand.nextInt(neighbours.size()) - ]; + @SuppressWarnings("unchecked") Entry entry = (Entry) neighbours.entrySet() + .toArray()[rand.nextInt( + neighbours.size())]; // currentCell.knockDownWall(entry.getValue(), entry.getKey()); - if(currentCell.internalWalls.get(entry.getKey()) == MansionInternalWallState.SOLID) { - currentCell.internalWalls.put(entry.getKey(), MansionInternalWallState.ROOM_ENTRANCE); - MansionStandardRoomPiece otherPiece = currentCell.adjacentPieces.get(entry.getKey()); - if(otherPiece.internalWalls.containsKey(entry.getKey().getOppositeFace())) - otherPiece.internalWalls.put(entry.getKey().getOppositeFace(), MansionInternalWallState.ROOM_ENTRANCE); - - } - + if (currentCell.internalWalls.get(entry.getKey()) == MansionInternalWallState.SOLID) { + currentCell.internalWalls.put(entry.getKey(), MansionInternalWallState.ROOM_ENTRANCE); + MansionStandardRoomPiece otherPiece = currentCell.adjacentPieces.get(entry.getKey()); + if (otherPiece.internalWalls.containsKey(entry.getKey().getOppositeFace())) { + otherPiece.internalWalls.put(entry.getKey().getOppositeFace(), + MansionInternalWallState.ROOM_ENTRANCE + ); + } + + } + cellStack.push(currentCell); currentCell = entry.getValue(); nv++; } - } - - /** - * Based on chance, randomly open a few walls + } + + /** + * Based on chance, randomly open a few walls */ - public static void knockdownRandomWalls(@NotNull Collection pieces, @NotNull Random rand) { - for(JigsawStructurePiece piece:pieces) { - MansionStandardRoomPiece spiece = (MansionStandardRoomPiece) piece; - for(BlockFace face:spiece.getShuffledInternalWalls()) { - if(spiece.internalWalls.get(face) == MansionInternalWallState.WINDOW - || spiece.internalWalls.get(face) == MansionInternalWallState.EXIT) - continue; - - if(GenUtils.chance(rand, 1, 10)) { - spiece.adjacentPieces.get(face).internalWalls.put(face.getOppositeFace(), MansionInternalWallState.ROOM_ENTRANCE); - spiece.internalWalls.put(face, MansionInternalWallState.ROOM_ENTRANCE); - } - } - } - } - - /** - * Returns a map of adjacent mansion pieces aren't connected to anything. + public static void knockdownRandomWalls(@NotNull Collection pieces, @NotNull Random rand) { + for (JigsawStructurePiece piece : pieces) { + MansionStandardRoomPiece spiece = (MansionStandardRoomPiece) piece; + for (BlockFace face : spiece.getShuffledInternalWalls()) { + if (spiece.internalWalls.get(face) == MansionInternalWallState.WINDOW + || spiece.internalWalls.get(face) == MansionInternalWallState.EXIT) + { + continue; + } + + if (GenUtils.chance(rand, 1, 10)) { + spiece.adjacentPieces.get(face).internalWalls.put( + face.getOppositeFace(), + MansionInternalWallState.ROOM_ENTRANCE + ); + spiece.internalWalls.put(face, MansionInternalWallState.ROOM_ENTRANCE); + } + } + } + } + + /** + * Returns a map of adjacent mansion pieces aren't connected to anything. */ - private static @NotNull Map getValidNeighbours(Collection pieces, @NotNull MansionStandardRoomPiece piece) { + private static @NotNull Map getValidNeighbours(Collection pieces, + @NotNull MansionStandardRoomPiece piece) + { Map neighbours = new EnumMap<>(BlockFace.class); // Loop NSEW for (BlockFace face : BlockUtils.directBlockFaces) { - if(!piece.adjacentPieces.containsKey(face)) - continue; - MansionStandardRoomPiece neighbour = piece.adjacentPieces.get(face); + if (!piece.adjacentPieces.containsKey(face)) { + continue; + } + MansionStandardRoomPiece neighbour = piece.adjacentPieces.get(face); if (neighbour != null && neighbour.areInternalWallsFullyBlocked()) { neighbours.put(face, neighbour); } @@ -104,5 +116,5 @@ public static void knockdownRandomWalls(@NotNull Collection highestCoords[0]) + if (piece.getRoom().getX() > highestCoords[0]) { highestCoords[0] = piece.getRoom().getX(); - if (piece.getRoom().getZ() > highestCoords[1]) + } + if (piece.getRoom().getZ() > highestCoords[1]) { highestCoords[1] = piece.getRoom().getZ(); + } } - - int previousNotInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords,highestCoords); + + int previousNotInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords, highestCoords); int i = 0; int stall = 0; // Shrink the rectangle one side at a time until it is a rectangle // If the shrink operation did not change the number of pieces not in the rectangle, // then undo the shrink. - while(previousNotInRect != 0) { - int piecesInRect = 0; - switch(i%4) { - case 0: - lowestCoords[0] += MansionJigsawBuilder.groundFloorRoomWidth; - piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords,highestCoords); - if(piecesInRect == previousNotInRect) { - stall++; - if(stall < 4) - lowestCoords[0] -= MansionJigsawBuilder.groundFloorRoomWidth; - else - stall = 0; - } - break; - case 1: - lowestCoords[1] += MansionJigsawBuilder.groundFloorRoomWidth; - piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords,highestCoords); - if(piecesInRect == previousNotInRect) { - stall++; - if(stall < 4) - lowestCoords[1] -= MansionJigsawBuilder.groundFloorRoomWidth; - else - stall = 0; - } - break; - case 2: - highestCoords[0] -= MansionJigsawBuilder.groundFloorRoomWidth; - piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords,highestCoords); - if(piecesInRect == previousNotInRect) { - stall++; - if(stall < 4) - highestCoords[0] += MansionJigsawBuilder.groundFloorRoomWidth; - else - stall = 0; - } - break; - case 3: - highestCoords[1] -= MansionJigsawBuilder.groundFloorRoomWidth; - piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords,highestCoords); - if(piecesInRect == previousNotInRect) { - stall++; - if(stall < 4) - highestCoords[1] += MansionJigsawBuilder.groundFloorRoomWidth; - else - stall = 0;} - break; - } - previousNotInRect = piecesInRect; - i++; + while (previousNotInRect != 0) { + int piecesInRect = 0; + switch (i % 4) { + case 0: + lowestCoords[0] += MansionJigsawBuilder.groundFloorRoomWidth; + piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords, highestCoords); + if (piecesInRect == previousNotInRect) { + stall++; + if (stall < 4) { + lowestCoords[0] -= MansionJigsawBuilder.groundFloorRoomWidth; + } + else { + stall = 0; + } + } + break; + case 1: + lowestCoords[1] += MansionJigsawBuilder.groundFloorRoomWidth; + piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords, highestCoords); + if (piecesInRect == previousNotInRect) { + stall++; + if (stall < 4) { + lowestCoords[1] -= MansionJigsawBuilder.groundFloorRoomWidth; + } + else { + stall = 0; + } + } + break; + case 2: + highestCoords[0] -= MansionJigsawBuilder.groundFloorRoomWidth; + piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords, highestCoords); + if (piecesInRect == previousNotInRect) { + stall++; + if (stall < 4) { + highestCoords[0] += MansionJigsawBuilder.groundFloorRoomWidth; + } + else { + stall = 0; + } + } + break; + case 3: + highestCoords[1] -= MansionJigsawBuilder.groundFloorRoomWidth; + piecesInRect = getNumberOfPiecesNotInRectangle(builder, lowestCoords, highestCoords); + if (piecesInRect == previousNotInRect) { + stall++; + if (stall < 4) { + highestCoords[1] += MansionJigsawBuilder.groundFloorRoomWidth; + } + else { + stall = 0; + } + } + break; + } + previousNotInRect = piecesInRect; + i++; } int y = builder.getCore().getY(); for (int x = lowestCoords[0]; x <= highestCoords[0]; x += builder.getPieceWidth()) { for (int z = lowestCoords[1]; z <= highestCoords[1]; z += builder.getPieceWidth()) { if (builder.getPieces().containsKey(new SimpleLocation(x, y, z))) { - builder.getRoofedLocations().add(new SimpleLocation(x, y+MansionJigsawBuilder.roomHeight + 1, z)); + builder.getRoofedLocations().add(new SimpleLocation(x, y + MansionJigsawBuilder.roomHeight + 1, z)); } } } return new int[][] {lowestCoords, highestCoords}; } - - private static int getNumberOfPiecesNotInRectangle(@NotNull MansionJigsawBuilder builder, int @NotNull [] lowestCoords, int @NotNull [] highestCoords) { - int y = builder.getCore().getY(); - int notInRect = 0; + + private static int getNumberOfPiecesNotInRectangle(@NotNull MansionJigsawBuilder builder, + int @NotNull [] lowestCoords, + int @NotNull [] highestCoords) + { + int y = builder.getCore().getY(); + int notInRect = 0; for (int x = lowestCoords[0]; x <= highestCoords[0]; x += builder.getPieceWidth()) { for (int z = lowestCoords[1]; z <= highestCoords[1]; z += builder.getPieceWidth()) { if (!builder.getPieces().containsKey(new SimpleLocation(x, y, z))) { - notInRect++; + notInRect++; } } } @@ -134,29 +152,37 @@ private static int getNumberOfPiecesNotInRectangle(@NotNull MansionJigsawBuilder // If all pieces accounted for by looping the coords, this is a rectangle. return notInRect; } - + public static @NotNull Axis getDominantAxis(int @NotNull [] lowestCoords, int @NotNull [] highestCoords) { - Axis superiorAxis; + Axis superiorAxis; // Longer axis is the superior one - if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) + if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) { superiorAxis = Axis.X; - else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) + } + else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) { superiorAxis = Axis.Z; + } else // Square house + { superiorAxis = Axis.X; + } return superiorAxis; } - + public static @NotNull BlockFace getDominantBlockFace(int @NotNull [] lowestCoords, int @NotNull [] highestCoords) { - BlockFace superiorAxis; + BlockFace superiorAxis; // Longer axis is the superior one - if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) + if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) { superiorAxis = BlockFace.WEST; - else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) + } + else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) { superiorAxis = BlockFace.NORTH; + } else // Square house + { superiorAxis = BlockFace.WEST; + } return superiorAxis; } @@ -167,18 +193,18 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] public static void placeTentRoof(Random rand, @NotNull MansionJigsawBuilder builder, int[][] bounds) { Axis superiorAxis; PopulatorDataAbstract data = builder.getCore().getPopData(); - + int highestY = -1; - + int[] lowestCoords = bounds[0]; int[] highestCoords = bounds[1]; - + // RoofY // Lol idk why 4 - int y = builder.getCore().getY() + 2*MansionJigsawBuilder.roomHeight + 4; - + int y = builder.getCore().getY() + 2 * MansionJigsawBuilder.roomHeight + 4; + superiorAxis = getDominantAxis(lowestCoords, highestCoords); - + lowestCoords[0] -= 5; lowestCoords[1] -= 5; highestCoords[0] += 5; @@ -191,7 +217,8 @@ public static void placeTentRoof(Random rand, @NotNull MansionJigsawBuilder buil length = highestCoords[0] - lowestCoords[0] + 5; breadth = (highestCoords[1] - lowestCoords[1]) + 3; w = new Wall(new SimpleBlock(data, highestCoords[0] + 2, y - 1, lowestCoords[1] - 1), BlockFace.WEST); - } else { + } + else { length = highestCoords[1] - lowestCoords[1] + 5; breadth = (highestCoords[0] - lowestCoords[0]) + 3; w = new Wall(new SimpleBlock(data, lowestCoords[0] - 1, y - 1, lowestCoords[1] - 2), BlockFace.SOUTH); @@ -200,35 +227,44 @@ public static void placeTentRoof(Random rand, @NotNull MansionJigsawBuilder buil for (int i = 0; i < length; i++) { Wall target = w; boolean ascendBlock = false; - for (int right = 0; right < breadth-1; right++) { + for (int right = 0; right < breadth - 1; right++) { // Place logs at the sides if (right != 0 && right != breadth - 1) { if (i == 0 || i == length - 1) { // Sandwiched by trapdoors - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setHalf(Half.TOP) - .setOpen(true) - .setFacing(i == 0 ? target.getDirection().getOppositeFace() : target.getDirection()) - .lapply(target.getDown()); - } else { - if(target.getDown(2).getType() != Material.DARK_OAK_PLANKS) - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(superiorAxis) - .apply(target.getDown().get()); - + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setHalf(Half.TOP) + .setOpen(true) + .setFacing(i == 0 + ? target.getDirection() + .getOppositeFace() + : target.getDirection()) + .lapply(target.getDown()); + } + else { + if (target.getDown(2).getType() != Material.DARK_OAK_PLANKS) { + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(superiorAxis) + .apply(target.getDown().get()); + } + // Connect the roof to the walls below - if(i == 2 || i == length - 3) { - // Lower Walls - Wall bottom = target.getAtY(builder.getCore().getY() + 2*MansionJigsawBuilder.roomHeight+2); - if(BlockUtils.isAir(bottom.getType()) || Tag.STAIRS.isTagged(bottom.getType()) || Tag.SLABS.isTagged(bottom.getType())) { + if (i == 2 || i == length - 3) { + // Lower Walls + Wall bottom = target.getAtY(builder.getCore().getY() + + 2 * MansionJigsawBuilder.roomHeight + + 2); + if (BlockUtils.isAir(bottom.getType()) + || Tag.STAIRS.isTagged(bottom.getType()) + || Tag.SLABS.isTagged(bottom.getType())) + { bottom.setType(Material.DARK_OAK_PLANKS); } - target.getDown(2).downPillar(new Random(), target.getY()-bottom.getY()-2, bottom.getType()); + target.getDown(2) + .downPillar(new Random(), target.getY() - bottom.getY() - 2, bottom.getType()); } - else if(i != 1 && i != length-2)// Force set air for things below the roof within the walls + else if (i != 1 && i != length - 2)// Force set air for things below the roof within the walls { - target.getDown(2).downPillar(new Random(), target.getY()-y+1, Material.AIR); + target.getDown(2).downPillar(new Random(), target.getY() - y + 1, Material.AIR); } } } @@ -242,63 +278,74 @@ else if(i != 1 && i != length-2)// Force set air for things below the roof withi if (breadth % 2 == 1) { // For odd breadth. if (right > breadth / 2) { // Slope down - attemptReplaceSlab(slabType,target,ascendBlock? Type.BOTTOM : Type.DOUBLE); - if(ascendBlock) { - target = target.getRight().getDown(); - ascendBlock = false; - }else{ - target = target.getRight(); - ascendBlock = true; - } - } else if (right < breadth / 2) { + attemptReplaceSlab(slabType, target, ascendBlock ? Type.BOTTOM : Type.DOUBLE); + if (ascendBlock) { + target = target.getRight().getDown(); + ascendBlock = false; + } + else { + target = target.getRight(); + ascendBlock = true; + } + } + else if (right < breadth / 2) { // Slope up - attemptReplaceSlab(slabType,target,ascendBlock? Type.DOUBLE : Type.BOTTOM); - if(ascendBlock) { - target = target.getRight().getUp(); - ascendBlock = false; - }else{ - target = target.getRight(); - ascendBlock = true; - } - } else { + attemptReplaceSlab(slabType, target, ascendBlock ? Type.DOUBLE : Type.BOTTOM); + if (ascendBlock) { + target = target.getRight().getUp(); + ascendBlock = false; + } + else { + target = target.getRight(); + ascendBlock = true; + } + } + else { // Top (Only exists when the breadth is odd. - highestY = target.getY(); + highestY = target.getY(); target.setType(slabType); - if(ascendBlock) { - target = target.getRight().getDown(); - ascendBlock = false; - }else{ - target = target.getRight(); - ascendBlock = true; - } + if (ascendBlock) { + target = target.getRight().getDown(); + ascendBlock = false; + } + else { + target = target.getRight(); + ascendBlock = true; + } } - } else { // For even breadth + } + else { // For even breadth if (right == breadth / 2 - 1) { - highestY = target.getY(); + highestY = target.getY(); target.setType(Material.DARK_OAK_PLANKS); - if(slabType == Material.COBBLESTONE_SLAB) - target.setType(Material.COBBLESTONE); + if (slabType == Material.COBBLESTONE_SLAB) { + target.setType(Material.COBBLESTONE); + } target = target.getRight(); - } else if (right >= breadth / 2) { + } + else if (right >= breadth / 2) { // Slope down - attemptReplaceSlab(slabType,target,ascendBlock? Type.BOTTOM : Type.DOUBLE); - if(ascendBlock) { - target = target.getRight().getDown(); - ascendBlock = false; - }else{ - target = target.getRight(); - ascendBlock = true; - } - } else if (right < breadth / 2) { + attemptReplaceSlab(slabType, target, ascendBlock ? Type.BOTTOM : Type.DOUBLE); + if (ascendBlock) { + target = target.getRight().getDown(); + ascendBlock = false; + } + else { + target = target.getRight(); + ascendBlock = true; + } + } + else if (right < breadth / 2) { // Slope up - attemptReplaceSlab(slabType,target,ascendBlock? Type.DOUBLE : Type.BOTTOM); - if(ascendBlock) { - target = target.getRight().getUp(); - ascendBlock = false; - }else{ - target = target.getRight(); - ascendBlock = true; - } + attemptReplaceSlab(slabType, target, ascendBlock ? Type.DOUBLE : Type.BOTTOM); + if (ascendBlock) { + target = target.getRight().getUp(); + ascendBlock = false; + } + else { + target = target.getRight(); + ascendBlock = true; + } } } } @@ -306,73 +353,86 @@ else if(i != 1 && i != length-2)// Force set air for things below the roof withi } } - + private static void attemptReplaceSlab(@NotNull Material slabType, @NotNull Wall w, @NotNull Type type) { - if(!w.isSolid()) { - if(w.findCeiling(5) != null) return; - new SlabBuilder(slabType) - .setType(type) - .lapply(w); - } else if(Tag.STAIRS.isTagged(w.getType()) || Tag.SLABS.isTagged(w.getType())) - w.setType(Material.DARK_OAK_PLANKS); + if (!w.isSolid()) { + if (w.findCeiling(5) != null) { + return; + } + new SlabBuilder(slabType).setType(type).lapply(w); + } + else if (Tag.STAIRS.isTagged(w.getType()) || Tag.SLABS.isTagged(w.getType())) { + w.setType(Material.DARK_OAK_PLANKS); + } } - - public static void atticDecorations(@NotNull Random rand, @NotNull PopulatorDataAbstract data, @NotNull JigsawStructurePiece piece) { - SimpleBlock core = piece.getRoom().getCenterSimpleBlock(data).getUp(8); - - if(!core.isSolid()) { - Wall ceiling = new Wall(core).getUp().findCeiling(15); - if(ceiling == null) return; - if(ceiling.getType().toString().contains("DARK_OAK")) { - ceiling = ceiling.getDown(); - int chainLength = ceiling.getY() - core.getY() - 2 - rand.nextInt(3); - if(chainLength < 0) chainLength = 0; - ceiling.downPillar(chainLength, Material.CHAIN); - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lantern.setHanging(true); - ceiling.getDown(chainLength).setBlockData(lantern); - if(ceiling.getY() - core.getY() > 5) { - // If height is high enough, spawn a couple of cave spiders and spiders - if(GenUtils.chance(rand, 1,2)) - data.addEntity(core.getX(), core.getY(), core.getZ(), EntityType.SPIDER); - if(GenUtils.chance(rand, 1,2)) - data.addEntity(core.getX(), core.getY(), core.getZ(), EntityType.CAVE_SPIDER); - - // If lucky, spawn allays - if(Version.isAtLeast(19) && rand.nextBoolean()) - for(int i = 0; i < 1 + rand.nextInt(3); i++) - data.addEntity(core.getX(), core.getY(), core.getZ(), OneOneNineBlockHandler.ALLAY); - - - } - } - } - - for(int[] loc:piece.getRoom().getAllCorners(2)) - { - SimpleBlock target = new SimpleBlock(data, loc[0], core.getY(), loc[1]); - Wall ceiling = new Wall(target).findCeiling(15); - // Height more than 1 - if(ceiling != null && ceiling.getY() > target.getY()+1) { - ceiling.getDown().downUntilSolid(new Random(), Material.DARK_OAK_LOG); - for(BlockFace face:BlockUtils.directBlockFaces) { - // Webs - if(GenUtils.chance(rand, 1, 8)) - ceiling.getDown().getRelative(face).get().lsetType(Material.COBWEB); - } - - // Small chance for chests against pillars - if(GenUtils.chance(rand, 1, 20)) - { - BlockFace f = BlockUtils.getDirectBlockFace(rand); - if(!target.getRelative(f).isSolid()) - new ChestBuilder(Material.CHEST) - .setFacing(f).setLootTable(TerraLootTable.WOODLAND_MANSION) - .apply(target.getRelative(f)); - } - - } - } + + public static void atticDecorations(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + @NotNull JigsawStructurePiece piece) + { + SimpleBlock core = piece.getRoom().getCenterSimpleBlock(data).getUp(8); + + if (!core.isSolid()) { + Wall ceiling = new Wall(core).getUp().findCeiling(15); + if (ceiling == null) { + return; + } + if (ceiling.getType().toString().contains("DARK_OAK")) { + ceiling = ceiling.getDown(); + int chainLength = ceiling.getY() - core.getY() - 2 - rand.nextInt(3); + if (chainLength < 0) { + chainLength = 0; + } + ceiling.downPillar(chainLength, Material.CHAIN); + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lantern.setHanging(true); + ceiling.getDown(chainLength).setBlockData(lantern); + if (ceiling.getY() - core.getY() > 5) { + // If height is high enough, spawn a couple of cave spiders and spiders + if (GenUtils.chance(rand, 1, 2)) { + data.addEntity(core.getX(), core.getY(), core.getZ(), EntityType.SPIDER); + } + if (GenUtils.chance(rand, 1, 2)) { + data.addEntity(core.getX(), core.getY(), core.getZ(), EntityType.CAVE_SPIDER); + } + + // If lucky, spawn allays + if (Version.isAtLeast(19) && rand.nextBoolean()) { + for (int i = 0; i < 1 + rand.nextInt(3); i++) { + data.addEntity(core.getX(), core.getY(), core.getZ(), OneOneNineBlockHandler.ALLAY); + } + } + + + } + } + } + + for (int[] loc : piece.getRoom().getAllCorners(2)) { + SimpleBlock target = new SimpleBlock(data, loc[0], core.getY(), loc[1]); + Wall ceiling = new Wall(target).findCeiling(15); + // Height more than 1 + if (ceiling != null && ceiling.getY() > target.getY() + 1) { + ceiling.getDown().downUntilSolid(new Random(), Material.DARK_OAK_LOG); + for (BlockFace face : BlockUtils.directBlockFaces) { + // Webs + if (GenUtils.chance(rand, 1, 8)) { + ceiling.getDown().getRelative(face).get().lsetType(Material.COBWEB); + } + } + + // Small chance for chests against pillars + if (GenUtils.chance(rand, 1, 20)) { + BlockFace f = BlockUtils.getDirectBlockFace(rand); + if (!target.getRelative(f).isSolid()) { + new ChestBuilder(Material.CHEST).setFacing(f) + .setLootTable(TerraLootTable.WOODLAND_MANSION) + .apply(target.getRelative(f)); + } + } + + } + } } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulator.java index 6ca34c31..5cd23fa3 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulator.java @@ -13,46 +13,58 @@ public abstract class MansionRoomPopulator { - private final HashMap internalWalls; - private final CubeRoom room; - public MansionRoomPopulator(CubeRoom room, HashMap internalWalls) { - super(); - this.internalWalls = internalWalls; - this.room = room; - } - - public abstract void decorateRoom(PopulatorDataAbstract data, Random random); - - public CubeRoom getRoom() { - return room; - } - - public @Nullable MansionRoomPopulator getInstance(CubeRoom room, HashMap internalWalls) { - MansionRoomPopulator pop; - try { - pop = (MansionRoomPopulator) this.getClass().getConstructors()[0].newInstance(room, internalWalls); - return pop; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - return null; - } - } - - public void decorateWall(Random rand, Wall w) {} - - public void decorateWindow(Random rand, Wall w) {} - - public void decorateEntrance(Random rand, Wall w) {} - - public void decorateExit(Random rand, Wall w) {} + private final HashMap internalWalls; + private final CubeRoom room; + + public MansionRoomPopulator(CubeRoom room, HashMap internalWalls) { + super(); + this.internalWalls = internalWalls; + this.room = room; + } + + public abstract void decorateRoom(PopulatorDataAbstract data, Random random); + + public CubeRoom getRoom() { + return room; + } + + public @Nullable MansionRoomPopulator getInstance(CubeRoom room, + HashMap internalWalls) + { + MansionRoomPopulator pop; + try { + pop = (MansionRoomPopulator) this.getClass().getConstructors()[0].newInstance(room, internalWalls); + return pop; + } + catch (InstantiationException | + IllegalAccessException | + IllegalArgumentException | + InvocationTargetException | + SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + return null; + } + } + + public void decorateWall(Random rand, Wall w) { + } + + public void decorateWindow(Random rand, Wall w) { + } + + public void decorateEntrance(Random rand, Wall w) { + } + + public void decorateExit(Random rand, Wall w) { + } public HashMap getInternalWalls() { - return internalWalls; - } - - public abstract MansionRoomSize getSize(); - - public int[] getSpawnLocation() { - return new int[] {this.room.getX(), this.room.getY()+1, this.room.getZ()}; - } + return internalWalls; + } + + public abstract MansionRoomSize getSize(); + + public int[] getSpawnLocation() { + return new int[] {this.room.getX(), this.room.getY() + 1, this.room.getZ()}; + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulatorRegistry.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulatorRegistry.java index afc7363d..2d8bec48 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulatorRegistry.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomPopulatorRegistry.java @@ -9,69 +9,73 @@ import org.terraform.structure.pillager.mansion.secondfloor.*; public enum MansionRoomPopulatorRegistry { - - GROUND_3_3(new MansionGrandStairwayPopulator(null,null)), // - GROUND_2_2( - new MansionGroundLevelLibraryPopulator(null,null), - new MansionGroundLevelWarroomPopulator(null,null)), - GROUND_1_2( - new MansionGroundLevelKitchenPopulator(null,null), - new MansionGroundLevelMushroomFarmPopulator(null,null), - new MansionGroundLevelForgePopulator(null,null)), - GROUND_2_1( - new MansionGroundLevelDiningRoomPopulator(null,null), - new MansionGroundLevelBrewingRoomPopulator(null,null)), - GROUND_1_1(new MansionGroundFloorHallwayPopulator(null,null)), - SECOND_3_3(new MansionGrandStairwayPopulator(null,null)), - SECOND_2_2( - new MansionSecondFloorBedroomPopulator(null,null), - new MansionSecondFloorStudyPopulator(null,null)), - SECOND_1_2( - new MansionSecondFloorLoungePopulator(null,null), - new MansionSecondFloorPianoRoomPopulator(null,null)), - SECOND_2_1( - new MansionSecondFloorBunkPopulator(null,null), - new MansionSecondFloorStoreroomPopulator(null,null)), - SECOND_1_1(new MansionSecondFloorHallwayPopulator(null,null)), - - ; - @NotNull - final - ArrayList populators = new ArrayList<>(); - MansionRoomPopulatorRegistry(MansionRoomPopulator... populators){ + GROUND_3_3(new MansionGrandStairwayPopulator(null, null)), // + GROUND_2_2(new MansionGroundLevelLibraryPopulator(null, null), new MansionGroundLevelWarroomPopulator(null, null)), + GROUND_1_2(new MansionGroundLevelKitchenPopulator(null, null), + new MansionGroundLevelMushroomFarmPopulator(null, null), + new MansionGroundLevelForgePopulator(null, null) + ), + GROUND_2_1(new MansionGroundLevelDiningRoomPopulator(null, null), + new MansionGroundLevelBrewingRoomPopulator(null, null) + ), + GROUND_1_1(new MansionGroundFloorHallwayPopulator(null, null)), + + SECOND_3_3(new MansionGrandStairwayPopulator(null, null)), + SECOND_2_2(new MansionSecondFloorBedroomPopulator(null, null), new MansionSecondFloorStudyPopulator(null, null)), + SECOND_1_2(new MansionSecondFloorLoungePopulator(null, null), new MansionSecondFloorPianoRoomPopulator(null, null)), + SECOND_2_1(new MansionSecondFloorBunkPopulator(null, null), new MansionSecondFloorStoreroomPopulator(null, null)), + SECOND_1_1(new MansionSecondFloorHallwayPopulator(null, null)), + + ; + @NotNull + final ArrayList populators = new ArrayList<>(); + + MansionRoomPopulatorRegistry(MansionRoomPopulator... populators) { this.populators.addAll(Arrays.asList(populators)); - } - - public @NotNull ArrayList getPopulators(){ + } + + public static @Nullable MansionRoomPopulatorRegistry getByRoomSize(@NotNull MansionRoomSize size, + boolean isGround) + { + if (isGround) { + if (size.getWidthX() == 3 && size.getWidthZ() == 3) { + return MansionRoomPopulatorRegistry.GROUND_3_3; + } + if (size.getWidthX() == 2 && size.getWidthZ() == 2) { + return MansionRoomPopulatorRegistry.GROUND_2_2; + } + if (size.getWidthX() == 1 && size.getWidthZ() == 2) { + return MansionRoomPopulatorRegistry.GROUND_1_2; + } + if (size.getWidthX() == 2 && size.getWidthZ() == 1) { + return MansionRoomPopulatorRegistry.GROUND_2_1; + } + if (size.getWidthX() == 1 && size.getWidthZ() == 1) { + return MansionRoomPopulatorRegistry.GROUND_1_1; + } + } + else { + if (size.getWidthX() == 3 && size.getWidthZ() == 3) { + return MansionRoomPopulatorRegistry.SECOND_3_3; + } + if (size.getWidthX() == 2 && size.getWidthZ() == 2) { + return MansionRoomPopulatorRegistry.SECOND_2_2; + } + if (size.getWidthX() == 1 && size.getWidthZ() == 2) { + return MansionRoomPopulatorRegistry.SECOND_1_2; + } + if (size.getWidthX() == 2 && size.getWidthZ() == 1) { + return MansionRoomPopulatorRegistry.SECOND_2_1; + } + if (size.getWidthX() == 1 && size.getWidthZ() == 1) { + return MansionRoomPopulatorRegistry.SECOND_1_1; + } + } + return null; + } + + public @NotNull ArrayList getPopulators() { return new ArrayList<>(populators); - } - - public static @Nullable MansionRoomPopulatorRegistry getByRoomSize(@NotNull MansionRoomSize size, boolean isGround) { - if(isGround) { - if(size.getWidthX() == 3 && size.getWidthZ() == 3) - return MansionRoomPopulatorRegistry.GROUND_3_3; - if(size.getWidthX() == 2 && size.getWidthZ() == 2) - return MansionRoomPopulatorRegistry.GROUND_2_2; - if(size.getWidthX() == 1 && size.getWidthZ() == 2) - return MansionRoomPopulatorRegistry.GROUND_1_2; - if(size.getWidthX() == 2 && size.getWidthZ() == 1) - return MansionRoomPopulatorRegistry.GROUND_2_1; - if(size.getWidthX() == 1 && size.getWidthZ() == 1) - return MansionRoomPopulatorRegistry.GROUND_1_1; - } - else{ - if(size.getWidthX() == 3 && size.getWidthZ() == 3) - return MansionRoomPopulatorRegistry.SECOND_3_3; - if(size.getWidthX() == 2 && size.getWidthZ() == 2) - return MansionRoomPopulatorRegistry.SECOND_2_2; - if(size.getWidthX() == 1 && size.getWidthZ() == 2) - return MansionRoomPopulatorRegistry.SECOND_1_2; - if(size.getWidthX() == 2 && size.getWidthZ() == 1) - return MansionRoomPopulatorRegistry.SECOND_2_1; - if(size.getWidthX() == 1 && size.getWidthZ() == 1) - return MansionRoomPopulatorRegistry.SECOND_1_1; - } - return null; - } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java index 03da5c7d..42e6bb9e 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java @@ -10,6 +10,7 @@ import org.terraform.schematic.SchematicParser; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; + import java.util.Random; public class MansionRoomSchematicParser extends SchematicParser { @@ -17,25 +18,28 @@ public class MansionRoomSchematicParser extends SchematicParser { protected final Random rand; protected final PopulatorDataAbstract pop; - public MansionRoomSchematicParser(Random rand, - PopulatorDataAbstract pop) { + public MansionRoomSchematicParser(Random rand, PopulatorDataAbstract pop) { this.rand = rand; this.pop = pop; } @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (TConfigOption.areDecorationsEnabled() && (data.getMaterial() == Material.CHEST || data.getMaterial() == Material.BARREL)) { + if (TConfigOption.areDecorationsEnabled() && (data.getMaterial() == Material.CHEST + || data.getMaterial() == Material.BARREL)) + { if (GenUtils.chance(rand, 2, 5)) { block.setType(Material.AIR); return; // 2 fifths of chests are not placed. } super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.WOODLAND_MANSION); - } else if (data.getMaterial() == Material.POTTED_POPPY) { + } + else if (data.getMaterial() == Material.POTTED_POPPY) { BlockUtils.pickPottedPlant().build(block); return; - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSize.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSize.java index 32212a60..348a5c2f 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSize.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSize.java @@ -2,31 +2,34 @@ public class MansionRoomSize { - private final int widthX; - private final int widthZ; - public MansionRoomSize(int widthX, int widthZ) { - super(); - this.widthX = widthX; - this.widthZ = widthZ; - } - public int getWidthX() { - return widthX; - } - public int getWidthZ() { - return widthZ; - } - - @Override - public int hashCode() { - return widthX + 74077*widthZ; - } - - @Override - public boolean equals(Object other) { - if(other instanceof MansionRoomSize) { - return ((MansionRoomSize) other).widthX == widthX && ((MansionRoomSize) other).widthZ == widthZ; - } - return false; - } - + private final int widthX; + private final int widthZ; + + public MansionRoomSize(int widthX, int widthZ) { + super(); + this.widthX = widthX; + this.widthZ = widthZ; + } + + public int getWidthX() { + return widthX; + } + + public int getWidthZ() { + return widthZ; + } + + @Override + public int hashCode() { + return widthX + 74077 * widthZ; + } + + @Override + public boolean equals(Object other) { + if (other instanceof MansionRoomSize) { + return ((MansionRoomSize) other).widthX == widthX && ((MansionRoomSize) other).widthZ == widthZ; + } + return false; + } + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java index 2b485def..fd258df6 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java @@ -28,209 +28,223 @@ public abstract class MansionStandardRoomPiece extends JigsawStructurePiece { - public @NotNull HashMap adjacentPieces = new HashMap<>(); - public @NotNull HashMap internalWalls = new HashMap<>(); - - // Mansion standard pieces decorate themselves with a special populator. - // If it is null, it will not do anything. - private @Nullable MansionRoomPopulator roomPopulator = null; - private boolean isPopulating = false; - + public static int spawnedGuards = 0; + public @NotNull HashMap adjacentPieces = new HashMap<>(); + public @NotNull HashMap internalWalls = new HashMap<>(); + // Mansion standard pieces decorate themselves with a special populator. + // If it is null, it will not do anything. + private @Nullable MansionRoomPopulator roomPopulator = null; + private boolean isPopulating = false; + public MansionStandardRoomPiece(int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { super(widthX, height, widthZ, type, validDirs); } - - public void setupInternalAttributes(@NotNull PopulatorDataAbstract data, @NotNull HashMap pieces) { - for(BlockFace face:BlockUtils.directBlockFaces) { - SimpleLocation otherLoc = this.getRoom().getSimpleLocation().getRelative(face, MansionJigsawBuilder.groundFloorRoomWidth); - if(!pieces.containsKey(otherLoc)) { - // This is likely to be a window. However, do checks to ensure that this - // isn't the main entrance or a balcony entrance. - SimpleBlock center = this.getRoom().getCenterSimpleBlock(data).getUp(); - if(center.getRelative(face,5).isSolid()) - this.internalWalls.put(face, MansionInternalWallState.WINDOW); - else - this.internalWalls.put(face, MansionInternalWallState.EXIT); - continue; - } - this.adjacentPieces.put(face, (MansionStandardRoomPiece) pieces.get(otherLoc)); - this.internalWalls.put(face, MansionInternalWallState.SOLID); - } + + public void setupInternalAttributes(@NotNull PopulatorDataAbstract data, + @NotNull HashMap pieces) + { + for (BlockFace face : BlockUtils.directBlockFaces) { + SimpleLocation otherLoc = this.getRoom() + .getSimpleLocation() + .getRelative(face, MansionJigsawBuilder.groundFloorRoomWidth); + if (!pieces.containsKey(otherLoc)) { + // This is likely to be a window. However, do checks to ensure that this + // isn't the main entrance or a balcony entrance. + SimpleBlock center = this.getRoom().getCenterSimpleBlock(data).getUp(); + if (center.getRelative(face, 5).isSolid()) { + this.internalWalls.put(face, MansionInternalWallState.WINDOW); + } + else { + this.internalWalls.put(face, MansionInternalWallState.EXIT); + } + continue; + } + this.adjacentPieces.put(face, (MansionStandardRoomPiece) pieces.get(otherLoc)); + this.internalWalls.put(face, MansionInternalWallState.SOLID); + } } - + public void buildWalls(Random random, @NotNull PopulatorDataAbstract data) { - for(BlockFace face:this.internalWalls.keySet()) { - if(internalWalls.get(face) == MansionInternalWallState.WINDOW - || internalWalls.get(face) == MansionInternalWallState.EXIT) - continue; - Entry entry = this.getRoom().getWall(data, face, 0); - Wall w = entry.getKey(); - Wall center = null; - for(int i = 0; i < entry.getValue(); i++) { - w.Pillar(this.getRoom().getHeight(), Material.DARK_OAK_PLANKS); - - if(i == entry.getValue()/2 && this.internalWalls.get(face) == MansionInternalWallState.ROOM_ENTRANCE) { - center = w.clone(); - } - - w = w.getLeft(); - } - if(center != null) { - - center.Pillar(5, Material.AIR); - center.getLeft().Pillar(5, Material.AIR); - center.getRight().Pillar(5, Material.AIR); - center.getLeft(2).Pillar(5, Material.AIR); - center.getRight(2).Pillar(5, Material.AIR); - - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .apply(center.getUp(5)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .apply(center.getUp(4).getLeft(2)) - .setFacing(BlockUtils.getRight(center.getDirection())) - .apply(center.getUp(4).getRight(2)); - - center.getLeft(3).Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); - center.getRight(3).Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); - } - } + for (BlockFace face : this.internalWalls.keySet()) { + if (internalWalls.get(face) == MansionInternalWallState.WINDOW + || internalWalls.get(face) == MansionInternalWallState.EXIT) + { + continue; + } + Entry entry = this.getRoom().getWall(data, face, 0); + Wall w = entry.getKey(); + Wall center = null; + for (int i = 0; i < entry.getValue(); i++) { + w.Pillar(this.getRoom().getHeight(), Material.DARK_OAK_PLANKS); + + if (i == entry.getValue() / 2 + && this.internalWalls.get(face) == MansionInternalWallState.ROOM_ENTRANCE) + { + center = w.clone(); + } + + w = w.getLeft(); + } + if (center != null) { + + center.Pillar(5, Material.AIR); + center.getLeft().Pillar(5, Material.AIR); + center.getRight().Pillar(5, Material.AIR); + center.getLeft(2).Pillar(5, Material.AIR); + center.getRight(2).Pillar(5, Material.AIR); + + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).apply(center.getUp(5)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(center.getDirection())) + .apply(center.getUp(4).getLeft(2)) + .setFacing(BlockUtils.getRight(center.getDirection())) + .apply(center.getUp(4).getRight(2)); + + center.getLeft(3).Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); + center.getRight(3).Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); + } + } } - + public void decorateInternalRoom(Random random, PopulatorDataAbstract data) { - /* - * if(roomPopulator == null) - * TerraformGeneratorPlugin.logger.info("Null room at " + - * this.getRoom().getCenterSimpleBlock(data)); else - * TerraformGeneratorPlugin.logger.info(roomPopulator.getClass().getSimpleName() - * + " invoked at " + this.getRoom().getCenterSimpleBlock(data)); - */ - if(roomPopulator != null && this.isPopulating) { - roomPopulator.decorateRoom(data, random); - } + /* + * if(roomPopulator == null) + * TerraformGeneratorPlugin.logger.info("Null room at " + + * this.getRoom().getCenterSimpleBlock(data)); else + * TerraformGeneratorPlugin.logger.info(roomPopulator.getClass().getSimpleName() + * + " invoked at " + this.getRoom().getCenterSimpleBlock(data)); + */ + if (roomPopulator != null && this.isPopulating) { + roomPopulator.decorateRoom(data, random); + } } public boolean areInternalWallsFullyBlocked() { - for(BlockFace face:this.internalWalls.keySet()) { - if(this.internalWalls.get(face) == MansionInternalWallState.ROOM_ENTRANCE) - return false; - } - return true; + for (BlockFace face : this.internalWalls.keySet()) { + if (this.internalWalls.get(face) == MansionInternalWallState.ROOM_ENTRANCE) { + return false; + } + } + return true; } - + @Override public @Nullable JigsawStructurePiece getInstance(@NotNull Random rand, int depth) { - MansionStandardRoomPiece clone = (MansionStandardRoomPiece) super.getInstance(rand, depth); - if(clone == null) return null; - clone.adjacentPieces = new HashMap<>(); + MansionStandardRoomPiece clone = (MansionStandardRoomPiece) super.getInstance(rand, depth); + if (clone == null) { + return null; + } + clone.adjacentPieces = new HashMap<>(); clone.internalWalls = new HashMap<>(); return clone; } - - public @NotNull Collection getShuffledInternalWalls(){ + + public @NotNull Collection getShuffledInternalWalls() { ArrayList shuffled = new ArrayList<>(internalWalls.keySet()); - Collections.shuffle(shuffled); - return shuffled; + Collections.shuffle(shuffled); + return shuffled; + } + + public @Nullable MansionRoomPopulator getRoomPopulator() { + return roomPopulator; } - public @Nullable MansionRoomPopulator getRoomPopulator() { - return roomPopulator; - } - - public void setRoomPopulator(MansionRoomPopulator roomPopulator) { - setRoomPopulator(roomPopulator, true); - } - - public void setRoomPopulator(MansionRoomPopulator roomPopulator, boolean isPopulating) { - // TerraformGeneratorPlugin.logger.info("Setting " + roomPopulator.getClass().getSimpleName() + " at " + this.getRoom().getSimpleLocation()); - this.roomPopulator = roomPopulator; - this.isPopulating = isPopulating; - } - - /** - * For special wall decorations depending on the room populator. + public void setRoomPopulator(MansionRoomPopulator roomPopulator) { + setRoomPopulator(roomPopulator, true); + } + + public void setRoomPopulator(MansionRoomPopulator roomPopulator, boolean isPopulating) { + // TerraformGeneratorPlugin.logger.info("Setting " + roomPopulator.getClass().getSimpleName() + " at " + this.getRoom().getSimpleLocation()); + this.roomPopulator = roomPopulator; + this.isPopulating = isPopulating; + } + + /** + * For special wall decorations depending on the room populator. */ public void decorateWalls(Random random, @NotNull PopulatorDataAbstract data) { - // UNLIKE ROOM POPULATOR, this will run even if isPopuating is false. - // This is because the other cells must decorate their walls. - if(this.roomPopulator == null) return; - - for(BlockFace face:BlockUtils.directBlockFaces) { - Wall target; - if(!this.internalWalls.containsKey(face)) - continue; - switch(this.internalWalls.get(face)) { - case EXIT: - target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); - this.roomPopulator.decorateExit(random, target.getRear(4)); - break; - case ROOM_ENTRANCE: - target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); - this.roomPopulator.decorateEntrance(random, target.getRear(3)); - break; - case SOLID: - target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); - this.roomPopulator.decorateWall(random, target.getRear(3)); - break; - case WINDOW: - target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); - this.roomPopulator.decorateWindow(random, target.getRear(4)); - break; - } - } + // UNLIKE ROOM POPULATOR, this will run even if isPopuating is false. + // This is because the other cells must decorate their walls. + if (this.roomPopulator == null) { + return; + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + Wall target; + if (!this.internalWalls.containsKey(face)) { + continue; + } + switch (this.internalWalls.get(face)) { + case EXIT: + target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); + this.roomPopulator.decorateExit(random, target.getRear(4)); + break; + case ROOM_ENTRANCE: + target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); + this.roomPopulator.decorateEntrance(random, target.getRear(3)); + break; + case SOLID: + target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); + this.roomPopulator.decorateWall(random, target.getRear(3)); + break; + case WINDOW: + target = new Wall(this.getRoom().getCenterSimpleBlock(data).getUp(), face.getOppositeFace()); + this.roomPopulator.decorateWindow(random, target.getRear(4)); + break; + } + } + } + + public boolean isPopulating() { + return isPopulating; } - public boolean isPopulating() { - return isPopulating; - } - - public static int spawnedGuards = 0; - public void spawnGuards(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { - if(this.roomPopulator == null) return; - - EntityType type = EntityType.VINDICATOR; - int[] spawnLoc = this.roomPopulator.getSpawnLocation(); - - // Always one evoker if the area is 3x3 or 2x2. - // Second floor grand stairway will also spawn the evoker downstairs. - if(this.isPopulating - && (this.roomPopulator.getSize().equals(new MansionRoomSize(3,3)) - || this.roomPopulator.getSize().equals(new MansionRoomSize(2,2)))) - type = EntityType.EVOKER; - - // 1x1 rooms don't spawn as often - if(this.roomPopulator.getSize().equals(new MansionRoomSize(1,1))) - if(GenUtils.chance(rand, 4, 5)) - return; - - SimpleBlock target = new SimpleBlock(data, spawnLoc[0], spawnLoc[1], spawnLoc[2]); - int limit = 5; - BlockFace dir = BlockUtils.getDirectBlockFace(rand); - while(limit > 0 && - ((target.getType() != Material.AIR - && target.getType() != Material.RED_CARPET) - || (target.getUp().getType() != Material.AIR))) { - target = target.getRelative(dir).getUp(); - limit--; - } - - if(limit > 0) { - // target = new Wall(target).findFloor(20).getUp().get(); - target.addEntity(type); - spawnedGuards++; - if(!this.roomPopulator.getSize().equals(new MansionRoomSize(1,1))) - { - for(int i = 0; i < TConfigOption.STRUCTURES_MANSION_SPAWNAGGRESSION.getInt(); i++) { - if(rand.nextBoolean()) { - target.addEntity(EntityType.VINDICATOR); - spawnedGuards++; - } - } - } - // new Wall(target).findFloor(20).getUp().get().addEntity(EntityType.ARMOR_STAND); - } - } + public void spawnGuards(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { + if (this.roomPopulator == null) { + return; + } + + EntityType type = EntityType.VINDICATOR; + int[] spawnLoc = this.roomPopulator.getSpawnLocation(); + + // Always one evoker if the area is 3x3 or 2x2. + // Second floor grand stairway will also spawn the evoker downstairs. + if (this.isPopulating && (this.roomPopulator.getSize().equals(new MansionRoomSize(3, 3)) + || this.roomPopulator.getSize().equals(new MansionRoomSize(2, 2)))) + { + type = EntityType.EVOKER; + } + + // 1x1 rooms don't spawn as often + if (this.roomPopulator.getSize().equals(new MansionRoomSize(1, 1))) { + if (GenUtils.chance(rand, 4, 5)) { + return; + } + } + + SimpleBlock target = new SimpleBlock(data, spawnLoc[0], spawnLoc[1], spawnLoc[2]); + int limit = 5; + BlockFace dir = BlockUtils.getDirectBlockFace(rand); + while (limit > 0 && ((target.getType() != Material.AIR && target.getType() != Material.RED_CARPET) + || (target.getUp().getType() != Material.AIR))) { + target = target.getRelative(dir).getUp(); + limit--; + } + + if (limit > 0) { + // target = new Wall(target).findFloor(20).getUp().get(); + target.addEntity(type); + spawnedGuards++; + if (!this.roomPopulator.getSize().equals(new MansionRoomSize(1, 1))) { + for (int i = 0; i < TConfigOption.STRUCTURES_MANSION_SPAWNAGGRESSION.getInt(); i++) { + if (rand.nextBoolean()) { + target.addEntity(EntityType.VINDICATOR); + spawnedGuards++; + } + } + } + // new Wall(target).findFloor(20).getUp().get().addEntity(EntityType.ARMOR_STAND); + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionEntrancePiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionEntrancePiece.java index 6d66d452..247574b0 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionEntrancePiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionEntrancePiece.java @@ -20,8 +20,15 @@ import java.util.Random; public class MansionEntrancePiece extends JigsawStructurePiece { - final MansionJigsawBuilder builder; - public MansionEntrancePiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + final MansionJigsawBuilder builder; + + public MansionEntrancePiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.builder = builder; @@ -30,80 +37,76 @@ public MansionEntrancePiece(MansionJigsawBuilder builder, int widthX, int height @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); for (int i = 0; i < entry.getValue(); i++) { w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.Pillar(1, rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(this.getRoom().getHeight(), rand, Material.DARK_OAK_PLANKS); - + w = w.getLeft(); } // Place doorway w = w.getRight(5).getUp(); - + // Carve empty frame w.getRight().Pillar(2, new Random(), Material.AIR); - w.Pillar(3, new Random(), Material.AIR); + w.Pillar(3, new Random(), Material.AIR); w.getLeft().Pillar(2, new Random(), Material.AIR); - + // Wall first layer decorations w.getFront().getRight(3).Pillar(3, new Random(), Material.DARK_OAK_LOG); w.getFront().getLeft(3).Pillar(3, new Random(), Material.DARK_OAK_LOG); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP).setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getFront().getRight(2).getUp(2)) - .apply(w.getFront().getRight(1).getUp(3)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP).setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getFront().getLeft(2).getUp(2)) - .apply(w.getFront().getLeft(1).getUp(3)); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp(4).getFront()) - .apply(w.getUp(3).getFront().getLeft(2)) - .apply(w.getUp(3).getFront().getRight(2)); - - new DirectionalBuilder(Material.STONE_BUTTON) - .setFacing(w.getDirection()) - .apply(w.getUp(4).getFront(2)) - .apply(w.getUp(3).getFront(2).getLeft(2)) - .apply(w.getUp(3).getFront(2).getRight(2)); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) - .apply(w.getUp(4).getFront().getLeft()) - .apply(w.getUp(4).getFront().getRight()); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.BOTTOM).setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getFront().getRight(3).getUp(3)) - .apply(w.getFront().getRight(2).getUp(4)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.BOTTOM).setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getFront().getLeft(3).getUp(3)) - .apply(w.getFront().getLeft(2).getUp(4)); - + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getFront().getRight(2).getUp(2)) + .apply(w.getFront().getRight(1).getUp(3)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getFront().getLeft(2).getUp(2)) + .apply(w.getFront().getLeft(1).getUp(3)); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp(4).getFront()) + .apply(w.getUp(3).getFront().getLeft(2)) + .apply(w.getUp(3).getFront().getRight(2)); + + new DirectionalBuilder(Material.STONE_BUTTON).setFacing(w.getDirection()) + .apply(w.getUp(4).getFront(2)) + .apply(w.getUp(3).getFront(2).getLeft(2)) + .apply(w.getUp(3).getFront(2).getRight(2)); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) + .apply(w.getUp(4).getFront().getLeft()) + .apply(w.getUp(4).getFront().getRight()); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.BOTTOM) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getFront().getRight(3).getUp(3)) + .apply(w.getFront().getRight(2).getUp(4)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.BOTTOM) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getFront().getLeft(3).getUp(3)) + .apply(w.getFront().getLeft(2).getUp(4)); + // Wall second layer decorations - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp(3)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP).setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight().getUp(2)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft().getUp(2)); - + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp(3)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight().getUp(2)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft().getUp(2)); + // Stone decorations on the outside w.getFront(2).getRight(3).setType(Material.COBBLESTONE); w.getFront(2).getLeft(3).setType(Material.COBBLESTONE); @@ -111,136 +114,165 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getFront(2).getLeft(3).getUp().setType(Material.COBBLESTONE_WALL); w.getFront(2).getRight(3).getUp(2).setType(Material.LANTERN); w.getFront(2).getLeft(3).getUp(2).setType(Material.LANTERN); - + // At the entrance, place a circle to give the entrance a slightly special look - w = new Wall(new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()),w.getDirection()); - + w = new Wall(new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()), + w.getDirection()); + ArrayList directions = new ArrayList<>(); - for(JigsawStructurePiece p:this.builder.getOverlapperPieces()) { - if(p.getRoom().getSimpleLocation().equals(this.getRoom().getSimpleLocation())) - directions.add(p.getRotation()); + for (JigsawStructurePiece p : this.builder.getOverlapperPieces()) { + if (p.getRoom().getSimpleLocation().equals(this.getRoom().getSimpleLocation())) { + directions.add(p.getRotation()); + } } - + // Door is in an awkward sink-in. // Redetermine entrance direction and move the circle outwards - if(directions.size() == 3) { - for(BlockFace face:directions) { - // Identify the outward direction, then remake w with it. - if(directions.contains(face.getOppositeFace())) - continue; - - w = new Wall(w.get(), face); - // after remaking the wall, move it outwards to allow the circle - // to protrude out better - w = w.getFront(4); - } + if (directions.size() == 3) { + for (BlockFace face : directions) { + // Identify the outward direction, then remake w with it. + if (directions.contains(face.getOppositeFace())) { + continue; + } + + w = new Wall(w.get(), face); + // after remaking the wall, move it outwards to allow the circle + // to protrude out better + w = w.getFront(4); + } } - else - w = w.getRear(3); // Push backwards if this is a direct entrance - + else { + w = w.getRear(3); // Push backwards if this is a direct entrance + } + int radius = 10; - int radiusSquared = radius*radius; - for(int nx = -radius; nx <= radius; nx++) { - for(int nz = -radius; nz <= radius; nz++) { - Wall rel = w.getRelative(nx,0,nz); - if(rel.get().distanceSquared(w.get()) < radiusSquared) - { - if(rel.getType() != Material.STONE_BRICKS) - rel.setType(Material.COBBLESTONE); - rel.getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - rel.getRelative(0,this.getRoom().getHeight()+1,0).setType(Material.STONE_BRICKS); - } + int radiusSquared = radius * radius; + for (int nx = -radius; nx <= radius; nx++) { + for (int nz = -radius; nz <= radius; nz++) { + Wall rel = w.getRelative(nx, 0, nz); + if (rel.get().distanceSquared(w.get()) < radiusSquared) { + if (rel.getType() != Material.STONE_BRICKS) { + rel.setType(Material.COBBLESTONE); + } + rel.getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + rel.getRelative(0, this.getRoom().getHeight() + 1, 0).setType(Material.STONE_BRICKS); + } } } - + // Stairway from the front door Wall stairway = w.getFront(10); - BlockUtils.stairwayUntilSolid(stairway.get(), stairway.getDirection(), - new Material[] {Material.COBBLESTONE}, - Material.COBBLESTONE_STAIRS); - BlockUtils.stairwayUntilSolid(stairway.getLeft().get(), stairway.getDirection(), - new Material[] {Material.COBBLESTONE}, - Material.COBBLESTONE_STAIRS); - BlockUtils.stairwayUntilSolid(stairway.getRight().get(), stairway.getDirection(), - new Material[] {Material.COBBLESTONE}, - Material.COBBLESTONE_STAIRS); - BlockUtils.stairwayUntilSolid(stairway.getLeft(2).get(), stairway.getDirection(), - new Material[] {Material.COBBLESTONE}, - Material.COBBLESTONE_STAIRS); - BlockUtils.stairwayUntilSolid(stairway.getRight(2).get(), stairway.getDirection(), - new Material[] {Material.COBBLESTONE}, - Material.COBBLESTONE_STAIRS); - + BlockUtils.stairwayUntilSolid(stairway.get(), + stairway.getDirection(), + new Material[] {Material.COBBLESTONE}, + Material.COBBLESTONE_STAIRS + ); + BlockUtils.stairwayUntilSolid(stairway.getLeft().get(), + stairway.getDirection(), + new Material[] {Material.COBBLESTONE}, + Material.COBBLESTONE_STAIRS + ); + BlockUtils.stairwayUntilSolid(stairway.getRight().get(), + stairway.getDirection(), + new Material[] {Material.COBBLESTONE}, + Material.COBBLESTONE_STAIRS + ); + BlockUtils.stairwayUntilSolid(stairway.getLeft(2).get(), + stairway.getDirection(), + new Material[] {Material.COBBLESTONE}, + Material.COBBLESTONE_STAIRS + ); + BlockUtils.stairwayUntilSolid(stairway.getRight(2).get(), + stairway.getDirection(), + new Material[] {Material.COBBLESTONE}, + Material.COBBLESTONE_STAIRS + ); + // Primary upper portion decorations - Wall ceilingCenter = stairway.getRear().getRelative(0,1+MansionJigsawBuilder.roomHeight,0); + Wall ceilingCenter = stairway.getRear().getRelative(0, 1 + MansionJigsawBuilder.roomHeight, 0); ceilingCenter.setType(Material.POLISHED_DIORITE); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(ceilingCenter.getDirection())) - .apply(ceilingCenter.getLeft()) - .setFacing(BlockUtils.getRight(ceilingCenter.getDirection())) - .apply(ceilingCenter.getRight()) - .setFacing(ceilingCenter.getDirection().getOppositeFace()) - .apply(ceilingCenter.getDown()); - + + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(ceilingCenter.getDirection())) + .apply(ceilingCenter.getLeft()) + .setFacing(BlockUtils.getRight(ceilingCenter.getDirection())) + .apply(ceilingCenter.getRight()) + .setFacing(ceilingCenter.getDirection().getOppositeFace()) + .apply(ceilingCenter.getDown()); + ceilingCenter.getUp().setType(Material.COBBLESTONE_SLAB); - for(int i = 1; i <= 3; i++) { - ceilingCenter.getUp().getLeft(i).setType(Material.STONE_BRICK_WALL); - ceilingCenter.getUp().getLeft(i).CorrectMultipleFacing(1); - ceilingCenter.getUp().getRight(i).setType(Material.STONE_BRICK_WALL); - ceilingCenter.getUp().getRight(i).CorrectMultipleFacing(1); + for (int i = 1; i <= 3; i++) { + ceilingCenter.getUp().getLeft(i).setType(Material.STONE_BRICK_WALL); + ceilingCenter.getUp().getLeft(i).CorrectMultipleFacing(1); + ceilingCenter.getUp().getRight(i).setType(Material.STONE_BRICK_WALL); + ceilingCenter.getUp().getRight(i).CorrectMultipleFacing(1); } // Replace corners with stone bricks instead of cobblestone // Place decorative pillars - for(BlockFace face:BlockUtils.getAdjacentFaces(stairway.getDirection())) { - Wall target = stairway.getRear().getRelative(face,3); - for(int i = 0; i < 6; i++) { - int maxRecursion = 3; - while(maxRecursion > 0 && target.getType() != Material.COBBLESTONE) { - target = target.getRear(); - maxRecursion--; - } - if(maxRecursion <= 0) break; // Wtf - - // Ceiling decor - if(i > 1) { - target.getRelative(0,2+MansionJigsawBuilder.roomHeight,0).setType(Material.COBBLESTONE_WALL); - target.getRelative(0,2+MansionJigsawBuilder.roomHeight,0).CorrectMultipleFacing(1); - } - - if(i % 2 == 0 || i > 4) { // Just a short stone brick stub - if(i == 0 || i > 4) - target.Pillar(2, Material.STONE_BRICKS); - else - target.getRear().Pillar(2, Material.STONE_BRICKS); - } - else - { - // Pillar - target.getRear().Pillar(1+MansionJigsawBuilder.roomHeight, Material.DARK_OAK_LOG); - - target.getUp().Pillar(MansionJigsawBuilder.roomHeight, Material.COBBLESTONE_WALL); - target.getUp().CorrectMultipleFacing(MansionJigsawBuilder.roomHeight); - - target.getUp(5).Pillar(5, Material.COBBLESTONE); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(face) - .setHalf(Half.TOP) - .apply(target.getRear().getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getRelative(face.getOppositeFace())) - .apply(target.getRear().getRelative(0,MansionJigsawBuilder.roomHeight,0).getRelative(face.getOppositeFace())) - .apply(target.getRear().getRelative(0,MansionJigsawBuilder.roomHeight,0).getRelative(face.getOppositeFace(),2)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(face) - .setHalf(Half.TOP) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight,0).getRelative(face.getOppositeFace())); - } - - target = target.getRelative(face); - } + for (BlockFace face : BlockUtils.getAdjacentFaces(stairway.getDirection())) { + Wall target = stairway.getRear().getRelative(face, 3); + for (int i = 0; i < 6; i++) { + int maxRecursion = 3; + while (maxRecursion > 0 && target.getType() != Material.COBBLESTONE) { + target = target.getRear(); + maxRecursion--; + } + if (maxRecursion <= 0) { + break; // Wtf + } + + // Ceiling decor + if (i > 1) { + target.getRelative(0, 2 + MansionJigsawBuilder.roomHeight, 0).setType(Material.COBBLESTONE_WALL); + target.getRelative(0, 2 + MansionJigsawBuilder.roomHeight, 0).CorrectMultipleFacing(1); + } + + if (i % 2 == 0 || i > 4) { // Just a short stone brick stub + if (i == 0 || i > 4) { + target.Pillar(2, Material.STONE_BRICKS); + } + else { + target.getRear().Pillar(2, Material.STONE_BRICKS); + } + } + else { + // Pillar + target.getRear().Pillar(1 + MansionJigsawBuilder.roomHeight, Material.DARK_OAK_LOG); + + target.getUp().Pillar(MansionJigsawBuilder.roomHeight, Material.COBBLESTONE_WALL); + target.getUp().CorrectMultipleFacing(MansionJigsawBuilder.roomHeight); + + target.getUp(5).Pillar(5, Material.COBBLESTONE); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(face) + .setHalf(Half.TOP) + .apply(target.getRear() + .getRelative(0, + MansionJigsawBuilder.roomHeight + - 1, + 0) + .getRelative(face.getOppositeFace())) + .apply(target.getRear() + .getRelative(0, + MansionJigsawBuilder.roomHeight, + 0) + .getRelative(face.getOppositeFace())) + .apply(target.getRear() + .getRelative(0, + MansionJigsawBuilder.roomHeight, + 0) + .getRelative(face.getOppositeFace(), 2)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(face) + .setHalf(Half.TOP) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight, + 0).getRelative(face.getOppositeFace())); + } + + target = target.getRelative(face); + } } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGrandStairwayPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGrandStairwayPopulator.java index 19a241d3..86b1e646 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGrandStairwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGrandStairwayPopulator.java @@ -28,93 +28,92 @@ public class MansionGrandStairwayPopulator extends MansionRoomPopulator { - public MansionGrandStairwayPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + public MansionGrandStairwayPopulator(CubeRoom room, HashMap internalWalls) { + super(room, internalWalls); + } - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - SimpleBlock target = this.getRoom().getCenterSimpleBlock(data); - try { - TerraSchematic schema = TerraSchematic.load("mansion/mansion-stairway", target); - // schema.parser = new MansionRoomSchematicParser(); - schema.setFace(BlockUtils.getDirectBlockFace(random)); - schema.apply(); - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + SimpleBlock target = this.getRoom().getCenterSimpleBlock(data); + try { + TerraSchematic schema = TerraSchematic.load("mansion/mansion-stairway", target); + // schema.parser = new MansionRoomSchematicParser(); + schema.setFace(BlockUtils.getDirectBlockFace(random)); + schema.apply(); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - // Arch - - w.getLeft(3).Pillar(7, Material.DARK_OAK_LOG); - w.getUp(6).setType(Material.DARK_OAK_PLANKS); - w.getRight(3).Pillar(7, Material.DARK_OAK_LOG); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(5).getLeft(2)) - .apply(w.getUp(6).getLeft(2)) - .apply(w.getUp(6).getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(5).getRight(2)) - .apply(w.getUp(6).getRight(2)) - .apply(w.getUp(6).getRight()); - int choice = rand.nextInt(2); + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + // Arch + + w.getLeft(3).Pillar(7, Material.DARK_OAK_LOG); + w.getUp(6).setType(Material.DARK_OAK_PLANKS); + w.getRight(3).Pillar(7, Material.DARK_OAK_LOG); + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(5).getLeft(2)) + .apply(w.getUp(6).getLeft(2)) + .apply(w.getUp(6).getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(5).getRight(2)) + .apply(w.getUp(6).getRight(2)) + .apply(w.getUp(6).getRight()); + int choice = rand.nextInt(2); // Armor stands - if(choice == 0) { // Wall carving + if (choice == 0) { // Wall carving w.getRear().getUp().Pillar(5, Material.DARK_OAK_LOG); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getRear().getUp(3)) - .apply(w.getRear().getUp(2).getLeft()) - .apply(w.getRear().getUp(2).getRight()) - .apply(w.getRear().getUp(4).getLeft()) - .apply(w.getRear().getUp(4).getRight()) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) - .apply(w.getRear().getUp(3).getLeft()) - .apply(w.getRear().getUp(3).getLeft(2)) - .apply(w.getRear().getUp(3).getRight()) - .apply(w.getRear().getUp(3).getRight(2)); - } else { + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getRear().getUp(3)) + .apply(w.getRear().getUp(2).getLeft()) + .apply(w.getRear().getUp(2).getRight()) + .apply(w.getRear().getUp(4).getLeft()) + .apply(w.getRear().getUp(4).getRight()) + .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) + .apply(w.getRear().getUp(3).getLeft()) + .apply(w.getRear().getUp(3).getLeft(2)) + .apply(w.getRear().getUp(3).getRight()) + .apply(w.getRear().getUp(3).getRight(2)); + } + else { BannerUtils.generatePillagerBanner(w.getUp(4).get(), w.getDirection(), true); - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w) - .apply(w.getLeft()) - .apply(w.getLeft(2)) - .apply(w.getRight()) - .apply(w.getRight(2)); + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP) + .apply(w) + .apply(w.getLeft()) + .apply(w.getLeft(2)) + .apply(w.getRight()) + .apply(w.getRight(2)); ArmorStandUtils.placeArmorStand(w.getUp(2).get(), w.getDirection(), rand); ArmorStandUtils.placeArmorStand(w.getUp(2).getLeft(2).get(), w.getDirection(), rand); ArmorStandUtils.placeArmorStand(w.getUp(2).getRight(2).get(), w.getDirection(), rand); } - } - - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - - Entry entry = this.getRoom().getWall(w.get().getPopData(), w.getDirection().getOppositeFace(), 0); - w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - if(w.getFront().getUp(6).getType() == Material.DARK_OAK_SLAB) { - w.getRear().Pillar(7, Material.DARK_OAK_PLANKS); - w.Pillar(7, Material.DARK_OAK_LOG); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - } - w = w.getLeft(); - } - } + } + + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + + Entry entry = this.getRoom() + .getWall(w.get().getPopData(), w.getDirection().getOppositeFace(), 0); + w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + if (w.getFront().getUp(6).getType() == Material.DARK_OAK_SLAB) { + w.getRear().Pillar(7, Material.DARK_OAK_PLANKS); + w.Pillar(7, Material.DARK_OAK_LOG); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + } + w = w.getLeft(); + } + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(3, 3); + } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(3,3); - } - } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundFloorHallwayPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundFloorHallwayPopulator.java index 3ac7ed17..279428c7 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundFloorHallwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundFloorHallwayPopulator.java @@ -27,214 +27,227 @@ public class MansionGroundFloorHallwayPopulator extends MansionRoomPopulator { - public MansionGroundFloorHallwayPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - SimpleBlock center = this.getRoom().getCenterSimpleBlock(data); - - center.getUp().setType(Material.RED_CARPET); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) - center.getUp().getRelative(face).setType(Material.RED_CARPET); - - for(BlockFace face:BlockUtils.directBlockFaces) { - if(getInternalWalls().get(face) != MansionInternalWallState.WINDOW) { - Wall w = new Wall(center, face); - // This is a solid wall. Bring it forward and decorate it. - if(getInternalWalls().get(face) == MansionInternalWallState.SOLID) { - Wall target = w.getFront(3); - applyHallwaySmoothing(target); - applyHallwaySmoothing(target.getLeft(1)); - applyHallwaySmoothing(target.getLeft(2)); - applyHallwaySmoothing(target.getLeft(3)); - applyHallwaySmoothing(target.getRight(1)); - applyHallwaySmoothing(target.getRight(2)); - applyHallwaySmoothing(target.getRight(3)); - - // Room is connected to a window. - // Spawn the arch and block out the window. - if(!target.getRight(4).getUp().isSolid()) { - applyHallwaySmoothing(target.getRight(4)); - target.getRight(5).Pillar(6, Material.DARK_OAK_PLANKS); - } - if(!target.getLeft(4).getUp().isSolid()) { - applyHallwaySmoothing(target.getLeft(4)); - target.getLeft(5).Pillar(6, Material.DARK_OAK_PLANKS); - } - decorateHallwayWall(random, new Wall(target.getRear().getUp().get(), w.getDirection().getOppositeFace()), false); - } - else if(getInternalWalls().get(face) == MansionInternalWallState.ROOM_ENTRANCE) - // This wall opens to another room somewhere. Connect a red carpet to it - { - for(int length = 2; length < 6; length++) { - Wall target = w.getFront(length).getUp(); - target.setType(Material.RED_CARPET); - if(length < 5) { - target.getLeft().setType(Material.RED_CARPET); - target.getRight().setType(Material.RED_CARPET); - } - } - } - } - else // This face connects to a window - { - center.getUp().getRelative(face,2).setType(Material.RED_CARPET); - decorateHallwayWall(random, new Wall(center.getRelative(face, 3).getUp(), face.getOppositeFace()), true); - } - } - - spawnSmallChandelier(center.getUp(7)); - } - - private void decorateHallwayWall(@NotNull Random random, @NotNull Wall center, boolean isWindow) { - int decorationType = random.nextInt(3); - if(!isWindow) { // Solid wall decorations - switch(decorationType) { - case 0: // 3 1x2 paintings - PaintingUtils.placePainting(center.getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - PaintingUtils.placePainting(center.getRight(2).getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - PaintingUtils.placePainting(center.getLeft(2).getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(center.getLeft()) - .apply(center.getRight()); - - center.getLeft().getUp().Pillar(3, Material.DARK_OAK_FENCE); - center.getLeft().getUp().CorrectMultipleFacing(3); - center.getRight().getUp().Pillar(3, Material.DARK_OAK_FENCE); - center.getRight().getUp().CorrectMultipleFacing(3); - center.getRight().getUp(4).setType(Material.DARK_OAK_PLANKS); - center.getLeft().getUp(4).setType(Material.DARK_OAK_PLANKS); - break; - case 1: // 3 banners - BannerUtils.generateBanner(random, center.getUp(2).get(), center.getDirection(), true); - BannerUtils.generateBanner(random, center.getRight(2).getUp(2).get(), center.getDirection(), true); - BannerUtils.generateBanner(random, center.getLeft(2).getUp(2).get(), center.getDirection(), true); - - center.getLeft().getRear().Pillar(4, Material.DARK_OAK_LOG); - center.getRight().getRear().Pillar(4, Material.DARK_OAK_LOG); - new DirectionalBuilder(Material.WALL_TORCH) - .setFacing(center.getDirection()) - .apply(center.getLeft().getUp(2)) - .apply(center.getRight().getUp(2)); - break; - case 2: // chair - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .apply(center) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setShape(Shape.INNER_RIGHT) - .apply(center.getLeft()) - .setFacing(BlockUtils.getRight(center.getDirection())) - .setShape(Shape.INNER_LEFT) - .apply(center.getRight()); - - center.getLeft(2).setType(Material.DARK_OAK_LOG); - center.getRight(2).setType(Material.DARK_OAK_LOG); - if(random.nextBoolean()) - center.getLeft(2).getUp().setType(Material.LANTERN); - if(random.nextBoolean()) - center.getRight(2).getUp().setType(Material.LANTERN); - break; - default: - break; - } - } else { // Window decorations - switch(decorationType) { - case 0: // Chair - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .apply(center) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setShape(Shape.INNER_RIGHT) - .apply(center.getLeft()) - .setFacing(BlockUtils.getRight(center.getDirection())) - .setShape(Shape.INNER_LEFT) - .apply(center.getRight()); - break; - case 1: // Big potted plants - center.setType(Material.DARK_OAK_PLANKS); - center.getLeft().setType(Material.GRASS_BLOCK); - center.getRight().setType(Material.GRASS_BLOCK); - center.getLeft().getUp().setType(Material.OAK_FENCE); - center.getRight().getUp().setType(Material.OAK_FENCE); - PlantBuilder.OAK_LEAVES.build(center.getLeft().getUp(2)); - PlantBuilder.OAK_LEAVES.build(center.getRight().getUp(2)); - - // Pot - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(center.getDirection()) - .setOpen(true) - .apply(center.getLeft().getFront()) - .apply(center.getRight().getFront()); - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(center.getDirection().getOppositeFace()) - .setOpen(true) - .apply(center.getLeft().getRear()) - .apply(center.getRight().getRear()); - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setOpen(true) - .apply(center.getLeft(2)) - .setFacing(BlockUtils.getRight(center.getDirection())) - .apply(center.getRight(2)); - break; - default: - // Sometimes windows don't get decorated. - break; - } - } - } - - private void spawnSmallChandelier(@NotNull SimpleBlock target) { - target.setType(Material.DARK_OAK_FENCE); - target.getDown().setType(Material.DARK_OAK_FENCE); - target.getDown(2).setType(Material.DARK_OAK_FENCE); - target.getDown(3).setType(Material.DARK_OAK_FENCE); - - target = target.getDown(3); - for(BlockFace face:BlockUtils.directBlockFaces) { - target.getRelative(face).setType(Material.DARK_OAK_FENCE); - target.getRelative(face).getUp().setType(Material.TORCH); - - } - BlockUtils.correctSurroundingMultifacingData(target); - } - - private void applyHallwaySmoothing(@NotNull Wall w) { - w.Pillar(7, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .setHalf(Half.TOP) - .lapply(w.getUp(5)); - w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .lapply(w.getUp(6)); - w.getUp(7).setType(Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .setHalf(Half.TOP) - .lapply(w.getUp(7)); - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,1); - } + public MansionGroundFloorHallwayPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + SimpleBlock center = this.getRoom().getCenterSimpleBlock(data); + + center.getUp().setType(Material.RED_CARPET); + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + center.getUp().getRelative(face).setType(Material.RED_CARPET); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + if (getInternalWalls().get(face) != MansionInternalWallState.WINDOW) { + Wall w = new Wall(center, face); + // This is a solid wall. Bring it forward and decorate it. + if (getInternalWalls().get(face) == MansionInternalWallState.SOLID) { + Wall target = w.getFront(3); + applyHallwaySmoothing(target); + applyHallwaySmoothing(target.getLeft(1)); + applyHallwaySmoothing(target.getLeft(2)); + applyHallwaySmoothing(target.getLeft(3)); + applyHallwaySmoothing(target.getRight(1)); + applyHallwaySmoothing(target.getRight(2)); + applyHallwaySmoothing(target.getRight(3)); + + // Room is connected to a window. + // Spawn the arch and block out the window. + if (!target.getRight(4).getUp().isSolid()) { + applyHallwaySmoothing(target.getRight(4)); + target.getRight(5).Pillar(6, Material.DARK_OAK_PLANKS); + } + if (!target.getLeft(4).getUp().isSolid()) { + applyHallwaySmoothing(target.getLeft(4)); + target.getLeft(5).Pillar(6, Material.DARK_OAK_PLANKS); + } + decorateHallwayWall( + random, + new Wall(target.getRear().getUp().get(), w.getDirection().getOppositeFace()), + false + ); + } + else if (getInternalWalls().get(face) == MansionInternalWallState.ROOM_ENTRANCE) + // This wall opens to another room somewhere. Connect a red carpet to it + { + for (int length = 2; length < 6; length++) { + Wall target = w.getFront(length).getUp(); + target.setType(Material.RED_CARPET); + if (length < 5) { + target.getLeft().setType(Material.RED_CARPET); + target.getRight().setType(Material.RED_CARPET); + } + } + } + } + else // This face connects to a window + { + center.getUp().getRelative(face, 2).setType(Material.RED_CARPET); + decorateHallwayWall( + random, + new Wall(center.getRelative(face, 3).getUp(), face.getOppositeFace()), + true + ); + } + } + + spawnSmallChandelier(center.getUp(7)); + } + + private void decorateHallwayWall(@NotNull Random random, @NotNull Wall center, boolean isWindow) { + int decorationType = random.nextInt(3); + if (!isWindow) { // Solid wall decorations + switch (decorationType) { + case 0: // 3 1x2 paintings + PaintingUtils.placePainting( + center.getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + PaintingUtils.placePainting( + center.getRight(2).getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + PaintingUtils.placePainting( + center.getLeft(2).getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(center.getDirection().getOppositeFace()) + .setHalf(Half.TOP) + .apply(center.getLeft()) + .apply(center.getRight()); + + center.getLeft().getUp().Pillar(3, Material.DARK_OAK_FENCE); + center.getLeft().getUp().CorrectMultipleFacing(3); + center.getRight().getUp().Pillar(3, Material.DARK_OAK_FENCE); + center.getRight().getUp().CorrectMultipleFacing(3); + center.getRight().getUp(4).setType(Material.DARK_OAK_PLANKS); + center.getLeft().getUp(4).setType(Material.DARK_OAK_PLANKS); + break; + case 1: // 3 banners + BannerUtils.generateBanner(random, center.getUp(2).get(), center.getDirection(), true); + BannerUtils.generateBanner(random, center.getRight(2).getUp(2).get(), center.getDirection(), true); + BannerUtils.generateBanner(random, center.getLeft(2).getUp(2).get(), center.getDirection(), true); + + center.getLeft().getRear().Pillar(4, Material.DARK_OAK_LOG); + center.getRight().getRear().Pillar(4, Material.DARK_OAK_LOG); + new DirectionalBuilder(Material.WALL_TORCH).setFacing(center.getDirection()) + .apply(center.getLeft().getUp(2)) + .apply(center.getRight().getUp(2)); + break; + case 2: // chair + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(center.getDirection() + .getOppositeFace()) + .apply(center) + .setFacing(BlockUtils.getLeft(center.getDirection())) + .setShape(Shape.INNER_RIGHT) + .apply(center.getLeft()) + .setFacing(BlockUtils.getRight(center.getDirection())) + .setShape(Shape.INNER_LEFT) + .apply(center.getRight()); + + center.getLeft(2).setType(Material.DARK_OAK_LOG); + center.getRight(2).setType(Material.DARK_OAK_LOG); + if (random.nextBoolean()) { + center.getLeft(2).getUp().setType(Material.LANTERN); + } + if (random.nextBoolean()) { + center.getRight(2).getUp().setType(Material.LANTERN); + } + break; + default: + break; + } + } + else { // Window decorations + switch (decorationType) { + case 0: // Chair + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(center.getDirection() + .getOppositeFace()) + .apply(center) + .setFacing(BlockUtils.getLeft(center.getDirection())) + .setShape(Shape.INNER_RIGHT) + .apply(center.getLeft()) + .setFacing(BlockUtils.getRight(center.getDirection())) + .setShape(Shape.INNER_LEFT) + .apply(center.getRight()); + break; + case 1: // Big potted plants + center.setType(Material.DARK_OAK_PLANKS); + center.getLeft().setType(Material.GRASS_BLOCK); + center.getRight().setType(Material.GRASS_BLOCK); + center.getLeft().getUp().setType(Material.OAK_FENCE); + center.getRight().getUp().setType(Material.OAK_FENCE); + PlantBuilder.OAK_LEAVES.build(center.getLeft().getUp(2)); + PlantBuilder.OAK_LEAVES.build(center.getRight().getUp(2)); + + // Pot + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(center.getDirection()) + .setOpen(true) + .apply(center.getLeft().getFront()) + .apply(center.getRight().getFront()); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(center.getDirection().getOppositeFace()) + .setOpen(true) + .apply(center.getLeft().getRear()) + .apply(center.getRight().getRear()); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(BlockUtils.getLeft(center.getDirection())) + .setOpen(true) + .apply(center.getLeft(2)) + .setFacing(BlockUtils.getRight(center.getDirection())) + .apply(center.getRight(2)); + break; + default: + // Sometimes windows don't get decorated. + break; + } + } + } + + private void spawnSmallChandelier(@NotNull SimpleBlock target) { + target.setType(Material.DARK_OAK_FENCE); + target.getDown().setType(Material.DARK_OAK_FENCE); + target.getDown(2).setType(Material.DARK_OAK_FENCE); + target.getDown(3).setType(Material.DARK_OAK_FENCE); + + target = target.getDown(3); + for (BlockFace face : BlockUtils.directBlockFaces) { + target.getRelative(face).setType(Material.DARK_OAK_FENCE); + target.getRelative(face).getUp().setType(Material.TORCH); + + } + BlockUtils.correctSurroundingMultifacingData(target); + } + + private void applyHallwaySmoothing(@NotNull Wall w) { + w.Pillar(7, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).setHalf(Half.TOP).lapply(w.getUp(5)); + w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).lapply(w.getUp(6)); + w.getUp(7).setType(Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).setHalf(Half.TOP).lapply(w.getUp(7)); + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 1); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelBrewingRoomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelBrewingRoomPopulator.java index d556ebd1..1b367362 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelBrewingRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelBrewingRoomPopulator.java @@ -29,110 +29,120 @@ public class MansionGroundLevelBrewingRoomPopulator extends MansionRoomPopulator { - public MansionGroundLevelBrewingRoomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 15; - private static final int roomWidthZ = 6; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-brewingroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-brewingroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 15; + private static final int roomWidthZ = 6; + public MansionGroundLevelBrewingRoomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-brewingroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-brewingroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + } @Override - public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { + public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { // table with potted mushrooms - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w) - .setShape(Shape.OUTER_RIGHT) - .apply(w.getLeft()) - .setShape(Shape.OUTER_LEFT) - .apply(w.getRight()); - if(rand.nextBoolean()) + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w) + .setShape(Shape.OUTER_RIGHT) + .apply(w.getLeft()) + .setShape(Shape.OUTER_LEFT) + .apply(w.getRight()); + if (rand.nextBoolean()) { w.getUp().setType(Material.POTTED_RED_MUSHROOM, Material.POTTED_BROWN_MUSHROOM); - if(rand.nextBoolean()) + } + if (rand.nextBoolean()) { w.getRight().getUp().setType(Material.POTTED_RED_MUSHROOM, Material.POTTED_BROWN_MUSHROOM); - if(rand.nextBoolean()) + } + if (rand.nextBoolean()) { w.getLeft().getUp().setType(Material.POTTED_RED_MUSHROOM, Material.POTTED_BROWN_MUSHROOM); + } + } + + // Brewing stand and mini library + @Override + public void decorateWall(Random rand, @NotNull Wall w) { + w.setType(Material.CAULDRON); + w.getLeft().setType(Material.BARREL); + w.getLeft().lootTableChest(TerraLootTable.VILLAGE_TEMPLE); + w.getRight().setType(Material.BARREL); + w.getRight().lootTableChest(TerraLootTable.VILLAGE_TEMPLE); + w.getLeft().getUp().setType(Material.BREWING_STAND); + w.getRight().getUp().setType(Material.BREWING_STAND); + + w.getRear().Pillar(5, Material.BOOKSHELF); + w.getLeft().getRear().Pillar(5, Material.BOOKSHELF); + w.getRight().getRear().Pillar(5, Material.BOOKSHELF); + w.getLeft(2).getRear().Pillar(7, Material.DARK_OAK_LOG); + w.getRight(2).getRear().Pillar(7, Material.DARK_OAK_LOG); + + w.getLeft(2).getUp(4).setType(Material.POLISHED_ANDESITE_SLAB); + w.getRight(2).getUp(4).setType(Material.POLISHED_ANDESITE_SLAB); + + w.getUp(5).setType(Material.POLISHED_ANDESITE_SLAB); + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP) + .apply(w.getUp(4).getLeft()) + .apply(w.getUp(4).getRight()); + + w.getUp(4).setType(Material.CHAIN); + w.getUp(3).setType(Material.CHAIN); + Lantern lat = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lat.setHanging(true); + w.getUp(2).setBlockData(lat); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRight(3)) + .apply(w.getRight(2).getUp()) + .apply(w.getRight(2).getUp(3)) + .apply(w.getLeft(2)) + .apply(w.getLeft(2).getUp(2)); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getLeft(3)) + .apply(w.getLeft(2).getUp()) + .apply(w.getLeft(2).getUp(3)) + .apply(w.getRight(2)) + .apply(w.getRight(2).getUp(2)); + + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 1); } - - // Brewing stand and mini library - @Override - public void decorateWall(Random rand, @NotNull Wall w) { - w.setType(Material.CAULDRON); - w.getLeft().setType(Material.BARREL); - w.getLeft().lootTableChest(TerraLootTable.VILLAGE_TEMPLE); - w.getRight().setType(Material.BARREL); - w.getRight().lootTableChest(TerraLootTable.VILLAGE_TEMPLE); - w.getLeft().getUp().setType(Material.BREWING_STAND); - w.getRight().getUp().setType(Material.BREWING_STAND); - - w.getRear().Pillar(5, Material.BOOKSHELF); - w.getLeft().getRear().Pillar(5, Material.BOOKSHELF); - w.getRight().getRear().Pillar(5, Material.BOOKSHELF); - w.getLeft(2).getRear().Pillar(7, Material.DARK_OAK_LOG); - w.getRight(2).getRear().Pillar(7, Material.DARK_OAK_LOG); - - w.getLeft(2).getUp(4).setType(Material.POLISHED_ANDESITE_SLAB); - w.getRight(2).getUp(4).setType(Material.POLISHED_ANDESITE_SLAB); - - w.getUp(5).setType(Material.POLISHED_ANDESITE_SLAB); - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w.getUp(4).getLeft()) - .apply(w.getUp(4).getRight()); - - w.getUp(4).setType(Material.CHAIN); - w.getUp(3).setType(Material.CHAIN); - Lantern lat = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lat.setHanging(true); - w.getUp(2).setBlockData(lat); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRight(3)) - .apply(w.getRight(2).getUp()) - .apply(w.getRight(2).getUp(3)) - .apply(w.getLeft(2)) - .apply(w.getLeft(2).getUp(2)); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft(3)) - .apply(w.getLeft(2).getUp()) - .apply(w.getLeft(2).getUp(3)) - .apply(w.getRight(2)) - .apply(w.getRight(2).getUp(2)); - - } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,1); - } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelDiningRoomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelDiningRoomPopulator.java index 652c7de5..9b247d80 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelDiningRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelDiningRoomPopulator.java @@ -23,87 +23,93 @@ public class MansionGroundLevelDiningRoomPopulator extends MansionRoomPopulator { - public MansionGroundLevelDiningRoomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 15; - private static final int roomWidthZ = 6; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-diningroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-diningroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - } - - @Override - public void decorateExit(Random rand, @NotNull Wall w) { - OrientableBuilder builder = new OrientableBuilder(Material.DARK_OAK_LOG); - builder.setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))); - for(int i = 0; i <= 4; i++) { - builder.lapply(w.getUp(6).getLeft(i)); - builder.lapply(w.getUp(6).getRight(i)); - } - } - - @Override - public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { - decorateExit(rand, w); // same code to join the top to the ceiling decor - - // Pillars to connect ceiling decor to ground (less square) - w = w.getUp(6).getRight(4); - for(int i = 0; i <= 8; i++) { - if(w.getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) { - w.downPillar(rand, 7, Material.DARK_OAK_LOG); - w.getRear().downPillar(rand, 7, Material.DARK_OAK_PLANKS); - } - w = w.getLeft(); - } - } - - // Decorate with paintings and wall texturing - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - - - PaintingUtils.placePainting( - w.getUp(2).get(), - w.getDirection(), - PaintingUtils.getArtFromDimensions(rand, 4, 4)); - - - w = w.getUp(6).getRight(4); - for(int i = 0; i <= 8; i++) { - if(w.getType() == Material.POLISHED_ANDESITE_STAIRS) { - w.getRear().downPillar(rand, 7, Material.DARK_OAK_LOG); - } - w = w.getLeft(); - } - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,1); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 15; + private static final int roomWidthZ = 6; + public MansionGroundLevelDiningRoomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-diningroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-diningroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + } + + @Override + public void decorateExit(Random rand, @NotNull Wall w) { + OrientableBuilder builder = new OrientableBuilder(Material.DARK_OAK_LOG); + builder.setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))); + for (int i = 0; i <= 4; i++) { + builder.lapply(w.getUp(6).getLeft(i)); + builder.lapply(w.getUp(6).getRight(i)); + } + } + + @Override + public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { + decorateExit(rand, w); // same code to join the top to the ceiling decor + + // Pillars to connect ceiling decor to ground (less square) + w = w.getUp(6).getRight(4); + for (int i = 0; i <= 8; i++) { + if (w.getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) { + w.downPillar(rand, 7, Material.DARK_OAK_LOG); + w.getRear().downPillar(rand, 7, Material.DARK_OAK_PLANKS); + } + w = w.getLeft(); + } + } + + // Decorate with paintings and wall texturing + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + + + PaintingUtils.placePainting(w.getUp(2).get(), w.getDirection(), PaintingUtils.getArtFromDimensions(rand, 4, 4)); + + + w = w.getUp(6).getRight(4); + for (int i = 0; i <= 8; i++) { + if (w.getType() == Material.POLISHED_ANDESITE_STAIRS) { + w.getRear().downPillar(rand, 7, Material.DARK_OAK_LOG); + } + w = w.getLeft(); + } + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 1); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelForgePopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelForgePopulator.java index c0c1d471..043fb5d9 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelForgePopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelForgePopulator.java @@ -28,94 +28,97 @@ public class MansionGroundLevelForgePopulator extends MansionRoomPopulator { - public MansionGroundLevelForgePopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 6; - private static final int roomWidthZ = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Mushroom Farm at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-forge", target); - schema.setFace(randomFace); - schema.parser = new MansionForgeSchematicParser(random, data); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1] + roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-forge", target); - schema.setFace(randomFace); - schema.parser = new MansionForgeSchematicParser(random, data); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w.getLeft()) - .apply(w.getRight()) - .setShape(Shape.OUTER_RIGHT) - .apply(w.getLeft(2)) - .setShape(Shape.OUTER_LEFT) - .apply(w.getRight(2)); - - w.setType(Material.FLETCHING_TABLE, - Material.SMITHING_TABLE); - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft(3)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight(3)); - - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w) - .apply(w.getLeft()) - .apply(w.getLeft(2)) - .apply(w.getRight()) - .apply(w.getRight(2)); - - ArmorStandUtils.placeArmorStand(w.getUp(2).get(), w.getDirection(), rand); - ArmorStandUtils.placeArmorStand(w.getUp(2).getLeft(2).get(), w.getDirection(), rand); - ArmorStandUtils.placeArmorStand(w.getUp(2).getRight(2).get(), w.getDirection(), rand); - - } - - private static class MansionForgeSchematicParser extends MansionRoomSchematicParser - { - public MansionForgeSchematicParser(Random rand, PopulatorDataAbstract pop) { - super(rand, pop); - } - - @Override - public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 6; + private static final int roomWidthZ = 15; + public MansionGroundLevelForgePopulator(CubeRoom room, HashMap internalWalls) { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Mushroom Farm at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-forge", target); + schema.setFace(randomFace); + schema.parser = new MansionForgeSchematicParser(random, data); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-forge", target); + schema.setFace(randomFace); + schema.parser = new MansionForgeSchematicParser(random, data); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getLeft()) + .apply(w.getRight()) + .setShape(Shape.OUTER_RIGHT) + .apply(w.getLeft(2)) + .setShape(Shape.OUTER_LEFT) + .apply(w.getRight(2)); + + w.setType(Material.FLETCHING_TABLE, Material.SMITHING_TABLE); + } + + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft(3)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight(3)); + + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP) + .apply(w) + .apply(w.getLeft()) + .apply(w.getLeft(2)) + .apply(w.getRight()) + .apply(w.getRight(2)); + + ArmorStandUtils.placeArmorStand(w.getUp(2).get(), w.getDirection(), rand); + ArmorStandUtils.placeArmorStand(w.getUp(2).getLeft(2).get(), w.getDirection(), rand); + ArmorStandUtils.placeArmorStand(w.getUp(2).getRight(2).get(), w.getDirection(), rand); + + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 2); + } + + private static class MansionForgeSchematicParser extends MansionRoomSchematicParser { + public MansionForgeSchematicParser(Random rand, PopulatorDataAbstract pop) { + super(rand, pop); + } + + @Override + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { super.applyData(block, data); - if (data.getMaterial() == Material.POLISHED_DIORITE) { - ArmorStandUtils.placeArmorStand(block.getUp(), BlockUtils.getDirectBlockFace(rand), rand); - } - } - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,2); - } + if (data.getMaterial() == Material.POLISHED_DIORITE) { + ArmorStandUtils.placeArmorStand(block.getUp(), BlockUtils.getDirectBlockFace(rand), rand); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelKitchenPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelKitchenPopulator.java index e7712933..f99aab2b 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelKitchenPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelKitchenPopulator.java @@ -30,135 +30,139 @@ public class MansionGroundLevelKitchenPopulator extends MansionRoomPopulator { - public MansionGroundLevelKitchenPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 6; - private static final int roomWidthZ = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - TerraformGeneratorPlugin.logger.info("Kitchen at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-kitchen", target); - schema.setFace(randomFace); - schema.parser = new MansionKitchenSchematicParser(random, data); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-kitchen", target); - schema.setFace(randomFace); - schema.parser = new MansionKitchenSchematicParser(random, data); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - private static class MansionKitchenSchematicParser extends MansionRoomSchematicParser - { - public MansionKitchenSchematicParser(Random rand, PopulatorDataAbstract pop) { - super(rand, pop); - } - - @Override - public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (data.getMaterial() == Material.MELON) { - block.setType( - Material.MELON, - Material.PUMPKIN, - Material.HAY_BLOCK, - Material.DRIED_KELP_BLOCK - ); - } else { - super.applyData(block, data); - } - } - } - - @Override - public void decorateExit(Random rand, @NotNull Wall w) { - w.getUp(6).setType(Material.DARK_OAK_PLANKS); - } - @Override - public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { - w.getUp(6).setType(Material.DARK_OAK_PLANKS); - int choice = rand.nextInt(3); - switch(choice) { - case 0: // Smokers & pressure plates - new DirectionalBuilder(Material.SMOKER) - .setFacing(w.getDirection()) - .apply(w) - .apply(w.getLeft()) - .apply(w.getRight()) - .apply(w.getLeft(2)) - .apply(w.getRight(2)); - - w.getUp().setType(Material.DARK_OAK_PRESSURE_PLATE); - w.getUp().getLeft().setType(Material.DARK_OAK_PRESSURE_PLATE); - w.getUp().getLeft(2).setType(Material.DARK_OAK_PRESSURE_PLATE); - w.getUp().getRight().setType(Material.DARK_OAK_PRESSURE_PLATE); - w.getUp().getRight(2).setType(Material.DARK_OAK_PRESSURE_PLATE); - break; - case 1: // Barrels - Wall target = w.getRight(2); - for(int i = 0; i < 5; i++) { - if(GenUtils.chance(rand, 1,3)) { - target.setBlockData(BlockUtils.getRandomBarrel()); - target.get().getPopData().lootTableChest( - target.getX(), target.getY(), target.getZ(), - TerraLootTable.VILLAGE_BUTCHER); - } - target = target.getLeft(); - } - break; - default: // Table - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .apply(w).apply(w.getLeft()).apply(w.getRight()); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight(2)); - - if(rand.nextBoolean()) - DecorationsBuilder.CRAFTING_TABLE.build(w.getLeft()); - - if(rand.nextBoolean()) - DecorationsBuilder.build(w.getRight(), DecorationsBuilder.MELON, DecorationsBuilder.PUMPKIN, DecorationsBuilder.CAKE); - - if(rand.nextBoolean()) - DecorationsBuilder.OAK_PRESSURE_PLATE.build(w.getUp()); - break; - } - - } - - // Decorate with paintings and wall texturing - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 6; + private static final int roomWidthZ = 15; + public MansionGroundLevelKitchenPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + TerraformGeneratorPlugin.logger.info("Kitchen at " + + this.getRoom().getSimpleLocation() + + " picking face: " + + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0], + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-kitchen", target); + schema.setFace(randomFace); + schema.parser = new MansionKitchenSchematicParser(random, data); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-kitchen", target); + schema.setFace(randomFace); + schema.parser = new MansionKitchenSchematicParser(random, data); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + @Override + public void decorateExit(Random rand, @NotNull Wall w) { + w.getUp(6).setType(Material.DARK_OAK_PLANKS); + } + + @Override + public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { + w.getUp(6).setType(Material.DARK_OAK_PLANKS); + int choice = rand.nextInt(3); + switch (choice) { + case 0: // Smokers & pressure plates + new DirectionalBuilder(Material.SMOKER).setFacing(w.getDirection()) + .apply(w) + .apply(w.getLeft()) + .apply(w.getRight()) + .apply(w.getLeft(2)) + .apply(w.getRight(2)); + + w.getUp().setType(Material.DARK_OAK_PRESSURE_PLATE); + w.getUp().getLeft().setType(Material.DARK_OAK_PRESSURE_PLATE); + w.getUp().getLeft(2).setType(Material.DARK_OAK_PRESSURE_PLATE); + w.getUp().getRight().setType(Material.DARK_OAK_PRESSURE_PLATE); + w.getUp().getRight(2).setType(Material.DARK_OAK_PRESSURE_PLATE); + break; + case 1: // Barrels + Wall target = w.getRight(2); + for (int i = 0; i < 5; i++) { + if (GenUtils.chance(rand, 1, 3)) { + target.setBlockData(BlockUtils.getRandomBarrel()); + target.get() + .getPopData() + .lootTableChest(target.getX(), + target.getY(), + target.getZ(), + TerraLootTable.VILLAGE_BUTCHER + ); + } + target = target.getLeft(); + } + break; + default: // Table + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP) + .apply(w) + .apply(w.getLeft()) + .apply(w.getRight()); + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight(2)); + + if (rand.nextBoolean()) { + DecorationsBuilder.CRAFTING_TABLE.build(w.getLeft()); + } + + if (rand.nextBoolean()) { + DecorationsBuilder.build( + w.getRight(), + DecorationsBuilder.MELON, + DecorationsBuilder.PUMPKIN, + DecorationsBuilder.CAKE + ); + } + + if (rand.nextBoolean()) { + DecorationsBuilder.OAK_PRESSURE_PLATE.build(w.getUp()); + } + break; + } + + } + + // Decorate with paintings and wall texturing + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { // Shelves w.getRear().getLeft().Pillar(7, Material.DARK_OAK_LOG); - if(rand.nextBoolean()) { - new DirectionalBuilder(Material.FURNACE) - .setFacing(w.getDirection()) - .apply(w.getLeft()); + if (rand.nextBoolean()) { + new DirectionalBuilder(Material.FURNACE).setFacing(w.getDirection()).apply(w.getLeft()); w.getLeft().getUp().Pillar(6, Material.COBBLESTONE_WALL); w.getLeft().getUp().CorrectMultipleFacing(6); } w.getRear().getRight().Pillar(7, Material.DARK_OAK_LOG); - if(rand.nextBoolean()) { - new DirectionalBuilder(Material.FURNACE) - .setFacing(w.getDirection()) - .apply(w.getRight()); + if (rand.nextBoolean()) { + new DirectionalBuilder(Material.FURNACE).setFacing(w.getDirection()).apply(w.getRight()); w.getRight().getUp().Pillar(6, Material.COBBLESTONE_WALL); w.getRight().getUp().CorrectMultipleFacing(6); } @@ -166,43 +170,65 @@ public void decorateWall(@NotNull Random rand, @NotNull Wall w) { shelfify(rand, w.getLeft(2).getRear()); shelfify(rand, w.getRight(2).getRear()); } - - private void shelfify(@NotNull Random rand, @NotNull Wall w) { - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w.getUp()) - .apply(w.getUp(3)); - w.setType(Material.AIR, Material.AIR, Material.CRAFTING_TABLE, Material.MELON, Material.PUMPKIN); - - w.getUp(2) - .setType(Material.POTTED_RED_MUSHROOM, Material.POTTED_BROWN_MUSHROOM - , Material.CAKE, Material.TURTLE_EGG, Material.AIR, Material.AIR); - - w.getUp(4) - .setType(Material.POTTED_RED_MUSHROOM, Material.POTTED_BROWN_MUSHROOM - , Material.CAKE, Material.TURTLE_EGG, Material.AIR, Material.AIR); - - // Barrel loot - if(GenUtils.chance(rand, 1, 5)) { - Wall target = w.getUp(2); - target.setBlockData(BlockUtils.getRandomBarrel()); - target.get().getPopData().lootTableChest( - target.getX(), target.getY(), target.getZ(), - TerraLootTable.VILLAGE_BUTCHER); - } - if(GenUtils.chance(rand, 1, 5)) { - Wall target = w.getUp(4); - target.setBlockData(BlockUtils.getRandomBarrel()); - target.get().getPopData().lootTableChest( - target.getX(), target.getY(), target.getZ(), - TerraLootTable.VILLAGE_PLAINS_HOUSE); - } - - } - - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,2); - } + + private void shelfify(@NotNull Random rand, @NotNull Wall w) { + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP).apply(w.getUp()).apply(w.getUp(3)); + w.setType(Material.AIR, Material.AIR, Material.CRAFTING_TABLE, Material.MELON, Material.PUMPKIN); + + w.getUp(2) + .setType(Material.POTTED_RED_MUSHROOM, + Material.POTTED_BROWN_MUSHROOM, + Material.CAKE, + Material.TURTLE_EGG, + Material.AIR, + Material.AIR + ); + + w.getUp(4) + .setType(Material.POTTED_RED_MUSHROOM, + Material.POTTED_BROWN_MUSHROOM, + Material.CAKE, + Material.TURTLE_EGG, + Material.AIR, + Material.AIR + ); + + // Barrel loot + if (GenUtils.chance(rand, 1, 5)) { + Wall target = w.getUp(2); + target.setBlockData(BlockUtils.getRandomBarrel()); + target.get() + .getPopData() + .lootTableChest(target.getX(), target.getY(), target.getZ(), TerraLootTable.VILLAGE_BUTCHER); + } + if (GenUtils.chance(rand, 1, 5)) { + Wall target = w.getUp(4); + target.setBlockData(BlockUtils.getRandomBarrel()); + target.get() + .getPopData() + .lootTableChest(target.getX(), target.getY(), target.getZ(), TerraLootTable.VILLAGE_PLAINS_HOUSE); + } + + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 2); + } + + private static class MansionKitchenSchematicParser extends MansionRoomSchematicParser { + public MansionKitchenSchematicParser(Random rand, PopulatorDataAbstract pop) { + super(rand, pop); + } + + @Override + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { + if (data.getMaterial() == Material.MELON) { + block.setType(Material.MELON, Material.PUMPKIN, Material.HAY_BLOCK, Material.DRIED_KELP_BLOCK); + } + else { + super.applyData(block, data); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelLibraryPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelLibraryPopulator.java index 2ce9aea6..edd7c60c 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelLibraryPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelLibraryPopulator.java @@ -26,103 +26,122 @@ public class MansionGroundLevelLibraryPopulator extends MansionRoomPopulator { - public MansionGroundLevelLibraryPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the library room width, not the width of one room cell. + private static final int roomWidth = 15; - // Refers to the library room width, not the width of one room cell. - private static final int roomWidth = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = BlockUtils.getDirectBlockFace(random); - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.EAST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.WEST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - w.getRear().Pillar(4, Material.BOOKSHELF); - w.getLeft().getRear().Pillar(3, Material.BOOKSHELF); - w.getRight().getRear().Pillar(3, Material.BOOKSHELF); - w.getLeft(2).getRear().Pillar(4, Material.DARK_OAK_LOG); - w.getRight(2).getRear().Pillar(4, Material.DARK_OAK_LOG); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getRear().getUp(5)); - - w.getUp(6).downPillar(rand, 2, Material.CHAIN); - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lantern.setHanging(true); - w.getUp(4).setBlockData(lantern); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRear().getUp(3).getRight()) - .apply(w.getRear().getUp(3).getRight(3)) - .apply(w.getRear().getUp(4).getRight(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRear().getUp(3).getLeft()) - .apply(w.getRear().getUp(3).getLeft(3)) - .apply(w.getRear().getUp(4).getLeft(2)); + public MansionGroundLevelLibraryPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getRear().getUp(4).getLeft()) - .apply(w.getRear().getUp(4).getRight()); - } - - @Override - public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .setShape(Shape.INNER_RIGHT) - .apply(w.getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .setShape(Shape.INNER_LEFT) - .apply(w.getRight()); - if(rand.nextBoolean()) { - w.getLeft().setType(Material.BOOKSHELF); - w.getLeft().getUp().setType(Material.LANTERN); - }else if(rand.nextBoolean()) { - w.getRight().setType(Material.BOOKSHELF); - w.getRight().getUp().setType(Material.LANTERN); - } - } + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = BlockUtils.getDirectBlockFace(random); + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.EAST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.WEST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0], + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-library", target); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,2); - } + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + w.getRear().Pillar(4, Material.BOOKSHELF); + w.getLeft().getRear().Pillar(3, Material.BOOKSHELF); + w.getRight().getRear().Pillar(3, Material.BOOKSHELF); + w.getLeft(2).getRear().Pillar(4, Material.DARK_OAK_LOG); + w.getRight(2).getRear().Pillar(4, Material.DARK_OAK_LOG); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getRear().getUp(5)); + + w.getUp(6).downPillar(rand, 2, Material.CHAIN); + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lantern.setHanging(true); + w.getUp(4).setBlockData(lantern); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRear().getUp(3).getRight()) + .apply(w.getRear().getUp(3).getRight(3)) + .apply(w.getRear().getUp(4).getRight(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRear().getUp(3).getLeft()) + .apply(w.getRear().getUp(3).getLeft(3)) + .apply(w.getRear().getUp(4).getLeft(2)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getRear().getUp(4).getLeft()) + .apply(w.getRear().getUp(4).getRight()); + } + + @Override + public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .setShape(Shape.INNER_RIGHT) + .apply(w.getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .setShape(Shape.INNER_LEFT) + .apply(w.getRight()); + if (rand.nextBoolean()) { + w.getLeft().setType(Material.BOOKSHELF); + w.getLeft().getUp().setType(Material.LANTERN); + } + else if (rand.nextBoolean()) { + w.getRight().setType(Material.BOOKSHELF); + w.getRight().getUp().setType(Material.LANTERN); + } + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelMushroomFarmPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelMushroomFarmPopulator.java index b2232ce6..5053b4b1 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelMushroomFarmPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelMushroomFarmPopulator.java @@ -22,62 +22,72 @@ public class MansionGroundLevelMushroomFarmPopulator extends MansionRoomPopulator { - public MansionGroundLevelMushroomFarmPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 6; + private static final int roomWidthZ = 15; + public MansionGroundLevelMushroomFarmPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 6; - private static final int roomWidthZ = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Mushroom Farm at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-mushroomfarm", target); - schema.setFace(randomFace); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1] + roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-mushroomfarm", target); - schema.setFace(randomFace); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Mushroom Farm at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-mushroomfarm", target); + schema.setFace(randomFace); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-mushroomfarm", target); + schema.setFace(randomFace); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - Entry entry = this.getRoom().getWall(w.get().getPopData(), w.getDirection().getOppositeFace(), 0); - w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - if(w.getUp(4).getRear().getType() == Material.LIGHT_GRAY_STAINED_GLASS_PANE) { - BannerUtils.generateBanner(w.getUp(4).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); - BannerUtils.generateBanner(w.getUp(3).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); - BannerUtils.generateBanner(w.getUp(2).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); - } - w = w.getLeft(); - } - } - - @Override - public void decorateWall(Random rand, @NotNull Wall w) { - w.getLeft().setType(Material.COMPOSTER); - w.getRight().setType(Material.COMPOSTER); - } - + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + Entry entry = this.getRoom() + .getWall(w.get().getPopData(), w.getDirection().getOppositeFace(), 0); + w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + if (w.getUp(4).getRear().getType() == Material.LIGHT_GRAY_STAINED_GLASS_PANE) { + BannerUtils.generateBanner(w.getUp(4).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); + BannerUtils.generateBanner(w.getUp(3).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); + BannerUtils.generateBanner(w.getUp(2).get(), w.getDirection(), Material.BLACK_WALL_BANNER, null); + } + w = w.getLeft(); + } + } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,2); - } + @Override + public void decorateWall(Random rand, @NotNull Wall w) { + w.getLeft().setType(Material.COMPOSTER); + w.getRight().setType(Material.COMPOSTER); + } + + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelWarroomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelWarroomPopulator.java index 30070d54..e3776c97 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelWarroomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundLevelWarroomPopulator.java @@ -21,57 +21,79 @@ public class MansionGroundLevelWarroomPopulator extends MansionRoomPopulator { - public MansionGroundLevelWarroomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the library room width, not the width of one room cell. + private static final int roomWidth = 15; - // Refers to the library room width, not the width of one room cell. - private static final int roomWidth = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = BlockUtils.getDirectBlockFace(random); - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.EAST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.WEST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - @Override - public void decorateWall(Random rand, @NotNull Wall w) { - BannerUtils.generatePillagerBanner(w.getLeft().getUp(3).get(), w.getDirection(),true); - BannerUtils.generatePillagerBanner(w.getRight().getUp(3).get(), w.getDirection(),true); - } + public MansionGroundLevelWarroomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = BlockUtils.getDirectBlockFace(random); + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.EAST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.WEST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0], + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-warroom", target); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + @Override + public void decorateWall(Random rand, @NotNull Wall w) { + BannerUtils.generatePillagerBanner(w.getLeft().getUp(3).get(), w.getDirection(), true); + BannerUtils.generatePillagerBanner(w.getRight().getUp(3).get(), w.getDirection(), true); + } @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,2); - } + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundRoomPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundRoomPiece.java index 554a54a7..f0457c00 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundRoomPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundRoomPiece.java @@ -9,8 +9,8 @@ */ public class MansionGroundRoomPiece extends MansionStandardGroundRoomPiece { - public MansionGroundRoomPiece(int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(widthX, height, widthZ, type, validDirs); - } + public MansionGroundRoomPiece(int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + super(widthX, height, widthZ, type, validDirs); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundWallPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundWallPiece.java index 6138865f..9812bd7e 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundWallPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionGroundWallPiece.java @@ -22,8 +22,15 @@ public class MansionGroundWallPiece extends JigsawStructurePiece { - private final MansionJigsawBuilder builder; - public MansionGroundWallPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + private final MansionJigsawBuilder builder; + + public MansionGroundWallPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.builder = builder; @@ -34,288 +41,297 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); - + for (int i = 0; i < entry.getValue(); i++) { - - // Primary Wall and ground beneath wall - w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + // Primary Wall and ground beneath wall + w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.Pillar(1, rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(this.getRoom().getHeight(), rand, Material.DARK_OAK_PLANKS); - + w = w.getLeft(); } } - + /** * Extra decorations like windows or walls, depending on the surrounding walls */ @Override public void postBuildDecoration(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - MansionWallType type = MansionWallType.THIN_WINDOWS; - if(rand.nextBoolean()) - type = MansionWallType.LARGE_WINDOW; - - for(JigsawStructurePiece otherPiece:builder.getOverlapperPieces()) { - int[] center = otherPiece.getRoom().getCenter(); - if(otherPiece instanceof MansionEntrancePiece - && center[0] == this.getRoom().getCenter()[0] - && center[1] == this.getRoom().getCenter()[1] - && center[2] == this.getRoom().getCenter()[2]) - type = MansionWallType.PLAIN; - } - - Wall w = entry.getKey().getDown(); - + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + MansionWallType type = MansionWallType.THIN_WINDOWS; + if (rand.nextBoolean()) { + type = MansionWallType.LARGE_WINDOW; + } + + for (JigsawStructurePiece otherPiece : builder.getOverlapperPieces()) { + int[] center = otherPiece.getRoom().getCenter(); + if (otherPiece instanceof MansionEntrancePiece + && center[0] == this.getRoom().getCenter()[0] + && center[1] == this.getRoom().getCenter()[1] + && center[2] == this.getRoom().getCenter()[2]) + { + type = MansionWallType.PLAIN; + } + } + + Wall w = entry.getKey().getDown(); + for (int i = 0; i < entry.getValue(); i++) { - - switch(type) { - case LARGE_WINDOW: - if(i == 1 || i == entry.getValue()-2) // Side decoration - w.getUp().Pillar(this.getRoom().getHeight(),new Random(),Material.DARK_OAK_LOG); - - if(i == 3 || i == 4 || i == 5) - { // Window Panes and decorations at the base - w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); - w.getUp(2).CorrectMultipleFacing(4); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp().getFront()); - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(w.getDirection()) - .setOpen(true) - .apply(w.getUp().getFront(2)); - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(w.getDirection()) - .apply(w.getUp().getFront().getUp()); - } - - if(i == 2 || i == entry.getValue()-3) - {// Supporting Pillars - w.getFront().getUp().setType(Material.COBBLESTONE); - w.getFront().getUp(2).Pillar(3, new Random(), Material.STONE_BRICK_WALL); - w.getFront().getUp(2).CorrectMultipleFacing(3); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getFront().getUp(5)); - } - - if(i == 4) { - // Place Main window decoration - spawnWindowOverhang(w.getFront().getUp(6)); - } - - break; - case PLAIN: - break; - case THIN_WINDOWS: - if(i == 2 || i == entry.getValue()-3) // Side decoration - { - w.getUp().Pillar(this.getRoom().getHeight(),new Random(),Material.DARK_OAK_LOG); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp(2).getFront()); - - - w.getUp(3).getFront().setType(Material.STONE_BRICK_WALL); - w.getUp(4).getFront().setType(Material.STONE_BRICK_WALL); - w.getUp(5).getFront().setType(Material.COBBLESTONE_SLAB); - } - if(i%2 == 1) { - w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); - w.getUp(2).CorrectMultipleFacing(4); - } - - if(i == (entry.getValue()/2)) { - spawnWallSupportingPillar(w.getFront().getUp(), this.getRoom().getHeight()); - } - break; - } - - if(type != MansionWallType.PLAIN && i == 4) { - // Frontal Decorations - Pillars - // Only spawn if the wall is not a sink-in - int overlaps = 0; - for(JigsawStructurePiece p:this.builder.getOverlapperPieces()) { - if(p.getRoom().getSimpleLocation().equals(this.getRoom().getSimpleLocation())) - overlaps++; - } - if(overlaps == 1) { - // Front-facing pillar with some shrubbery and grass - Wall target = w.getFront(4).getUp(); - target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); - target.getFront().Pillar(MansionJigsawBuilder.roomHeight, Material.COBBLESTONE_WALL); - target.getFront().CorrectMultipleFacing(MansionJigsawBuilder.roomHeight); - - target.getFront().setType(Material.COBBLESTONE); - target.getFront().getRelative(0,MansionJigsawBuilder.roomHeight-1,0).setType(Material.COBBLESTONE); - target.getFront().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(target.getFront().getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getLeft()) - .apply(target.getFront().getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getRight()); - - target.getRight().setType(Material.COBBLESTONE); - target.getLeft().setType(Material.COBBLESTONE); + + switch (type) { + case LARGE_WINDOW: + if (i == 1 || i == entry.getValue() - 2) // Side decoration + { + w.getUp().Pillar(this.getRoom().getHeight(), new Random(), Material.DARK_OAK_LOG); + } + + if (i == 3 || i == 4 || i == 5) { // Window Panes and decorations at the base + w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); + w.getUp(2).CorrectMultipleFacing(4); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp().getFront()); + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(w.getDirection()) + .setOpen(true) + .apply(w.getUp().getFront(2)); + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(w.getDirection()) + .apply(w.getUp().getFront().getUp()); + } + + if (i == 2 || i == entry.getValue() - 3) {// Supporting Pillars + w.getFront().getUp().setType(Material.COBBLESTONE); + w.getFront().getUp(2).Pillar(3, new Random(), Material.STONE_BRICK_WALL); + w.getFront().getUp(2).CorrectMultipleFacing(3); + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getFront().getUp(5)); + } + + if (i == 4) { + // Place Main window decoration + spawnWindowOverhang(w.getFront().getUp(6)); + } + + break; + case PLAIN: + break; + case THIN_WINDOWS: + if (i == 2 || i == entry.getValue() - 3) // Side decoration + { + w.getUp().Pillar(this.getRoom().getHeight(), new Random(), Material.DARK_OAK_LOG); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection() + .getOppositeFace()) + .apply(w.getUp(2).getFront()); + + + w.getUp(3).getFront().setType(Material.STONE_BRICK_WALL); + w.getUp(4).getFront().setType(Material.STONE_BRICK_WALL); + w.getUp(5).getFront().setType(Material.COBBLESTONE_SLAB); + } + if (i % 2 == 1) { + w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); + w.getUp(2).CorrectMultipleFacing(4); + } + + if (i == (entry.getValue() / 2)) { + spawnWallSupportingPillar(w.getFront().getUp(), this.getRoom().getHeight()); + } + break; + } + + if (type != MansionWallType.PLAIN && i == 4) { + // Frontal Decorations - Pillars + // Only spawn if the wall is not a sink-in + int overlaps = 0; + for (JigsawStructurePiece p : this.builder.getOverlapperPieces()) { + if (p.getRoom().getSimpleLocation().equals(this.getRoom().getSimpleLocation())) { + overlaps++; + } + } + if (overlaps == 1) { + // Front-facing pillar with some shrubbery and grass + Wall target = w.getFront(4).getUp(); + target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); + target.getFront().Pillar(MansionJigsawBuilder.roomHeight, Material.COBBLESTONE_WALL); + target.getFront().CorrectMultipleFacing(MansionJigsawBuilder.roomHeight); + + target.getFront().setType(Material.COBBLESTONE); + target.getFront() + .getRelative(0, MansionJigsawBuilder.roomHeight - 1, 0) + .setType(Material.COBBLESTONE); + target.getFront().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .apply(target.getFront() + .getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0) + .getLeft()) + .apply(target.getFront() + .getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0) + .getRight()); + + target.getRight().setType(Material.COBBLESTONE); + target.getLeft().setType(Material.COBBLESTONE); PlantBuilder.DARK_OAK_LEAVES.build(target.getFront().getRight()); PlantBuilder.DARK_OAK_LEAVES.build(target.getFront().getLeft()); - target.getUp().getRight().setType(Material.GRASS_BLOCK); + target.getUp().getRight().setType(Material.GRASS_BLOCK); PlantBuilder.GRASS.build(target.getUp(2).getRight()); - target.getUp().getLeft().setType(Material.GRASS_BLOCK); + target.getUp().getLeft().setType(Material.GRASS_BLOCK); PlantBuilder.GRASS.build(target.getUp(2).getLeft()); - target.getFront().getRight().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - target.getFront().getLeft().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(target.getDirection()) - .setOpen(true) - .apply(target.getUp().getFront().getRight()) - .apply(target.getUp().getFront().getLeft()) - .setFacing(target.getDirection().getOppositeFace()) - .apply(target.getUp().getRear().getRight()) - .apply(target.getUp().getRear().getLeft()); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(target.getDirection().getOppositeFace()) - .apply(target.getRight(2).getFront()) - .apply(target.getLeft(2).getFront()); - target.getFront().getRight(2).getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - target.getFront().getLeft(2).getDown().downUntilSolid(new Random(), Material.COBBLESTONE); - - target.getRight(2).setType(Material.STONE_BRICKS); - target.getLeft(2).setType(Material.STONE_BRICKS); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(target.getDirection())) - .apply(target.getRight(2).getUp()) - .setFacing(BlockUtils.getRight(target.getDirection())) - .apply(target.getLeft(2).getUp()); - - // underhanging stair decorations - - // Two more slabs at the corner - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(target.getDirection())) - .setHalf(Half.TOP) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-2,0).getLeft()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getLeft()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getLeft(2)); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(target.getDirection())) - .setHalf(Half.TOP) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-2,0).getRight()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getRight()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getRight(2)); - - } - else if(overlaps == 2) - { // Corner pillar - Wall target = w.getFront(4).getUp(); - target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(target.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-2,0).getFront()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getFront()) - .apply(target.getRelative(0,MansionJigsawBuilder.roomHeight-1,0).getFront(2)); - - - } - } - + target.getFront().getRight().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + target.getFront().getLeft().getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(target.getDirection()) + .setOpen(true) + .apply(target.getUp().getFront().getRight()) + .apply(target.getUp().getFront().getLeft()) + .setFacing(target.getDirection().getOppositeFace()) + .apply(target.getUp().getRear().getRight()) + .apply(target.getUp().getRear().getLeft()); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(target.getDirection().getOppositeFace()) + .apply(target.getRight(2).getFront()) + .apply(target.getLeft(2).getFront()); + target.getFront().getRight(2).getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + target.getFront().getLeft(2).getDown().downUntilSolid(new Random(), Material.COBBLESTONE); + + target.getRight(2).setType(Material.STONE_BRICKS); + target.getLeft(2).setType(Material.STONE_BRICKS); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getLeft(target.getDirection())) + .apply(target.getRight(2).getUp()) + .setFacing(BlockUtils.getRight(target.getDirection())) + .apply(target.getLeft(2).getUp()); + + // underhanging stair decorations + + // Two more slabs at the corner + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getRight(target.getDirection())) + .setHalf(Half.TOP) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 2, + 0).getLeft()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getLeft()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getLeft(2)); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getLeft(target.getDirection())) + .setHalf(Half.TOP) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 2, + 0).getRight()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getRight()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getRight(2)); + + } + else if (overlaps == 2) { // Corner pillar + Wall target = w.getFront(4).getUp(); + target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(target.getDirection().getOppositeFace()) + .setHalf(Half.TOP) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 2, + 0).getFront()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getFront()) + .apply(target.getRelative(0, + MansionJigsawBuilder.roomHeight - 1, + 0).getFront(2)); + + + } + } + w = w.getLeft(); } } - + private void spawnWallSupportingPillar(@NotNull Wall w, int height) { - w.Pillar(height, new Random(), Material.POLISHED_ANDESITE); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRelative(BlockUtils.getLeft(w.getDirection()))); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRelative(BlockUtils.getRight(w.getDirection()))); - - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getRelative(0,height-1,0).getFront()); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRelative(0,height-1,0).getRelative(BlockUtils.getLeft(w.getDirection()))); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRelative(0,height-1,0).getRelative(BlockUtils.getRight(w.getDirection()))); - - w.getUp(2).setType(Material.STONE_BRICK_WALL); - w.getUp(3).setType(Material.POLISHED_DIORITE); - w.getUp(4).setType(Material.STONE_BRICK_WALL); - w.getUp(2).CorrectMultipleFacing(3); + w.Pillar(height, new Random(), Material.POLISHED_ANDESITE); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRelative(BlockUtils.getLeft(w.getDirection()))); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRelative(BlockUtils.getRight(w.getDirection()))); + + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getRelative(0, height - 1, 0).getFront()); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRelative(0, height - 1, 0) + .getRelative(BlockUtils.getLeft(w.getDirection()))); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRelative(0, height - 1, 0) + .getRelative(BlockUtils.getRight(w.getDirection()))); + + w.getUp(2).setType(Material.STONE_BRICK_WALL); + w.getUp(3).setType(Material.POLISHED_DIORITE); + w.getUp(4).setType(Material.STONE_BRICK_WALL); + w.getUp(2).CorrectMultipleFacing(3); } - + private void spawnWindowOverhang(@NotNull Wall w) { - // log row - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) - .apply(w).apply(w.getLeft()).apply(w.getRight()); - - // Upsidedown overhang in front of log row. - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(w.getFront().getLeft()) - .apply(w.getFront().getRight()); - - - // Inner upside down stairs - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getDown().getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getDown().getRight()); - - // Stairs at the top - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRight(2)) - .apply(w.getRight().getUp()); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft(2)) - .apply(w.getLeft().getUp()); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp()); + // log row + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) + .apply(w) + .apply(w.getLeft()) + .apply(w.getRight()); + + // Upsidedown overhang in front of log row. + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .apply(w.getFront().getLeft()) + .apply(w.getFront().getRight()); + + + // Inner upside down stairs + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getDown().getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getDown().getRight()); + + // Stairs at the top + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRight(2)) + .apply(w.getRight().getUp()); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getLeft(2)) + .apply(w.getLeft().getUp()); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp()); } - - private enum MansionWallType{ - PLAIN, - THIN_WINDOWS, - LARGE_WINDOW + + private enum MansionWallType { + PLAIN, THIN_WINDOWS, LARGE_WINDOW } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionStandardGroundRoomPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionStandardGroundRoomPiece.java index e120eefe..a9edf585 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionStandardGroundRoomPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/ground/MansionStandardGroundRoomPiece.java @@ -18,127 +18,139 @@ import java.util.Random; public abstract class MansionStandardGroundRoomPiece extends MansionStandardRoomPiece { - + public MansionStandardGroundRoomPiece(int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { super(widthX, height, widthZ, type, validDirs); } - + @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { int[] lowerCorner = this.getRoom().getLowerCorner(0); int[] upperCorner = this.getRoom().getUpperCorner(0); // Place flooring. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - + data.setType(x, this.getRoom().getY(), z, Material.STONE_BRICKS); - + // Supporting ground - new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)) - .downUntilSolid(rand,Material.STONE_BRICKS); + new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)).downUntilSolid(rand, + Material.STONE_BRICKS + ); } + } } - + /** * For forcefully removing anything in the area before any building. */ public void purgeMinimalArea(@NotNull PopulatorDataAbstract data) { - - int[] lowerCorner = this.getRoom().getLowerCorner(-5); + + int[] lowerCorner = this.getRoom().getLowerCorner(-5); int[] upperCorner = this.getRoom().getUpperCorner(-5); - + // Places extended ground and roofing over the piece. // If this piece is identified as a corner, place a pillar. - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - SimpleBlock b = new SimpleBlock(data, nx, this.getRoom().getY(), nz); - new Wall(b).Pillar(8, Material.AIR); - } + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + SimpleBlock b = new SimpleBlock(data, nx, this.getRoom().getY(), nz); + new Wall(b).Pillar(8, Material.AIR); + } + } } @Override public void postBuildDecoration(Random random, @NotNull PopulatorDataAbstract data) { CubeRoom targetRoom = this.getRoom(); - if(!this.getWalledFaces().isEmpty()) - targetRoom = this.getExtendedRoom(6); - - int[] lowerCorner = targetRoom.getLowerCorner(0); + if (!this.getWalledFaces().isEmpty()) { + targetRoom = this.getExtendedRoom(6); + } + + int[] lowerCorner = targetRoom.getLowerCorner(0); int[] upperCorner = targetRoom.getUpperCorner(0); - + // Places extended ground and roofing over the piece. // If this piece is identified as a corner, place a pillar. - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - SimpleBlock b = new SimpleBlock(data, nx, targetRoom.getY(), nz); - - // Edge Piece of extended room. Place cobblestone on ceiling edges - if(upperCorner[0] - lowerCorner[0] > this.getRoom().getWidthX() - && (nx == lowerCorner[0] || nx == upperCorner[0] || nz == lowerCorner[1] || nz == upperCorner[1])) { - if(b.getRelative(0,targetRoom.getHeight()+1,0).getType() != Material.STONE_BRICKS) - b.getRelative(0,targetRoom.getHeight()+1,0).setType(Material.COBBLESTONE); - } - else - { - if(b.getType() != Material.STONE_BRICKS) { - - b.setType(Material.COBBLESTONE); - } - - new Wall(b.getDown()).downUntilSolid(new Random(), Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - - b.getRelative(0,targetRoom.getHeight()+1,0).setType(Material.STONE_BRICKS); - } - } + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + SimpleBlock b = new SimpleBlock(data, nx, targetRoom.getY(), nz); + + // Edge Piece of extended room. Place cobblestone on ceiling edges + if (upperCorner[0] - lowerCorner[0] > this.getRoom().getWidthX() && (nx == lowerCorner[0] + || nx == upperCorner[0] + || nz == lowerCorner[1] + || nz == upperCorner[1])) + { + if (b.getRelative(0, targetRoom.getHeight() + 1, 0).getType() != Material.STONE_BRICKS) { + b.getRelative(0, targetRoom.getHeight() + 1, 0).setType(Material.COBBLESTONE); + } + } + else { + if (b.getType() != Material.STONE_BRICKS) { + + b.setType(Material.COBBLESTONE); + } + + new Wall(b.getDown()).downUntilSolid(new Random(), + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ); + + b.getRelative(0, targetRoom.getHeight() + 1, 0).setType(Material.STONE_BRICKS); + } + } + } } - + /** * Mansions are complex, and they need a third pass to properly ensure that * previous important details were planted before placing the final edge pieces. */ public void thirdStageDecoration(Random random, @NotNull PopulatorDataAbstract data) { - CubeRoom targetRoom; - if(!this.getWalledFaces().isEmpty()) { - targetRoom = this.getExtendedRoom(6); - // Decorate the top and bottom areas - for(Entry entry:this.getRoom().getFourWalls(data, -5).entrySet()) { - if(this.getWalledFaces().contains(entry.getKey().getDirection().getOppositeFace())) { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - if(w.getRear().getRelative(0,targetRoom.getHeight(),0).getType() == Material.COBBLESTONE) - { - // Lower decorations - if(!w.isSolid() || w.getType() == Material.POLISHED_ANDESITE) { - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .setHalf(Half.BOTTOM) - .apply(w); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .setHalf(Half.TOP) - .apply(w.getUp()); - - w.getLeft().get().lsetType(Material.POLISHED_ANDESITE); - w.getLeft().getUp().get().lsetType(Material.POLISHED_ANDESITE); - w.getRight().getUp().get().lsetType(Material.POLISHED_ANDESITE); - w.getRight().get().lsetType(Material.POLISHED_ANDESITE); - } - // Upper decorations - if(i % 2 == 0) { - w.getRear().getRelative(0,targetRoom.getHeight()+1,0).setType(Material.COBBLESTONE); - } - else - { - new DirectionalBuilder(Material.DARK_OAK_FENCE_GATE) - .setFacing(w.getDirection()) - .apply(w.getRear().getRelative(0,targetRoom.getHeight()+1,0)); - } - } - - w = w.getLeft(); - } - } + CubeRoom targetRoom; + if (!this.getWalledFaces().isEmpty()) { + targetRoom = this.getExtendedRoom(6); + // Decorate the top and bottom areas + for (Entry entry : this.getRoom().getFourWalls(data, -5).entrySet()) { + if (this.getWalledFaces().contains(entry.getKey().getDirection().getOppositeFace())) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + if (w.getRear().getRelative(0, targetRoom.getHeight(), 0).getType() == Material.COBBLESTONE) { + // Lower decorations + if (!w.isSolid() || w.getType() == Material.POLISHED_ANDESITE) { + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .setHalf(Half.BOTTOM) + .apply(w); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .setHalf(Half.TOP) + .apply(w.getUp()); + + w.getLeft().get().lsetType(Material.POLISHED_ANDESITE); + w.getLeft().getUp().get().lsetType(Material.POLISHED_ANDESITE); + w.getRight().getUp().get().lsetType(Material.POLISHED_ANDESITE); + w.getRight().get().lsetType(Material.POLISHED_ANDESITE); + } + // Upper decorations + if (i % 2 == 0) { + w.getRear().getRelative(0, targetRoom.getHeight() + 1, 0).setType(Material.COBBLESTONE); + } + else { + new DirectionalBuilder(Material.DARK_OAK_FENCE_GATE).setFacing(w.getDirection()) + .apply(w.getRear() + .getRelative(0, + targetRoom.getHeight() + + 1, + 0)); + } + } + + w = w.getLeft(); + } + } } } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBedroomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBedroomPopulator.java index fb4e69e3..55d6d638 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBedroomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBedroomPopulator.java @@ -29,159 +29,176 @@ public class MansionSecondFloorBedroomPopulator extends MansionRoomPopulator { - public MansionSecondFloorBedroomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the bedroom room width, not the width of one room cell. - private static final int roomWidth = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = BlockUtils.getDirectBlockFace(random); - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.EAST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.WEST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - @Override - public void decorateEntrance(Random rand, Wall w) { - w = w.getRear(); - w.getLeft(2).Pillar(5, Material.DARK_OAK_PLANKS); - w.getRight(2).Pillar(5, Material.DARK_OAK_PLANKS); - w.getLeft(2).Pillar(3, Material.DARK_OAK_LOG); - w.getRight(2).Pillar(3, Material.DARK_OAK_LOG); - - w.getLeft().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - w.getRight().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - w.getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()).setHalf(Half.TOP) - .apply(w.getUp(4)) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(3).getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(3).getRight()); - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - int choice = rand.nextInt(2); + // Refers to the bedroom room width, not the width of one room cell. + private static final int roomWidth = 15; + + public MansionSecondFloorBedroomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = BlockUtils.getDirectBlockFace(random); + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.EAST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.WEST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0], + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bedroom", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + @Override + public void decorateEntrance(Random rand, Wall w) { + w = w.getRear(); + w.getLeft(2).Pillar(5, Material.DARK_OAK_PLANKS); + w.getRight(2).Pillar(5, Material.DARK_OAK_PLANKS); + w.getLeft(2).Pillar(3, Material.DARK_OAK_LOG); + w.getRight(2).Pillar(3, Material.DARK_OAK_LOG); + + w.getLeft().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + w.getRight().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + w.getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()) + .setHalf(Half.TOP) + .apply(w.getUp(4)) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(3).getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(3).getRight()); + } + + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + int choice = rand.nextInt(2); // Table - if(choice == 0) { // Andesite table with banner and lectern + if (choice == 0) { // Andesite table with banner and lectern w.getLeft(3).Pillar(6, Material.DARK_OAK_LOG); w.getRight(3).Pillar(6, Material.DARK_OAK_LOG); - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft(2)) - .apply(w.getLeft(2).getUp(4)) - .apply(w.getLeft(2).getUp(5)) - .apply(w.getLeft().getUp(5)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight(2)) - .apply(w.getRight(2).getUp(4)) - .apply(w.getRight(2).getUp(5)) - .apply(w.getRight().getUp(5)); + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft(2)) + .apply(w.getLeft(2).getUp(4)) + .apply(w.getLeft(2).getUp(5)) + .apply(w.getLeft().getUp(5)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight(2)) + .apply(w.getRight(2).getUp(4)) + .apply(w.getRight(2).getUp(5)) + .apply(w.getRight().getUp(5)); w.getUp(5).setType(Material.POLISHED_ANDESITE); BannerUtils.generatePillagerBanner(w.getUp(3).get(), w.getDirection(), true); - new DirectionalBuilder(Material.LECTERN) - .setFacing(w.getDirection()).apply(w); + new DirectionalBuilder(Material.LECTERN).setFacing(w.getDirection()).apply(w); - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w.getLeft()) - .apply(w.getRight()); - } else { + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP).apply(w.getLeft()).apply(w.getRight()); + } + else { table(rand, w.getLeft(2)); table(rand, w.getRight(2)); } - } - - @Override - public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { - int choice = rand.nextInt(2); + } + + @Override + public void decorateWindow(@NotNull Random rand, @NotNull Wall w) { + int choice = rand.nextInt(2); // Utility Block - if(choice == 0) { // Table with flowers - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight(2)); - - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w) - .apply(w.getLeft()) - .apply(w.getRight()); + if (choice == 0) { // Table with flowers + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight(2)); + + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP) + .apply(w) + .apply(w.getLeft()) + .apply(w.getRight()); BlockUtils.pickPottedPlant().build(w.getUp()); BlockUtils.pickPottedPlant().build(w.getLeft()); BlockUtils.pickPottedPlant().build(w.getRight()); w.getRight().getUp().setType(); - } else { + } + else { DecorationsBuilder.build(w, - DecorationsBuilder.CRAFTING_TABLE, DecorationsBuilder.FLETCHING_TABLE, - DecorationsBuilder.CARTOGRAPHY_TABLE, DecorationsBuilder.ENCHANTING_TABLE, - DecorationsBuilder.BREWING_STAND, DecorationsBuilder.ANVIL, - DecorationsBuilder.NOTE_BLOCK, DecorationsBuilder.JUKEBOX); + DecorationsBuilder.CRAFTING_TABLE, + DecorationsBuilder.FLETCHING_TABLE, + DecorationsBuilder.CARTOGRAPHY_TABLE, + DecorationsBuilder.ENCHANTING_TABLE, + DecorationsBuilder.BREWING_STAND, + DecorationsBuilder.ANVIL, + DecorationsBuilder.NOTE_BLOCK, + DecorationsBuilder.JUKEBOX + ); } - } - - private void table(@NotNull Random rand, @NotNull Wall w) { - w.getLeft().getRear().Pillar(6, Material.DARK_OAK_LOG); - w.getRight().getRear().Pillar(6, Material.DARK_OAK_LOG); - - w.getLeft().setType(Material.STRIPPED_DARK_OAK_LOG); - w.getRight().setType(Material.STRIPPED_DARK_OAK_LOG); - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .apply(w); - - w.getUp().setType(Material.BROWN_CARPET); - w.getLeft().getUp().setType(Material.BROWN_CARPET); - w.getRight().getUp().setType(Material.BROWN_CARPET); - - PaintingUtils.placePainting( - w.getUp(2).get(), - w.getDirection(), - PaintingUtils.getArtFromDimensions(rand, 1, 2)); - } - - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,2); - } + } + + private void table(@NotNull Random rand, @NotNull Wall w) { + w.getLeft().getRear().Pillar(6, Material.DARK_OAK_LOG); + w.getRight().getRear().Pillar(6, Material.DARK_OAK_LOG); + + w.getLeft().setType(Material.STRIPPED_DARK_OAK_LOG); + w.getRight().setType(Material.STRIPPED_DARK_OAK_LOG); + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).apply(w); + + w.getUp().setType(Material.BROWN_CARPET); + w.getLeft().getUp().setType(Material.BROWN_CARPET); + w.getRight().getUp().setType(Material.BROWN_CARPET); + + PaintingUtils.placePainting(w.getUp(2).get(), w.getDirection(), PaintingUtils.getArtFromDimensions(rand, 1, 2)); + } + + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBunkPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBunkPopulator.java index 517cb0d4..52443daa 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBunkPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorBunkPopulator.java @@ -18,43 +18,50 @@ public class MansionSecondFloorBunkPopulator extends MansionRoomPopulator { - public MansionSecondFloorBunkPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 15; - private static final int roomWidthZ = 6; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bunk", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-bunk", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - } - - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,1); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 15; + private static final int roomWidthZ = 6; + public MansionSecondFloorBunkPopulator(CubeRoom room, HashMap internalWalls) { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bunk", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-bunk", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + } + + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 1); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorGrandStairwayPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorGrandStairwayPopulator.java index 662548d8..a3993251 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorGrandStairwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorGrandStairwayPopulator.java @@ -23,103 +23,102 @@ public class MansionSecondFloorGrandStairwayPopulator extends MansionRoomPopulator { - public MansionSecondFloorGrandStairwayPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - @Override - public void decorateRoom(PopulatorDataAbstract data, Random random) { - - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - // Arch - - w.getLeft(3).Pillar(6, Material.DARK_OAK_LOG); - w.getUp(5).setType(Material.DARK_OAK_PLANKS); - w.getRight(3).Pillar(6, Material.DARK_OAK_LOG); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(4).getLeft(2)) - .apply(w.getUp(5).getLeft(2)) - .apply(w.getUp(5).getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(4).getRight(2)) - .apply(w.getUp(5).getRight(2)) - .apply(w.getUp(5).getRight()); - int choice = rand.nextInt(2); + public MansionSecondFloorGrandStairwayPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(PopulatorDataAbstract data, Random random) { + + } + + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + // Arch + + w.getLeft(3).Pillar(6, Material.DARK_OAK_LOG); + w.getUp(5).setType(Material.DARK_OAK_PLANKS); + w.getRight(3).Pillar(6, Material.DARK_OAK_LOG); + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(4).getLeft(2)) + .apply(w.getUp(5).getLeft(2)) + .apply(w.getUp(5).getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(4).getRight(2)) + .apply(w.getUp(5).getRight(2)) + .apply(w.getUp(5).getRight()); + int choice = rand.nextInt(2); // Armor stands - if(choice == 0) { // Wall carving + if (choice == 0) { // Wall carving w.getRear().Pillar(5, Material.DARK_OAK_LOG); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getRear().getUp(2)) - .apply(w.getRear().getUp().getLeft()) - .apply(w.getRear().getUp().getRight()) - .apply(w.getRear().getUp(3).getLeft()) - .apply(w.getRear().getUp(3).getRight()) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) - .apply(w.getRear().getUp(2).getLeft()) - .apply(w.getRear().getUp(2).getLeft(2)) - .apply(w.getRear().getUp(2).getRight()) - .apply(w.getRear().getUp(2).getRight(2)); - - for(BlockFace face : BlockUtils.directBlockFaces) - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(face.getOppositeFace()) - .lapply(w.getLeft(3).getRelative(face)); - - for(BlockFace face : BlockUtils.directBlockFaces) - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(face.getOppositeFace()) - .lapply(w.getRight(3).getRelative(face)); - } else { + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getRear().getUp(2)) + .apply(w.getRear().getUp().getLeft()) + .apply(w.getRear().getUp().getRight()) + .apply(w.getRear().getUp(3).getLeft()) + .apply(w.getRear().getUp(3).getRight()) + .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) + .apply(w.getRear().getUp(2).getLeft()) + .apply(w.getRear().getUp(2).getLeft(2)) + .apply(w.getRear().getUp(2).getRight()) + .apply(w.getRear().getUp(2).getRight(2)); + + for (BlockFace face : BlockUtils.directBlockFaces) { + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(face.getOppositeFace()) + .lapply(w.getLeft(3).getRelative(face)); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(face.getOppositeFace()) + .lapply(w.getRight(3).getRelative(face)); + } + } + else { BannerUtils.generatePillagerBanner(w.getUp(4).get(), w.getDirection(), true); - new SlabBuilder(Material.POLISHED_ANDESITE_SLAB) - .setType(Type.TOP) - .apply(w) - .apply(w.getLeft()) - .apply(w.getLeft(2)) - .apply(w.getRight()) - .apply(w.getRight(2)); + new SlabBuilder(Material.POLISHED_ANDESITE_SLAB).setType(Type.TOP) + .apply(w) + .apply(w.getLeft()) + .apply(w.getLeft(2)) + .apply(w.getRight()) + .apply(w.getRight(2)); ArmorStandUtils.placeArmorStand(w.getUp(2).get(), w.getDirection(), rand); ArmorStandUtils.placeArmorStand(w.getUp(2).getLeft(2).get(), w.getDirection(), rand); ArmorStandUtils.placeArmorStand(w.getUp(2).getRight(2).get(), w.getDirection(), rand); } - } - - - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - w.getRear().Pillar(6, Material.DARK_OAK_PLANKS); - w.Pillar(6, Material.DARK_OAK_LOG); - w.getLeft(3).Pillar(6, Material.DARK_OAK_LOG); - w.getRight(3).Pillar(6, Material.DARK_OAK_LOG); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()) - .apply(w.getLeft(3).getFront()) - .apply(w.getRight(3).getFront()); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getLeft()) - .apply(w.getLeft(2)) - .apply(w.getRight()) - .apply(w.getRight(2)); - } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(3,3); - } - - @Override - public int[] getSpawnLocation() { - return new int[] {getRoom().getX(), getRoom().getY()-7, getRoom().getZ()}; - } + } + + + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + w.getRear().Pillar(6, Material.DARK_OAK_PLANKS); + w.Pillar(6, Material.DARK_OAK_LOG); + w.getLeft(3).Pillar(6, Material.DARK_OAK_LOG); + w.getRight(3).Pillar(6, Material.DARK_OAK_LOG); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()) + .apply(w.getLeft(3).getFront()) + .apply(w.getRight(3).getFront()); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getLeft()) + .apply(w.getLeft(2)) + .apply(w.getRight()) + .apply(w.getRight(2)); + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(3, 3); + } + + @Override + public int[] getSpawnLocation() { + return new int[] {getRoom().getX(), getRoom().getY() - 7, getRoom().getZ()}; + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHallwayPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHallwayPopulator.java index 0220b1e2..23590741 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHallwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHallwayPopulator.java @@ -27,213 +27,226 @@ public class MansionSecondFloorHallwayPopulator extends MansionRoomPopulator { - public MansionSecondFloorHallwayPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - SimpleBlock center = this.getRoom().getCenterSimpleBlock(data); - - center.getUp().setType(Material.RED_CARPET); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) - center.getUp().getRelative(face).setType(Material.RED_CARPET); - - for(BlockFace face:BlockUtils.directBlockFaces) { - if(getInternalWalls().get(face) != MansionInternalWallState.WINDOW) { - Wall w = new Wall(center, face); - // This is a solid wall. Bring it forward and decorate it. - if(getInternalWalls().get(face) == MansionInternalWallState.SOLID) { - Wall target = w.getFront(3); - applyHallwaySmoothing(target); - applyHallwaySmoothing(target.getLeft(1)); - applyHallwaySmoothing(target.getLeft(2)); - applyHallwaySmoothing(target.getLeft(3)); - applyHallwaySmoothing(target.getRight(1)); - applyHallwaySmoothing(target.getRight(2)); - applyHallwaySmoothing(target.getRight(3)); - - // Room is connected to a window. - // Spawn the arch and block out the window. - if(!target.getRight(4).getUp().isSolid()) { - applyHallwaySmoothing(target.getRight(4)); - target.getRight(5).Pillar(6, Material.DARK_OAK_PLANKS); - } - if(!target.getLeft(4).getUp().isSolid()) { - applyHallwaySmoothing(target.getLeft(4)); - target.getLeft(5).Pillar(6, Material.DARK_OAK_PLANKS); - } - decorateHallwayWall(random, new Wall(target.getRear().getUp().get(), w.getDirection().getOppositeFace()), false); - } - else if(getInternalWalls().get(face) == MansionInternalWallState.ROOM_ENTRANCE) - // This wall opens to another room somewhere. Connect a red carpet to it - { - for(int length = 2; length < 6; length++) { - Wall target = w.getFront(length).getUp(); - target.setType(Material.RED_CARPET); - if(length < 5) { - target.getLeft().setType(Material.RED_CARPET); - target.getRight().setType(Material.RED_CARPET); - } - } - } - } - else // This face connects to a window - { - center.getUp().getRelative(face,2).setType(Material.RED_CARPET); - decorateHallwayWall(random, new Wall(center.getRelative(face, 3).getUp(), face.getOppositeFace()), true); - } - } - - spawnSmallChandelier(center.getUp(6)); - } - - private void decorateHallwayWall(@NotNull Random random, @NotNull Wall center, boolean isWindow) { - int decorationType = random.nextInt(3); - if(!isWindow) { // Solid wall decorations - switch(decorationType) { - case 0: // 3 1x2 paintings - PaintingUtils.placePainting(center.getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - PaintingUtils.placePainting(center.getRight(2).getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - PaintingUtils.placePainting(center.getLeft(2).getUp().get(), center.getDirection(), PaintingUtils.getArtFromDimensions(random, 1, 2)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(center.getLeft()) - .apply(center.getRight()); - - center.getLeft().getUp().Pillar(3, Material.DARK_OAK_FENCE); - center.getLeft().getUp().CorrectMultipleFacing(3); - center.getRight().getUp().Pillar(3, Material.DARK_OAK_FENCE); - center.getRight().getUp().CorrectMultipleFacing(3); - center.getRight().getUp(4).setType(Material.DARK_OAK_PLANKS); - center.getLeft().getUp(4).setType(Material.DARK_OAK_PLANKS); - break; - case 1: // 3 banners - BannerUtils.generateBanner(random, center.getUp(2).get(), center.getDirection(), true); - BannerUtils.generateBanner(random, center.getRight(2).getUp(2).get(), center.getDirection(), true); - BannerUtils.generateBanner(random, center.getLeft(2).getUp(2).get(), center.getDirection(), true); - - center.getLeft().getRear().Pillar(4, Material.DARK_OAK_LOG); - center.getRight().getRear().Pillar(4, Material.DARK_OAK_LOG); - new DirectionalBuilder(Material.WALL_TORCH) - .setFacing(center.getDirection()) - .apply(center.getLeft().getUp(2)) - .apply(center.getRight().getUp(2)); - break; - case 2: // chair - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .apply(center) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setShape(Shape.INNER_RIGHT) - .apply(center.getLeft()) - .setFacing(BlockUtils.getRight(center.getDirection())) - .setShape(Shape.INNER_LEFT) - .apply(center.getRight()); - - center.getLeft(2).setType(Material.DARK_OAK_LOG); - center.getRight(2).setType(Material.DARK_OAK_LOG); - if(random.nextBoolean()) - center.getLeft(2).getUp().setType(Material.LANTERN); - if(random.nextBoolean()) - center.getRight(2).getUp().setType(Material.LANTERN); - break; - default: - break; - } - } else { // Window decorations - switch(decorationType) { - case 0: // Chair - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(center.getDirection().getOppositeFace()) - .apply(center) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setShape(Shape.INNER_RIGHT) - .apply(center.getLeft()) - .setFacing(BlockUtils.getRight(center.getDirection())) - .setShape(Shape.INNER_LEFT) - .apply(center.getRight()); - break; - case 1: // Big potted plants - center.setType(Material.DARK_OAK_PLANKS); - center.getLeft().setType(Material.GRASS_BLOCK); - center.getRight().setType(Material.GRASS_BLOCK); - center.getLeft().getUp().setType(Material.OAK_FENCE); - center.getRight().getUp().setType(Material.OAK_FENCE); - PlantBuilder.OAK_LEAVES.build(center.getLeft().getUp(2)); - PlantBuilder.OAK_LEAVES.build(center.getRight().getUp(2)); - - // Pot - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(center.getDirection()) - .setOpen(true) - .apply(center.getLeft().getFront()) - .apply(center.getRight().getFront()); - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(center.getDirection().getOppositeFace()) - .setOpen(true) - .apply(center.getLeft().getRear()) - .apply(center.getRight().getRear()); - - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(BlockUtils.getLeft(center.getDirection())) - .setOpen(true) - .apply(center.getLeft(2)) - .setFacing(BlockUtils.getRight(center.getDirection())) - .apply(center.getRight(2)); - break; - default: - // Sometimes windows don't get decorated. - break; - } - } - } - - private void spawnSmallChandelier(@NotNull SimpleBlock target) { - target.setType(Material.DARK_OAK_FENCE); - target.getDown().setType(Material.DARK_OAK_FENCE); - target.getDown(2).setType(Material.DARK_OAK_FENCE); - - target = target.getDown(2); - for(BlockFace face:BlockUtils.directBlockFaces) { - target.getRelative(face).setType(Material.DARK_OAK_FENCE); - target.getRelative(face).getUp().setType(Material.TORCH); - - } - BlockUtils.correctSurroundingMultifacingData(target); - } - - private void applyHallwaySmoothing(@NotNull Wall w) { - w.Pillar(7, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .setHalf(Half.TOP) - .lapply(w.getUp(5)); - w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .lapply(w.getUp(6)); - w.getUp(7).setType(Material.DARK_OAK_PLANKS); - - w = w.getRear(); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .setHalf(Half.TOP) - .lapply(w.getUp(7)); - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,1); - } + public MansionSecondFloorHallwayPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + SimpleBlock center = this.getRoom().getCenterSimpleBlock(data); + + center.getUp().setType(Material.RED_CARPET); + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + center.getUp().getRelative(face).setType(Material.RED_CARPET); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + if (getInternalWalls().get(face) != MansionInternalWallState.WINDOW) { + Wall w = new Wall(center, face); + // This is a solid wall. Bring it forward and decorate it. + if (getInternalWalls().get(face) == MansionInternalWallState.SOLID) { + Wall target = w.getFront(3); + applyHallwaySmoothing(target); + applyHallwaySmoothing(target.getLeft(1)); + applyHallwaySmoothing(target.getLeft(2)); + applyHallwaySmoothing(target.getLeft(3)); + applyHallwaySmoothing(target.getRight(1)); + applyHallwaySmoothing(target.getRight(2)); + applyHallwaySmoothing(target.getRight(3)); + + // Room is connected to a window. + // Spawn the arch and block out the window. + if (!target.getRight(4).getUp().isSolid()) { + applyHallwaySmoothing(target.getRight(4)); + target.getRight(5).Pillar(6, Material.DARK_OAK_PLANKS); + } + if (!target.getLeft(4).getUp().isSolid()) { + applyHallwaySmoothing(target.getLeft(4)); + target.getLeft(5).Pillar(6, Material.DARK_OAK_PLANKS); + } + decorateHallwayWall( + random, + new Wall(target.getRear().getUp().get(), w.getDirection().getOppositeFace()), + false + ); + } + else if (getInternalWalls().get(face) == MansionInternalWallState.ROOM_ENTRANCE) + // This wall opens to another room somewhere. Connect a red carpet to it + { + for (int length = 2; length < 6; length++) { + Wall target = w.getFront(length).getUp(); + target.setType(Material.RED_CARPET); + if (length < 5) { + target.getLeft().setType(Material.RED_CARPET); + target.getRight().setType(Material.RED_CARPET); + } + } + } + } + else // This face connects to a window + { + center.getUp().getRelative(face, 2).setType(Material.RED_CARPET); + decorateHallwayWall( + random, + new Wall(center.getRelative(face, 3).getUp(), face.getOppositeFace()), + true + ); + } + } + + spawnSmallChandelier(center.getUp(6)); + } + + private void decorateHallwayWall(@NotNull Random random, @NotNull Wall center, boolean isWindow) { + int decorationType = random.nextInt(3); + if (!isWindow) { // Solid wall decorations + switch (decorationType) { + case 0: // 3 1x2 paintings + PaintingUtils.placePainting( + center.getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + PaintingUtils.placePainting( + center.getRight(2).getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + PaintingUtils.placePainting( + center.getLeft(2).getUp().get(), + center.getDirection(), + PaintingUtils.getArtFromDimensions(random, 1, 2) + ); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(center.getDirection().getOppositeFace()) + .setHalf(Half.TOP) + .apply(center.getLeft()) + .apply(center.getRight()); + + center.getLeft().getUp().Pillar(3, Material.DARK_OAK_FENCE); + center.getLeft().getUp().CorrectMultipleFacing(3); + center.getRight().getUp().Pillar(3, Material.DARK_OAK_FENCE); + center.getRight().getUp().CorrectMultipleFacing(3); + center.getRight().getUp(4).setType(Material.DARK_OAK_PLANKS); + center.getLeft().getUp(4).setType(Material.DARK_OAK_PLANKS); + break; + case 1: // 3 banners + BannerUtils.generateBanner(random, center.getUp(2).get(), center.getDirection(), true); + BannerUtils.generateBanner(random, center.getRight(2).getUp(2).get(), center.getDirection(), true); + BannerUtils.generateBanner(random, center.getLeft(2).getUp(2).get(), center.getDirection(), true); + + center.getLeft().getRear().Pillar(4, Material.DARK_OAK_LOG); + center.getRight().getRear().Pillar(4, Material.DARK_OAK_LOG); + new DirectionalBuilder(Material.WALL_TORCH).setFacing(center.getDirection()) + .apply(center.getLeft().getUp(2)) + .apply(center.getRight().getUp(2)); + break; + case 2: // chair + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(center.getDirection() + .getOppositeFace()) + .apply(center) + .setFacing(BlockUtils.getLeft(center.getDirection())) + .setShape(Shape.INNER_RIGHT) + .apply(center.getLeft()) + .setFacing(BlockUtils.getRight(center.getDirection())) + .setShape(Shape.INNER_LEFT) + .apply(center.getRight()); + + center.getLeft(2).setType(Material.DARK_OAK_LOG); + center.getRight(2).setType(Material.DARK_OAK_LOG); + if (random.nextBoolean()) { + center.getLeft(2).getUp().setType(Material.LANTERN); + } + if (random.nextBoolean()) { + center.getRight(2).getUp().setType(Material.LANTERN); + } + break; + default: + break; + } + } + else { // Window decorations + switch (decorationType) { + case 0: // Chair + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(center.getDirection() + .getOppositeFace()) + .apply(center) + .setFacing(BlockUtils.getLeft(center.getDirection())) + .setShape(Shape.INNER_RIGHT) + .apply(center.getLeft()) + .setFacing(BlockUtils.getRight(center.getDirection())) + .setShape(Shape.INNER_LEFT) + .apply(center.getRight()); + break; + case 1: // Big potted plants + center.setType(Material.DARK_OAK_PLANKS); + center.getLeft().setType(Material.GRASS_BLOCK); + center.getRight().setType(Material.GRASS_BLOCK); + center.getLeft().getUp().setType(Material.OAK_FENCE); + center.getRight().getUp().setType(Material.OAK_FENCE); + PlantBuilder.OAK_LEAVES.build(center.getLeft().getUp(2)); + PlantBuilder.OAK_LEAVES.build(center.getRight().getUp(2)); + + // Pot + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(center.getDirection()) + .setOpen(true) + .apply(center.getLeft().getFront()) + .apply(center.getRight().getFront()); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(center.getDirection().getOppositeFace()) + .setOpen(true) + .apply(center.getLeft().getRear()) + .apply(center.getRight().getRear()); + + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(BlockUtils.getLeft(center.getDirection())) + .setOpen(true) + .apply(center.getLeft(2)) + .setFacing(BlockUtils.getRight(center.getDirection())) + .apply(center.getRight(2)); + break; + default: + // Sometimes windows don't get decorated. + break; + } + } + } + + private void spawnSmallChandelier(@NotNull SimpleBlock target) { + target.setType(Material.DARK_OAK_FENCE); + target.getDown().setType(Material.DARK_OAK_FENCE); + target.getDown(2).setType(Material.DARK_OAK_FENCE); + + target = target.getDown(2); + for (BlockFace face : BlockUtils.directBlockFaces) { + target.getRelative(face).setType(Material.DARK_OAK_FENCE); + target.getRelative(face).getUp().setType(Material.TORCH); + + } + BlockUtils.correctSurroundingMultifacingData(target); + } + + private void applyHallwaySmoothing(@NotNull Wall w) { + w.Pillar(7, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).setHalf(Half.TOP).lapply(w.getUp(5)); + w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + w.getUp(6).Pillar(2, Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).lapply(w.getUp(6)); + w.getUp(7).setType(Material.DARK_OAK_PLANKS); + + w = w.getRear(); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).setHalf(Half.TOP).lapply(w.getUp(7)); + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 1); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHandler.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHandler.java index 8f9b2ec6..b2e5fdfb 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHandler.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorHandler.java @@ -17,100 +17,115 @@ import org.terraform.utils.BlockUtils; public class MansionSecondFloorHandler { - public final @NotNull HashMap secondFloorPieces = new HashMap<>(); + public final @NotNull HashMap secondFloorPieces = new HashMap<>(); public final @NotNull ArrayList secondFloorOverlapperPieces = new ArrayList<>(); - private final MansionJigsawBuilder builder; - private Random random; - - public MansionSecondFloorHandler(MansionJigsawBuilder builder) { - this.builder = builder; - this.random = new Random(); - } - - public void decorateAwkwardCorners() - { + private final MansionJigsawBuilder builder; + private Random random; + + public MansionSecondFloorHandler(MansionJigsawBuilder builder) { + this.builder = builder; + this.random = new Random(); + } + + public void decorateAwkwardCorners() + { // Make sure awkward corners are fixed for (JigsawStructurePiece piece : secondFloorPieces.values()) { - SimpleBlock core = new SimpleBlock( - builder.getCore().getPopData(), + SimpleBlock core = new SimpleBlock(builder.getCore().getPopData(), piece.getRoom().getX(), piece.getRoom().getY(), - piece.getRoom().getZ()); + piece.getRoom().getZ() + ); Wall target; - - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // nw + + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // nw target = new Wall(core.getRelative(-5, 1, -5)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST); } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // ne + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // ne target = new Wall(core.getRelative(5, 1, -5)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // sw + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // sw target = new Wall(core.getRelative(-5, 1, 5)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // se + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // se target = new Wall(core.getRelative(5, 1, 5)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST); } } - } - - public void decorateAwkwardCorner(@NotNull Wall target, Random random, BlockFace one, BlockFace two) { - - // Fill in gap in the corner - target.Pillar(MansionJigsawBuilder.roomHeight, Material.DARK_OAK_LOG); - } - + + public void decorateAwkwardCorner(@NotNull Wall target, Random random, BlockFace one, BlockFace two) { + + // Fill in gap in the corner + target.Pillar(MansionJigsawBuilder.roomHeight, Material.DARK_OAK_LOG); + + } + public void populateSecondFloorRoomLayout() { - for(JigsawStructurePiece piece:builder.getPieces().values()) { - JigsawStructurePiece newPiece = new MansionStandardSecondFloorPiece( - builder, - MansionJigsawBuilder.groundFloorRoomWidth, MansionJigsawBuilder.roomHeight, MansionJigsawBuilder.groundFloorRoomWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - newPiece.getRoom().setX(piece.getRoom().getX()); - newPiece.getRoom().setY(piece.getRoom().getY() + MansionJigsawBuilder.roomHeight + 1); - newPiece.getRoom().setZ(piece.getRoom().getZ()); - ArrayList faces = new ArrayList<>(); - for(BlockFace face:piece.getWalledFaces()) { - JigsawStructurePiece newWall = new MansionSecondFloorWallPiece( - builder, - MansionJigsawBuilder.groundFloorRoomWidth, MansionJigsawBuilder.roomHeight, MansionJigsawBuilder.groundFloorRoomWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - - newWall.getRoom().setX(piece.getRoom().getX() + face.getModX()*MansionJigsawBuilder.groundFloorRoomWidth); - newWall.getRoom().setY(piece.getRoom().getY() + MansionJigsawBuilder.roomHeight+1); - newWall.getRoom().setZ(piece.getRoom().getZ() + face.getModZ()*MansionJigsawBuilder.groundFloorRoomWidth); - newWall.setRotation(face); - this.secondFloorOverlapperPieces.add(newWall); - faces.add(face); - } - newPiece.setWalledFaces(faces); - - this.secondFloorPieces.put(newPiece.getRoom().getSimpleLocation(), newPiece); - } + for (JigsawStructurePiece piece : builder.getPieces().values()) { + JigsawStructurePiece newPiece = new MansionStandardSecondFloorPiece(builder, + MansionJigsawBuilder.groundFloorRoomWidth, + MansionJigsawBuilder.roomHeight, + MansionJigsawBuilder.groundFloorRoomWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + newPiece.getRoom().setX(piece.getRoom().getX()); + newPiece.getRoom().setY(piece.getRoom().getY() + MansionJigsawBuilder.roomHeight + 1); + newPiece.getRoom().setZ(piece.getRoom().getZ()); + ArrayList faces = new ArrayList<>(); + for (BlockFace face : piece.getWalledFaces()) { + JigsawStructurePiece newWall = new MansionSecondFloorWallPiece(builder, + MansionJigsawBuilder.groundFloorRoomWidth, + MansionJigsawBuilder.roomHeight, + MansionJigsawBuilder.groundFloorRoomWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + + newWall.getRoom() + .setX(piece.getRoom().getX() + face.getModX() * MansionJigsawBuilder.groundFloorRoomWidth); + newWall.getRoom().setY(piece.getRoom().getY() + MansionJigsawBuilder.roomHeight + 1); + newWall.getRoom() + .setZ(piece.getRoom().getZ() + face.getModZ() * MansionJigsawBuilder.groundFloorRoomWidth); + newWall.setRotation(face); + this.secondFloorOverlapperPieces.add(newWall); + faces.add(face); + } + newPiece.setWalledFaces(faces); + + this.secondFloorPieces.put(newPiece.getRoom().getSimpleLocation(), newPiece); + } } - + public void buildSecondFloor(Random random) { for (JigsawStructurePiece piece : this.secondFloorPieces.values()) { - // Force room to be air first - int[] lowerCorner = piece.getRoom().getLowerCorner(0); - int[] upperCorner = piece.getRoom().getUpperCorner(0); - int lowestY = piece.getRoom().getY() + 1; - int upperY = piece.getRoom().getY() + piece.getRoom().getHeight(); - - for(int x = lowerCorner[0]; x<= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) - for(int y = lowestY; y <= upperY; y++) - builder.getCore().getPopData().setType(x, y, z, Material.AIR); - + // Force room to be air first + int[] lowerCorner = piece.getRoom().getLowerCorner(0); + int[] upperCorner = piece.getRoom().getUpperCorner(0); + int lowestY = piece.getRoom().getY() + 1; + int upperY = piece.getRoom().getY() + piece.getRoom().getHeight(); + + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + for (int y = lowestY; y <= upperY; y++) { + builder.getCore().getPopData().setType(x, y, z, Material.AIR); + } + } + } + // Build room piece.build(builder.getCore().getPopData(), random); } @@ -120,14 +135,19 @@ public void buildSecondFloor(Random random) { Collections.shuffle(this.secondFloorOverlapperPieces); for (JigsawStructurePiece piece : this.secondFloorOverlapperPieces) { // Don't place overlapper objects where rooms have been placed. - SimpleLocation pieceLoc = new SimpleLocation(piece.getRoom().getX(), piece.getRoom().getY(), piece.getRoom().getZ()); + SimpleLocation pieceLoc = new SimpleLocation( + piece.getRoom().getX(), + piece.getRoom().getY(), + piece.getRoom().getZ() + ); if (secondFloorPieces.containsKey(pieceLoc)) { toRemove.add(piece); continue; } JigsawStructurePiece host = builder.getAdjacentPiece(pieceLoc, piece.getRotation().getOppositeFace()); - if (host != null) + if (host != null) { host.getWalledFaces().add(piece.getRotation()); + } // TerraformGeneratorPlugin.logger.info("Populating at " + piece.getClass().getSimpleName() + "::" + piece.getRoom().getX() + "," + piece.getRoom().getZ() + "," + piece.getRotation()); piece.build(builder.getCore().getPopData(), random); } @@ -135,9 +155,9 @@ public void buildSecondFloor(Random random) { // Remove pieces that weren't placed and replace the unused wall with the entrance. secondFloorOverlapperPieces.removeIf(toRemove::contains); } - + public void setRandom(Random random) { - this.random = random; + this.random = random; } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorLoungePopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorLoungePopulator.java index 62e28cc8..f24695c6 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorLoungePopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorLoungePopulator.java @@ -24,121 +24,135 @@ public class MansionSecondFloorLoungePopulator extends MansionRoomPopulator { - public MansionSecondFloorLoungePopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 6; + private static final int roomWidthZ = 15; + public MansionSecondFloorLoungePopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 6; - private static final int roomWidthZ = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - TerraformGeneratorPlugin.logger.info("Lounge at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-lounge", target); - schema.setFace(randomFace); - schema.parser = new MansionLoungeSchematicParser(random, data); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-lounge", target); - schema.setFace(randomFace); - schema.parser = new MansionLoungeSchematicParser(random, data); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - private static class MansionLoungeSchematicParser extends MansionRoomSchematicParser - { - private final Material terracottaType; - public MansionLoungeSchematicParser(@NotNull Random rand, PopulatorDataAbstract pop) { - super(rand, pop); - terracottaType = GenUtils.randChoice(rand, - Material.WHITE_GLAZED_TERRACOTTA, - Material.ORANGE_GLAZED_TERRACOTTA, - Material.MAGENTA_GLAZED_TERRACOTTA, - Material.LIGHT_BLUE_GLAZED_TERRACOTTA, - Material.YELLOW_GLAZED_TERRACOTTA, - Material.LIME_GLAZED_TERRACOTTA, - Material.PINK_GLAZED_TERRACOTTA, - Material.GRAY_GLAZED_TERRACOTTA, - Material.LIGHT_GRAY_GLAZED_TERRACOTTA, - Material.CYAN_GLAZED_TERRACOTTA, - Material.PURPLE_GLAZED_TERRACOTTA, - Material.BLUE_GLAZED_TERRACOTTA, - Material.BROWN_GLAZED_TERRACOTTA, - Material.GREEN_GLAZED_TERRACOTTA, - Material.RED_GLAZED_TERRACOTTA, - Material.BLACK_GLAZED_TERRACOTTA - ); - } - - @Override - public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (data.getMaterial() == Material.BLACK_GLAZED_TERRACOTTA) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "black_glazed_terracotta", - terracottaType - .toString().toLowerCase(Locale.ENGLISH) - ) - ); - super.applyData(block, data); - } else { - super.applyData(block, data); - } - } - } + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + TerraformGeneratorPlugin.logger.info("Lounge at " + + this.getRoom().getSimpleLocation() + + " picking face: " + + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-lounge", target); + schema.setFace(randomFace); + schema.parser = new MansionLoungeSchematicParser(random, data); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-lounge", target); + schema.setFace(randomFace); + schema.parser = new MansionLoungeSchematicParser(random, data); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } - @Override - public void decorateExit(Random rand, @NotNull Wall w) { - w.getUp(6).setType(Material.DARK_OAK_PLANKS); - } - - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - for(int i = 0; i <= 3; i++) { - w.getLeft(i).setType(Material.POLISHED_DIORITE); - if(!w.getLeft(i).getFront().isSolid() - || w.getLeft(i).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) - w.getLeft(i).getFront().setType(Material.POLISHED_ANDESITE); - - w.getRight(i).setType(Material.POLISHED_DIORITE); - if(!w.getRight(i).getFront().isSolid() - || w.getRight(i).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) - w.getRight(i).getFront().setType(Material.POLISHED_ANDESITE); - } - - if(!w.getRight(4).getFront().isSolid() - || w.getRight(4).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) - { - w.getRight(4).Pillar(6, Material.DARK_OAK_LOG); - } - if(!w.getLeft(4).getFront().isSolid() - || w.getLeft(4).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) - { - w.getLeft(4).Pillar(6, Material.DARK_OAK_LOG); - } - } - - @Override - public void decorateWall(Random rand, @NotNull Wall w) { - for(int i = 0; i <= 3; i++) { - w.getLeft(i).setType(Material.POLISHED_ANDESITE); - - w.getRight(i).setType(Material.POLISHED_ANDESITE); - } - } + @Override + public void decorateExit(Random rand, @NotNull Wall w) { + w.getUp(6).setType(Material.DARK_OAK_PLANKS); + } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,2); - } + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + for (int i = 0; i <= 3; i++) { + w.getLeft(i).setType(Material.POLISHED_DIORITE); + if (!w.getLeft(i).getFront().isSolid() + || w.getLeft(i).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) + { + w.getLeft(i).getFront().setType(Material.POLISHED_ANDESITE); + } + + w.getRight(i).setType(Material.POLISHED_DIORITE); + if (!w.getRight(i).getFront().isSolid() + || w.getRight(i).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) + { + w.getRight(i).getFront().setType(Material.POLISHED_ANDESITE); + } + } + + if (!w.getRight(4).getFront().isSolid() + || w.getRight(4).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) + { + w.getRight(4).Pillar(6, Material.DARK_OAK_LOG); + } + if (!w.getLeft(4).getFront().isSolid() + || w.getLeft(4).getFront().getType() == Material.POLISHED_ANDESITE_STAIRS) + { + w.getLeft(4).Pillar(6, Material.DARK_OAK_LOG); + } + } + + @Override + public void decorateWall(Random rand, @NotNull Wall w) { + for (int i = 0; i <= 3; i++) { + w.getLeft(i).setType(Material.POLISHED_ANDESITE); + + w.getRight(i).setType(Material.POLISHED_ANDESITE); + } + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 2); + } + + private static class MansionLoungeSchematicParser extends MansionRoomSchematicParser { + private final Material terracottaType; + + public MansionLoungeSchematicParser(@NotNull Random rand, PopulatorDataAbstract pop) { + super(rand, pop); + terracottaType = GenUtils.randChoice(rand, + Material.WHITE_GLAZED_TERRACOTTA, + Material.ORANGE_GLAZED_TERRACOTTA, + Material.MAGENTA_GLAZED_TERRACOTTA, + Material.LIGHT_BLUE_GLAZED_TERRACOTTA, + Material.YELLOW_GLAZED_TERRACOTTA, + Material.LIME_GLAZED_TERRACOTTA, + Material.PINK_GLAZED_TERRACOTTA, + Material.GRAY_GLAZED_TERRACOTTA, + Material.LIGHT_GRAY_GLAZED_TERRACOTTA, + Material.CYAN_GLAZED_TERRACOTTA, + Material.PURPLE_GLAZED_TERRACOTTA, + Material.BLUE_GLAZED_TERRACOTTA, + Material.BROWN_GLAZED_TERRACOTTA, + Material.GREEN_GLAZED_TERRACOTTA, + Material.RED_GLAZED_TERRACOTTA, + Material.BLACK_GLAZED_TERRACOTTA + ); + } + + @Override + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { + if (data.getMaterial() == Material.BLACK_GLAZED_TERRACOTTA) { + data = Bukkit.createBlockData(data.getAsString() + .replaceAll("black_glazed_terracotta", + terracottaType.toString().toLowerCase(Locale.ENGLISH) + )); + super.applyData(block, data); + } + else { + super.applyData(block, data); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorPianoRoomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorPianoRoomPopulator.java index 72962396..33330253 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorPianoRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorPianoRoomPopulator.java @@ -23,65 +23,76 @@ public class MansionSecondFloorPianoRoomPopulator extends MansionRoomPopulator { - public MansionSecondFloorPianoRoomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 6; + private static final int roomWidthZ = 15; + public MansionSecondFloorPianoRoomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 6; - private static final int roomWidthZ = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - TerraformGeneratorPlugin.logger.info("Piano at " + this.getRoom().getSimpleLocation() + " picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-piano", target); - schema.setFace(randomFace); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-piano", target); - schema.setFace(randomFace); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + TerraformGeneratorPlugin.logger.info("Piano at " + + this.getRoom().getSimpleLocation() + + " picking face: " + + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-piano", target); + schema.setFace(randomFace); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-piano", target); + schema.setFace(randomFace); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - w.setType(Material.DARK_OAK_LOG); + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + w.setType(Material.DARK_OAK_LOG); BlockUtils.pickPottedPlant().build(w.getUp()); - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight()); - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - PaintingUtils.placePainting( - w.getUp(2).getLeft().get(), - w.getDirection(), - PaintingUtils.getArtFromDimensions(rand, 1, 2)); - PaintingUtils.placePainting( - w.getUp(2).getRight().get(), - w.getDirection(), - PaintingUtils.getArtFromDimensions(rand, 1, 2)); - w.getRear().Pillar(6, Material.DARK_OAK_LOG); - w.getLeft(2).getRear().Pillar(6, Material.DARK_OAK_LOG); - w.getRight(2).getRear().Pillar(6, Material.DARK_OAK_LOG); - } + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight()); + } - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,2); - } + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + PaintingUtils.placePainting(w.getUp(2).getLeft().get(), + w.getDirection(), + PaintingUtils.getArtFromDimensions(rand, 1, 2) + ); + PaintingUtils.placePainting(w.getUp(2).getRight().get(), + w.getDirection(), + PaintingUtils.getArtFromDimensions(rand, 1, 2) + ); + w.getRear().Pillar(6, Material.DARK_OAK_LOG); + w.getLeft(2).getRear().Pillar(6, Material.DARK_OAK_LOG); + w.getRight(2).getRear().Pillar(6, Material.DARK_OAK_LOG); + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStoreroomPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStoreroomPopulator.java index a635f878..e662e23a 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStoreroomPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStoreroomPopulator.java @@ -24,83 +24,93 @@ public class MansionSecondFloorStoreroomPopulator extends MansionRoomPopulator { - public MansionSecondFloorStoreroomPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } + // Refers to the kitchen room width, not the width of one room cell. + private static final int roomWidthX = 15; + private static final int roomWidthZ = 6; + public MansionSecondFloorStoreroomPopulator(CubeRoom room, + HashMap internalWalls) + { + super(room, internalWalls); + } - // Refers to the kitchen room width, not the width of one room cell. - private static final int roomWidthX = 15; - private static final int roomWidthZ = 6; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-storageroom", target); - schema.parser = new MansionStoreroomSchematicParser(random); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidthX, this.getRoom().getY(), lowerBounds[1]+roomWidthZ); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-storageroom", target); - schema.parser = new MansionStoreroomSchematicParser(random); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - } - + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[random.nextInt(2)]; + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-storageroom", target); + schema.parser = new MansionStoreroomSchematicParser(random); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidthX, + this.getRoom().getY(), + lowerBounds[1] + roomWidthZ + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-storageroom", target); + schema.parser = new MansionStoreroomSchematicParser(random); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + // TODO Auto-generated catch block + TerraformGeneratorPlugin.logger.stackTrace(e); + } - // Do not extend MansionRoomSchematicParser, as we want the looting to - // be done differently for this room specifically. - private static class MansionStoreroomSchematicParser extends SchematicParser - { - private final Random rand; - public MansionStoreroomSchematicParser(Random rand) { - this.rand = rand; - } - - @Override - public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (data.getMaterial() == Material.CHEST) { - Material replacement = GenUtils.randChoice(rand, - Material.CHEST, - Material.CHEST, - Material.CHEST, - Material.CHEST, - Material.CHEST, - Material.BARREL, - Material.BARREL, - Material.BARREL, - Material.BARREL, - Material.BARREL, - Material.CRAFTING_TABLE, - Material.DARK_OAK_LOG, - Material.CAKE, - Material.LANTERN, - Material.COAL_BLOCK); - data = Bukkit.createBlockData(replacement); - BlockUtils.randRotateBlockData(rand, data); - } - - super.applyData(block, data); - if(data.getMaterial() == Material.CHEST || data.getMaterial() == Material.BARREL) - block.getPopData().lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.WOODLAND_MANSION); - } - } - + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 1); + } + + // Do not extend MansionRoomSchematicParser, as we want the looting to + // be done differently for this room specifically. + private static class MansionStoreroomSchematicParser extends SchematicParser { + private final Random rand; - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,1); - } + public MansionStoreroomSchematicParser(Random rand) { + this.rand = rand; + } + + @Override + public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { + if (data.getMaterial() == Material.CHEST) { + Material replacement = GenUtils.randChoice(rand, + Material.CHEST, + Material.CHEST, + Material.CHEST, + Material.CHEST, + Material.CHEST, + Material.BARREL, + Material.BARREL, + Material.BARREL, + Material.BARREL, + Material.BARREL, + Material.CRAFTING_TABLE, + Material.DARK_OAK_LOG, + Material.CAKE, + Material.LANTERN, + Material.COAL_BLOCK + ); + data = Bukkit.createBlockData(replacement); + BlockUtils.randRotateBlockData(rand, data); + } + + super.applyData(block, data); + if (data.getMaterial() == Material.CHEST || data.getMaterial() == Material.BARREL) { + block.getPopData() + .lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.WOODLAND_MANSION); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStudyPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStudyPopulator.java index 70d40a2a..13517f80 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStudyPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorStudyPopulator.java @@ -27,135 +27,156 @@ public class MansionSecondFloorStudyPopulator extends MansionRoomPopulator { - public MansionSecondFloorStudyPopulator(CubeRoom room, HashMap internalWalls) { - super(room, internalWalls); - } - - // Refers to the bedroom room width, not the width of one room cell. - private static final int roomWidth = 15; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { - int[] lowerBounds = this.getRoom().getLowerCorner(1); - BlockFace randomFace = BlockUtils.getDirectBlockFace(random); - // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); - try { - if(randomFace == BlockFace.NORTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.SOUTH) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.EAST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0]+roomWidth, this.getRoom().getY(), lowerBounds[1]); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - }else if(randomFace == BlockFace.WEST) { - SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]+roomWidth); - TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); - schema.parser = new MansionRoomSchematicParser(random, data); - schema.setFace(randomFace); - schema.apply(); - } - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - @Override - public void decorateEntrance(Random rand, Wall w) { - w = w.getRear(); - w.getLeft(2).Pillar(5, Material.DARK_OAK_PLANKS); - w.getRight(2).Pillar(5, Material.DARK_OAK_PLANKS); - w.getLeft(2).Pillar(3, Material.DARK_OAK_LOG); - w.getRight(2).Pillar(3, Material.DARK_OAK_LOG); - - w.getLeft().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - w.getRight().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - w.getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()).setHalf(Half.TOP) - .apply(w.getUp(4)) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(3).getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(3).getRight()); - } - - @Override - public void decorateWall(@NotNull Random rand, @NotNull Wall w) { - w.getRear().Pillar(4, Material.BOOKSHELF); - w.getLeft().getRear().Pillar(3, Material.BOOKSHELF); - w.getRight().getRear().Pillar(3, Material.BOOKSHELF); - w.getLeft(2).getRear().Pillar(4, Material.DARK_OAK_LOG); - w.getRight(2).getRear().Pillar(4, Material.DARK_OAK_LOG); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getRear().getUp(5)); - - w.getUp(5).downPillar(rand, 2, Material.CHAIN); - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lantern.setHanging(true); - w.getUp(3).setBlockData(lantern); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRear().getUp(3).getRight()) - .apply(w.getRear().getUp(3).getRight(3)) - .apply(w.getRear().getUp(4).getRight(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRear().getUp(3).getLeft()) - .apply(w.getRear().getUp(3).getLeft(3)) - .apply(w.getRear().getUp(4).getLeft(2)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getRear().getUp(4).getLeft()) - .apply(w.getRear().getUp(4).getRight()); - } - - @Override - public void decorateWindow(Random rand, @NotNull Wall w) { - clearRoguePillar(w); - } - - @Override - public void decorateExit(Random rand, @NotNull Wall w) { - clearRoguePillar(w); - } - - public void clearRoguePillar(@NotNull Wall base) { - Entry entry = this.getRoom().getWall(base.get().getPopData(), base.getDirection().getOppositeFace(), 0); - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - if(!w.isSolid()) w.setType(Material.RED_CARPET); - if(w.getFront().getType() == Material.POLISHED_ANDESITE) { - w.getFront().Pillar(6, Material.AIR); - w.getFront().setType(Material.RED_CARPET); - Wall target = w.getFront().getUp(5); - for(BlockFace face:BlockUtils.directBlockFaces) { - if(target.getRelative(face).getType() == Material.DARK_OAK_STAIRS - || target.getRelative(face).getType() == Material.DARK_OAK_SLAB) { - target.getRelative(face).setType(Material.AIR); - target.getDown().getRelative(face).setType(Material.AIR); - target.getRelative(face,2).setType(Material.AIR); - } - } - } - w = w.getLeft(); - } - } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(2,2); - } + // Refers to the bedroom room width, not the width of one room cell. + private static final int roomWidth = 15; + + public MansionSecondFloorStudyPopulator(CubeRoom room, HashMap internalWalls) { + super(room, internalWalls); + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + int[] lowerBounds = this.getRoom().getLowerCorner(1); + BlockFace randomFace = BlockUtils.getDirectBlockFace(random); + // TerraformGeneratorPlugin.logger.info("Library picking face: " + randomFace); + try { + if (randomFace == BlockFace.NORTH) { + SimpleBlock target = new SimpleBlock(data, lowerBounds[0], this.getRoom().getY(), lowerBounds[1]); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.SOUTH) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.EAST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0] + roomWidth, + this.getRoom().getY(), + lowerBounds[1] + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + else if (randomFace == BlockFace.WEST) { + SimpleBlock target = new SimpleBlock( + data, + lowerBounds[0], + this.getRoom().getY(), + lowerBounds[1] + roomWidth + ); + TerraSchematic schema = TerraSchematic.load("mansion/mansion-study", target); + schema.parser = new MansionRoomSchematicParser(random, data); + schema.setFace(randomFace); + schema.apply(); + } + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + @Override + public void decorateEntrance(Random rand, Wall w) { + w = w.getRear(); + w.getLeft(2).Pillar(5, Material.DARK_OAK_PLANKS); + w.getRight(2).Pillar(5, Material.DARK_OAK_PLANKS); + w.getLeft(2).Pillar(3, Material.DARK_OAK_LOG); + w.getRight(2).Pillar(3, Material.DARK_OAK_LOG); + + w.getLeft().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + w.getRight().getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + w.getUp(5).downPillar(2, Material.DARK_OAK_PLANKS); + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()) + .setHalf(Half.TOP) + .apply(w.getUp(4)) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(3).getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(3).getRight()); + } + + @Override + public void decorateWall(@NotNull Random rand, @NotNull Wall w) { + w.getRear().Pillar(4, Material.BOOKSHELF); + w.getLeft().getRear().Pillar(3, Material.BOOKSHELF); + w.getRight().getRear().Pillar(3, Material.BOOKSHELF); + w.getLeft(2).getRear().Pillar(4, Material.DARK_OAK_LOG); + w.getRight(2).getRear().Pillar(4, Material.DARK_OAK_LOG); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getRear().getUp(5)); + + w.getUp(5).downPillar(rand, 2, Material.CHAIN); + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lantern.setHanging(true); + w.getUp(3).setBlockData(lantern); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRear().getUp(3).getRight()) + .apply(w.getRear().getUp(3).getRight(3)) + .apply(w.getRear().getUp(4).getRight(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRear().getUp(3).getLeft()) + .apply(w.getRear().getUp(3).getLeft(3)) + .apply(w.getRear().getUp(4).getLeft(2)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getRear().getUp(4).getLeft()) + .apply(w.getRear().getUp(4).getRight()); + } + + @Override + public void decorateWindow(Random rand, @NotNull Wall w) { + clearRoguePillar(w); + } + + @Override + public void decorateExit(Random rand, @NotNull Wall w) { + clearRoguePillar(w); + } + + public void clearRoguePillar(@NotNull Wall base) { + Entry entry = this.getRoom() + .getWall(base.get().getPopData(), base.getDirection().getOppositeFace(), 0); + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + if (!w.isSolid()) { + w.setType(Material.RED_CARPET); + } + if (w.getFront().getType() == Material.POLISHED_ANDESITE) { + w.getFront().Pillar(6, Material.AIR); + w.getFront().setType(Material.RED_CARPET); + Wall target = w.getFront().getUp(5); + for (BlockFace face : BlockUtils.directBlockFaces) { + if (target.getRelative(face).getType() == Material.DARK_OAK_STAIRS + || target.getRelative(face).getType() == Material.DARK_OAK_SLAB) + { + target.getRelative(face).setType(Material.AIR); + target.getDown().getRelative(face).setType(Material.AIR); + target.getRelative(face, 2).setType(Material.AIR); + } + } + } + w = w.getLeft(); + } + } + + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(2, 2); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorWallPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorWallPiece.java index ee462349..884aff4e 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorWallPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionSecondFloorWallPiece.java @@ -23,124 +23,144 @@ public class MansionSecondFloorWallPiece extends JigsawStructurePiece { - public boolean isTentRoofFace = false; - private final MansionJigsawBuilder builder; - public MansionSecondFloorWallPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + private final MansionJigsawBuilder builder; + public boolean isTentRoofFace = false; + + public MansionSecondFloorWallPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.builder = builder; } - - public void buildIndividualRoofs(Random random, @NotNull PopulatorDataAbstract data, int[] lowerBound, int[] upperBound) { - - // Don't build roofs for pieces that are in sink-ins - if(this.builder.countOverlappingPiecesAtLocation( - this.getRoom().getSimpleLocation().getRelative( - 0,-MansionJigsawBuilder.roomHeight-1,0 - )) >= 3) { - return; - } - - BlockFace walledFace = this.getRotation(); - Wall w = new Wall( - new SimpleBlock(data,this.getRoom().getSimpleLocation()) - .getRelative(walledFace.getOppositeFace(),3) - .getUp(7), - walledFace); - - int maxDepth = -1; - BlockFace roofOuterFace = null; - // Figure out where the roof's position is, so as to determine which direction - // the individual roof should face. - if(lowerBound[0] <= w.getX() - && lowerBound[1] <= w.getZ() - && upperBound[0] >= w.getX() - && upperBound[1] >= w.getZ()) { - // Piece is inside the roof. Don't do anything. - builder.getRoofedLocations().add(this.getRoom().getSimpleLocation().getRelative(this.getRotation().getOppositeFace(), MansionJigsawBuilder.groundFloorRoomWidth)); - return; - } - else if(w.getX() >= lowerBound[0] && w.getX() <= upperBound[0]) - { - // Z Axis aligned. - if(w.getZ() > upperBound[1]) { - roofOuterFace = BlockFace.SOUTH; - maxDepth = w.getZ() - upperBound[1]; - }else { - roofOuterFace = BlockFace.NORTH; - maxDepth = lowerBound[1] - w.getZ(); - } - } - else if(w.getZ() >= lowerBound[1] && w.getZ() <= upperBound[1]) - { - // X Axis aligned. - if(w.getX() > upperBound[0]) { - roofOuterFace = BlockFace.EAST; - maxDepth = w.getX() - upperBound[0]; - }else { - roofOuterFace = BlockFace.WEST; - maxDepth = lowerBound[0] - w.getX(); - } - } - - // Increase it to force it to properly sink into the main roof - maxDepth = (maxDepth*2); - if(maxDepth < 6) maxDepth*=2; - // Only place the roof if the walled face is correct. If not, ignore it. - if(roofOuterFace == null || walledFace != roofOuterFace) - { - return; - } - isTentRoofFace = true; - builder.getRoofedLocations().add(this.getRoom().getSimpleLocation().getRelative(this.getRotation().getOppositeFace(), MansionJigsawBuilder.groundFloorRoomWidth)); - // Place the actual roof - for(BlockFace side:BlockUtils.getAdjacentFaces(walledFace)) { - - for(int i = 0; i < 6; i++) { - int position = 1+5-i; - Wall roofPiece = w.getRelative(0,position,0).getRelative(side, i); - - if(i==0) { - roofPiece.setType(Material.COBBLESTONE_SLAB); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .lapply(roofPiece.getDown()); - }else { - StairBuilder builder = new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(side.getOppositeFace()) - .lapply(roofPiece); - - if(BlockUtils.isAir(roofPiece.getDown().getType()) - || roofPiece.getDown().getType() == Material.COBBLESTONE_STAIRS) - builder - .setFacing(side) - .setHalf(Half.TOP) - .apply(roofPiece.getDown()); - - if(i == 5 - && (roofPiece.getDown().getRelative(side).getType() == Material.COBBLESTONE_STAIRS - || roofPiece.getDown().getRelative(side.getOppositeFace()).getType() == Material.COBBLESTONE_STAIRS)) - { - roofPiece.getDown().setType(Material.AIR); - roofPiece.getDown().getRelative(side).setType(Material.AIR); - roofPiece.getDown().getRelative(side.getOppositeFace()).setType(Material.AIR); - } - - } - for(int depth = 1; depth < maxDepth; depth++) { - if(i == 0) { - roofPiece.getRear(depth).setType(Material.COBBLESTONE_SLAB); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .lapply(roofPiece.getRear(depth).getDown()); - - }else// if(i != 5) - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(side.getOppositeFace()) - .lapply(roofPiece.getRear(depth)); - } - } - } + + public void buildIndividualRoofs(Random random, + @NotNull PopulatorDataAbstract data, + int[] lowerBound, + int[] upperBound) + { + + // Don't build roofs for pieces that are in sink-ins + if (this.builder.countOverlappingPiecesAtLocation(this.getRoom() + .getSimpleLocation() + .getRelative(0, -MansionJigsawBuilder.roomHeight - 1, 0)) + >= 3) + { + return; + } + + BlockFace walledFace = this.getRotation(); + Wall w = new Wall(new SimpleBlock(data, + this.getRoom().getSimpleLocation()).getRelative(walledFace.getOppositeFace(), 3) + .getUp(7), walledFace); + + int maxDepth = -1; + BlockFace roofOuterFace = null; + // Figure out where the roof's position is, so as to determine which direction + // the individual roof should face. + if (lowerBound[0] <= w.getX() + && lowerBound[1] <= w.getZ() + && upperBound[0] >= w.getX() + && upperBound[1] >= w.getZ()) + { + // Piece is inside the roof. Don't do anything. + builder.getRoofedLocations() + .add(this.getRoom() + .getSimpleLocation() + .getRelative( + this.getRotation().getOppositeFace(), + MansionJigsawBuilder.groundFloorRoomWidth + )); + return; + } + else if (w.getX() >= lowerBound[0] && w.getX() <= upperBound[0]) { + // Z Axis aligned. + if (w.getZ() > upperBound[1]) { + roofOuterFace = BlockFace.SOUTH; + maxDepth = w.getZ() - upperBound[1]; + } + else { + roofOuterFace = BlockFace.NORTH; + maxDepth = lowerBound[1] - w.getZ(); + } + } + else if (w.getZ() >= lowerBound[1] && w.getZ() <= upperBound[1]) { + // X Axis aligned. + if (w.getX() > upperBound[0]) { + roofOuterFace = BlockFace.EAST; + maxDepth = w.getX() - upperBound[0]; + } + else { + roofOuterFace = BlockFace.WEST; + maxDepth = lowerBound[0] - w.getX(); + } + } + + // Increase it to force it to properly sink into the main roof + maxDepth = (maxDepth * 2); + if (maxDepth < 6) { + maxDepth *= 2; + } + // Only place the roof if the walled face is correct. If not, ignore it. + if (roofOuterFace == null || walledFace != roofOuterFace) { + return; + } + isTentRoofFace = true; + builder.getRoofedLocations() + .add(this.getRoom() + .getSimpleLocation() + .getRelative(this.getRotation().getOppositeFace(), MansionJigsawBuilder.groundFloorRoomWidth)); + // Place the actual roof + for (BlockFace side : BlockUtils.getAdjacentFaces(walledFace)) { + + for (int i = 0; i < 6; i++) { + int position = 1 + 5 - i; + Wall roofPiece = w.getRelative(0, position, 0).getRelative(side, i); + + if (i == 0) { + roofPiece.setType(Material.COBBLESTONE_SLAB); + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .lapply(roofPiece.getDown()); + } + else { + StairBuilder builder = new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(side.getOppositeFace()) + .lapply(roofPiece); + + if (BlockUtils.isAir(roofPiece.getDown().getType()) + || roofPiece.getDown().getType() == Material.COBBLESTONE_STAIRS) + { + builder.setFacing(side).setHalf(Half.TOP).apply(roofPiece.getDown()); + } + + if (i == 5 && (roofPiece.getDown().getRelative(side).getType() == Material.COBBLESTONE_STAIRS + || roofPiece.getDown().getRelative(side.getOppositeFace()).getType() + == Material.COBBLESTONE_STAIRS)) + { + roofPiece.getDown().setType(Material.AIR); + roofPiece.getDown().getRelative(side).setType(Material.AIR); + roofPiece.getDown().getRelative(side.getOppositeFace()).setType(Material.AIR); + } + + } + for (int depth = 1; depth < maxDepth; depth++) { + if (i == 0) { + roofPiece.getRear(depth).setType(Material.COBBLESTONE_SLAB); + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .lapply(roofPiece.getRear(depth).getDown()); + + } + else// if(i != 5) + { + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(side.getOppositeFace()) + .lapply(roofPiece.getRear(depth)); + } + } + } + } } @Override @@ -148,25 +168,25 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); - + for (int i = 0; i < entry.getValue(); i++) { - - // Primary Wall and ground beneath wall - // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + // Primary Wall and ground beneath wall + // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(this.getRoom().getHeight(), rand, Material.DARK_OAK_PLANKS); - + w = w.getLeft(); } } - + /** * Extra decorations like windows or walls, depending on the surrounding walls */ @Override public void postBuildDecoration(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { - + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - MansionSecondFloorWallType type = switch(rand.nextInt(3)) { + MansionSecondFloorWallType type = switch (rand.nextInt(3)) { case 0 -> MansionSecondFloorWallType.LARGE_WINDOW; case 1 -> MansionSecondFloorWallType.THIN_WINDOWS; case 2 -> MansionSecondFloorWallType.BALCONY; @@ -174,259 +194,252 @@ public void postBuildDecoration(@NotNull Random rand, @NotNull PopulatorDataAbst }; // Don't allow balconies in sink in areas - if(type == MansionSecondFloorWallType.BALCONY) { - int overlappers = 0; - for(JigsawStructurePiece otherPiece:builder.getOverlapperPieces()) { - int[] center = otherPiece.getRoom().getCenter(); - // Only check X and Z, as they're identical to bottom floor - if(center[0] == this.getRoom().getCenter()[0] - && center[2] == this.getRoom().getCenter()[2]) - overlappers++; - } - if(overlappers > 1) - type = MansionSecondFloorWallType.LARGE_WINDOW; - } - - Wall w = entry.getKey().getDown(); - + if (type == MansionSecondFloorWallType.BALCONY) { + int overlappers = 0; + for (JigsawStructurePiece otherPiece : builder.getOverlapperPieces()) { + int[] center = otherPiece.getRoom().getCenter(); + // Only check X and Z, as they're identical to bottom floor + if (center[0] == this.getRoom().getCenter()[0] && center[2] == this.getRoom().getCenter()[2]) { + overlappers++; + } + } + if (overlappers > 1) { + type = MansionSecondFloorWallType.LARGE_WINDOW; + } + } + + Wall w = entry.getKey().getDown(); + for (int i = 0; i < entry.getValue(); i++) { - - switch(type) { - case LARGE_WINDOW: - if(i == 1 || i == entry.getValue()-2) // Side decoration - w.getUp().Pillar(this.getRoom().getHeight(),new Random(),Material.DARK_OAK_LOG); - - if(i == 3 || i == 4 || i == 5) - { // Window Panes and decorations at the base - w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); - w.getUp(2).CorrectMultipleFacing(4); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp().getFront()); - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(w.getDirection()) - .setOpen(true) - .apply(w.getUp().getFront(2)); - new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR) - .setFacing(w.getDirection()) - .apply(w.getUp().getFront().getUp()); - } - - if(i == 2 || i == entry.getValue()-3) - {// Supporting Pillars - w.getFront().getUp().setType(Material.COBBLESTONE); - w.getFront().getUp(2).Pillar(3, new Random(), Material.STONE_BRICK_WALL); - w.getFront().getUp(2).CorrectMultipleFacing(3); - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getFront().getUp(5)); - } - - if(i == 4) { - // Place Main window decoration - spawnWindowOverhang(w.getFront().getUp(6)); - } - - break; - case BALCONY: - if(i == 4) { // center - w.getUp().getLeft().Pillar(3, Material.AIR); - w.getUp().getRight().Pillar(3, Material.AIR); - w.getUp().Pillar(4, Material.AIR); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp(5)) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getLeft().getUp(4)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRight().getUp(4)); - - w.getUp(6).getFront().setType(Material.COBBLESTONE_SLAB); - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(w.getUp(5).getFront().getLeft()) - .apply(w.getUp(5).getFront().getRight()); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp(6)) - .apply(w.getRight().getUp(5)) - .apply(w.getLeft().getUp(5)); - - w.getUp().getRight(2).getFront().setType(Material.POLISHED_ANDESITE); - w.getUp(2).getRight(2).getFront().Pillar(2, Material.STONE_BRICK_WALL); - w.getUp(2).getRight(2).getFront().CorrectMultipleFacing(2); - - w.getUp().getLeft(2).getFront().setType(Material.POLISHED_ANDESITE); - w.getUp(2).getLeft(2).getFront().Pillar(2, Material.STONE_BRICK_WALL); - w.getUp(2).getLeft(2).getFront().CorrectMultipleFacing(2); - - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp().getRight(2).getFront(2)) - .apply(w.getRight(2).getFront().getUp(4)) - .apply(w.getUp().getLeft(2).getFront(2)) - .apply(w.getLeft(2).getFront().getUp(4)) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp().getRight(3).getFront()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp().getLeft(3).getFront()) - ; - } - else if (i == 1 || i == entry.getValue() - 2) - { // Side lamps and oak log - w.getUp().Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront().getUp(5)); - w.getFront().getUp(6).setType(Material.LANTERN); - } - break; - case THIN_WINDOWS: - if(i == 2 || i == entry.getValue()-3) // Side decoration - { - w.getUp().Pillar(this.getRoom().getHeight(),new Random(),Material.DARK_OAK_LOG); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp(2).getFront()); - - - w.getUp(3).getFront().setType(Material.STONE_BRICK_WALL); - w.getUp(4).getFront().setType(Material.STONE_BRICK_WALL); - w.getUp(5).getFront().setType(Material.COBBLESTONE_SLAB); - } - if(i%2 == 1) { - w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); - w.getUp(2).CorrectMultipleFacing(4); - } - - if(i == (entry.getValue()/2)) { - spawnWallSupportingPillar(w.getFront().getUp(), this.getRoom().getHeight()); - } - break; - } - + + switch (type) { + case LARGE_WINDOW: + if (i == 1 || i == entry.getValue() - 2) // Side decoration + { + w.getUp().Pillar(this.getRoom().getHeight(), new Random(), Material.DARK_OAK_LOG); + } + + if (i == 3 || i == 4 || i == 5) { // Window Panes and decorations at the base + w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); + w.getUp(2).CorrectMultipleFacing(4); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp().getFront()); + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(w.getDirection()) + .setOpen(true) + .apply(w.getUp().getFront(2)); + new TrapdoorBuilder(Material.DARK_OAK_TRAPDOOR).setFacing(w.getDirection()) + .apply(w.getUp().getFront().getUp()); + } + + if (i == 2 || i == entry.getValue() - 3) {// Supporting Pillars + w.getFront().getUp().setType(Material.COBBLESTONE); + w.getFront().getUp(2).Pillar(3, new Random(), Material.STONE_BRICK_WALL); + w.getFront().getUp(2).CorrectMultipleFacing(3); + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getFront().getUp(5)); + } + + if (i == 4) { + // Place Main window decoration + spawnWindowOverhang(w.getFront().getUp(6)); + } + + break; + case BALCONY: + if (i == 4) { // center + w.getUp().getLeft().Pillar(3, Material.AIR); + w.getUp().getRight().Pillar(3, Material.AIR); + w.getUp().Pillar(4, Material.AIR); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp(5)) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getLeft().getUp(4)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRight().getUp(4)); + + w.getUp(6).getFront().setType(Material.COBBLESTONE_SLAB); + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .apply(w.getUp(5).getFront().getLeft()) + .apply(w.getUp(5).getFront().getRight()); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp(6)) + .apply(w.getRight().getUp(5)) + .apply(w.getLeft().getUp(5)); + + w.getUp().getRight(2).getFront().setType(Material.POLISHED_ANDESITE); + w.getUp(2).getRight(2).getFront().Pillar(2, Material.STONE_BRICK_WALL); + w.getUp(2).getRight(2).getFront().CorrectMultipleFacing(2); + + w.getUp().getLeft(2).getFront().setType(Material.POLISHED_ANDESITE); + w.getUp(2).getLeft(2).getFront().Pillar(2, Material.STONE_BRICK_WALL); + w.getUp(2).getLeft(2).getFront().CorrectMultipleFacing(2); + + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection() + .getOppositeFace()) + .apply(w.getUp().getRight(2).getFront(2)) + .apply(w.getRight(2).getFront().getUp(4)) + .apply(w.getUp().getLeft(2).getFront(2)) + .apply(w.getLeft(2).getFront().getUp(4)) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp().getRight(3).getFront()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp().getLeft(3).getFront()); + } + else if (i == 1 || i == entry.getValue() - 2) { // Side lamps and oak log + w.getUp().Pillar(this.getRoom().getHeight(), Material.DARK_OAK_LOG); + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection() + .getOppositeFace()) + .apply(w.getFront().getUp(5)); + w.getFront().getUp(6).setType(Material.LANTERN); + } + break; + case THIN_WINDOWS: + if (i == 2 || i == entry.getValue() - 3) // Side decoration + { + w.getUp().Pillar(this.getRoom().getHeight(), new Random(), Material.DARK_OAK_LOG); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection() + .getOppositeFace()) + .apply(w.getUp(2).getFront()); + + + w.getUp(3).getFront().setType(Material.STONE_BRICK_WALL); + w.getUp(4).getFront().setType(Material.STONE_BRICK_WALL); + w.getUp(5).getFront().setType(Material.COBBLESTONE_SLAB); + } + if (i % 2 == 1) { + w.getUp(2).Pillar(4, new Random(), Material.LIGHT_GRAY_STAINED_GLASS_PANE); + w.getUp(2).CorrectMultipleFacing(4); + } + + if (i == (entry.getValue() / 2)) { + spawnWallSupportingPillar(w.getFront().getUp(), this.getRoom().getHeight()); + } + break; + } + w = w.getLeft(); } - - // Raise walls to meet roof. + + // Raise walls to meet roof. entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); w = entry.getKey().getDown(); - + for (int i = 0; i < entry.getValue(); i++) { - - Wall target = w.getRelative(0, this.getRoom().getHeight(), 0); - - if(target.getUp().getType() == Material.DARK_OAK_LOG) - target.getUp().setType(Material.AIR); - - // Link the wall to the roof above - if(target.findCeiling(10) != null) - { - int spawnedHeight = target.getUp().LPillar(10, new Random(), target.getType()); - - if(!isTentRoofFace) - // Spawn slightly overhanging roof - if(spawnedHeight == 0 && target.getUp().getFront().isAir() && Tag.STAIRS.isTagged(target.getUp().getType())) { - StairBuilder builder = new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(target.getDirection().getOppositeFace()) - .lapply(target.getFront()); - - for(int depth = 1; depth <= 2; depth++) { - if(Tag.STAIRS.isTagged(target.getLeft(depth).getUp().getType()) - && target.getLeft(depth).getUp().getFront().isAir()) - builder.lapply(target.getLeft(depth).getFront()); - if(Tag.STAIRS.isTagged(target.getRight(depth).getUp().getType()) - && target.getRight(depth).getUp().getFront().isAir()) - builder.lapply(target.getRight(depth).getFront()); - } - - } - } - + + Wall target = w.getRelative(0, this.getRoom().getHeight(), 0); + + if (target.getUp().getType() == Material.DARK_OAK_LOG) { + target.getUp().setType(Material.AIR); + } + + // Link the wall to the roof above + if (target.findCeiling(10) != null) { + int spawnedHeight = target.getUp().LPillar(10, new Random(), target.getType()); + + if (!isTentRoofFace) + // Spawn slightly overhanging roof + { + if (spawnedHeight == 0 && target.getUp().getFront().isAir() && Tag.STAIRS.isTagged(target.getUp() + .getType())) + { + StairBuilder builder = new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(target.getDirection() + .getOppositeFace()) + .lapply(target.getFront()); + + for (int depth = 1; depth <= 2; depth++) { + if (Tag.STAIRS.isTagged(target.getLeft(depth).getUp().getType()) && target.getLeft(depth) + .getUp() + .getFront() + .isAir()) + { + builder.lapply(target.getLeft(depth).getFront()); + } + if (Tag.STAIRS.isTagged(target.getRight(depth).getUp().getType()) && target.getRight(depth) + .getUp() + .getFront() + .isAir()) + { + builder.lapply(target.getRight(depth).getFront()); + } + } + + } + } + } + w = w.getLeft(); } - + } - + private void spawnWallSupportingPillar(@NotNull Wall w, int height) { - w.Pillar(height, new Random(), Material.POLISHED_ANDESITE); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getRelative(BlockUtils.getLeft(w.getDirection()))); - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRelative(BlockUtils.getRight(w.getDirection()))); - - - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getRelative(0,height-1,0)); - - w.getUp(2).setType(Material.STONE_BRICK_WALL); - w.getUp(3).setType(Material.POLISHED_DIORITE); - w.getUp(4).setType(Material.STONE_BRICK_WALL); - w.getUp(2).CorrectMultipleFacing(3); + w.Pillar(height, new Random(), Material.POLISHED_ANDESITE); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getRelative(BlockUtils.getLeft(w.getDirection()))); + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRelative(BlockUtils.getRight(w.getDirection()))); + + + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getRelative(0, height - 1, 0)); + + w.getUp(2).setType(Material.STONE_BRICK_WALL); + w.getUp(3).setType(Material.POLISHED_DIORITE); + w.getUp(4).setType(Material.STONE_BRICK_WALL); + w.getUp(2).CorrectMultipleFacing(3); } - + private void spawnWindowOverhang(@NotNull Wall w) { - // log row - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) - .apply(w).apply(w.getLeft()).apply(w.getRight()); - - // Upsidedown overhang in front of log row. - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(w.getFront().getLeft()) - .apply(w.getFront().getRight()); - - - // Inner upside down stairs - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getDown().getLeft()) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getDown().getRight()); - - // Stairs at the top - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRight(2)) - .apply(w.getRight().getUp()); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft(2)) - .apply(w.getLeft().getUp()); - - new OrientableBuilder(Material.DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp()); + // log row + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))) + .apply(w) + .apply(w.getLeft()) + .apply(w.getRight()); + + // Upsidedown overhang in front of log row. + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .apply(w.getFront().getLeft()) + .apply(w.getFront().getRight()); + + + // Inner upside down stairs + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getDown().getLeft()) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getDown().getRight()); + + // Stairs at the top + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getRight(2)) + .apply(w.getRight().getUp()); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getLeft(2)) + .apply(w.getLeft().getUp()); + + new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp()); } - - private enum MansionSecondFloorWallType{ - THIN_WINDOWS, - LARGE_WINDOW, - BALCONY + + private enum MansionSecondFloorWallType { + THIN_WINDOWS, LARGE_WINDOW, BALCONY } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionStandardSecondFloorPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionStandardSecondFloorPiece.java index a707da0c..1564dd43 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionStandardSecondFloorPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionStandardSecondFloorPiece.java @@ -7,12 +7,19 @@ import org.terraform.structure.pillager.mansion.MansionJigsawBuilder; import org.terraform.structure.pillager.mansion.MansionStandardRoomPiece; import org.terraform.structure.room.jigsaw.JigsawType; + import java.util.Random; public class MansionStandardSecondFloorPiece extends MansionStandardRoomPiece { - public MansionStandardSecondFloorPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(widthX, height, widthZ, type, validDirs); + public MansionStandardSecondFloorPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(widthX, height, widthZ, type, validDirs); } @Override @@ -21,11 +28,12 @@ public void build(@NotNull PopulatorDataAbstract data, Random rand) { int[] upperCorner = this.getRoom().getUpperCorner(0); // Place attic ceiling - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setType(x, this.getRoom().getY()+this.getRoom().getHeight(), z, Material.DARK_OAK_PLANKS); - + data.setType(x, this.getRoom().getY() + this.getRoom().getHeight(), z, Material.DARK_OAK_PLANKS); + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionTowerStairwayPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionTowerStairwayPopulator.java index c7cd705c..3cb8cdd3 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionTowerStairwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/secondfloor/MansionTowerStairwayPopulator.java @@ -22,73 +22,83 @@ public class MansionTowerStairwayPopulator extends MansionRoomPopulator { - private final int towerHeight; - public MansionTowerStairwayPopulator(CubeRoom room, HashMap internalWalls, int towerHeight) { - super(room, internalWalls); - this.towerHeight = towerHeight; - } + private final int towerHeight; - @Override - public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { + public MansionTowerStairwayPopulator(CubeRoom room, + HashMap internalWalls, + int towerHeight) + { + super(room, internalWalls); + this.towerHeight = towerHeight; + } + + protected static int getNextIndex(int bfIndex) { + bfIndex++; + if (bfIndex >= 8) { + bfIndex = 0; + } + return bfIndex; + } + + @Override + public void decorateRoom(@NotNull PopulatorDataAbstract data, @NotNull Random random) { int bfIndex = 0; Wall b = new Wall(this.getRoom().getCenterSimpleBlock(data)); int height = 8; - if(towerHeight == 2) - height = 15; + if (towerHeight == 2) { + height = 15; + } // Slabs curving upwards for (int i = 1; i < height; i++) { - b.getRelative(0,i,0).setType(Material.STONE_BRICKS); + b.getRelative(0, i, 0).setType(Material.STONE_BRICKS); BlockFace face = BlockUtils.xzPlaneBlockFaces[bfIndex]; Slab bottom = (Slab) Bukkit.createBlockData(Material.STONE_BRICK_SLAB); bottom.setType(Type.BOTTOM); - b.getRelative(face).getRelative(0,i,0).setBlockData(bottom); - b.getRelative(face).getRelative(0,i+1,0).Pillar(3, Material.AIR); + b.getRelative(face).getRelative(0, i, 0).setBlockData(bottom); + b.getRelative(face).getRelative(0, i + 1, 0).Pillar(3, Material.AIR); bfIndex = getNextIndex(bfIndex); face = BlockUtils.xzPlaneBlockFaces[bfIndex]; Slab top = (Slab) Bukkit.createBlockData(Material.STONE_BRICK_SLAB); top.setType(Type.TOP); - b.getRelative(face).getRelative(0,i,0).setBlockData(top); - b.getRelative(face).getRelative(0,i+1,0).Pillar(3, Material.AIR); + b.getRelative(face).getRelative(0, i, 0).setBlockData(top); + b.getRelative(face).getRelative(0, i + 1, 0).Pillar(3, Material.AIR); bfIndex = getNextIndex(bfIndex); } - + // 7 blocks above, place some chests and decorations at the stairs b = b.getUp(8); - - for(Entry entry:this.getRoom().getFourWalls(data, 2).entrySet()) { - Wall w = entry.getKey().getAtY(b.getY()); - for(int i = 0; i < entry.getValue(); i++) { - int pileHeight = GenUtils.randInt(random, 1, 2); - w.Pillar( - pileHeight, random, - Material.CRAFTING_TABLE, Material.FLETCHING_TABLE, - Material.CARTOGRAPHY_TABLE, Material.ANVIL, - Material.NOTE_BLOCK, Material.SMITHING_TABLE); - if(GenUtils.chance(random, 1, 5)) { - w.setBlockData(BlockUtils.getRandomBarrel()); - data.lootTableChest(w.getX(), w.getY(), w.getZ(), TerraLootTable.WOODLAND_MANSION); - } - if(GenUtils.chance(random, 1, 5)) { - w.getRelative(0,pileHeight,0).setType(Material.LANTERN); - } - - w = w.getLeft(); - } + + for (Entry entry : this.getRoom().getFourWalls(data, 2).entrySet()) { + Wall w = entry.getKey().getAtY(b.getY()); + for (int i = 0; i < entry.getValue(); i++) { + int pileHeight = GenUtils.randInt(random, 1, 2); + w.Pillar(pileHeight, + random, + Material.CRAFTING_TABLE, + Material.FLETCHING_TABLE, + Material.CARTOGRAPHY_TABLE, + Material.ANVIL, + Material.NOTE_BLOCK, + Material.SMITHING_TABLE + ); + if (GenUtils.chance(random, 1, 5)) { + w.setBlockData(BlockUtils.getRandomBarrel()); + data.lootTableChest(w.getX(), w.getY(), w.getZ(), TerraLootTable.WOODLAND_MANSION); + } + if (GenUtils.chance(random, 1, 5)) { + w.getRelative(0, pileHeight, 0).setType(Material.LANTERN); + } + + w = w.getLeft(); + } } - } - - protected static int getNextIndex(int bfIndex) { - bfIndex++; - if (bfIndex >= 8) bfIndex = 0; - return bfIndex; } - - @Override - public @NotNull MansionRoomSize getSize() { - return new MansionRoomSize(1,1); - } + @Override + public @NotNull MansionRoomSize getSize() { + return new MansionRoomSize(1, 1); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerPiece.java index d857064c..887c1555 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerPiece.java @@ -14,39 +14,48 @@ public class MansionBaseTowerPiece extends MansionStandardTowerPiece { - public MansionBaseTowerPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, - BlockFace[] validDirs) { - super(builder, widthX, height, widthZ, type, validDirs); - } - - @Override - public void decorateAwkwardCorner(@NotNull Wall target, Random random, @NotNull BlockFace one, @NotNull BlockFace two) { - // Fill in gap in the corner - target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); - target.getRelative(one).getRelative(two).setType(Material.COBBLESTONE_SLAB); - - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(target.getRelative(one).getRelative(two).getUp(3)); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(one.getOppositeFace()) - .apply(target.getRelative(two).getUp(4)) - .setFacing(two.getOppositeFace()) - .apply(target.getRelative(one).getUp(4)); - - target.getRelative(one).Pillar(4, Material.COBBLESTONE_WALL); - target.getRelative(one).CorrectMultipleFacing(4); - target.getRelative(two).Pillar(4, Material.COBBLESTONE_WALL); - target.getRelative(two).CorrectMultipleFacing(4); - - target.getRelative(one).setType(Material.COBBLESTONE); - target.getRelative(two).setType(Material.COBBLESTONE); - if(target.getRelative(two).getDown(2).isSolid()) - target.getRelative(two).getDown().setType(Material.COBBLESTONE); - if(target.getRelative(one).getDown(2).isSolid()) - target.getRelative(one).getDown().setType(Material.COBBLESTONE); - + public MansionBaseTowerPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(builder, widthX, height, widthZ, type, validDirs); + } + + @Override + public void decorateAwkwardCorner(@NotNull Wall target, + Random random, + @NotNull BlockFace one, + @NotNull BlockFace two) + { + // Fill in gap in the corner + target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); + target.getRelative(one).getRelative(two).setType(Material.COBBLESTONE_SLAB); + + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP) + .apply(target.getRelative(one).getRelative(two).getUp(3)); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(one.getOppositeFace()) + .apply(target.getRelative(two).getUp(4)) + .setFacing(two.getOppositeFace()) + .apply(target.getRelative(one).getUp(4)); + + target.getRelative(one).Pillar(4, Material.COBBLESTONE_WALL); + target.getRelative(one).CorrectMultipleFacing(4); + target.getRelative(two).Pillar(4, Material.COBBLESTONE_WALL); + target.getRelative(two).CorrectMultipleFacing(4); + + target.getRelative(one).setType(Material.COBBLESTONE); + target.getRelative(two).setType(Material.COBBLESTONE); + if (target.getRelative(two).getDown(2).isSolid()) { + target.getRelative(two).getDown().setType(Material.COBBLESTONE); + } + if (target.getRelative(one).getDown(2).isSolid()) { + target.getRelative(one).getDown().setType(Material.COBBLESTONE); + } + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerWallPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerWallPiece.java index f29fc88e..ed3c6a5e 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerWallPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionBaseTowerWallPiece.java @@ -19,89 +19,86 @@ public class MansionBaseTowerWallPiece extends MansionTowerWallPiece { - public MansionBaseTowerWallPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, - BlockFace[] validDirs) { - super(builder, widthX, height, widthZ, type, validDirs); - // TODO Auto-generated constructor stub - } - + public MansionBaseTowerWallPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(builder, widthX, height, widthZ, type, validDirs); + // TODO Auto-generated constructor stub + } + @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); - + for (int i = 0; i < entry.getValue(); i++) { - - // Primary Wall and wooden stair decorations - // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + // Primary Wall and wooden stair decorations + // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(this.getRoom().getHeight(), rand, Material.DARK_OAK_PLANKS); - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp().getFront()); - + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp().getFront()); + w = w.getLeft(); } } - + @Override public void postBuildDecoration(Random rand, @NotNull PopulatorDataAbstract data) { - + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey().getDown(); + Wall w = entry.getKey().getDown(); - - OrientableBuilder logBuilder = new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getRight(w.getDirection()))); - // Carving + + OrientableBuilder logBuilder = new OrientableBuilder(Material.DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace( + BlockUtils.getRight(w.getDirection()))); + // Carving for (int i = 0; i < entry.getValue(); i++) { - - w.getRear().getUp().Pillar(6,Material.STONE); - logBuilder.apply(w.getUp(7)); - - // Decorative Roofing & carving - if(i == 0 || i == entry.getValue()-1) { - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(w.getUp(5).getFront()); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(i > 0 ? BlockUtils.getLeft(w.getDirection()) : BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(3)); - } - else if(i == 1 || i == entry.getValue()-2) { - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(i > 2 ? BlockUtils.getRight(w.getDirection()) : BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(6).getFront()); - - w.getUp(3).setType(Material.AIR); - } - else if(i == 2 || i == entry.getValue()-3) { - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.TOP) - .apply(w.getUp(6).getFront()); - - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .apply(w.getUp(5)); - } - else{ // center - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setType(Type.BOTTOM) - .apply(w.getUp(7).getFront()); - - - w.getUp(5).setType(Material.AIR); - new SlabBuilder(Material.DARK_OAK_SLAB) - .setType(Type.TOP) - .apply(w.getUp(4)); - w.getUp(3).setType(Material.AIR); - } - + + w.getRear().getUp().Pillar(6, Material.STONE); + logBuilder.apply(w.getUp(7)); + + // Decorative Roofing & carving + if (i == 0 || i == entry.getValue() - 1) { + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP).apply(w.getUp(5).getFront()); + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(i > 0 + ? BlockUtils.getLeft(w.getDirection()) + : BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(3)); + } + else if (i == 1 || i == entry.getValue() - 2) { + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(i > 2 + ? BlockUtils.getRight(w.getDirection()) + : BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(6).getFront()); + + w.getUp(3).setType(Material.AIR); + } + else if (i == 2 || i == entry.getValue() - 3) { + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.TOP).apply(w.getUp(6).getFront()); + + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).apply(w.getUp(5)); + } + else { // center + new SlabBuilder(Material.COBBLESTONE_SLAB).setType(Type.BOTTOM).apply(w.getUp(7).getFront()); + + + w.getUp(5).setType(Material.AIR); + new SlabBuilder(Material.DARK_OAK_SLAB).setType(Type.TOP).apply(w.getUp(4)); + w.getUp(3).setType(Material.AIR); + } + w = w.getLeft(); - } + } } - + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionLookoutTowerWallPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionLookoutTowerWallPiece.java index d32ee6d0..6a7651bb 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionLookoutTowerWallPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionLookoutTowerWallPiece.java @@ -20,100 +20,97 @@ public class MansionLookoutTowerWallPiece extends MansionTowerWallPiece { - public MansionLookoutTowerWallPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, - BlockFace[] validDirs) { - super(builder, widthX, height, widthZ, type, validDirs); - } - + public MansionLookoutTowerWallPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(builder, widthX, height, widthZ, type, validDirs); + } + @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { - super.build(data, rand); + super.build(data, rand); } - + @Override public void postBuildDecoration(Random rand, @NotNull PopulatorDataAbstract data) { - + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey().getDown(); + Wall w = entry.getKey().getDown(); + - - // Carving + // Carving for (int i = 0; i < entry.getValue(); i++) { - - // sides - if(i == 0 || i == entry.getValue()-1) { - w.getUp().Pillar(8, Material.DARK_OAK_LOG); - new SlabBuilder(Material.STONE_BRICK_SLAB) - .setType(Type.TOP) - .apply(w.getFront().getUp(4)); - - }else if(i == 1 || i == entry.getValue()-2) { - w.getUp().Pillar(3, Material.AIR); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w.getFront()); - - new OrientableBuilder(Material.STRIPPED_DARK_OAK_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) - .apply(w.getUp()) - .apply(w.getUp().getFront()); - - w.getUp(2).getFront().Pillar(3, Material.STONE_BRICK_WALL); - w.getUp(2).getFront().CorrectMultipleFacing(3); - - w.getUp(5).getFront().setType(Material.STONE_BRICK_SLAB); - - }else if(i == 2 || i == entry.getValue()-3) { - w.getUp().Pillar(4, Material.AIR); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp().getFront()); - new DirectionalBuilder(Material.DARK_OAK_FENCE_GATE) - .setFacing(w.getDirection()) - .apply(w.getUp(2).getFront()); - w.getUp(2).getFront().CorrectMultipleFacing(1); - - new SlabBuilder(Material.STONE_BRICK_SLAB) - .setType(Type.TOP) - .apply(w.getFront().getUp(5)); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getUp()); - }else { // center - w.getUp().Pillar(5, Material.AIR); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setHalf(Half.TOP).setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp().getFront()); - w.getUp(2).getFront().setType(Material.STONE_BRICK_WALL); - w.getUp(2).getFront().CorrectMultipleFacing(1); - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getUp()); - - // Edit stairs on the left and right - - new StairBuilder(Material.DARK_OAK_STAIRS) - .setHalf(Half.TOP) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(5).getLeft()) - .apply(w.getUp(4).getLeft(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(5).getRight()) - .apply(w.getUp(4).getRight(2)); - - w.getUp(6).getFront().setType(Material.STONE_BRICK_SLAB); - } - - + + // sides + if (i == 0 || i == entry.getValue() - 1) { + w.getUp().Pillar(8, Material.DARK_OAK_LOG); + new SlabBuilder(Material.STONE_BRICK_SLAB).setType(Type.TOP).apply(w.getFront().getUp(4)); + + } + else if (i == 1 || i == entry.getValue() - 2) { + w.getUp().Pillar(3, Material.AIR); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getFront()); + + new OrientableBuilder(Material.STRIPPED_DARK_OAK_LOG).setAxis(BlockUtils.getAxisFromBlockFace(w.getDirection())) + .apply(w.getUp()) + .apply(w.getUp().getFront()); + + w.getUp(2).getFront().Pillar(3, Material.STONE_BRICK_WALL); + w.getUp(2).getFront().CorrectMultipleFacing(3); + + w.getUp(5).getFront().setType(Material.STONE_BRICK_SLAB); + + } + else if (i == 2 || i == entry.getValue() - 3) { + w.getUp().Pillar(4, Material.AIR); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp().getFront()); + new DirectionalBuilder(Material.DARK_OAK_FENCE_GATE).setFacing(w.getDirection()) + .apply(w.getUp(2).getFront()); + w.getUp(2).getFront().CorrectMultipleFacing(1); + + new SlabBuilder(Material.STONE_BRICK_SLAB).setType(Type.TOP).apply(w.getFront().getUp(5)); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).apply(w.getUp()); + } + else { // center + w.getUp().Pillar(5, Material.AIR); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp().getFront()); + w.getUp(2).getFront().setType(Material.STONE_BRICK_WALL); + w.getUp(2).getFront().CorrectMultipleFacing(1); + + new StairBuilder(Material.DARK_OAK_STAIRS).setFacing(w.getDirection()).apply(w.getUp()); + + // Edit stairs on the left and right + + new StairBuilder(Material.DARK_OAK_STAIRS).setHalf(Half.TOP) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(5).getLeft()) + .apply(w.getUp(4).getLeft(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(5).getRight()) + .apply(w.getUp(4).getRight(2)); + + w.getUp(6).getFront().setType(Material.STONE_BRICK_SLAB); + } + + w = w.getLeft(); - } + } } - + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionStandardTowerPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionStandardTowerPiece.java index 06921096..ff6daa4b 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionStandardTowerPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionStandardTowerPiece.java @@ -18,10 +18,17 @@ public class MansionStandardTowerPiece extends JigsawStructurePiece { - private final MansionJigsawBuilder builder; - boolean isHighestPieceInTower = false; - public MansionStandardTowerPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(widthX, height, widthZ, type, validDirs); + private final MansionJigsawBuilder builder; + boolean isHighestPieceInTower = false; + + public MansionStandardTowerPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(widthX, height, widthZ, type, validDirs); this.builder = builder; } @@ -29,158 +36,149 @@ public MansionStandardTowerPiece(MansionJigsawBuilder builder, int widthX, int h public void build(@NotNull PopulatorDataAbstract data, Random rand) { int[] lowerCorner = this.getRoom().getLowerCorner(0); int[] upperCorner = this.getRoom().getUpperCorner(0); - + // Place ground - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { data.setType(x, this.getRoom().getY(), z, Material.DARK_OAK_PLANKS); - + } + } } public void decorateAwkwardCorners(Random random) - { + { // Make sure awkward corners are fixed - SimpleBlock core = new SimpleBlock( - builder.getCore().getPopData(), + SimpleBlock core = new SimpleBlock(builder.getCore().getPopData(), getRoom().getX(), getRoom().getY(), - getRoom().getZ()); + getRoom().getZ() + ); Wall target; - - if (getWalledFaces().contains(BlockFace.NORTH) - && getWalledFaces().contains(BlockFace.WEST)) { // nw + + if (getWalledFaces().contains(BlockFace.NORTH) && getWalledFaces().contains(BlockFace.WEST)) { // nw target = new Wall(core.getRelative(-4, 1, -4)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST); } - if (getWalledFaces().contains(BlockFace.NORTH) - && getWalledFaces().contains(BlockFace.EAST)) { // ne + if (getWalledFaces().contains(BlockFace.NORTH) && getWalledFaces().contains(BlockFace.EAST)) { // ne target = new Wall(core.getRelative(4, 1, -4)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST); } - if (getWalledFaces().contains(BlockFace.SOUTH) - && getWalledFaces().contains(BlockFace.WEST)) { // sw + if (getWalledFaces().contains(BlockFace.SOUTH) && getWalledFaces().contains(BlockFace.WEST)) { // sw target = new Wall(core.getRelative(-4, 1, 4)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST); } - if (getWalledFaces().contains(BlockFace.SOUTH) - && getWalledFaces().contains(BlockFace.EAST)) { // se + if (getWalledFaces().contains(BlockFace.SOUTH) && getWalledFaces().contains(BlockFace.EAST)) { // se target = new Wall(core.getRelative(4, 1, 4)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST); } - } + } + + public void decorateAwkwardCorner(@NotNull Wall target, Random random, BlockFace one, BlockFace two) { + // Fill in gap in the corner + target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); + } + + public void placeTentRoof(@NotNull PopulatorDataAbstract data, BlockFace roofFacing, Random random) { + Wall core = new Wall(this.getRoom() + .getCenterSimpleBlock(data) + .getRelative(0, MansionJigsawBuilder.roomHeight, 0), + roofFacing + ).getFront(1 + (MansionJigsawBuilder.groundFloorRoomWidth / 2)); + + for (BlockFace dir : BlockUtils.getAdjacentFaces(core.getDirection())) { + // Index from the side + for (int i = 0; i <= 2 + (MansionJigsawBuilder.groundFloorRoomWidth / 2); i++) { + for (int depth = 0; depth < 2 + MansionJigsawBuilder.groundFloorRoomWidth; depth++) { + Wall w = core.getRear(depth).getRelative(dir, i); + + if (i == 0) { // Center + w.getUp(5).Pillar(2, Material.COBBLESTONE); + w.getUp(7).setType(Material.COBBLESTONE_WALL); + w.getUp(7).CorrectMultipleFacing(1); + } + else if (i == 1) { + new StairBuilder(getStairs(i, depth)).setFacing(dir.getOppositeFace()).apply(w.getUp(5)); + w.getUp(3).Pillar(2, getBlock(i, depth)); + } + else if (i == 2) { + new StairBuilder(getStairs(i, depth)).setFacing(dir.getOppositeFace()).apply(w.getUp(3)); + w.getUp(2).setType(getBlock(i, depth)); + } + else if (i == 3) { + new StairBuilder(getStairs(i, depth)).setFacing(dir.getOppositeFace()).apply(w.getUp(2)); + + new SlabBuilder(getSlab(i, depth)).setType(Type.TOP).apply(w.getUp()); + } + else if (i == 4) { + w.getUp().setType(getBlock(i, depth)); + } + else if (i == 5) { + w.getUp().setType(getSlab(i, depth)); + new SlabBuilder(getSlab(i, depth)).setType(Type.TOP).apply(w); + } + else // Final + { + new SlabBuilder(getSlab(i, depth)).setType(Type.TOP).apply(w); + } + + // Join the walls to the roof + if (i <= 3) { + if (depth == 1 || depth == MansionJigsawBuilder.groundFloorRoomWidth) { + w.getUp().setType(Material.DARK_OAK_PLANKS); + w.getUp(2).LPillar(4, new Random(), Material.DARK_OAK_PLANKS); + } + } + + } + } + } - public void decorateAwkwardCorner(@NotNull Wall target, Random random, BlockFace one, BlockFace two) { - // Fill in gap in the corner - target.Pillar(MansionJigsawBuilder.roomHeight, Material.STONE_BRICKS); } - - public void placeTentRoof(@NotNull PopulatorDataAbstract data, BlockFace roofFacing, Random random) { - Wall core = new Wall( - this.getRoom().getCenterSimpleBlock(data).getRelative(0, MansionJigsawBuilder.roomHeight,0), - roofFacing - ) - .getFront(1+(MansionJigsawBuilder.groundFloorRoomWidth/2)); - - for(BlockFace dir:BlockUtils.getAdjacentFaces(core.getDirection())) { - // Index from the side - for(int i = 0; i <= 2+(MansionJigsawBuilder.groundFloorRoomWidth/2); i++) { - for(int depth = 0; depth < 2 + MansionJigsawBuilder.groundFloorRoomWidth; depth++) { - Wall w = core.getRear(depth).getRelative(dir,i); - - if(i == 0) { // Center - w.getUp(5).Pillar(2, Material.COBBLESTONE); - w.getUp(7).setType(Material.COBBLESTONE_WALL); - w.getUp(7).CorrectMultipleFacing(1); - } - else if(i == 1) - { - new StairBuilder(getStairs(i, depth)) - .setFacing(dir.getOppositeFace()) - .apply(w.getUp(5)); - w.getUp(3).Pillar(2, getBlock(i,depth)); - } - else if(i == 2) - { - new StairBuilder(getStairs(i, depth)) - .setFacing(dir.getOppositeFace()) - .apply(w.getUp(3)); - w.getUp(2).setType(getBlock(i,depth)); - } - else if(i == 3) - { - new StairBuilder(getStairs(i, depth)) - .setFacing(dir.getOppositeFace()) - .apply(w.getUp(2)); - - new SlabBuilder(getSlab(i,depth)) - .setType(Type.TOP) - .apply(w.getUp()); - } - else if(i == 4) - { - w.getUp().setType(getBlock(i,depth)); - } - else if(i == 5) - { - w.getUp().setType(getSlab(i,depth)); - new SlabBuilder(getSlab(i,depth)) - .setType(Type.TOP) - .apply(w); - } - else // Final - new SlabBuilder(getSlab(i,depth)) - .setType(Type.TOP) - .apply(w); - - // Join the walls to the roof - if(i <= 3) - if(depth == 1 || depth == MansionJigsawBuilder.groundFloorRoomWidth) - { - w.getUp().setType(Material.DARK_OAK_PLANKS); - w.getUp(2).LPillar(4, new Random(), Material.DARK_OAK_PLANKS); - } - - } - } - } - - } - -// i <= 2+(MansionJigsawBuilder.groundFloorRoomWidth/2 -// depth < 2 + MansionJigsawBuilder.groundFloorRoomWidth - - private @NotNull Material getStairs(int i, int depth) { - if(i == 0 || i == 2+(MansionJigsawBuilder.groundFloorRoomWidth/2) - || depth == 0 || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth){ - return Material.COBBLESTONE_STAIRS; - } - return Material.DARK_OAK_STAIRS; - } - - private @NotNull Material getSlab(int i, int depth) { - if(i == 0 || i == 2+(MansionJigsawBuilder.groundFloorRoomWidth/2) - || depth == 0 || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth){ - return Material.COBBLESTONE_SLAB; - } - return Material.DARK_OAK_SLAB; - } - - private @NotNull Material getBlock(int i, int depth) { - if(i == 0 || i == 2+(MansionJigsawBuilder.groundFloorRoomWidth/2) - || depth == 0 || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth){ - return Material.COBBLESTONE; - } - return Material.DARK_OAK_PLANKS; - } - - public boolean isHighestPieceInTower() { - return isHighestPieceInTower; - } - - public void setHighestPieceInTower(boolean isHighestPieceInTower) { - this.isHighestPieceInTower = isHighestPieceInTower; - } - + + // i <= 2+(MansionJigsawBuilder.groundFloorRoomWidth/2 + // depth < 2 + MansionJigsawBuilder.groundFloorRoomWidth + + private @NotNull Material getStairs(int i, int depth) { + if (i == 0 + || i == 2 + (MansionJigsawBuilder.groundFloorRoomWidth / 2) + || depth == 0 + || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth) + { + return Material.COBBLESTONE_STAIRS; + } + return Material.DARK_OAK_STAIRS; + } + + private @NotNull Material getSlab(int i, int depth) { + if (i == 0 + || i == 2 + (MansionJigsawBuilder.groundFloorRoomWidth / 2) + || depth == 0 + || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth) + { + return Material.COBBLESTONE_SLAB; + } + return Material.DARK_OAK_SLAB; + } + + private @NotNull Material getBlock(int i, int depth) { + if (i == 0 + || i == 2 + (MansionJigsawBuilder.groundFloorRoomWidth / 2) + || depth == 0 + || depth == 1 + MansionJigsawBuilder.groundFloorRoomWidth) + { + return Material.COBBLESTONE; + } + return Material.DARK_OAK_PLANKS; + } + + public boolean isHighestPieceInTower() { + return isHighestPieceInTower; + } + + public void setHighestPieceInTower(boolean isHighestPieceInTower) { + this.isHighestPieceInTower = isHighestPieceInTower; + } + } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerPieceHandler.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerPieceHandler.java index 5b78dd49..8035544e 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerPieceHandler.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerPieceHandler.java @@ -17,118 +17,139 @@ public class MansionTowerPieceHandler { - // Contains rooms in 3d. - public final @NotNull HashMap pieces = new HashMap<>(); - public final @NotNull ArrayList overlapperPieces = new ArrayList<>(); public static final int towerPieceWidth = 7; // 2 less than groundFloorPiece - - private final MansionJigsawBuilder builder; - private final PopulatorDataAbstract data; - public MansionTowerPieceHandler(MansionJigsawBuilder builder, PopulatorDataAbstract data) { - super(); - this.builder = builder; - this.data = data; - } - - public int registerTowerPiece(@NotNull Random rand, @NotNull JigsawStructurePiece piece) { - - int height = GenUtils.randInt(rand, 1, 2); - - for(int i = 1; i <= height; i++) { - JigsawStructurePiece newPiece; - if(i == 1) - newPiece = new MansionBaseTowerPiece( - builder, - towerPieceWidth, MansionJigsawBuilder.roomHeight, towerPieceWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - else - newPiece = new MansionStandardTowerPiece( - builder, - towerPieceWidth, MansionJigsawBuilder.roomHeight, towerPieceWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - - if(i == height) - ((MansionStandardTowerPiece) newPiece).setHighestPieceInTower(true); - newPiece.getRoom().setX(piece.getRoom().getX()); - newPiece.getRoom().setY(piece.getRoom().getY() + i*(MansionJigsawBuilder.roomHeight)); - newPiece.getRoom().setZ(piece.getRoom().getZ()); - - this.pieces.put(newPiece.getRoom().getSimpleLocation(), newPiece); - } - return height; - } - - public void setupWalls() { - for(JigsawStructurePiece piece:this.pieces.values()) { - ArrayList faces = new ArrayList<>(); - for(BlockFace face:BlockUtils.directBlockFaces) { - // Only wall off this area if there are no adjacent rooms there. - // Place the wall regardless. - if(!this.pieces.containsKey(piece.getRoom().getSimpleLocation() - .getRelative(face, towerPieceWidth))) { - JigsawStructurePiece newWall; - if(piece instanceof MansionBaseTowerPiece) { - newWall = new MansionBaseTowerWallPiece( - builder, - towerPieceWidth, MansionJigsawBuilder.roomHeight, towerPieceWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - } - else - { - newWall = new MansionLookoutTowerWallPiece( - builder, - towerPieceWidth, MansionJigsawBuilder.roomHeight, towerPieceWidth, - JigsawType.STANDARD, BlockUtils.directBlockFaces).getInstance(new Random(), 0); - } - - newWall.getRoom().setX(piece.getRoom().getX() + face.getModX()*towerPieceWidth); - newWall.getRoom().setY(piece.getRoom().getY()); - newWall.getRoom().setZ(piece.getRoom().getZ() + face.getModZ()*towerPieceWidth); - newWall.setRotation(face); - this.overlapperPieces.add(newWall); - faces.add(face); - } - } - piece.setWalledFaces(faces); - } - } - - public void buildPieces(Random rand) { + // Contains rooms in 3d. + public final @NotNull HashMap pieces = new HashMap<>(); + public final @NotNull ArrayList overlapperPieces = new ArrayList<>(); + private final MansionJigsawBuilder builder; + private final PopulatorDataAbstract data; + + public MansionTowerPieceHandler(MansionJigsawBuilder builder, PopulatorDataAbstract data) { + super(); + this.builder = builder; + this.data = data; + } + + public int registerTowerPiece(@NotNull Random rand, @NotNull JigsawStructurePiece piece) { + + int height = GenUtils.randInt(rand, 1, 2); + + for (int i = 1; i <= height; i++) { + JigsawStructurePiece newPiece; + if (i == 1) { + newPiece = new MansionBaseTowerPiece( + builder, + towerPieceWidth, + MansionJigsawBuilder.roomHeight, + towerPieceWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + } + else { + newPiece = new MansionStandardTowerPiece( + builder, + towerPieceWidth, + MansionJigsawBuilder.roomHeight, + towerPieceWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + } + + if (i == height) { + ((MansionStandardTowerPiece) newPiece).setHighestPieceInTower(true); + } + newPiece.getRoom().setX(piece.getRoom().getX()); + newPiece.getRoom().setY(piece.getRoom().getY() + i * (MansionJigsawBuilder.roomHeight)); + newPiece.getRoom().setZ(piece.getRoom().getZ()); + + this.pieces.put(newPiece.getRoom().getSimpleLocation(), newPiece); + } + return height; + } + + public void setupWalls() { + for (JigsawStructurePiece piece : this.pieces.values()) { + ArrayList faces = new ArrayList<>(); + for (BlockFace face : BlockUtils.directBlockFaces) { + // Only wall off this area if there are no adjacent rooms there. + // Place the wall regardless. + if (!this.pieces.containsKey(piece.getRoom().getSimpleLocation().getRelative(face, towerPieceWidth))) { + JigsawStructurePiece newWall; + if (piece instanceof MansionBaseTowerPiece) { + newWall = new MansionBaseTowerWallPiece( + builder, + towerPieceWidth, + MansionJigsawBuilder.roomHeight, + towerPieceWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + } + else { + newWall = new MansionLookoutTowerWallPiece( + builder, + towerPieceWidth, + MansionJigsawBuilder.roomHeight, + towerPieceWidth, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ).getInstance(new Random(), 0); + } + + newWall.getRoom().setX(piece.getRoom().getX() + face.getModX() * towerPieceWidth); + newWall.getRoom().setY(piece.getRoom().getY()); + newWall.getRoom().setZ(piece.getRoom().getZ() + face.getModZ() * towerPieceWidth); + newWall.setRotation(face); + this.overlapperPieces.add(newWall); + faces.add(face); + } + } + piece.setWalledFaces(faces); + } + } + + public void buildPieces(Random rand) { for (JigsawStructurePiece piece : this.pieces.values()) { - // Force room to be air first - int[] lowerCorner = piece.getRoom().getLowerCorner(0); - int[] upperCorner = piece.getRoom().getUpperCorner(0); - int lowestY = piece.getRoom().getY() + 1; - int upperY = piece.getRoom().getY() + piece.getRoom().getHeight(); - - for(int x = lowerCorner[0]; x<= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) - for(int y = lowestY; y < upperY; y++) - builder.getCore().getPopData().setType(x, y, z, Material.AIR); - + // Force room to be air first + int[] lowerCorner = piece.getRoom().getLowerCorner(0); + int[] upperCorner = piece.getRoom().getUpperCorner(0); + int lowestY = piece.getRoom().getY() + 1; + int upperY = piece.getRoom().getY() + piece.getRoom().getHeight(); + + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + for (int y = lowestY; y < upperY; y++) { + builder.getCore().getPopData().setType(x, y, z, Material.AIR); + } + } + } + // Build room - if(piece instanceof MansionStandardTowerPiece) - ((MansionStandardTowerPiece) piece).decorateAwkwardCorners(rand); + if (piece instanceof MansionStandardTowerPiece) { + ((MansionStandardTowerPiece) piece).decorateAwkwardCorners(rand); + } piece.build(builder.getCore().getPopData(), rand); } - } - - public void buildRoofs(BlockFace roofFacing, Random rand) { + } + + public void buildRoofs(BlockFace roofFacing, Random rand) { for (JigsawStructurePiece piece : this.pieces.values()) { - // Build roof. - if(((MansionStandardTowerPiece) piece).isHighestPieceInTower()) - ((MansionStandardTowerPiece) piece).placeTentRoof(data, roofFacing, rand); + // Build roof. + if (((MansionStandardTowerPiece) piece).isHighestPieceInTower()) { + ((MansionStandardTowerPiece) piece).placeTentRoof(data, roofFacing, rand); + } } - } - - public void buildOverlapperPieces(Random rand) { + } + + public void buildOverlapperPieces(Random rand) { for (JigsawStructurePiece piece : this.overlapperPieces) { // Build room piece.build(builder.getCore().getPopData(), rand); } - } + } - } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerWallPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerWallPiece.java index 12686366..39bd6c56 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerWallPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/tower/MansionTowerWallPiece.java @@ -14,28 +14,34 @@ public class MansionTowerWallPiece extends JigsawStructurePiece { - public boolean isTentRoofFace = false; - - public MansionTowerWallPiece(MansionJigsawBuilder builder, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public boolean isTentRoofFace = false; + + public MansionTowerWallPiece(MansionJigsawBuilder builder, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); } - + @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); - + for (int i = 0; i < entry.getValue(); i++) { - - // Primary Wall and wooden stair decorations - // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + // Primary Wall and wooden stair decorations + // w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(this.getRoom().getHeight(), rand, Material.DARK_OAK_PLANKS); - + w = w.getLeft(); } } - + } diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostCampfire.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostCampfire.java index 59731627..fd9b4242 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostCampfire.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostCampfire.java @@ -18,40 +18,46 @@ public OutpostCampfire(Random rand, boolean forceSpawn, boolean unique) { } public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - SimpleBlock core = new SimpleBlock(data,room.getX(),room.getY(),room.getZ()).getGroundOrSeaLevel(); - - BlockUtils.replaceCircularPatch( - rand.nextInt(12322), 3f, core, - Material.COAL_ORE, - Material.STONE, - Material.COARSE_DIRT, Material.COARSE_DIRT, Material.COARSE_DIRT, Material.COARSE_DIRT); - - core = core.getUp(); - unitCampfire(core); - for(BlockFace face:BlockUtils.xzDiagonalPlaneBlockFaces) { - unitCampfire(core.getRelative(face).getGround().getUp()); - } + SimpleBlock core = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGroundOrSeaLevel(); + + BlockUtils.replaceCircularPatch(rand.nextInt(12322), + 3f, + core, + Material.COAL_ORE, + Material.STONE, + Material.COARSE_DIRT, + Material.COARSE_DIRT, + Material.COARSE_DIRT, + Material.COARSE_DIRT + ); + + core = core.getUp(); + unitCampfire(core); + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + unitCampfire(core.getRelative(face).getGround().getUp()); + } } - + private void unitCampfire(@NotNull SimpleBlock block) { - switch(rand.nextInt(3)) { - case 0: - block.setType(Material.CAMPFIRE); - break; - case 1: - block.setType(Material.CAMPFIRE); - block.getDown().setType(Material.HAY_BLOCK); - break; - case 2: - block.setType(Material.HAY_BLOCK); - block.getUp().setType(Material.CAMPFIRE); - for(BlockFace face:BlockUtils.directBlockFaces) { - SimpleBlock target = block.getRelative(face).getGround().getUp(); - if(!target.isSolid()) - target.setType(Material.CAMPFIRE); - } - break; - } + switch (rand.nextInt(3)) { + case 0: + block.setType(Material.CAMPFIRE); + break; + case 1: + block.setType(Material.CAMPFIRE); + block.getDown().setType(Material.HAY_BLOCK); + break; + case 2: + block.setType(Material.HAY_BLOCK); + block.getUp().setType(Material.CAMPFIRE); + for (BlockFace face : BlockUtils.directBlockFaces) { + SimpleBlock target = block.getRelative(face).getGround().getUp(); + if (!target.isSolid()) { + target.setType(Material.CAMPFIRE); + } + } + break; + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostLogpile.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostLogpile.java index c474ac1c..a621a542 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostLogpile.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostLogpile.java @@ -20,67 +20,95 @@ public class OutpostLogpile extends RoomPopulatorAbstract { - private final BiomeBank biome; + private final BiomeBank biome; + public OutpostLogpile(Random rand, boolean forceSpawn, boolean unique, BiomeBank biome) { super(rand, forceSpawn, unique); this.biome = biome; } public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); - Material planksMat = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); - int stackHeight = GenUtils.randInt(rand, 2, 4); - BlockFace facing = BlockUtils.getDirectBlockFace(rand); - OrientableBuilder ob = new OrientableBuilder(WoodUtils.getWoodForBiome(biome, WoodType.LOG)) - .setAxis(BlockUtils.getAxisFromBlockFace(facing)); - Wall core = new Wall(new SimpleBlock(data,room.getX(),room.getY(),room.getZ()).getGroundOrSeaLevel(), facing); - - for(int i = 0; i <= stackHeight; i++) { - for(int width = 0; width < stackHeight - i; width++) { - int logLength = GenUtils.randInt(rand, 2, 3); - for(int len = 0; len <= logLength; len++) { - ob.apply(core.getRelative(0,i+1,0).getLeft(width).getFront(len)); - ob.apply(core.getRelative(0,i+1,0).getLeft(width).getRear(len)); - - ob.apply(core.getRelative(0,i+1,0).getRight(width).getFront(len)); - ob.apply(core.getRelative(0,i+1,0).getRight(width).getRear(len)); - - // Place rails - if(len == 1) { - core.getRelative(0,i+2,0).getLeft(width).getFront(len).setType(Material.RAIL); - core.getRelative(0,i+2,0).getRight(width).getFront(len).setType(Material.RAIL); - core.getRelative(0,i+2,0).getLeft(width).getRear(len).setType(Material.RAIL); - core.getRelative(0,i+2,0).getRight(width).getRear(len).setType(Material.RAIL); - BlockUtils.correctSurroundingRails(core.getRelative(0,i+2,0).getLeft(width).getFront(len).get()); - BlockUtils.correctSurroundingRails(core.getRelative(0,i+2,0).getRight(width).getFront(len).get()); - BlockUtils.correctSurroundingRails(core.getRelative(0,i+2,0).getLeft(width).getRear(len).get()); - BlockUtils.correctSurroundingRails(core.getRelative(0,i+2,0).getRight(width).getRear(len).get()); - if(i == 0) { - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(BlockUtils.getRight(core.getDirection())) - .apply(core.getRelative(0,i+1,0).getLeft(width+1).getFront(len)) - .apply(core.getRelative(0,i+1,0).getLeft(width+1).getRear(len)) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(core.getRelative(0,i+1,0).getRight(width+1).getFront(len)) - .apply(core.getRelative(0,i+1,0).getRight(width+1).getRear(len)); - } - - } - } - } - } - - // Replace the top rails with stone slabs, because they're buggy. - // Fuck rails - core.getRelative(0,stackHeight+1,0).getRelative(facing).setType(Material.COBBLESTONE_SLAB); - core.getRelative(0,stackHeight+1,0).getRelative(facing.getOppositeFace()).setType(Material.COBBLESTONE_SLAB); - - for(int nx = -4; nx <= 4; nx++) - for(int nz = -4; nz <= 4; nz++) { - core.getRelative(nx,0,nz).get().lsetType(planksMat); - core.getRelative(nx,-1,nz).downUntilSolid(new Random(), fenceMat); - } - + Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); + Material planksMat = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); + int stackHeight = GenUtils.randInt(rand, 2, 4); + BlockFace facing = BlockUtils.getDirectBlockFace(rand); + OrientableBuilder ob = new OrientableBuilder(WoodUtils.getWoodForBiome( + biome, + WoodType.LOG + )).setAxis(BlockUtils.getAxisFromBlockFace(facing)); + Wall core = new Wall( + new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGroundOrSeaLevel(), + facing + ); + + for (int i = 0; i <= stackHeight; i++) { + for (int width = 0; width < stackHeight - i; width++) { + int logLength = GenUtils.randInt(rand, 2, 3); + for (int len = 0; len <= logLength; len++) { + ob.apply(core.getRelative(0, i + 1, 0).getLeft(width).getFront(len)); + ob.apply(core.getRelative(0, i + 1, 0).getLeft(width).getRear(len)); + + ob.apply(core.getRelative(0, i + 1, 0).getRight(width).getFront(len)); + ob.apply(core.getRelative(0, i + 1, 0).getRight(width).getRear(len)); + + // Place rails + if (len == 1) { + core.getRelative(0, i + 2, 0).getLeft(width).getFront(len).setType(Material.RAIL); + core.getRelative(0, i + 2, 0).getRight(width).getFront(len).setType(Material.RAIL); + core.getRelative(0, i + 2, 0).getLeft(width).getRear(len).setType(Material.RAIL); + core.getRelative(0, i + 2, 0).getRight(width).getRear(len).setType(Material.RAIL); + BlockUtils.correctSurroundingRails(core.getRelative(0, i + 2, 0) + .getLeft(width) + .getFront(len) + .get()); + BlockUtils.correctSurroundingRails(core.getRelative(0, i + 2, 0) + .getRight(width) + .getFront(len) + .get()); + BlockUtils.correctSurroundingRails(core.getRelative(0, i + 2, 0) + .getLeft(width) + .getRear(len) + .get()); + BlockUtils.correctSurroundingRails(core.getRelative(0, i + 2, 0) + .getRight(width) + .getRear(len) + .get()); + if (i == 0) { + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(BlockUtils.getRight(core.getDirection())) + .apply(core.getRelative(0, i + 1, 0) + .getLeft(width + 1) + .getFront(len)) + .apply(core.getRelative(0, i + 1, 0) + .getLeft(width + 1) + .getRear(len)) + .setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(core.getRelative(0, i + 1, 0) + .getRight(width + 1) + .getFront(len)) + .apply(core.getRelative(0, i + 1, 0) + .getRight(width + 1) + .getRear(len)); + } + + } + } + } + } + + // Replace the top rails with stone slabs, because they're buggy. + // Fuck rails + core.getRelative(0, stackHeight + 1, 0).getRelative(facing).setType(Material.COBBLESTONE_SLAB); + core.getRelative(0, stackHeight + 1, 0) + .getRelative(facing.getOppositeFace()) + .setType(Material.COBBLESTONE_SLAB); + + for (int nx = -4; nx <= 4; nx++) { + for (int nz = -4; nz <= 4; nz++) { + core.getRelative(nx, 0, nz).get().lsetType(planksMat); + core.getRelative(nx, -1, nz).downUntilSolid(new Random(), fenceMat); + } + } + } diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java index 447272f6..25bff9c8 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java @@ -34,10 +34,42 @@ import java.util.Random; public class OutpostPopulator extends SingleMegaChunkStructurePopulator { - private Material[] stakeGravel; + private Material[] stakeGravel; + + private static void setupPillagerSpawns(@NotNull PopulatorDataAbstract data, int x, int y, int z) { + int i = -5; + ArrayList done = new ArrayList<>(); + for (int nx = x - 80 / 2 - i; nx <= x + 80 / 2 + i; nx++) { + for (int nz = z - 80 / 2 - i; nz <= z + 80 / 2 + i; nz++) { + int chunkX = nx >> 4; + int chunkZ = nz >> 4; + int hash = Objects.hash(chunkX, chunkZ); + + if (done.contains(hash)) { + continue; + } + + done.add(hash); + + TerraformGeneratorPlugin.injector.getICAData(((PopulatorDataPostGen) data).getWorld() + .getChunkAt(chunkX, chunkZ)) + .registerNaturalSpawns(NaturalSpawnType.PILLAGER, + x - 80 / 2, + y, + z - 80 / 2, + x + 80 / 2, + 255, + z + 80 / 2 + ); + } + } + } + @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); @@ -47,36 +79,60 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract spawnOutpost(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, height + 1, z); } - public void spawnOutpost(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnOutpost(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { try { - TerraformGeneratorPlugin.logger.info("Spawning outpost at " + x + "," + y + "," + z); - - BiomeBank biome = tw.getBiomeBank(x, z); - - stakeGravel = new Material[] {Material.COBBLESTONE,Material.STONE,Material.ANDESITE,Material.GRAVEL}; - - if(biome == BiomeBank.BADLANDS) - stakeGravel = new Material[] { Material.TERRACOTTA, Material.RED_TERRACOTTA, Material.BROWN_TERRACOTTA, Material.YELLOW_TERRACOTTA, Material.ORANGE_TERRACOTTA }; - - - spawnStakes(random, new SimpleBlock(data,x,y,z),biome); - - TerraSchematic outpostBase = TerraSchematic.load("outpost/outpostbase1", new SimpleBlock(data,x,y,z)); - outpostBase.parser = new OutpostSchematicParser(biome, random, data, y-1); + TerraformGeneratorPlugin.logger.info("Spawning outpost at " + x + "," + y + "," + z); + + BiomeBank biome = tw.getBiomeBank(x, z); + + stakeGravel = new Material[] {Material.COBBLESTONE, Material.STONE, Material.ANDESITE, Material.GRAVEL}; + + if (biome == BiomeBank.BADLANDS) { + stakeGravel = new Material[] { + Material.TERRACOTTA, + Material.RED_TERRACOTTA, + Material.BROWN_TERRACOTTA, + Material.YELLOW_TERRACOTTA, + Material.ORANGE_TERRACOTTA + }; + } + + + spawnStakes(random, new SimpleBlock(data, x, y, z), biome); + + TerraSchematic outpostBase = TerraSchematic.load("outpost/outpostbase1", new SimpleBlock(data, x, y, z)); + outpostBase.parser = new OutpostSchematicParser(biome, random, data, y - 1); outpostBase.setFace(BlockUtils.getDirectBlockFace(random)); outpostBase.apply(); - TerraSchematic outpostCore = TerraSchematic.load("outpost/outpostcore1", new SimpleBlock(data,x,y+5,z)); - outpostCore.parser = new OutpostSchematicParser(biome, random, data, y-1); + TerraSchematic outpostCore = TerraSchematic.load( + "outpost/outpostcore1", + new SimpleBlock(data, x, y + 5, z) + ); + outpostCore.parser = new OutpostSchematicParser(biome, random, data, y - 1); outpostCore.setFace(BlockUtils.getDirectBlockFace(random)); outpostCore.apply(); - TerraSchematic outpostTop = TerraSchematic.load("outpost/outposttop1", new SimpleBlock(data,x,y+11,z)); - outpostTop.parser = new OutpostSchematicParser(biome, random, data, y-1); + TerraSchematic outpostTop = TerraSchematic.load("outpost/outposttop1", new SimpleBlock(data, x, y + 11, z)); + outpostTop.parser = new OutpostSchematicParser(biome, random, data, y - 1); outpostTop.setFace(BlockUtils.getDirectBlockFace(random)); outpostTop.apply(); - - spawnStairway(random, biome, new SimpleBlock(data,x,y,z), 11); - - RoomLayoutGenerator propGenerator = new RoomLayoutGenerator(random, RoomLayout.RANDOM_BRUTEFORCE, 100, x, y, z, 35); + + spawnStairway(random, biome, new SimpleBlock(data, x, y, z), 11); + + RoomLayoutGenerator propGenerator = new RoomLayoutGenerator( + random, + RoomLayout.RANDOM_BRUTEFORCE, + 100, + x, + y, + z, + 35 + ); propGenerator.setRoomMinX(12); propGenerator.setRoomMinZ(12); propGenerator.setRoomMaxX(12); @@ -85,164 +141,155 @@ public void spawnOutpost(@NotNull TerraformWorld tw, @NotNull Random random, @No // get overlapped. CubeRoom placeholder = new CubeRoom(20, 20, 15, x, y, z); propGenerator.getRooms().add(placeholder); - + propGenerator.registerRoomPopulator(new OutpostTent(random, false, false, biome)); propGenerator.registerRoomPopulator(new OutpostCampfire(random, false, true)); propGenerator.registerRoomPopulator(new OutpostLogpile(random, false, true, biome)); propGenerator.registerRoomPopulator(new OutpostStakeCage(random, false, true, biome, stakeGravel)); - + // No paths propGenerator.setGenPaths(false); propGenerator.calculateRoomPlacement(); - + // Remove the placeholder room propGenerator.getRooms().remove(placeholder); - + // Only run room populators. We don't want any room space carving. - propGenerator.runRoomPopulators(data,tw); + propGenerator.runRoomPopulators(data, tw); setupPillagerSpawns(data, x, y, z); - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place outpost at " + x + "," + y + "," + z + "!"); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place outpost at " + + x + + "," + + y + + "," + + z + + "!"); TerraformGeneratorPlugin.logger.stackTrace(e); } } - + /** * Spawns the surrounding stakes. Additionally, will raise ground levels up * with wood planks to make structures less floaty. */ public void spawnStakes(@NotNull Random rand, @NotNull SimpleBlock center, @NotNull BiomeBank bank) { - int radius = 40; - Material planksMat = WoodUtils.getWoodForBiome(bank, WoodType.PLANKS); - - FastNoise noise = new FastNoise(rand.nextInt(5000)); + int radius = 40; + Material planksMat = WoodUtils.getWoodForBiome(bank, WoodType.PLANKS); + + FastNoise noise = new FastNoise(rand.nextInt(5000)); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); - + for (float x = -radius; x <= radius; x++) { for (float z = -radius; z <= radius; z++) { SimpleBlock rel = center.getRelative(Math.round(x), 0, Math.round(z)).getGroundOrSeaLevel(); - + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double mainRadiusResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); - double secondaryRadiusResult = mainRadiusResult*1.3; + double mainRadiusResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); + double secondaryRadiusResult = mainRadiusResult * 1.3; double noiseVal = noise.GetNoise(rel.getX(), rel.getZ()); if (mainRadiusResult <= 1 + 0.7 * noiseVal) { - - // Raise water ground - rel.lsetType(planksMat); - if(secondaryRadiusResult > 1 + 0.7 * noiseVal) { - // Rocky ground - BlockUtils.replaceCircularPatch(rand.nextInt(4211), 1.5f, rel, stakeGravel); - - spawnOneStake(rand,rel.getUp(),bank,stakeGravel); - } - + + // Raise water ground + rel.lsetType(planksMat); + if (secondaryRadiusResult > 1 + 0.7 * noiseVal) { + // Rocky ground + BlockUtils.replaceCircularPatch(rand.nextInt(4211), 1.5f, rel, stakeGravel); + + spawnOneStake(rand, rel.getUp(), bank, stakeGravel); + } + } } } } - - public void spawnOneStake(@NotNull Random rand, @NotNull SimpleBlock base, @NotNull BiomeBank bank, Material... stakeGravel) { - WoodType type = new WoodType[] {WoodType.LOG, WoodType.STRIPPED_LOG}[rand.nextInt(2)]; - Wall w = new Wall(base); - // Don't spawn stake next to another one - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - if(Tag.LOGS.isTagged(base.getRelative(face).getType())) - return; - } - int h = GenUtils.randInt(3, 5); - - for(BlockFace face:BlockUtils.directBlockFaces) { - if(rand.nextBoolean()) - w.getRelative(face).downUntilSolid(rand, stakeGravel); - } + + public void spawnOneStake(@NotNull Random rand, + @NotNull SimpleBlock base, + @NotNull BiomeBank bank, + Material... stakeGravel) + { + WoodType type = new WoodType[] {WoodType.LOG, WoodType.STRIPPED_LOG}[rand.nextInt(2)]; + Wall w = new Wall(base); + // Don't spawn stake next to another one + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + if (Tag.LOGS.isTagged(base.getRelative(face).getType())) { + return; + } + } + int h = GenUtils.randInt(3, 5); + + for (BlockFace face : BlockUtils.directBlockFaces) { + if (rand.nextBoolean()) { + w.getRelative(face).downUntilSolid(rand, stakeGravel); + } + } w.Pillar(h, rand, WoodUtils.getWoodForBiome(bank, type)); - w.getRelative(0,h,0).Pillar(GenUtils.randInt(1,2), rand, WoodUtils.getWoodForBiome(bank, WoodType.FENCE)); + w.getRelative(0, h, 0).Pillar(GenUtils.randInt(1, 2), rand, WoodUtils.getWoodForBiome(bank, WoodType.FENCE)); w.getDown().downUntilSolid(rand, stakeGravel); w.getDown(2).downUntilSolid(rand, stakeGravel); } - + public void spawnStairway(Random rand, @NotNull BiomeBank biome, @NotNull SimpleBlock core, int height) { - Material pillarMat = GenUtils.randChoice( - WoodUtils.getWoodForBiome(biome, WoodType.LOG), - Material.COBBLESTONE); - Material stair = WoodUtils.getWoodForBiome(biome, WoodType.STAIRS); - Material slab = WoodUtils.getWoodForBiome(biome, WoodType.SLAB); - - BlockFace face = BlockFace.NORTH; - - for(int i = 0; i < height; i++){ - core.setType(pillarMat); - - for(BlockFace adj:BlockUtils.xzPlaneBlockFaces) { - core.getRelative(adj).setType(Material.AIR); - } - - new StairBuilder(stair) - .setFacing(BlockUtils.getLeft(face)) - .apply(core.getRelative(face)); - - new SlabBuilder(slab) - .setType(Type.TOP) - .apply(core.getRelative(BlockUtils.rotateXZPlaneBlockFace(face, 1))); - - core = core.getUp(); - face = BlockUtils.rotateFace(face, 1); - } - } - - private static void setupPillagerSpawns(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - int i = -5; - ArrayList done = new ArrayList<>(); - for (int nx = x - 80 / 2 - i; nx <= x + 80 / 2 + i; nx++) { - for (int nz = z - 80 / 2 - i; nz <= z + 80 / 2 + i; nz++) { - int chunkX = nx >> 4; - int chunkZ = nz >> 4; - int hash = Objects.hash(chunkX, chunkZ); + Material pillarMat = GenUtils.randChoice(WoodUtils.getWoodForBiome(biome, WoodType.LOG), Material.COBBLESTONE); + Material stair = WoodUtils.getWoodForBiome(biome, WoodType.STAIRS); + Material slab = WoodUtils.getWoodForBiome(biome, WoodType.SLAB); - if (done.contains(hash)) - continue; + BlockFace face = BlockFace.NORTH; - done.add(hash); + for (int i = 0; i < height; i++) { + core.setType(pillarMat); - TerraformGeneratorPlugin.injector.getICAData(((PopulatorDataPostGen) data).getWorld().getChunkAt(chunkX, chunkZ)) - .registerNaturalSpawns(NaturalSpawnType.PILLAGER, x - 80 / 2, y, z - 80 / 2, - x + 80 / 2, 255, z + 80 / 2); + for (BlockFace adj : BlockUtils.xzPlaneBlockFaces) { + core.getRelative(adj).setType(Material.AIR); } + + new StairBuilder(stair).setFacing(BlockUtils.getLeft(face)).apply(core.getRelative(face)); + + new SlabBuilder(slab).setType(Type.TOP).apply(core.getRelative(BlockUtils.rotateXZPlaneBlockFace(face, 1))); + + core = core.getUp(); + face = BlockUtils.rotateFace(face, 1); } } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } - if (!biome.isDry()) + if (!biome.isDry()) { return false; - if(biome == BiomeBank.DESERT || - biome == BiomeBank.SNOWY_WASTELAND || - biome == BiomeBank.BADLANDS || - biome == BiomeBank.BAMBOO_FOREST) - return rollSpawnRatio(tw, chunkX, chunkZ); - else - return false; + } + if (biome == BiomeBank.DESERT + || biome == BiomeBank.SNOWY_WASTELAND + || biome == BiomeBank.BADLANDS + || biome == BiomeBank.BAMBOO_FOREST) + { + return rollSpawnRatio(tw, chunkX, chunkZ); + } + else { + return false; + } } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 92992), - (int) (TConfigOption.STRUCTURES_OUTPOST_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_OUTPOST_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } - @Override - public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_OUTPOST_ENABLED.getBoolean(); - } + @Override + public boolean isEnabled() { + return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_OUTPOST_ENABLED.getBoolean(); + } - @Override - public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { - return world.getHashedRand(81903212, chunkX, chunkZ); - } + @Override + public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { + return world.getHashedRand(81903212, chunkX, chunkZ); + } } diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostSchematicParser.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostSchematicParser.java index 4a195c07..ff56bd48 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostSchematicParser.java @@ -28,73 +28,90 @@ public class OutpostSchematicParser extends SchematicParser { private final int baseY; private Material[] toReplace; - public OutpostSchematicParser(BiomeBank biome, Random rand, - PopulatorDataAbstract pop, int baseY) { + public OutpostSchematicParser(BiomeBank biome, Random rand, PopulatorDataAbstract pop, int baseY) { this.biome = biome; this.rand = rand; this.pop = pop; this.baseY = baseY; - toReplace = new Material[] {Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE}; - if(biome == BiomeBank.BADLANDS || biome == BiomeBank.DESERT) - toReplace = new Material[] {Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.ANDESITE}; - + toReplace = new Material[] { + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + }; + if (biome == BiomeBank.BADLANDS || biome == BiomeBank.DESERT) { + toReplace = new Material[] { + Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.ANDESITE + }; + } + } @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - // No moss on desert areas. + // No moss on desert areas. if (data.getMaterial().toString().contains("COBBLESTONE")) { - - // Desert variants replace cobblestone with andesite instead of mossy cobble. - - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, toReplace) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); - + + // Desert variants replace cobblestone with andesite instead of mossy cobble. + + data = Bukkit.createBlockData(data.getAsString() + .replaceAll("cobblestone", + GenUtils.randChoice(rand, toReplace) + .toString() + .toLowerCase(Locale.ENGLISH) + )); + super.applyData(block, data); - } else if (data.getMaterial().toString().contains("OAK")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - data.getMaterial().toString().toLowerCase(Locale.ENGLISH), - WoodUtils.getWoodForBiome(biome, - WoodType.parse(data.getMaterial())).toString().toLowerCase(Locale.ENGLISH) - ).toString().toLowerCase(Locale.ENGLISH)); + } + else if (data.getMaterial().toString().contains("OAK")) { + data = Bukkit.createBlockData(data.getAsString() + .replaceAll(data.getMaterial().toString().toLowerCase(Locale.ENGLISH), + WoodUtils.getWoodForBiome(biome, + WoodType.parse(data.getMaterial()) + ).toString().toLowerCase(Locale.ENGLISH) + ) + .toString() + .toLowerCase(Locale.ENGLISH)); super.applyData(block, data); - } else if (data.getMaterial() == Material.CHEST) { + } + else if (data.getMaterial() == Material.CHEST) { if (GenUtils.chance(rand, 1, 5)) { block.setType(Material.AIR); // A fifth of chests are not placed. - } else { - super.applyData(block, data); + } + else { + super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.PILLAGER_OUTPOST); } - } else if (data.getMaterial() == Material.BARREL) { + } + else if (data.getMaterial() == Material.BARREL) { if (GenUtils.chance(rand, 3, 5)) { block.setType(Material.HAY_BLOCK); // 3 fifths of barrels are not placed. - } else { - super.applyData(block, data); + } + else { + super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.PILLAGER_OUTPOST); } - } else if (data.getMaterial() == Material.WHITE_WALL_BANNER||data.getMaterial() == Material.WHITE_BANNER) { - // Set it first to make the target block a banner - super.applyData(block, data); - if(block.getPopData() instanceof PopulatorDataPostGen) { - // org.bukkit.block.Banner; - Banner banner = (Banner) ((PopulatorDataPostGen) block.getPopData()).getBlockState(block.getX(),block.getY(),block.getZ()); - banner.setPatterns(BannerUtils.getOminousBannerPatterns()); + } + else if (data.getMaterial() == Material.WHITE_WALL_BANNER || data.getMaterial() == Material.WHITE_BANNER) { + // Set it first to make the target block a banner + super.applyData(block, data); + if (block.getPopData() instanceof PopulatorDataPostGen) { + // org.bukkit.block.Banner; + Banner banner = (Banner) ((PopulatorDataPostGen) block.getPopData()).getBlockState(block.getX(), + block.getY(), + block.getZ()); + banner.setPatterns(BannerUtils.getOminousBannerPatterns()); banner.update(); - } - } else { + } + } + else { super.applyData(block, data); } - - if(block.getY() == baseY) { - new Wall(block.getDown()).downUntilSolid(new Random(), toReplace); + + if (block.getY() == baseY) { + new Wall(block.getDown()).downUntilSolid(new Random(), toReplace); } } diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostStakeCage.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostStakeCage.java index 478fb87d..a4840618 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostStakeCage.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostStakeCage.java @@ -22,8 +22,9 @@ public class OutpostStakeCage extends RoomPopulatorAbstract { - private final BiomeBank biome; - private final Material[] stakeGravel; + private final BiomeBank biome; + private final Material[] stakeGravel; + public OutpostStakeCage(Random rand, boolean forceSpawn, boolean unique, BiomeBank biome, Material... stakeGravel) { super(rand, forceSpawn, unique); this.biome = biome; @@ -31,99 +32,108 @@ public OutpostStakeCage(Random rand, boolean forceSpawn, boolean unique, BiomeBa } public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); - Material plankMat = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); - - int[] lowerCorner = room.getLowerCorner(2); - int[] upperCorner = room.getUpperCorner(2); - int highestHeight = 0; - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - SimpleBlock target = new SimpleBlock(data,nx,0,nz); - int y = target.getGroundOrSeaLevel().getY(); - if(y > highestHeight) { - highestHeight = y; - } - target.lsetType(plankMat); - new Wall(target).downUntilSolid(rand, fenceMat); - } - - for(Entry entry:room.getFourWalls(data, 2).entrySet()) { - Wall w = entry.getKey().getGroundOrSeaLevel().getUp(); - for(int i = 0; i < entry.getValue(); i++) { - int baseHeight = 4 + highestHeight - w.getY(); - if(i % 2 == 0) - spawnOneStake(rand, baseHeight, w.get()); - else { - int fenceHeight = baseHeight + 2 + rand.nextInt(3); - w.RPillar(fenceHeight, rand, fenceMat); - w.CorrectMultipleFacing(fenceHeight); - } - w = w.getLeft().getGroundOrSeaLevel().getUp(); - } - - } - - if(Version.isAtLeast(19)) { - // Spawn the mob. - switch(rand.nextInt(3)) { - case 0: - // Iron Golem - data.addEntity( - room.getX(), - new SimpleBlock(data, room.getX(),room.getY(),room.getZ()) - .getGroundOrDry().getY()+1, - room.getZ(), - EntityType.IRON_GOLEM); - break; - case 1: - // Allay (1 to 3) - for(int i = 0; i < 1 + rand.nextInt(3); i++) - data.addEntity( - room.getX(), - new SimpleBlock(data, room.getX(),room.getY(),room.getZ()) - .getGroundOrDry().getY()+1, - room.getZ(), - OneOneNineBlockHandler.ALLAY); - - // If spawning allays, a roof must be added to the cage. - for(int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) - for(int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { - int baseHeight = 6 + highestHeight; - SimpleBlock target = new SimpleBlock(data,nx,baseHeight,nz); - - target.setType(plankMat); - } - break; - case 2: - // Nothing - break; - } - } - else - { - if(rand.nextBoolean()) - data.addEntity( - room.getX(), - new SimpleBlock(data, room.getX(),room.getY(),room.getZ()) - .getGroundOrDry().getY()+1, - room.getZ(), - EntityType.IRON_GOLEM); - } - + Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); + Material plankMat = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); + + int[] lowerCorner = room.getLowerCorner(2); + int[] upperCorner = room.getUpperCorner(2); + int highestHeight = 0; + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + SimpleBlock target = new SimpleBlock(data, nx, 0, nz); + int y = target.getGroundOrSeaLevel().getY(); + if (y > highestHeight) { + highestHeight = y; + } + target.lsetType(plankMat); + new Wall(target).downUntilSolid(rand, fenceMat); + } + } + + for (Entry entry : room.getFourWalls(data, 2).entrySet()) { + Wall w = entry.getKey().getGroundOrSeaLevel().getUp(); + for (int i = 0; i < entry.getValue(); i++) { + int baseHeight = 4 + highestHeight - w.getY(); + if (i % 2 == 0) { + spawnOneStake(rand, baseHeight, w.get()); + } + else { + int fenceHeight = baseHeight + 2 + rand.nextInt(3); + w.RPillar(fenceHeight, rand, fenceMat); + w.CorrectMultipleFacing(fenceHeight); + } + w = w.getLeft().getGroundOrSeaLevel().getUp(); + } + + } + + if (Version.isAtLeast(19)) { + // Spawn the mob. + switch (rand.nextInt(3)) { + case 0: + // Iron Golem + data.addEntity(room.getX(), + new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGroundOrDry().getY() + 1, + room.getZ(), + EntityType.IRON_GOLEM + ); + break; + case 1: + // Allay (1 to 3) + for (int i = 0; i < 1 + rand.nextInt(3); i++) { + data.addEntity( + room.getX(), + new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGroundOrDry().getY() + + 1, + room.getZ(), + OneOneNineBlockHandler.ALLAY + ); + } + + // If spawning allays, a roof must be added to the cage. + for (int nx = lowerCorner[0]; nx <= upperCorner[0]; nx++) { + for (int nz = lowerCorner[1]; nz <= upperCorner[1]; nz++) { + int baseHeight = 6 + highestHeight; + SimpleBlock target = new SimpleBlock(data, nx, baseHeight, nz); + + target.setType(plankMat); + } + } + break; + case 2: + // Nothing + break; + } + } + else { + if (rand.nextBoolean()) { + data.addEntity( + room.getX(), + new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGroundOrDry().getY() + 1, + room.getZ(), + EntityType.IRON_GOLEM + ); + } + } + } public void spawnOneStake(@NotNull Random rand, int baseHeight, @NotNull SimpleBlock base) { - WoodType type = new WoodType[] {WoodType.LOG, WoodType.STRIPPED_LOG}[rand.nextInt(2)]; + WoodType type = new WoodType[] {WoodType.LOG, WoodType.STRIPPED_LOG}[rand.nextInt(2)]; - int h = baseHeight + GenUtils.randInt(1, 3); + int h = baseHeight + GenUtils.randInt(1, 3); - for(BlockFace face:BlockUtils.directBlockFaces) { - if(rand.nextBoolean()) - base.getRelative(face).setType(stakeGravel); - } + for (BlockFace face : BlockUtils.directBlockFaces) { + if (rand.nextBoolean()) { + base.getRelative(face).setType(stakeGravel); + } + } new Wall(base).Pillar(h, rand, WoodUtils.getWoodForBiome(biome, type)); - new Wall(base.getRelative(0,h,0)).Pillar(GenUtils.randInt(2,3), rand, WoodUtils.getWoodForBiome(biome, WoodType.FENCE)); + new Wall(base.getRelative(0, h, 0)).Pillar( + GenUtils.randInt(2, 3), + rand, + WoodUtils.getWoodForBiome(biome, WoodType.FENCE) + ); } @Override diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostTent.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostTent.java index da7ef568..f07d693c 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostTent.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostTent.java @@ -25,159 +25,168 @@ public class OutpostTent extends RoomPopulatorAbstract { - final Material @NotNull [] edgyWools = new Material[] { - Material.BLACK_WOOL, - Material.GRAY_WOOL, - Material.BROWN_WOOL, - Material.LIGHT_GRAY_WOOL, - Material.WHITE_WOOL - }; - - final BiomeBank biome; + final Material @NotNull [] edgyWools = new Material[] { + Material.BLACK_WOOL, Material.GRAY_WOOL, Material.BROWN_WOOL, Material.LIGHT_GRAY_WOOL, Material.WHITE_WOOL + }; + + final BiomeBank biome; + public OutpostTent(Random rand, boolean forceSpawn, boolean unique, BiomeBank biome) { super(rand, forceSpawn, unique); this.biome = biome; } private void placeProp(int size, @NotNull SimpleBlock core, @NotNull BlockFace facing, @NotNull Material cloth) { - Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); - new Wall(core).Pillar(size, rand, fenceMat); - - for(BlockFace face:BlockUtils.getAdjacentFaces(facing)) { - SimpleBlock corner = core.getRelative(face,size-1); - corner.getRelative(facing.getOppositeFace()).setType(cloth); - corner.getRelative(facing.getOppositeFace()).getUp().setType(fenceMat); - // Place corner. Cache the builder to prevent recalculation from woodutils - StairBuilder builder = new StairBuilder(WoodUtils.getWoodForBiome(biome, WoodType.STAIRS)); - - builder.setFacing(face.getOppositeFace()) - .apply(corner) - .setFacing(face) - .setHalf(Half.TOP) - .apply(corner.getRelative(face.getOppositeFace())); - corner = corner.getRelative(face.getOppositeFace()).getUp(); - - builder.setHalf(Half.BOTTOM).setFacing(face.getOppositeFace()); - - // Place slopes - for(int i = 0; i < size-2; i++) { - builder.apply(corner); - // Hollow out bottom so tent entrance is clear - for(int j = corner.getY()-1; j > core.getY()-1; j--) { - if(!Tag.BEDS.isTagged(corner.getAtY(j).getType()) - && !Tag.STAIRS.isTagged(corner.getAtY(j).getType())) - corner.getAtY(j).setType(Material.AIR); - } - - SimpleBlock target = corner.getRelative(facing.getOppositeFace()); - target.setType(cloth); - - // Hollow out bottom so tent entrance is clear - for(int j = target.getY()-1; j > core.getY()-1; j--) { - if(!Tag.BEDS.isTagged(target.getAtY(j).getType())) - target.getAtY(j).setType(Material.AIR); - } - - target.getUp().setType(fenceMat); - corner = corner.getUp().getRelative(face.getOppositeFace()); - } - } + Material fenceMat = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); + new Wall(core).Pillar(size, rand, fenceMat); + + for (BlockFace face : BlockUtils.getAdjacentFaces(facing)) { + SimpleBlock corner = core.getRelative(face, size - 1); + corner.getRelative(facing.getOppositeFace()).setType(cloth); + corner.getRelative(facing.getOppositeFace()).getUp().setType(fenceMat); + // Place corner. Cache the builder to prevent recalculation from woodutils + StairBuilder builder = new StairBuilder(WoodUtils.getWoodForBiome(biome, WoodType.STAIRS)); + + builder.setFacing(face.getOppositeFace()) + .apply(corner) + .setFacing(face) + .setHalf(Half.TOP) + .apply(corner.getRelative(face.getOppositeFace())); + corner = corner.getRelative(face.getOppositeFace()).getUp(); + + builder.setHalf(Half.BOTTOM).setFacing(face.getOppositeFace()); + + // Place slopes + for (int i = 0; i < size - 2; i++) { + builder.apply(corner); + // Hollow out bottom so tent entrance is clear + for (int j = corner.getY() - 1; j > core.getY() - 1; j--) { + if (!Tag.BEDS.isTagged(corner.getAtY(j).getType()) && !Tag.STAIRS.isTagged(corner.getAtY(j) + .getType())) + { + corner.getAtY(j).setType(Material.AIR); + } + } + + SimpleBlock target = corner.getRelative(facing.getOppositeFace()); + target.setType(cloth); + + // Hollow out bottom so tent entrance is clear + for (int j = target.getY() - 1; j > core.getY() - 1; j--) { + if (!Tag.BEDS.isTagged(target.getAtY(j).getType())) { + target.getAtY(j).setType(Material.AIR); + } + } + + target.getUp().setType(fenceMat); + corner = corner.getUp().getRelative(face.getOppositeFace()); + } + } } - + public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - Material planks = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); - Material fence = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); - Material cloth = GenUtils.randChoice(rand, edgyWools); - - int height = GenUtils.randInt(rand, 4, 6); - int length = GenUtils.randInt(rand, 5, 9); - - BlockFace facing = BlockUtils.getDirectBlockFace(rand); - SimpleBlock firstProp = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()) - .getRelative(facing,length/2).getGroundOrSeaLevel(); - - // Tent props - placeProp(height, firstProp.getUp(), facing, cloth); - placeProp(height, firstProp.getUp().getRelative(facing.getOppositeFace(),length), facing.getOppositeFace(), cloth); - - // Tent ground to account for water or potential uneven ground. - Wall wallProp = new Wall(firstProp, facing); - for(int relWidth = 0; relWidth < height; relWidth++){ - for(int relLen = 0; relLen <= length; relLen++) { - Wall target = wallProp.getLeft(relWidth).getRelative(facing.getOppositeFace(),relLen); - target.get().lsetType(planks); - target.getDown().downUntilSolid(getRand(), fence); - // target.getUp().get().lsetType(Material.WHITE_CARPET); - target = wallProp.getRight(relWidth).getRelative(facing.getOppositeFace(),relLen); - target.get().lsetType(planks); - target.getDown().downUntilSolid(getRand(), fence); - // target.getUp().get().lsetType(Material.WHITE_CARPET); - } - } - - // Connect the 2 props with one long log - OrientableBuilder ob = new OrientableBuilder(WoodUtils.getWoodForBiome(biome, WoodType.LOG)) - .setAxis(BlockUtils.getAxisFromBlockFace(facing)); - wallProp = wallProp.getRelative(0,height,0); - for(int relLen = 0; relLen <= length; relLen++) { - ob.apply(wallProp); - - if(relLen != 0 && relLen != length) - for(int i = wallProp.getY()-1; i > firstProp.getY(); i--) { - if(!Tag.BEDS.isTagged(wallProp.getAtY(i).getType())) + Material planks = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); + Material fence = WoodUtils.getWoodForBiome(biome, WoodType.FENCE); + Material cloth = GenUtils.randChoice(rand, edgyWools); + + int height = GenUtils.randInt(rand, 4, 6); + int length = GenUtils.randInt(rand, 5, 9); + + BlockFace facing = BlockUtils.getDirectBlockFace(rand); + SimpleBlock firstProp = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getRelative(facing, + length / 2).getGroundOrSeaLevel(); + + // Tent props + placeProp(height, firstProp.getUp(), facing, cloth); + placeProp( + height, + firstProp.getUp().getRelative(facing.getOppositeFace(), length), + facing.getOppositeFace(), + cloth + ); + + // Tent ground to account for water or potential uneven ground. + Wall wallProp = new Wall(firstProp, facing); + for (int relWidth = 0; relWidth < height; relWidth++) { + for (int relLen = 0; relLen <= length; relLen++) { + Wall target = wallProp.getLeft(relWidth).getRelative(facing.getOppositeFace(), relLen); + target.get().lsetType(planks); + target.getDown().downUntilSolid(getRand(), fence); + // target.getUp().get().lsetType(Material.WHITE_CARPET); + target = wallProp.getRight(relWidth).getRelative(facing.getOppositeFace(), relLen); + target.get().lsetType(planks); + target.getDown().downUntilSolid(getRand(), fence); + // target.getUp().get().lsetType(Material.WHITE_CARPET); + } + } + + // Connect the 2 props with one long log + OrientableBuilder ob = new OrientableBuilder(WoodUtils.getWoodForBiome( + biome, + WoodType.LOG + )).setAxis(BlockUtils.getAxisFromBlockFace(facing)); + wallProp = wallProp.getRelative(0, height, 0); + for (int relLen = 0; relLen <= length; relLen++) { + ob.apply(wallProp); + + if (relLen != 0 && relLen != length) { + for (int i = wallProp.getY() - 1; i > firstProp.getY(); i--) { + if (!Tag.BEDS.isTagged(wallProp.getAtY(i).getType())) { wallProp.getAtY(i).setType(Material.AIR); + } + } + } + wallProp = wallProp.getRelative(facing.getOppositeFace()); + } + + // Place wool walls + for (BlockFace face : BlockUtils.getAdjacentFaces(facing)) { + + for (int relLen = 2; relLen <= length - 2; relLen++) { + SimpleBlock corner = firstProp.getRelative(face, height - 1) + .getRelative(facing.getOppositeFace(), relLen) + .getUp(); // Off the ground + for (int relWidth = height - 2; relWidth >= 0; relWidth--) { + + for (int i = corner.getY(); i > firstProp.getY(); i--) { + if (GenUtils.isGroundLike(corner.getAtY(i).getType())) { + corner.getAtY(i).setType(Material.AIR); + } + } + + if (relWidth == height - 2) { + corner.setType(cloth); + // Empty out tent area + SimpleBlock target = corner.getRelative(face.getOppositeFace()); + if (!target.isSolid() && GenUtils.chance(rand, 1, 2)) { + switch (rand.nextInt(4)) { + case 0: + target.setType(Material.CRAFTING_TABLE); + break; + case 1: + target.setType(Material.FLETCHING_TABLE); + break; + case 2: + new ChestBuilder(Material.CHEST).setFacing(face.getOppositeFace()) + .setLootTable(TerraLootTable.PILLAGER_OUTPOST) + .apply(target); + break; + case 3: + BlockUtils.placeBed(target, BlockUtils.pickBed(), face.getOppositeFace()); + break; + } + } + + if (GenUtils.chance(rand, 1, 4)) { + target.getRelative(face.getOppositeFace()).addEntity(EntityType.PILLAGER); + } + + } + corner.getUp().setType(cloth); + corner = corner.getRelative(face.getOppositeFace()).getUp(); } - wallProp = wallProp.getRelative(facing.getOppositeFace()); - } - - // Place wool walls - for(BlockFace face:BlockUtils.getAdjacentFaces(facing)) { - - for(int relLen = 2; relLen <= length-2; relLen++) { - SimpleBlock corner = firstProp - .getRelative(face,height-1) - .getRelative(facing.getOppositeFace(),relLen) - .getUp(); // Off the ground - for(int relWidth = height-2; relWidth >= 0; relWidth--) { - - for(int i = corner.getY(); i > firstProp.getY(); i--) { - if(GenUtils.isGroundLike(corner.getAtY(i).getType())) - corner.getAtY(i).setType(Material.AIR); - } - - if(relWidth == height-2) { - corner.setType(cloth); - // Empty out tent area - SimpleBlock target = corner.getRelative(face.getOppositeFace()); - if(!target.isSolid() && GenUtils.chance(rand, 1,2)) { - switch(rand.nextInt(4)) { - case 0: - target.setType(Material.CRAFTING_TABLE); - break; - case 1: - target.setType(Material.FLETCHING_TABLE); - break; - case 2: - new ChestBuilder(Material.CHEST).setFacing(face.getOppositeFace()) - .setLootTable(TerraLootTable.PILLAGER_OUTPOST) - .apply(target); - break; - case 3: - BlockUtils.placeBed(target, BlockUtils.pickBed(), face.getOppositeFace()); - break; - } - } - - if(GenUtils.chance(rand, 1,4)) { - target.getRelative(face.getOppositeFace()).addEntity(EntityType.PILLAGER); - } - - } - corner.getUp().setType(cloth); - corner = corner.getRelative(face.getOppositeFace()).getUp(); - } - } - } + } + } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java b/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java index dd81c20f..29208ac9 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java @@ -36,72 +36,102 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int[] corner : corners) { Wall w = new Wall(new SimpleBlock(data, corner[0], room.getY() + room.getHeight() - 1, corner[1])); w.downLPillar(rand, 2, Material.CUT_SANDSTONE, Material.SMOOTH_SANDSTONE); - for (BlockFace face : BlockUtils.directBlockFaces) + for (BlockFace face : BlockUtils.directBlockFaces) { w.getRelative(face).setType(GenUtils.randChoice(Material.CUT_SANDSTONE, Material.SMOOTH_SANDSTONE)); + } } // Create randomised patterns int[] choices = {-2, -1, 0, 1, 2}; int[] steps = new int[15]; - for (int i = 0; i < 15; i++) steps[i] = choices[rand.nextInt(choices.length)]; + for (int i = 0; i < 15; i++) { + steps[i] = choices[rand.nextInt(choices.length)]; + } // For the floor SimpleBlock center = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()); for (BlockFace face : BlockUtils.directBlockFaces) { int length = room.getWidthX() / 2; - if (face == BlockFace.NORTH || face == BlockFace.SOUTH) + if (face == BlockFace.NORTH || face == BlockFace.SOUTH) { length = room.getWidthZ() / 2; + } for (int i = 0; i < length; i++) { - if (face == BlockFace.NORTH || face == BlockFace.SOUTH) - center.getRelative(face, i).getRelative(steps[i] * face.getModZ(), 0, 0) - .setType(Material.ORANGE_TERRACOTTA); - else - center.getRelative(face, i).getRelative(0, 0, steps[i] * face.getModX()) - .setType(Material.ORANGE_TERRACOTTA); + if (face == BlockFace.NORTH || face == BlockFace.SOUTH) { + center.getRelative(face, i) + .getRelative(steps[i] * face.getModZ(), 0, 0) + .setType(Material.ORANGE_TERRACOTTA); + } + else { + center.getRelative(face, i) + .getRelative(0, 0, steps[i] * face.getModX()) + .setType(Material.ORANGE_TERRACOTTA); + } } } center.setType(Material.BLUE_TERRACOTTA); // If at 1.20, spawn suspicious sand in the floor - if(Version.isAtLeast(20)) - for(int i = 0; i < TConfigOption.STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER.getInt(); i++) - { - SimpleBlock target = center.getRelative(GenUtils.getSign(rand)*GenUtils.randInt(rand,1,room.getWidthX()/2 -1), - 0, GenUtils.getSign(rand)*GenUtils.randInt(rand,1,room.getWidthZ()/2 -1)); + if (Version.isAtLeast(20)) { + for (int i = 0; i < TConfigOption.STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER.getInt(); i++) { + SimpleBlock target = center.getRelative(GenUtils.getSign(rand) * GenUtils.randInt(rand, + 1, + room.getWidthX() / 2 - 1 + ), + 0, + GenUtils.getSign(rand) * GenUtils.randInt(rand, 1, room.getWidthZ() / 2 - 1) + ); target.setType(OneTwentyBlockHandler.SUSPICIOUS_SAND); - data.lootTableChest(target.getX(),target.getY(),target.getZ(), TerraLootTable.DESERT_PYRAMID_ARCHAEOLOGY); + data.lootTableChest(target.getX(), + target.getY(), + target.getZ(), + TerraLootTable.DESERT_PYRAMID_ARCHAEOLOGY + ); } + } // For the ceiling center = new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()); for (BlockFace face : BlockUtils.directBlockFaces) { int length = room.getWidthX() / 2; - if (face == BlockFace.NORTH || face == BlockFace.SOUTH) + if (face == BlockFace.NORTH || face == BlockFace.SOUTH) { length = room.getWidthZ() / 2; + } for (int i = 0; i < length; i++) { - if (face == BlockFace.NORTH || face == BlockFace.SOUTH) - center.getRelative(face, i).getRelative(steps[i] * face.getModZ(), 0, 0) - .setType(Material.ORANGE_TERRACOTTA); - else - center.getRelative(face, i).getRelative(0, 0, steps[i] * face.getModX()) - .setType(Material.ORANGE_TERRACOTTA); + if (face == BlockFace.NORTH || face == BlockFace.SOUTH) { + center.getRelative(face, i) + .getRelative(steps[i] * face.getModZ(), 0, 0) + .setType(Material.ORANGE_TERRACOTTA); + } + else { + center.getRelative(face, i) + .getRelative(0, 0, steps[i] * face.getModX()) + .setType(Material.ORANGE_TERRACOTTA); + } } } center.setType(Material.BLUE_TERRACOTTA); } - protected void randomRoomPlacement(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room, int lowerbound, int upperbound, Material... types) { + protected void randomRoomPlacement(@NotNull PopulatorDataAbstract data, + @NotNull CubeRoom room, + int lowerbound, + int upperbound, + Material... types) + { for (int i = 0; i < GenUtils.randInt(lowerbound, upperbound); i++) { int[] coords = room.randomCoords(rand, 1); BlockData bd = Bukkit.createBlockData(GenUtils.randChoice(types)); - if (bd instanceof Waterlogged) + if (bd instanceof Waterlogged) { ((Waterlogged) bd).setWaterlogged(false); - if (!data.getType(coords[0], room.getY() + 1, coords[2]).isSolid()) + } + if (!data.getType(coords[0], room.getY() + 1, coords[2]).isSolid()) { data.setBlockData(coords[0], room.getY() + 1, coords[2], bd); - else + } + else { data.setBlockData(coords[0], room.getY() + 2, coords[2], bd); + } } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/CryptRoom.java b/common/src/main/java/org/terraform/structure/pyramid/CryptRoom.java index 74d5ba8d..8a84fc3a 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/CryptRoom.java +++ b/common/src/main/java/org/terraform/structure/pyramid/CryptRoom.java @@ -41,11 +41,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { - w.Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); + w.Pillar( + room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); if (w.getDirection() == face) { // Thicker entryway - w.getFront().Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); + w.getFront() + .Pillar(room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); if (i == 1) { // Redstone wiring @@ -75,9 +87,16 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.getRear().getUp().setBlockData(lever); // Cover - w.getFront(3).Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); + w.getFront(3) + .Pillar(room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); - } else if (i == 2) { // Redstone wiring + } + else if (i == 2) { // Redstone wiring RedstoneWire wire = (RedstoneWire) Bukkit.createBlockData(Material.REDSTONE_WIRE); wire.setFace(BlockUtils.getAdjacentFaces(face)[1], Connection.SIDE); wire.setFace(face.getOppositeFace(), Connection.SIDE); @@ -94,10 +113,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.getFront().getUp(3).setBlockData(wire); // Cover - w.getFront(3).Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); - w.getFront(2).Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); + w.getFront(3) + .Pillar(room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); + w.getFront(2) + .Pillar(room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); - } else if (i == 3) { // Entry holes & pistons + } + else if (i == 3) { // Entry holes & pistons // Drill hole w.Pillar(2, rand, Material.AIR); w.getFront().Pillar(2, rand, Material.AIR); @@ -110,12 +142,27 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Piston faceUp = (Piston) Bukkit.createBlockData(Material.STICKY_PISTON); faceUp.setFacing(BlockFace.UP); w.getFront().getDown(2).setBlockData(faceUp); - w.getUp(2).getFront(2).Pillar(room.getHeight() - 2, rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); + w.getUp(2) + .getFront(2) + .Pillar(room.getHeight() - 2, + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); - } else { // even thicker layer - w.getFront(2).Pillar(room.getHeight(), rand, Material.SANDSTONE, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE); } - } else if (w.getDirection() == face.getOppositeFace()) { + else { // even thicker layer + w.getFront(2) + .Pillar(room.getHeight(), + rand, + Material.SANDSTONE, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE + ); + } + } + else if (w.getDirection() == face.getOppositeFace()) { // Create treasure chest inside the crypt if (GenUtils.chance(rand, 1, 10)) { SimpleBlock pos = w.getFront().get(); diff --git a/common/src/main/java/org/terraform/structure/pyramid/CursedChamber.java b/common/src/main/java/org/terraform/structure/pyramid/CursedChamber.java index add62b75..b013369b 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/CursedChamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/CursedChamber.java @@ -35,12 +35,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (Entry entry : room.getFourWalls(data, 1).entrySet()) { Wall w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { - for (int h = 0; h < room.getHeight() - 2; h++) + for (int h = 0; h < room.getHeight() - 2; h++) { if (w.getRelative(0, h, 0).getRear().isSolid() && GenUtils.chance(rand, 1, 5)) { Directional head = (Directional) Bukkit.createBlockData(Material.SKELETON_WALL_SKULL); head.setFacing(w.getDirection()); w.getRelative(0, h, 0).setBlockData(head); } + } w = w.getLeft(); } @@ -52,7 +53,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (room.getWidthX() > 10) { availableX.add(lowerCorner[0]); availableX.add(upperCorner[0]); - } else { // Spawn only one. + } + else { // Spawn only one. availableX.add(room.getX()); } @@ -60,26 +62,31 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (room.getWidthZ() > 10) { availableZ.add(lowerCorner[1]); availableZ.add(upperCorner[1]); - } else { // Spawn only one. + } + else { // Spawn only one. availableZ.add(room.getZ()); } // Build the pillars - for (int nx : availableX) - for (int nz : availableZ) + for (int nx : availableX) { + for (int nz : availableZ) { spawnSkullPillar(new Wall(new SimpleBlock(data, nx, room.getY() + 1, nz)), room); + } + } // Ceiling erosions for (int i = 0; i < GenUtils.randInt(3, 10); i++) { int[] loc = room.randomCoords(rand, 1); - if (data.getType(loc[0], room.getY() + room.getHeight() + 1, loc[2]) == Material.SAND) + if (data.getType(loc[0], room.getY() + room.getHeight() + 1, loc[2]) == Material.SAND) { data.setType(loc[0], room.getY() + room.getHeight() + 1, loc[2], Material.SANDSTONE); + } BlockUtils.dropDownBlock(new SimpleBlock(data, loc[0], room.getY() + room.getHeight(), loc[2])); } // Skeletons - for (int i = 0; i < GenUtils.randInt(rand, 1, 4); i++) + for (int i = 0; i < GenUtils.randInt(rand, 1, 4); i++) { data.addEntity(room.getX() - room.getWidthX() / 2 + 1, room.getY() + 1, room.getZ(), EntityType.SKELETON); + } } public void spawnSkullPillar(@NotNull Wall w, @NotNull CubeRoom room) { @@ -88,12 +95,20 @@ public void spawnSkullPillar(@NotNull Wall w, @NotNull CubeRoom room) { // Stair base and ceiling for (BlockFace face : BlockUtils.directBlockFaces) { - Stairs stair = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(Material.SANDSTONE_STAIRS, Material.STONE_STAIRS, Material.COBBLESTONE_STAIRS)); + Stairs stair = (Stairs) Bukkit.createBlockData(GenUtils.randChoice( + Material.SANDSTONE_STAIRS, + Material.STONE_STAIRS, + Material.COBBLESTONE_STAIRS + )); stair.setFacing(face.getOppositeFace()); w.getRelative(face).setBlockData(stair); - stair = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(Material.SANDSTONE_STAIRS, Material.STONE_STAIRS, Material.COBBLESTONE_STAIRS)); + stair = (Stairs) Bukkit.createBlockData(GenUtils.randChoice( + Material.SANDSTONE_STAIRS, + Material.STONE_STAIRS, + Material.COBBLESTONE_STAIRS + )); stair.setFacing(face.getOppositeFace()); stair.setHalf(Half.TOP); w.getRelative(face).getRelative(0, room.getHeight() - 2, 0).setBlockData(stair); @@ -103,7 +118,9 @@ public void spawnSkullPillar(@NotNull Wall w, @NotNull CubeRoom room) { for (int h = 1; h < room.getHeight() - 3; h++) { Wall target = w.getRelative(0, h, 0); for (BlockFace face : BlockUtils.directBlockFaces) { - if (GenUtils.chance(4, 5)) continue; + if (GenUtils.chance(4, 5)) { + continue; + } Directional head = (Directional) Bukkit.createBlockData(Material.SKELETON_WALL_SKULL); head.setFacing(face); target.getRelative(face).setBlockData(head); @@ -111,10 +128,12 @@ public void spawnSkullPillar(@NotNull Wall w, @NotNull CubeRoom room) { } // Corrupt Ceiling - for (int nz = -2; nz <= 2; nz++) + for (int nz = -2; nz <= 2; nz++) { for (int nx = -2; nx <= 2; nx++) { - w.getRelative(nx, room.getHeight() - 1, nz).setType(GenUtils.randChoice(Material.ANDESITE, Material.COBBLESTONE, Material.SANDSTONE)); + w.getRelative(nx, room.getHeight() - 1, nz) + .setType(GenUtils.randChoice(Material.ANDESITE, Material.COBBLESTONE, Material.SANDSTONE)); } + } } @Override diff --git a/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java b/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java index 856ed38b..00866ee3 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java @@ -47,12 +47,15 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room center.setType(Material.BLUE_TERRACOTTA); for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { center.getRelative(face).setType(Material.ORANGE_TERRACOTTA); - new Wall(center.getRelative(face).getRelative(face).getUp()) - .Pillar(room.getHeight(), rand, Material.CUT_SANDSTONE); + new Wall(center.getRelative(face).getRelative(face).getUp()).Pillar( + room.getHeight(), + rand, + Material.CUT_SANDSTONE + ); + } + for (BlockFace face : BlockUtils.directBlockFaces) { + center.getRelative(face).getRelative(face).setType(Material.ORANGE_TERRACOTTA); } - for (BlockFace face : BlockUtils.directBlockFaces) - center.getRelative(face).getRelative(face) - .setType(Material.ORANGE_TERRACOTTA); // On the ceiling as well SimpleBlock ceiling = new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()); @@ -60,9 +63,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { ceiling.getRelative(face).setType(Material.ORANGE_TERRACOTTA); } - for (BlockFace face : BlockUtils.directBlockFaces) - ceiling.getRelative(face).getRelative(face) - .setType(Material.ORANGE_TERRACOTTA); + for (BlockFace face : BlockUtils.directBlockFaces) { + ceiling.getRelative(face).getRelative(face).setType(Material.ORANGE_TERRACOTTA); + } // Elder Guardian cage if (TConfigOption.STRUCTURES_PYRAMID_SPAWN_ELDER_GUARDIAN.getBoolean()) { @@ -124,7 +127,8 @@ private void placeElderGuardianCage(@NotNull SimpleBlock cageCenter) { } - cageCenter.getPopData().addEntity(cageCenter.getX(), cageCenter.getY(), cageCenter.getZ(), EntityType.ELDER_GUARDIAN); + cageCenter.getPopData() + .addEntity(cageCenter.getX(), cageCenter.getY(), cageCenter.getZ(), EntityType.ELDER_GUARDIAN); } private void placePillar(@NotNull Wall base, int height) { @@ -134,8 +138,16 @@ private void placePillar(@NotNull Wall base, int height) { } for (BlockFace face : BlockUtils.directBlockFaces) { - base.getRelative(face).Pillar(height, true, rand, Material.CUT_SANDSTONE, Material.CHISELED_SANDSTONE, Material.AIR, Material.AIR, Material.AIR, - Material.CHISELED_SANDSTONE); + base.getRelative(face).Pillar(height, + true, + rand, + Material.CUT_SANDSTONE, + Material.CHISELED_SANDSTONE, + Material.AIR, + Material.AIR, + Material.AIR, + Material.CHISELED_SANDSTONE + ); } base.Pillar(height, rand, Material.CHISELED_RED_SANDSTONE); } @@ -146,7 +158,8 @@ private void placeStatue(SimpleBlock base, BlockFace dir) { schema.parser = new SchematicParser(); schema.setFace(dir); schema.apply(); - } catch (Throwable e) { + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/EnchantmentAntechamber.java b/common/src/main/java/org/terraform/structure/pyramid/EnchantmentAntechamber.java index eb0fbe37..b63d1d32 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/EnchantmentAntechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/EnchantmentAntechamber.java @@ -46,12 +46,15 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (i % 2 == 0) { int h = 1; - if (i == 2) h = 2; + if (i == 2) { + h = 2; + } w.LPillar(h, rand, Material.BOOKSHELF); w.getRelative(0, room.getHeight() - 2, 0).downLPillar(rand, h, Material.BOOKSHELF); w.RPillar(room.getHeight(), rand, Material.SANDSTONE_WALL); - } else { + } + else { Directional decor = (Directional) Bukkit.createBlockData(Material.LECTERN); decor.setFacing(w.getDirection()); w.setBlockData(decor); diff --git a/common/src/main/java/org/terraform/structure/pyramid/GenericAntechamber.java b/common/src/main/java/org/terraform/structure/pyramid/GenericAntechamber.java index 608f1b62..146ba9f6 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/GenericAntechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/GenericAntechamber.java @@ -28,8 +28,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room super.populate(data, room); for (int i = 0; i < GenUtils.randInt(2, 5); i++) { int[] coords = room.randomCoords(rand, 2); - data.setType(coords[0], room.getY() + 1, coords[2], GenUtils.randChoice(Material.CHISELED_SANDSTONE, Material.CHISELED_SANDSTONE, Material.CHISELED_SANDSTONE, - Material.BONE_BLOCK)); + data.setType(coords[0], room.getY() + 1, coords[2], GenUtils.randChoice(Material.CHISELED_SANDSTONE, + Material.CHISELED_SANDSTONE, + Material.CHISELED_SANDSTONE, + Material.BONE_BLOCK + )); } // Flower pots @@ -49,30 +52,44 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Material.DEAD_TUBE_CORAL_FAN }; - if (GenUtils.chance(rand, 1, 2)) + if (GenUtils.chance(rand, 1, 2)) { randomRoomPlacement(data, room, 1, 5, deadCorals); + } // Animal items - if (GenUtils.chance(rand, 1, 3)) + if (GenUtils.chance(rand, 1, 3)) { randomRoomPlacement(data, room, 1, 1, Material.TURTLE_EGG); + } // Logs - if (GenUtils.chance(rand, 1, 2)) - randomRoomPlacement(data, room, 1, 5, Material.ACACIA_LOG, + if (GenUtils.chance(rand, 1, 2)) { + randomRoomPlacement( + data, + room, + 1, + 5, + Material.ACACIA_LOG, Material.BIRCH_LOG, Material.DARK_OAK_LOG, Material.JUNGLE_LOG, Material.SPRUCE_LOG, - Material.OAK_LOG); + Material.OAK_LOG + ); + } // Rare, monster head if (GenUtils.chance(1, 3)) { - randomRoomPlacement(data, room, 1, 1, Material.CREEPER_HEAD, + randomRoomPlacement(data, + room, + 1, + 1, + Material.CREEPER_HEAD, Material.BIRCH_LOG, Material.DARK_OAK_LOG, Material.JUNGLE_LOG, Material.SPRUCE_LOG, - Material.OAK_LOG); + Material.OAK_LOG + ); } // Oceanic Treasure Chest diff --git a/common/src/main/java/org/terraform/structure/pyramid/GuardianChamberPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/GuardianChamberPopulator.java index 96c00d8c..d814f02b 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/GuardianChamberPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/GuardianChamberPopulator.java @@ -38,19 +38,24 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Sides have more platforms. if (x == lowerCorner[0] || x == upperCorner[0] || z == lowerCorner[1] || z == upperCorner[1]) { - if (rand.nextBoolean()) continue; + if (rand.nextBoolean()) { + continue; + } } // The closer to the center, the deeper the pool. - double heightMultiplierX = ((double) (2 * Math.abs(room.getX() - x))) / ((double) Math.abs(room.getWidthX())); - double heightMultiplierZ = ((double) (2 * Math.abs(room.getZ() - z))) / ((double) Math.abs(room.getWidthZ())); + double heightMultiplierX = ((double) (2 * Math.abs(room.getX() - x))) + / ((double) Math.abs(room.getWidthX())); + double heightMultiplierZ = ((double) (2 * Math.abs(room.getZ() - z))) + / ((double) Math.abs(room.getWidthZ())); double heightMultiplier = 1 - ((heightMultiplierX + heightMultiplierZ) / 2); int poolDepth = (int) (1 + heightMultiplier * 4); // Set water and delete pressure plate deathpit traps for (int y = room.getY(); y > room.getY() - poolDepth; y--) { data.setType(x, y, z, Material.WATER); - if (data.getType(x, y + 1, z) == Material.STONE_PRESSURE_PLATE) + if (data.getType(x, y + 1, z) == Material.STONE_PRESSURE_PLATE) { data.setType(x, y + 1, z, Material.AIR); + } } } } @@ -63,8 +68,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room @Override public boolean canPopulate(@NotNull CubeRoom room) { // Don't compete with crypt rooms for space - return room.getWidthX() >= 5 && room.getWidthZ() >= 5 - && room.getWidthX() < 13 && room.getWidthZ() < 13; + return room.getWidthX() >= 5 && room.getWidthZ() >= 5 && room.getWidthX() < 13 && room.getWidthZ() < 13; } diff --git a/common/src/main/java/org/terraform/structure/pyramid/HuskTombPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/HuskTombPopulator.java index ad4fb10c..53e9f9e6 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/HuskTombPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/HuskTombPopulator.java @@ -29,14 +29,20 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { if (w.isSolid()) { // Don't block off pathways - if (w.getType().toString().contains("SAND")) - w.Pillar(room.getHeight() - 1, rand, + if (w.getType().toString().contains("SAND")) { + w.Pillar( + room.getHeight() - 1, + rand, Material.SANDSTONE, Material.SANDSTONE_SLAB, Material.CUT_SANDSTONE, - Material.CHISELED_SANDSTONE); - else - w.Pillar(room.getHeight() - 1, rand, + Material.CHISELED_SANDSTONE + ); + } + else { + w.Pillar( + room.getHeight() - 1, + rand, Material.ANDESITE, Material.ANDESITE, Material.ANDESITE, @@ -44,17 +50,19 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Material.STONE_BRICKS, Material.STONE_BRICK_SLAB, Material.CRACKED_STONE_BRICKS, - Material.STONE_BRICKS); + Material.STONE_BRICKS + ); + } // Spawn chests if (GenUtils.chance(this.rand, 1, 50) && i != 0 && i != entry.getValue() - 1) { Directional chest = (Directional) Bukkit.createBlockData(Material.CHEST); chest.setFacing(w.getDirection()); w.getFront().setBlockData(chest); - data.lootTableChest( - w.getFront().getX(), + data.lootTableChest(w.getFront().getX(), w.getFront().getY(), w.getFront().getZ(), - TerraLootTable.SIMPLE_DUNGEON); + TerraLootTable.SIMPLE_DUNGEON + ); } } @@ -68,8 +76,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Ceiling erosions for (int i = 0; i < GenUtils.randInt(3, 10); i++) { int[] loc = room.randomCoords(rand, 1); - if (data.getType(loc[0], room.getY() + room.getHeight() + 1, loc[2]) == Material.SAND) + if (data.getType(loc[0], room.getY() + room.getHeight() + 1, loc[2]) == Material.SAND) { data.setType(loc[0], room.getY() + room.getHeight() + 1, loc[2], Material.SANDSTONE); + } BlockUtils.dropDownBlock(new SimpleBlock(data, loc[0], room.getY() + room.getHeight(), loc[2])); } } @@ -78,7 +87,6 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room @Override public boolean canPopulate(@NotNull CubeRoom room) { // Don't compete with Crypt rooms for space - return room.getWidthX() >= 5 && room.getWidthZ() >= 5 - && room.getWidthX() < 13 && room.getWidthZ() < 13; + return room.getWidthX() >= 5 && room.getWidthZ() >= 5 && room.getWidthX() < 13 && room.getWidthZ() < 13; } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/MainEntrancePopulator.java b/common/src/main/java/org/terraform/structure/pyramid/MainEntrancePopulator.java index 52a2b08b..7579f660 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/MainEntrancePopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/MainEntrancePopulator.java @@ -25,7 +25,7 @@ public MainEntrancePopulator(Random rand, boolean forceSpawn, boolean unique, Bl @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - int entranceHeightOffsetFromBase = room.getHeight() - 5; + int entranceHeightOffsetFromBase = room.getHeight() - 5; // Make the entrance pyramid shaped int[] upperRoomCorner = room.getUpperCorner(); int[] lowerRoomCorner = room.getLowerCorner(); @@ -36,26 +36,50 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { // Don't place blocks on the inside of the room if ((x > lowerRoomCorner[0] - && x < upperRoomCorner[0] - && z > lowerRoomCorner[1] - && z < upperRoomCorner[1]) - || h == 6) continue; - - if (h == 2) - data.setType(x, room.getY() + entranceHeightOffsetFromBase + 2, z, Material.CHISELED_RED_SANDSTONE); - else - data.setType(x, room.getY() + entranceHeightOffsetFromBase + h, z, GenUtils.randChoice(Material.SANDSTONE, Material.SMOOTH_SANDSTONE)); - + && x < upperRoomCorner[0] + && z > lowerRoomCorner[1] + && z < upperRoomCorner[1]) || h == 6) + { + continue; + } + + if (h == 2) { + data.setType(x, + room.getY() + entranceHeightOffsetFromBase + 2, + z, + Material.CHISELED_RED_SANDSTONE + ); + } + else { + data.setType(x, + room.getY() + entranceHeightOffsetFromBase + h, + z, + GenUtils.randChoice(Material.SANDSTONE, Material.SMOOTH_SANDSTONE) + ); + } + // Down until solid to cover potential gaps if (h == 0) { - BlockUtils.setDownUntilSolid(x, room.getY() + entranceHeightOffsetFromBase - 1, z, data, Material.SANDSTONE); + BlockUtils.setDownUntilSolid( + x, + room.getY() + entranceHeightOffsetFromBase - 1, + z, + data, + Material.SANDSTONE + ); } - + // Sand Wall Corner Decor - if ((x == lowerCorner[0] + 1 || x == upperCorner[0] - 1) - && (z == lowerCorner[1] + 1 || z == upperCorner[1] - 1)) { + if ((x == lowerCorner[0] + 1 || x == upperCorner[0] - 1) && (z == lowerCorner[1] + 1 + || z == upperCorner[1] - 1)) + { if (data.getType(x, room.getY() + entranceHeightOffsetFromBase + h + 1, z) == Material.AIR) { - data.setType(x, room.getY() + entranceHeightOffsetFromBase + h + 1, z, Material.SANDSTONE_WALL); + data.setType( + x, + room.getY() + entranceHeightOffsetFromBase + h + 1, + z, + Material.SANDSTONE_WALL + ); } } } @@ -64,18 +88,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Ceiling Decor SimpleBlock b = new SimpleBlock(data, room.getX(), room.getY() + room.getHeight(), room.getZ()); - for (int nx = -1; nx <= 1; nx++) + for (int nx = -1; nx <= 1; nx++) { for (int nz = -1; nz <= 1; nz++) { b.getRelative(nx, 0, nz).setType(Material.ORANGE_TERRACOTTA); b.getRelative(nx, 1, nz).setType(Material.CUT_RED_SANDSTONE); } - for (int nx = -2; nx <= 2; nx += 2) - for (int nz = -2; nz <= 2; nz += 2) + } + for (int nx = -2; nx <= 2; nx += 2) { + for (int nz = -2; nz <= 2; nz += 2) { b.getRelative(nx, 0, nz).setType(Material.ORANGE_TERRACOTTA); + } + } // Carve entrance - Wall w = new Wall(new SimpleBlock(data, room.getX(), room.getY() + entranceHeightOffsetFromBase+1, room.getZ()), - entranceFace.getOppositeFace()); + Wall w = new Wall( + new SimpleBlock(data, room.getX(), room.getY() + entranceHeightOffsetFromBase + 1, room.getZ()), + entranceFace.getOppositeFace() + ); w = w.getFront(3); for (int depth = 0; depth <= 6; depth++) { w = w.getFront(1); @@ -86,17 +115,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Pillar Stairs for (int h = entranceHeightOffsetFromBase; h > 0; h--) { - w = new Wall( - new SimpleBlock(data, room.getX(), room.getY() + h, room.getZ()), + w = new Wall(new SimpleBlock(data, room.getX(), room.getY() + h, room.getZ()), BlockUtils.rotateFace(entranceFace.getOppositeFace(), entranceHeightOffsetFromBase - h) ); - if (h > 3) + if (h > 3) { for (int i = 1; i <= 3; i++) { w.getFront(i).setType(Material.CUT_SANDSTONE); } - else + } + else { w.getFront().downUntilSolid(new Random(), Material.CUT_SANDSTONE); + } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/MazeLevelMonsterRoom.java b/common/src/main/java/org/terraform/structure/pyramid/MazeLevelMonsterRoom.java index 751637fa..1078570d 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/MazeLevelMonsterRoom.java +++ b/common/src/main/java/org/terraform/structure/pyramid/MazeLevelMonsterRoom.java @@ -23,10 +23,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room data.setType(room.getX(), room.getY(), room.getZ(), Material.RED_TERRACOTTA); int choice = rand.nextInt(3); // 0,1,2 - EntityType monster = new EntityType[]{ - EntityType.HUSK, - EntityType.CAVE_SPIDER, - EntityType.SILVERFISH + EntityType monster = new EntityType[] { + EntityType.HUSK, EntityType.CAVE_SPIDER, EntityType.SILVERFISH }[choice]; for (int i = 0; i < GenUtils.randInt(1, 5); i++) { data.addEntity(room.getX(), room.getY() + 1, room.getZ(), monster); diff --git a/common/src/main/java/org/terraform/structure/pyramid/PyramidDungeonPathPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/PyramidDungeonPathPopulator.java index 5af5eaeb..36073cef 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/PyramidDungeonPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/PyramidDungeonPathPopulator.java @@ -40,8 +40,9 @@ public void populate(@NotNull PathPopulatorData ppd) { // Generate cross-shaped hole. for (int i = -2; i > -8; i--) { ppd.base.getRelative(0, i, 0).setType(Material.AIR); - for (BlockFace face : BlockUtils.directBlockFaces) + for (BlockFace face : BlockUtils.directBlockFaces) { ppd.base.getRelative(face).getRelative(0, i, 0).setType(Material.AIR); + } } // Place torches against the tnt. This leads to a larger pit when the trap is triggered. diff --git a/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java index ed4efa55..7464fd72 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java @@ -22,8 +22,8 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.MazeSpawner; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import java.util.ArrayList; @@ -33,25 +33,30 @@ public class PyramidPopulator extends SingleMegaChunkStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } // Check biome - if (biome != BiomeBank.DESERT) + if (biome != BiomeBank.DESERT) { return false; + } return rollSpawnRatio(tw, chunkX, chunkZ); } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 163456), - (int) (TConfigOption.STRUCTURES_PYRAMID_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_PYRAMID_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } int[] coords = new MegaChunk(data.getChunkX(), data.getChunkZ()).getCenterBiomeSectionBlockCoords(); int x = coords[0]; @@ -60,37 +65,53 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int y = HeightMap.getBlockHeight(tw, x, z);// GenUtils.getHighestGround(data, x, z); try { spawnPyramid(tw, tw.getHashedRand(x, y, z, 1211222), data, x, y, z); - } catch (Throwable e) { + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } - public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnPyramid(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { y -= 10; - TerraformGeneratorPlugin.logger.info("Spawning Pyramid at: " + x + "," + z); + TerraformGeneratorPlugin.logger.info("Spawning Pyramid at: " + x + "," + z); int numRooms = 1000; int range = 70; - if(y >= TerraformGenerator.seaLevel+3) { + if (y >= TerraformGenerator.seaLevel + 3) { spawnSandBase(tw, data, x, y, z); - } else { - spawnSandBase(tw, data, x, TerraformGenerator.seaLevel+3, z); - y = TerraformGenerator.seaLevel-7; } - + else { + spawnSandBase(tw, data, x, TerraformGenerator.seaLevel + 3, z); + y = TerraformGenerator.seaLevel - 7; + } + spawnPyramidBase(data, x, y, z); Random hashedRand = tw.getHashedRand(x, y, z); // Level 0 - Labyrinth Layer (Dark, full of traps). Also the entry level. - RoomLayoutGenerator level0 = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y - 8, z, range); -// private int roomMaxHeight = 7; -// private int roomMinHeight = 5; -// private int roomMaxX = 15; -// private int roomMinX = 10; -// private int roomMaxZ = 15; -// private int roomMinZ = 10; + RoomLayoutGenerator level0 = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y - 8, + z, + range + ); + // private int roomMaxHeight = 7; + // private int roomMinHeight = 5; + // private int roomMaxX = 15; + // private int roomMinX = 10; + // private int roomMaxZ = 15; + // private int roomMinZ = 10; // Add pyramid entrance at the pyramid corner - int entranceRoomHeight = 4 + GenUtils.getHighestGround(data, x, z + 5 + range / 2) - (y-8); + int entranceRoomHeight = 4 + GenUtils.getHighestGround(data, x, z + 5 + range / 2) - (y - 8); CubeRoom entranceRoom = new CubeRoom(9, 9, entranceRoomHeight, x, y - 8, z + 5 + range / 2); MainEntrancePopulator entrancePopulator = new MainEntrancePopulator(hashedRand, false, false, BlockFace.NORTH); entranceRoom.setRoomPopulator(entrancePopulator); @@ -107,7 +128,15 @@ public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @No // Level 1 - Maze level (?) - RoomLayoutGenerator level1 = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range + 10); + RoomLayoutGenerator level1 = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + 10 + ); level1.setMazePathGenerator(new MazeSpawner()); level1.setRoomMinX(5); level1.setRoomMaxX(6); @@ -118,9 +147,9 @@ public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @No level1.registerRoomPopulator(new MazeLevelMonsterRoom(random, false, false)); // Manually add a room for HuskTomb to work. - CubeRoom room = level1.forceAddRoom( + CubeRoom room = level1.forceAddRoom(GenUtils.randInt(6, 12), GenUtils.randInt(6, 12), - GenUtils.randInt(6, 12), // 6 and 12 because these are the bounds for husk tombs. + // 6 and 12 because these are the bounds for husk tombs. GenUtils.randInt(level1.getRoomMinHeight(), level1.getRoomMaxHeight()) ); room.setRoomPopulator(new HuskTombPopulator(random, true, true)); @@ -146,7 +175,15 @@ public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @No range -= 10; // Level 2 - RoomLayoutGenerator level2 = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y + 8, z, range); + RoomLayoutGenerator level2 = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y + 8, + z, + range + ); level2.setRoomMaxX(10); level2.setRoomMinX(7); level2.setRoomMaxZ(10); @@ -195,18 +232,47 @@ public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @No }}; for (int nx = -50; nx <= 50; nx++) { for (int nz = -50; nz <= 50; nz++) { - if (toReplace.contains(data.getType(x + nx, y - 8, z + nz))) - data.setType(x + nx, y - 8, z + nz, GenUtils.randChoice(Material.STONE, Material.STONE, Material.STONE, Material.COBBLESTONE, Material.ANDESITE)); + if (toReplace.contains(data.getType(x + nx, y - 8, z + nz))) { + data.setType( + x + nx, + y - 8, + z + nz, + GenUtils.randChoice(Material.STONE, + Material.STONE, + Material.STONE, + Material.COBBLESTONE, + Material.ANDESITE + ) + ); + } // Dither. Include infested stone here. if (random.nextBoolean()) { - if (toReplace.contains(data.getType(x + nx, y - 7, z + nz))) - data.setType(x + nx, y - 7, z + nz, GenUtils.weightedRandomMaterial(random, Material.STONE, 9, Material.INFESTED_STONE, 5, Material.COBBLESTONE, 3, - Material.ANDESITE, 3)); + if (toReplace.contains(data.getType(x + nx, y - 7, z + nz))) { + data.setType(x + nx, y - 7, z + nz, GenUtils.weightedRandomMaterial(random, + Material.STONE, + 9, + Material.INFESTED_STONE, + 5, + Material.COBBLESTONE, + 3, + Material.ANDESITE, + 3 + )); + } if (random.nextBoolean()) { - if (toReplace.contains(data.getType(x + nx, y - 6, z + nz))) - data.setType(x + nx, y - 6, z + nz, GenUtils.weightedRandomMaterial(random, Material.STONE, 9, Material.INFESTED_STONE, 5, Material.COBBLESTONE, 3, - Material.ANDESITE, 3)); + if (toReplace.contains(data.getType(x + nx, y - 6, z + nz))) { + data.setType(x + nx, y - 6, z + nz, GenUtils.weightedRandomMaterial(random, + Material.STONE, + 9, + Material.INFESTED_STONE, + 5, + Material.COBBLESTONE, + 3, + Material.ANDESITE, + 3 + )); + } } } @@ -229,29 +295,26 @@ public void spawnPyramid(@NotNull TerraformWorld tw, @NotNull Random random, @No public void spawnSandBase(TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { int squareRadius = 45; - FastNoise noiseGenerator = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.STRUCTURE_PYRAMID_BASEELEVATOR, - world -> { - FastNoise n = new FastNoise((int)world.getSeed()); + FastNoise noiseGenerator = NoiseCacheHandler.getNoise(tw, + NoiseCacheEntry.STRUCTURE_PYRAMID_BASEELEVATOR, + world -> { + FastNoise n = new FastNoise((int) world.getSeed()); n.SetNoiseType(NoiseType.PerlinFractal); n.SetFrequency(0.007f); n.SetFractalOctaves(6); - - return n; - }); - - FastNoise vertNoise = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.STRUCTURE_PYRAMID_BASEFUZZER, - world -> { - FastNoise n = new FastNoise((int)world.getSeed()); - n.SetNoiseType(NoiseType.PerlinFractal); - n.SetFrequency(0.01f); - n.SetFractalOctaves(8); - - return n; - }); + + return n; + } + ); + + FastNoise vertNoise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_PYRAMID_BASEFUZZER, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.PerlinFractal); + n.SetFrequency(0.01f); + n.SetFractalOctaves(8); + + return n; + }); for (int nx = x - squareRadius; nx <= x + squareRadius; nx++) { for (int nz = z - squareRadius; nz <= z + squareRadius; nz++) { @@ -263,34 +326,46 @@ public void spawnSandBase(TerraformWorld tw, @NotNull PopulatorDataAbstract data int raiseDone = 0; int noise = Math.round(noiseGenerator.GetNoise(nx, nz) * 5); int newHeight = y + noise - 1; - if (newHeight < y - 1) newHeight = y - 1; + if (newHeight < y - 1) { + newHeight = y - 1; + } while (height < newHeight) { raiseDone++; if (!data.getType(nx, height + 1, nz).isSolid() - || data.getType(nx, height + 1, nz) == Material.CACTUS) + || data.getType(nx, height + 1, nz) == Material.CACTUS) + { data.setType(nx, height + 1, nz, mat); + } height++; } if (raiseDone > 0) { // Make the sides sink down naturally (lol. Or try to, anyway) - int XdistanceFromCenter = (int) (Math.abs(nx - x) + Math.abs(vertNoise.GetNoise(nx - 80, nz - 80) * 25)); - int ZdistanceFromCenter = (int) (Math.abs(nz - z) + Math.abs(vertNoise.GetNoise(nx - 80, nz - 80) * 25)); -// - if (XdistanceFromCenter > squareRadius-10 || ZdistanceFromCenter > squareRadius-10) { + int XdistanceFromCenter = (int) (Math.abs(nx - x) + Math.abs(vertNoise.GetNoise(nx - 80, nz - 80) + * 25)); + int ZdistanceFromCenter = (int) (Math.abs(nz - z) + Math.abs(vertNoise.GetNoise(nx - 80, nz - 80) + * 25)); + // + if (XdistanceFromCenter > squareRadius - 10 || ZdistanceFromCenter > squareRadius - 10) { // Depress downwards int dist = Math.max(XdistanceFromCenter, ZdistanceFromCenter); // Bukkit.getLogger().info(height + ":" + (height-raiseDone+((raiseDone)*((50.0f-dist)/5.0f)))); - float comp = original + ((raiseDone) * ((((float) squareRadius-5) - dist) / 5.0f)) + Math.abs(vertNoise.GetNoise(nx, nz) * 30); - if (comp < original) comp = original; + float comp = original + ((raiseDone) * ((((float) squareRadius - 5) - dist) / 5.0f)) + Math.abs( + vertNoise.GetNoise(nx, nz) * 30); + if (comp < original) { + comp = original; + } while (height > comp) { - if (data.getType(nx, height, nz) == mat) - if (height > TerraformGenerator.seaLevel) + if (data.getType(nx, height, nz) == mat) { + if (height > TerraformGenerator.seaLevel) { data.setType(nx, height, nz, Material.AIR); - else + } + else { data.setType(nx, height, nz, Material.WATER); + } + } height--; } } @@ -304,31 +379,45 @@ public void spawnPyramidBase(@NotNull PopulatorDataAbstract data, int x, int y, int radius = 40 - height; for (int nx = -radius; nx <= radius; nx++) { for (int nz = -radius; nz <= radius; nz++) { - data.setType(x + nx, y + height, z + nz, GenUtils.randChoice(Material.SANDSTONE, Material.SMOOTH_SANDSTONE)); + data.setType( + x + nx, + y + height, + z + nz, + GenUtils.randChoice(Material.SANDSTONE, Material.SMOOTH_SANDSTONE) + ); // data.setType(x + nx, y + height, z + nz, Material.GLASS); // dEBUG. // Corners have special decorations if (Math.abs(nx) == radius && Math.abs(nz) == radius) { - if (!data.getType(x + nx, y + height + 1, z + nz).isSolid()) + if (!data.getType(x + nx, y + height + 1, z + nz).isSolid()) { data.setType(x + nx, y + height + 1, z + nz, Material.SANDSTONE_WALL); + } - if (height == 38) + if (height == 38) { data.setType(x + nx, y + 38 + 2, z + nz, Material.CAMPFIRE); - } else if (GenUtils.chance(1, 20)) { + } + } + else if (GenUtils.chance(1, 20)) { // Side Decorations (Stairs) BlockFace dir = null; if (nx == -radius) { dir = BlockFace.EAST; - } else if (nx == radius) { + } + else if (nx == radius) { dir = BlockFace.WEST; - } else if (nz == -radius) { + } + else if (nz == -radius) { dir = BlockFace.SOUTH; - } else if (nz == radius) { + } + else if (nz == radius) { dir = BlockFace.NORTH; } if (dir != null) { - Stairs s = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(Material.SANDSTONE_STAIRS, Material.SMOOTH_SANDSTONE_STAIRS)); + Stairs s = (Stairs) Bukkit.createBlockData(GenUtils.randChoice( + Material.SANDSTONE_STAIRS, + Material.SMOOTH_SANDSTONE_STAIRS + )); s.setFacing(dir); data.setBlockData(x + nx, y + height, z + nz, s); } @@ -345,29 +434,36 @@ public void spawnPyramidBase(@NotNull PopulatorDataAbstract data, int x, int y, int elevation = 14; for (int height = elevation; height <= elevation + 16; height++) { int radius = 40 - height; - for (int nx : new int[]{-radius, 0, radius}) { - for (int nz : new int[]{-radius, 0, radius}) { + for (int nx : new int[] {-radius, 0, radius}) { + for (int nz : new int[] {-radius, 0, radius}) { // Pyramid Surface Decal int carveLength = (height - elevation); - if (carveLength > 8) + if (carveLength > 8) { carveLength = 16 - carveLength; - if (nx != 0 && nz != 0) continue; + } + if (nx != 0 && nz != 0) { + continue; + } Wall w = null; if (nx == -radius) { w = new Wall(new SimpleBlock(data, x + nx, y + height, z + nz), BlockFace.WEST); - } else if (nx == radius) { + } + else if (nx == radius) { w = new Wall(new SimpleBlock(data, x + nx, y + height, z + nz), BlockFace.EAST); - } else if (nz == -radius) { + } + else if (nz == -radius) { w = new Wall(new SimpleBlock(data, x + nx, y + height, z + nz), BlockFace.NORTH); - } else if (nz == radius) { + } + else if (nz == radius) { w = new Wall(new SimpleBlock(data, x + nx, y + height, z + nz), BlockFace.SOUTH); } - if (w != null) + if (w != null) { for (int i = 0; i <= carveLength; i++) { if (carveLength == 0) { if (height == elevation) { w.getFront().setType(Material.SANDSTONE_WALL); - } else if (height == elevation + 16) { + } + else if (height == elevation + 16) { w.getRear().getUp(2).setType(Material.SANDSTONE_WALL); } } @@ -382,6 +478,7 @@ public void spawnPyramidBase(@NotNull PopulatorDataAbstract data, int x, int y, w.getLeft(i + 1).getUp().setType(Material.SANDSTONE_WALL); } } + } } } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/SilverfishNestPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/SilverfishNestPopulator.java index b5004468..5dd233e8 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/SilverfishNestPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/SilverfishNestPopulator.java @@ -28,7 +28,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { if (w.isSolid()) { // Don't block off pathways - w.Pillar(room.getHeight() - 1, rand, + w.Pillar(room.getHeight() - 1, + rand, Material.ANDESITE, Material.ANDESITE, Material.ANDESITE, @@ -37,12 +38,24 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Material.STONE_BRICK_SLAB, Material.CRACKED_STONE_BRICKS, Material.SANDSTONE, - Material.STONE_BRICKS); + Material.STONE_BRICKS + ); // Make "lumps" on the walls if (i > 1 && i < entry.getValue() - 2) { - w.getFront().Pillar(room.getHeight() - 1, rand, Material.AIR, Material.AIR, Material.AIR, Material.AIR, Material.AIR, - Material.STONE, Material.INFESTED_STONE, Material.INFESTED_STONE_BRICKS, Material.STONE_BRICKS, Material.ANDESITE); + w.getFront().Pillar(room.getHeight() - 1, + rand, + Material.AIR, + Material.AIR, + Material.AIR, + Material.AIR, + Material.AIR, + Material.STONE, + Material.INFESTED_STONE, + Material.INFESTED_STONE_BRICKS, + Material.STONE_BRICKS, + Material.ANDESITE + ); } // Spawn chests @@ -50,11 +63,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Directional chest = (Directional) Bukkit.createBlockData(Material.CHEST); chest.setFacing(w.getDirection()); w.getFront().setBlockData(chest); - data.lootTableChest( - w.getFront().getX(), + data.lootTableChest(w.getFront().getX(), w.getFront().getY(), w.getFront().getZ(), - TerraLootTable.SIMPLE_DUNGEON); + TerraLootTable.SIMPLE_DUNGEON + ); } } @@ -73,8 +86,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Place a spawner if the nest is large - if (room.getWidthX() >= 10 && room.getWidthZ() >= 10) + if (room.getWidthX() >= 10 && room.getWidthZ() >= 10) { data.setSpawner(room.getX(), room.getY() + 1, room.getZ(), EntityType.SILVERFISH); + } } diff --git a/common/src/main/java/org/terraform/structure/pyramid/TerracottaRoom.java b/common/src/main/java/org/terraform/structure/pyramid/TerracottaRoom.java index e5d84d71..045a1dd2 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/TerracottaRoom.java +++ b/common/src/main/java/org/terraform/structure/pyramid/TerracottaRoom.java @@ -27,21 +27,35 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int i = 0; i < entry.getValue(); i++) { if (i != 0 && i != entry.getValue() - 1) { if (w.getRear().isSolid()) { - if(i != 1 && i != entry.getValue() - 2) { // Terracotta - if (!w.getRear().getLeft().isSolid() || - !w.getRear().getRight().isSolid()) { + if (i != 1 && i != entry.getValue() - 2) { // Terracotta + if (!w.getRear().getLeft().isSolid() || !w.getRear().getRight().isSolid()) { w.Pillar(room.getHeight(), rand, Material.CHISELED_SANDSTONE); - } else { + } + else { if (i % 3 == 0) { - w.Pillar(room.getHeight(), true, rand, Material.BLUE_TERRACOTTA, Material.YELLOW_TERRACOTTA); + w.Pillar( + room.getHeight(), + true, + rand, + Material.BLUE_TERRACOTTA, + Material.YELLOW_TERRACOTTA + ); // w.getRear().Pillar(room.getHeight(), true, rand, Material.BLUE_TERRACOTTA,Material.BARRIER,Material.BLUE_TERRACOTTA,Material.BARRIER); - } else { - w.Pillar(room.getHeight(), true, rand, Material.YELLOW_TERRACOTTA, Material.BLUE_TERRACOTTA); + } + else { + w.Pillar( + room.getHeight(), + true, + rand, + Material.YELLOW_TERRACOTTA, + Material.BLUE_TERRACOTTA + ); // w.getRear().Pillar(room.getHeight(), true, rand, Material.BARRIER,Material.BLUE_TERRACOTTA,Material.BARRIER,Material.BLUE_TERRACOTTA); } } } - } else { + } + else { entrances.add(w.clone()); w.getUp(3).Pillar(room.getHeight() - 3, rand, Material.CHISELED_SANDSTONE); } diff --git a/common/src/main/java/org/terraform/structure/pyramid/TrapChestChamberPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/TrapChestChamberPopulator.java index db8f2fa3..b856a47f 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/TrapChestChamberPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/TrapChestChamberPopulator.java @@ -26,21 +26,26 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // We don't want any mobs stepping on bombs here. The whole room explodes. int[] lowerCorner = room.getLowerCorner(1); int[] upperCorner = room.getUpperCorner(1); - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { data.setType(x, room.getY() + 1, z, Material.AIR); + } + } // Classic Pyramid interior look SimpleBlock center = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()); center.setType(Material.BLUE_TERRACOTTA); for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { center.getRelative(face).setType(Material.ORANGE_TERRACOTTA); - new Wall(center.getRelative(face).getRelative(face).getUp()) - .Pillar(room.getHeight(), rand, Material.CUT_SANDSTONE); + new Wall(center.getRelative(face).getRelative(face).getUp()).Pillar( + room.getHeight(), + rand, + Material.CUT_SANDSTONE + ); + } + for (BlockFace face : BlockUtils.directBlockFaces) { + center.getRelative(face).getRelative(face).setType(Material.ORANGE_TERRACOTTA); } - for (BlockFace face : BlockUtils.directBlockFaces) - center.getRelative(face).getRelative(face) - .setType(Material.ORANGE_TERRACOTTA); center.getUp().setType(Material.TRAPPED_CHEST); data.lootTableChest(center.getX(), center.getY() + 1, center.getZ(), TerraLootTable.DESERT_PYRAMID); diff --git a/common/src/main/java/org/terraform/structure/pyramid/TreasureAntechamber.java b/common/src/main/java/org/terraform/structure/pyramid/TreasureAntechamber.java index fad91ca1..1c634f71 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/TreasureAntechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/TreasureAntechamber.java @@ -31,14 +31,14 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { - if (i != 0 && i != entry.getValue() - 1) - if (w.getRear().isSolid() && !w.isSolid() - && GenUtils.chance(rand, 1, 4)) { + if (i != 0 && i != entry.getValue() - 1) { + if (w.getRear().isSolid() && !w.isSolid() && GenUtils.chance(rand, 1, 4)) { Chest chest = (Chest) Bukkit.createBlockData(Material.CHEST); chest.setFacing(w.getDirection()); w.setBlockData(chest); data.lootTableChest(w.getX(), w.getY(), w.getZ(), TerraLootTable.DESERT_PYRAMID); } + } w = w.getLeft(); } diff --git a/common/src/main/java/org/terraform/structure/pyramid/WarAntechamber.java b/common/src/main/java/org/terraform/structure/pyramid/WarAntechamber.java index ad2846b1..21a7ec63 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/WarAntechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/WarAntechamber.java @@ -37,8 +37,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey().getUp(2); for (int i = 0; i < entry.getValue(); i++) { - if (w.getRear().isSolid() && !w.isSolid() - && GenUtils.chance(rand, 3, 10)) { + if (w.getRear().isSolid() && !w.isSolid() && GenUtils.chance(rand, 3, 10)) { BannerUtils.generateBanner(rand, w.get(), w.getDirection(), true); } @@ -65,16 +64,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Central Precious Block - w.getRelative(0, room.getHeight() / 2 - 1, 0).setType(GenUtils.randChoice(rand, + w.getRelative(0, room.getHeight() / 2 - 1, 0).setType(GenUtils.randChoice( + rand, Material.GOLD_BLOCK, Material.LAPIS_BLOCK, Material.LAPIS_BLOCK, Material.EMERALD_BLOCK, - Material.IRON_BLOCK)); + Material.IRON_BLOCK + )); } - + @Override public boolean canPopulate(@NotNull CubeRoom room) { return room.getWidthX() >= 6 && room.getWidthZ() >= 6; diff --git a/common/src/main/java/org/terraform/structure/room/CarvedRoom.java b/common/src/main/java/org/terraform/structure/room/CarvedRoom.java index 628cbf71..ef941782 100644 --- a/common/src/main/java/org/terraform/structure/room/CarvedRoom.java +++ b/common/src/main/java/org/terraform/structure/room/CarvedRoom.java @@ -10,10 +10,11 @@ public class CarvedRoom extends CubeRoom { - private float xMultiplier = 1.0f; - private float yMultiplier = 1.0f; - private float zMultiplier = 1.0f; - private float frequency = 0.09f; + private float xMultiplier = 1.0f; + private float yMultiplier = 1.0f; + private float zMultiplier = 1.0f; + private float frequency = 0.09f; + public CarvedRoom(int widthX, int widthZ, int height, int x, int y, int z) { super(widthX, widthZ, height, x, y, z); } @@ -28,45 +29,48 @@ public CarvedRoom(@NotNull CubeRoom room) { @Override public void fillRoom(@NotNull PopulatorDataAbstract data, int tile, Material[] mat, Material fillMat) { int heightOffset = height - (2 * height / 3); - BlockUtils.carveCaveAir(new Random().nextInt(9999291), - xMultiplier*(widthX / 2f), - yMultiplier*(2 * height / 3f), - zMultiplier*(widthZ / 2f), + BlockUtils.carveCaveAir( + new Random().nextInt(9999291), + xMultiplier * (widthX / 2f), + yMultiplier * (2 * height / 3f), + zMultiplier * (widthZ / 2f), frequency, new SimpleBlock(data, x, y + heightOffset, z), true, - true, BlockUtils.caveCarveReplace); + true, + BlockUtils.caveCarveReplace + ); } - public double getxMultiplier() { - return xMultiplier; - } + public double getxMultiplier() { + return xMultiplier; + } - public void setxMultiplier(float xMultiplier) { - this.xMultiplier = xMultiplier; - } + public void setxMultiplier(float xMultiplier) { + this.xMultiplier = xMultiplier; + } - public float getyMultiplier() { - return yMultiplier; - } + public float getyMultiplier() { + return yMultiplier; + } - public void setyMultiplier(float yMultiplier) { - this.yMultiplier = yMultiplier; - } + public void setyMultiplier(float yMultiplier) { + this.yMultiplier = yMultiplier; + } - public float getzMultiplier() { - return zMultiplier; - } + public float getzMultiplier() { + return zMultiplier; + } - public void setzMultiplier(float zMultiplier) { - this.zMultiplier = zMultiplier; - } + public void setzMultiplier(float zMultiplier) { + this.zMultiplier = zMultiplier; + } - public float getFrequency() { - return frequency; - } + public float getFrequency() { + return frequency; + } - public void setFrequency(float frequency) { - this.frequency = frequency; - } + public void setFrequency(float frequency) { + this.frequency = frequency; + } } diff --git a/common/src/main/java/org/terraform/structure/room/CubeRoom.java b/common/src/main/java/org/terraform/structure/room/CubeRoom.java index 2cbbbc83..28302b23 100644 --- a/common/src/main/java/org/terraform/structure/room/CubeRoom.java +++ b/common/src/main/java/org/terraform/structure/room/CubeRoom.java @@ -33,39 +33,38 @@ public CubeRoom(int widthX, int widthZ, int height, int x, int y, int z) { } /** - * @param face Direction of the wall relative to the center + * @param face Direction of the wall relative to the center * @param padding padding of 0 refers to the room's wall. * 1 refers to one layer inside the room and so on. * @return The walls of one side of the room */ - public @NotNull SimpleEntry getWall(@NotNull PopulatorDataAbstract data, @NotNull BlockFace face, int padding) { + public @NotNull SimpleEntry getWall(@NotNull PopulatorDataAbstract data, + @NotNull BlockFace face, + int padding) + { int[] lowerBounds = getLowerCorner(); int[] upperBounds = getUpperCorner(); Wall wall; int length = 0; - switch(face) { + switch (face) { case SOUTH -> { - wall = new Wall( - new SimpleBlock(data, lowerBounds[0] + padding, y + 1, upperBounds[1] - padding) - , BlockFace.NORTH); + wall = new Wall(new SimpleBlock(data, lowerBounds[0] + padding, y + 1, upperBounds[1] - padding), + BlockFace.NORTH); length = widthX - 2 * padding; } case NORTH -> { - wall = new Wall( - new SimpleBlock(data, upperBounds[0] - padding, y + 1, lowerBounds[1] + padding) - , BlockFace.SOUTH); + wall = new Wall(new SimpleBlock(data, upperBounds[0] - padding, y + 1, lowerBounds[1] + padding), + BlockFace.SOUTH); length = widthX - 2 * padding; } case WEST -> { - wall = new Wall( - new SimpleBlock(data, lowerBounds[0] + padding, y + 1, lowerBounds[1] + padding) - , BlockFace.EAST); + wall = new Wall(new SimpleBlock(data, lowerBounds[0] + padding, y + 1, lowerBounds[1] + padding), + BlockFace.EAST); length = widthZ - 2 * padding; } case EAST -> { - wall = new Wall( - new SimpleBlock(data, upperBounds[0] - padding, y + 1, upperBounds[1] - padding) - , BlockFace.WEST); + wall = new Wall(new SimpleBlock(data, upperBounds[0] - padding, y + 1, upperBounds[1] - padding), + BlockFace.WEST); length = widthZ - 2 * padding; } default -> { @@ -81,18 +80,14 @@ public CubeRoom(int widthX, int widthZ, int height, int x, int y, int z) { int[] lowerBounds = getLowerCorner(); int[] upperBounds = getUpperCorner(); HashMap walls = new HashMap<>(); - Wall north = new Wall( - new SimpleBlock(data, lowerBounds[0] + padding, y + 1, upperBounds[1] - padding) - , BlockFace.NORTH); - Wall south = new Wall( - new SimpleBlock(data, upperBounds[0] - padding, y + 1, lowerBounds[1] + padding) - , BlockFace.SOUTH); - Wall east = new Wall( - new SimpleBlock(data, lowerBounds[0] + padding, y + 1, lowerBounds[1] + padding) - , BlockFace.EAST); - Wall west = new Wall( - new SimpleBlock(data, upperBounds[0] - padding, y + 1, upperBounds[1] - padding) - , BlockFace.WEST); + Wall north = new Wall(new SimpleBlock(data, lowerBounds[0] + padding, y + 1, upperBounds[1] - padding), + BlockFace.NORTH); + Wall south = new Wall(new SimpleBlock(data, upperBounds[0] - padding, y + 1, lowerBounds[1] + padding), + BlockFace.SOUTH); + Wall east = new Wall(new SimpleBlock(data, lowerBounds[0] + padding, y + 1, lowerBounds[1] + padding), + BlockFace.EAST); + Wall west = new Wall(new SimpleBlock(data, upperBounds[0] - padding, y + 1, upperBounds[1] - padding), + BlockFace.WEST); walls.put(north, widthX - 2 * padding); walls.put(south, widthX - 2 * padding); @@ -106,7 +101,9 @@ public void setRoomPopulator(RoomPopulatorAbstract pop) { } public void populate(PopulatorDataAbstract data) { - if (pop != null) pop.populate(data, this); + if (pop != null) { + pop.populate(data, this); + } } public void fillRoom(@NotNull PopulatorDataAbstract data, Material... mat) { @@ -115,10 +112,11 @@ public void fillRoom(@NotNull PopulatorDataAbstract data, Material... mat) { /** * Carves a hollow cube room. - * @param data populator data to use for writing - * @param tile whether to treat mat as a pattern to tile with. If this is -1, - * no repetition will occur and instead mat will be sampled randomly - * @param mat the array of materials for the walls, floor and ceiling of the room + * + * @param data populator data to use for writing + * @param tile whether to treat mat as a pattern to tile with. If this is -1, + * no repetition will occur and instead mat will be sampled randomly + * @param mat the array of materials for the walls, floor and ceiling of the room * @param fillMat material to use for the hollow area. Typically a fluid like air or water */ public void fillRoom(@NotNull PopulatorDataAbstract data, int tile, Material[] mat, Material fillMat) { @@ -127,7 +125,7 @@ public void fillRoom(@NotNull PopulatorDataAbstract data, int tile, Material[] m } public int[] getCenter() { - return new int[]{x, y, z}; + return new int[] {x, y, z}; } public @NotNull SimpleBlock getCenterSimpleBlock(@NotNull PopulatorDataAbstract data) { @@ -140,21 +138,29 @@ public double centralDistanceSquared(int @NotNull [] other) { public @NotNull CubeRoom getCloneSubsetRoom(int paddingX, int paddingZ) { - return new CubeRoom(this.widthX - paddingX*2, this.widthZ - paddingZ*2, this.height, this.x, this.y, this.z); + return new CubeRoom( + this.widthX - paddingX * 2, + this.widthZ - paddingZ * 2, + this.height, + this.x, + this.y, + this.z + ); } - + public boolean isClone(@NotNull CubeRoom other) { return this.x == other.x - && this.y == other.y - && this.z == other.z - && this.widthX == other.widthX - && this.height == other.height - && this.widthZ == other.widthZ; + && this.y == other.y + && this.z == other.z + && this.widthX == other.widthX + && this.height == other.height + && this.widthZ == other.widthZ; } public boolean isOverlapping(@NotNull CubeRoom room) { - return Math.abs(room.x - this.x) < (Math.abs(room.widthX + this.widthX) / 2) - && (Math.abs(room.z - this.z) < (Math.abs(room.widthZ + this.widthZ) / 2)); + return Math.abs(room.x - this.x) < (Math.abs(room.widthX + this.widthX) / 2) && (Math.abs(room.z - this.z) < ( + Math.abs(room.widthZ + this.widthZ) + / 2)); } /** @@ -169,8 +175,9 @@ public int[] randomCoords(@NotNull Random rand) { */ public int[] randomCoords(@NotNull Random rand, int pad) { return GenUtils.randomCoords(rand, - new int[]{x - widthX / 2 + pad, y + pad, z - widthZ / 2 + pad}, - new int[]{x + widthX / 2 - pad, y + height - 1 - pad, z + widthZ / 2 - pad}); + new int[] {x - widthX / 2 + pad, y + pad, z - widthZ / 2 + pad}, + new int[] {x + widthX / 2 - pad, y + height - 1 - pad, z + widthZ / 2 - pad} + ); } @@ -181,10 +188,8 @@ public boolean isPointInside(int @NotNull [] point, int pad) { int[] boundOne = getUpperCorner(pad); int[] boundTwo = getLowerCorner(pad); - if (boundOne[0] >= point[0] - && boundOne[1] >= point[1]) { - return boundTwo[0] <= point[0] - && boundTwo[1] <= point[1]; + if (boundOne[0] >= point[0] && boundOne[1] >= point[1]) { + return boundTwo[0] <= point[0] && boundTwo[1] <= point[1]; } return false; @@ -197,10 +202,8 @@ public boolean isPointInside(int @NotNull [] point) { int[] boundOne = getUpperCorner(); int[] boundTwo = getLowerCorner(); - if (boundOne[0] >= point[0] - && boundOne[1] >= point[1]) { - return boundTwo[0] <= point[0] - && boundTwo[1] <= point[1]; + if (boundOne[0] >= point[0] && boundOne[1] >= point[1]) { + return boundTwo[0] <= point[0] && boundTwo[1] <= point[1]; } return false; @@ -213,31 +216,28 @@ public boolean isPointInside(@NotNull SimpleLocation loc) { int[] boundOne = getUpperCorner(); int[] boundTwo = getLowerCorner(); - if (boundOne[0] >= loc.getX() - && boundOne[1] >= loc.getZ()) { - return boundTwo[0] <= loc.getX() - && boundTwo[1] <= loc.getZ(); + if (boundOne[0] >= loc.getX() && boundOne[1] >= loc.getZ()) { + return boundTwo[0] <= loc.getX() && boundTwo[1] <= loc.getZ(); } return false; } - + public @NotNull SimpleLocation getSimpleLocation() { - return new SimpleLocation(getX(),getY(),getZ()); + return new SimpleLocation(getX(), getY(), getZ()); } /** * IGNORES Y AXIS. + * * @param point 2d point (size 2 int array) */ public boolean isPointInside(@NotNull SimpleBlock point) { int[] boundOne = getUpperCorner(); int[] boundTwo = getLowerCorner(); - if (boundOne[0] >= point.getX() - && boundOne[1] >= point.getZ()) { - return boundTwo[0] <= point.getX() - && boundTwo[1] <= point.getZ(); + if (boundOne[0] >= point.getX() && boundOne[1] >= point.getZ()) { + return boundTwo[0] <= point.getX() && boundTwo[1] <= point.getZ(); } return false; @@ -245,8 +245,9 @@ public boolean isPointInside(@NotNull SimpleBlock point) { public boolean isInside(@NotNull CubeRoom other) { for (int[] corner : getAllCorners()) { - if (!other.isPointInside(corner)) + if (!other.isPointInside(corner)) { return false; + } } return true; } @@ -282,10 +283,10 @@ public int[][] getAllCorners() { public int[][] getAllCorners(int padding) { int[][] corners = new int[4][2]; - corners[0] = new int[]{x + widthX / 2 - padding, z + widthZ / 2 - padding}; // ++ - corners[1] = new int[]{x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ - corners[2] = new int[]{x + widthX / 2 - padding, z - widthZ / 2 + padding}; // +- - corners[3] = new int[]{x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- + corners[0] = new int[] {x + widthX / 2 - padding, z + widthZ / 2 - padding}; // ++ + corners[1] = new int[] {x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ + corners[2] = new int[] {x + widthX / 2 - padding, z - widthZ / 2 + padding}; // +- + corners[3] = new int[] {x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- return corners; } @@ -298,17 +299,20 @@ public int[][] getCornersAlongFace(BlockFace face, int padding) { int[][] corners = new int[2][2]; if (face == BlockFace.NORTH) { - corners[0] = new int[]{x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- - corners[1] = new int[]{x + widthX / 2 - padding, z - widthZ / 2 + padding}; // +- - } else if (face == BlockFace.SOUTH) { - corners[0] = new int[]{x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ - corners[1] = new int[]{x + widthX / 2 - padding, z + widthZ / 2 - padding}; // ++ - } else if (face == BlockFace.WEST) { - corners[0] = new int[]{x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- - corners[1] = new int[]{x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ - } else if (face == BlockFace.EAST) { - corners[0] = new int[]{x + widthX / 2 - padding, z - widthZ / 2 + padding}; // -- - corners[1] = new int[]{x + widthX / 2 - padding, z + widthZ / 2 - padding}; // -+ + corners[0] = new int[] {x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- + corners[1] = new int[] {x + widthX / 2 - padding, z - widthZ / 2 + padding}; // +- + } + else if (face == BlockFace.SOUTH) { + corners[0] = new int[] {x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ + corners[1] = new int[] {x + widthX / 2 - padding, z + widthZ / 2 - padding}; // ++ + } + else if (face == BlockFace.WEST) { + corners[0] = new int[] {x - widthX / 2 + padding, z - widthZ / 2 + padding}; // -- + corners[1] = new int[] {x - widthX / 2 + padding, z + widthZ / 2 - padding}; // -+ + } + else if (face == BlockFace.EAST) { + corners[0] = new int[] {x + widthX / 2 - padding, z - widthZ / 2 + padding}; // -- + corners[1] = new int[] {x + widthX / 2 - padding, z + widthZ / 2 - padding}; // -+ } return corners; @@ -316,53 +320,67 @@ public int[][] getCornersAlongFace(BlockFace face, int padding) { // Positive x,z corner public int[] getUpperCorner() { - return new int[]{x + widthX / 2, z + widthZ / 2}; + return new int[] {x + widthX / 2, z + widthZ / 2}; } // Negative x,z corner public int[] getLowerCorner() { - return new int[]{x - widthX / 2, z - widthZ / 2}; + return new int[] {x - widthX / 2, z - widthZ / 2}; } public boolean isInRegion(@NotNull LimitedRegion region) { - return region.isInRegion(x-widthX / 2, y,z-widthZ / 2) - && region.isInRegion(x+widthX / 2, y, z+widthZ / 2); + return region.isInRegion(x - widthX / 2, y, z - widthZ / 2) && region.isInRegion( + x + widthX / 2, + y, + z + widthZ / 2 + ); } // Positive x,z corner public int[] getUpperCorner(int pad) { int Z = z - pad + widthZ / 2; int X = x - pad + widthX / 2; - if (pad > widthZ / 2) Z = z; - if (pad > widthX / 2) X = x; - return new int[]{X, Z}; + if (pad > widthZ / 2) { + Z = z; + } + if (pad > widthX / 2) { + X = x; + } + return new int[] {X, Z}; } // Negative x,z corner public int[] getLowerCorner(int pad) { int Z = z + pad - widthZ / 2; int X = x + pad - widthX / 2; - if (pad > widthZ / 2) Z = z; - if (pad > widthX / 2) X = x; - return new int[]{X, Z}; + if (pad > widthZ / 2) { + Z = z; + } + if (pad > widthX / 2) { + X = x; + } + return new int[] {X, Z}; } /** * Forces all 3D coords in the room with the specified padding to be air. */ public void purgeRoomContents(@NotNull PopulatorDataAbstract data, int padding) { - int[] lowerCorner = getLowerCorner(padding); - int[] upperCorner = getUpperCorner(padding); - int lowestY = y + padding; - int upperY = y + height - padding; - - for(int x = lowerCorner[0]; x<= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) - for(int y = lowestY; y <= upperY; y++) - data.setType(x, y, z, Material.AIR); - } - + int[] lowerCorner = getLowerCorner(padding); + int[] upperCorner = getUpperCorner(padding); + int lowestY = y + padding; + int upperY = y + height - padding; + + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + for (int y = lowestY; y <= upperY; y++) { + data.setType(x, y, z, Material.AIR); + } + } + } + } + public boolean isBig() { return widthX * widthZ * height >= 2000; } @@ -370,7 +388,7 @@ public boolean isBig() { public boolean isHuge() { return widthX * widthZ * height >= 7000; } - + public boolean largerThanVolume(int vol) { return widthX * widthZ * height >= vol; } @@ -462,14 +480,14 @@ public int getZ() { public void setZ(int z) { this.z = z; } - + public void debugRedGround(@NotNull PopulatorDataAbstract data) { - int[] lowerCorner = getLowerCorner(); - int[] upperCorner = getUpperCorner(); - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) { - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setType(x, GenUtils.getHighestGround(data, x, z), z, Material.RED_WOOL); - } - } + int[] lowerCorner = getLowerCorner(); + int[] upperCorner = getUpperCorner(); + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + data.setType(x, GenUtils.getHighestGround(data, x, z), z, Material.RED_WOOL); + } + } } } diff --git a/common/src/main/java/org/terraform/structure/room/LegacyPathGenerator.java b/common/src/main/java/org/terraform/structure/room/LegacyPathGenerator.java index fa8e8173..dd71a3bc 100644 --- a/common/src/main/java/org/terraform/structure/room/LegacyPathGenerator.java +++ b/common/src/main/java/org/terraform/structure/room/LegacyPathGenerator.java @@ -14,34 +14,41 @@ import java.util.Random; public class LegacyPathGenerator { - private final int[] upperBound; - private final int[] lowerBound; @NotNull - final - HashSet path = new HashSet<>(); - PathPopulatorAbstract populator; + final HashSet path = new HashSet<>(); final Random rand; final Material[] mat; + private final int[] upperBound; + private final int[] lowerBound; + private final int maxNoBend; + PathPopulatorAbstract populator; private SimpleBlock base; private BlockFace dir; - private final int maxNoBend; private int straightInARow = 0; private int length = 0; private int pathWidth = 3; private int pathHeight = 3; private boolean dead = false; - public LegacyPathGenerator(SimpleBlock origin, Material[] mat, @NotNull Random rand, int[] upperBound, int[] lowerBound, int maxNoBend) { + public LegacyPathGenerator(SimpleBlock origin, + Material[] mat, + @NotNull Random rand, + int[] upperBound, + int[] lowerBound, + int maxNoBend) + { this.base = origin; this.rand = rand; this.dir = BlockUtils.directBlockFaces[GenUtils.randInt(rand, 0, 3)]; this.upperBound = upperBound; this.lowerBound = lowerBound; this.mat = mat; - if(maxNoBend != -1) - this.maxNoBend = maxNoBend; - else + if (maxNoBend != -1) { + this.maxNoBend = maxNoBend; + } + else { this.maxNoBend = (int) ((upperBound[0] - lowerBound[0]) * 0.5); + } } @SuppressWarnings("BooleanMethodIsAlwaysInverted") @@ -51,23 +58,22 @@ public boolean isDead() { private boolean isOutOfBounds(@NotNull SimpleBlock base) { return base.getX() >= upperBound[0] + 10 - || base.getZ() >= upperBound[1] + 10 - || base.getX() <= lowerBound[0] - 10 - || base.getZ() <= lowerBound[1] - 10; + || base.getZ() >= upperBound[1] + 10 + || base.getX() <= lowerBound[0] - 10 + || base.getZ() <= lowerBound[1] - 10; } public void die() { this.dead = true; wall(); - + PathPopulatorData candidate = new PathPopulatorData(base, dir, pathWidth, false); candidate.isEnd = true; // Prevent overlapping - path populators don't need to rerun against the same locations - if(!path.add(candidate)) - { - path.remove(candidate); - candidate.isOverlapped = true; - path.add(candidate); + if (!path.add(candidate)) { + path.remove(candidate); + candidate.isOverlapped = true; + path.add(candidate); } } @@ -93,20 +99,23 @@ public void placeNext() { BlockFace oldDir = dir; // Only turn if the path is turning at a nice degree // This should prevent weird intersections. - if(length % (1+2*this.pathWidth) == 0) { + if (length % (1 + 2 * this.pathWidth) == 0) { // Make a turn if out of bounds while (isOutOfBounds(base.getRelative(dir))) { straightInARow = 0; // For ensuring that corners are covered. int cover = this.pathWidth - 1; - if (cover == 0) cover = 1; + if (cover == 0) { + cover = 1; + } for (int i = 0; i < cover; i++) { setHall(); base = base.getRelative(dir); } - for (int i = 0; i < cover; i++) + for (int i = 0; i < cover; i++) { base = base.getRelative(dir.getOppositeFace()); + } // turn dir = BlockUtils.getTurnBlockFace(rand, dir); } @@ -118,13 +127,16 @@ public void placeNext() { // For ensuring that corners are covered int cover = this.pathWidth - 1; - if (cover == 0) cover = 1; + if (cover == 0) { + cover = 1; + } for (int i = 0; i < cover; i++) { setHall(); base = base.getRelative(dir); } - for (int i = 0; i < cover; i++) + for (int i = 0; i < cover; i++) { base = base.getRelative(dir.getOppositeFace()); + } // turn dir = BlockUtils.getTurnBlockFace(rand, dir); } @@ -137,15 +149,15 @@ public void placeNext() { // / Handle populating the paths PathPopulatorData candidate = new PathPopulatorData(base, dir, pathWidth, oldDir != dir); - + // Prevent overlapping - path populators don't need to rerun against the same locations - if(!path.contains(candidate)) - path.add(candidate); - else - { - path.remove(candidate); - candidate.isOverlapped = true; - path.add(candidate); + if (!path.contains(candidate)) { + path.add(candidate); + } + else { + path.remove(candidate); + candidate.isOverlapped = true; + path.add(candidate); } base = base.getRelative(dir); @@ -153,32 +165,42 @@ public void placeNext() { } private void wall() { - if (mat[0] == Material.BARRIER) return; - for (int h = 1; h <= pathHeight; h++) - if (base.getRelative(0, h, 0).getType() != Material.CAVE_AIR) + if (mat[0] == Material.BARRIER) { + return; + } + for (int h = 1; h <= pathHeight; h++) { + if (base.getRelative(0, h, 0).getType() != Material.CAVE_AIR) { base.getRelative(0, h, 0).setType(GenUtils.randChoice(mat)); + } + } for (BlockFace f : BlockUtils.getAdjacentFaces(dir)) { SimpleBlock rel = base; for (int i = 0; i <= pathWidth / 2; i++) { rel = rel.getRelative(f); - for (int h = 1; h <= pathHeight; h++) - if (rel.getRelative(0, h, 0).getType() != Material.CAVE_AIR) + for (int h = 1; h <= pathHeight; h++) { + if (rel.getRelative(0, h, 0).getType() != Material.CAVE_AIR) { rel.getRelative(0, h, 0).setType(GenUtils.randChoice(mat)); + } + } } } } private void setHall() { - if (mat[0] == Material.BARRIER) return; + if (mat[0] == Material.BARRIER) { + return; + } - if (base.getType() != Material.CAVE_AIR) + if (base.getType() != Material.CAVE_AIR) { base.setType(GenUtils.randChoice(mat)); + } Wall w = new Wall(base).getUp(); w.Pillar(pathHeight, rand, Material.CAVE_AIR); - if (base.getRelative(0, pathHeight + 1, 0).getType() != Material.CAVE_AIR) + if (base.getRelative(0, pathHeight + 1, 0).getType() != Material.CAVE_AIR) { base.getRelative(0, pathHeight + 1, 0).setType(GenUtils.randChoice(mat)); + } for (BlockFace f : BlockUtils.getAdjacentFaces(dir)) { SimpleBlock rel = base; @@ -186,17 +208,22 @@ private void setHall() { rel = rel.getRelative(f); // Bukkit.getLogger().info(i + ":" + pathWidth/2); if (i == pathWidth / 2) { // Walls - for (int h = 1; h <= pathHeight; h++) - if (rel.getRelative(0, h, 0).getType() != Material.CAVE_AIR) + for (int h = 1; h <= pathHeight; h++) { + if (rel.getRelative(0, h, 0).getType() != Material.CAVE_AIR) { rel.getRelative(0, h, 0).setType(GenUtils.randChoice(mat)); - } else { // Air in hallway (And floor and ceiling) - if (rel.getType() != Material.CAVE_AIR) + } + } + } + else { // Air in hallway (And floor and ceiling) + if (rel.getType() != Material.CAVE_AIR) { rel.setType(GenUtils.randChoice(mat)); - + } + w = new Wall(rel).getUp(); w.Pillar(pathHeight, rand, Material.CAVE_AIR); - if (rel.getRelative(0, pathHeight + 1, 0).getType() != Material.CAVE_AIR) + if (rel.getRelative(0, pathHeight + 1, 0).getType() != Material.CAVE_AIR) { rel.getRelative(0, pathHeight + 1, 0).setType(GenUtils.randChoice(mat)); + } } } } @@ -204,17 +231,24 @@ private void setHall() { /** * Generate a straight path - * @param start Start block. Can be null, in which case base block of the instance is used. + * + * @param start Start block. Can be null, in which case base block of the instance is used. * @param direction Start direction. Can be null, when random direction is used. */ public void generateStraightPath(@Nullable SimpleBlock start, @Nullable BlockFace direction, int length) { ArrayList pathPopulatorDatas = new ArrayList<>(); - if (direction == null) direction = this.dir; - if (start == null) start = this.base; + if (direction == null) { + direction = this.dir; + } + if (start == null) { + start = this.base; + } for (int i = 0; i < length; i++) { - if (!populator.customCarve(start, direction, pathWidth)) setHall(); + if (!populator.customCarve(start, direction, pathWidth)) { + setHall(); + } start = start.getRelative(direction); pathPopulatorDatas.add(new PathPopulatorData(start, direction, pathWidth, false)); } diff --git a/common/src/main/java/org/terraform/structure/room/PathPopulatorAbstract.java b/common/src/main/java/org/terraform/structure/room/PathPopulatorAbstract.java index a41bfc02..3d477cc9 100644 --- a/common/src/main/java/org/terraform/structure/room/PathPopulatorAbstract.java +++ b/common/src/main/java/org/terraform/structure/room/PathPopulatorAbstract.java @@ -12,6 +12,7 @@ public int getPathWidth() { public int getPathHeight() { return 3; } + public int getPathMaxBend() { return -1; } diff --git a/common/src/main/java/org/terraform/structure/room/PathPopulatorData.java b/common/src/main/java/org/terraform/structure/room/PathPopulatorData.java index 1b43f5a0..9d00f040 100644 --- a/common/src/main/java/org/terraform/structure/room/PathPopulatorData.java +++ b/common/src/main/java/org/terraform/structure/room/PathPopulatorData.java @@ -6,10 +6,10 @@ import org.terraform.data.Wall; public class PathPopulatorData { - public SimpleBlock base; public final BlockFace dir; - public boolean isOverlapped = false; public final int pathWidth; + public SimpleBlock base; + public boolean isOverlapped = false; public boolean isTurn; public boolean isEnd = false; @@ -32,9 +32,11 @@ public PathPopulatorData(@NotNull Wall base, int pathWidth) { public int calcRemainder(int multiplier) { if (dir.getModX() != 0) { return base.getX() % multiplier; - } else if (dir.getModZ() != 0) { + } + else if (dir.getModZ() != 0) { return base.getZ() % multiplier; - } else { + } + else { return 0; // BlockFace was not NSEW } } @@ -51,10 +53,12 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (!(obj instanceof PathPopulatorData other)) return false; - return base.getX() == other.base.getX() - && base.getZ() == other.base.getZ() - && base.getY() == other.base.getY(); + if (this == obj) { + return true; + } + if (!(obj instanceof PathPopulatorData other)) { + return false; + } + return base.getX() == other.base.getX() && base.getZ() == other.base.getZ() && base.getY() == other.base.getY(); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/structure/room/RoomLayout.java b/common/src/main/java/org/terraform/structure/room/RoomLayout.java index c0873f2d..fa421b68 100644 --- a/common/src/main/java/org/terraform/structure/room/RoomLayout.java +++ b/common/src/main/java/org/terraform/structure/room/RoomLayout.java @@ -1,6 +1,5 @@ package org.terraform.structure.room; public enum RoomLayout { - RANDOM_BRUTEFORCE, - OVERLAP_CONNECTED + RANDOM_BRUTEFORCE, OVERLAP_CONNECTED } diff --git a/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java b/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java index f306a293..43ca3659 100644 --- a/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java +++ b/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java @@ -1,12 +1,5 @@ package org.terraform.structure.room; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,6 +13,8 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.MazeSpawner; +import java.util.*; + /** * This class is a fucking disgrace. *
    @@ -28,46 +23,42 @@ */ public class RoomLayoutGenerator { - /** - * Needed for normal function or part of the recode - */ - private PathState pathState; private final HashSet rooms = new HashSet<>(); private final int @NotNull [] upperBound; private final int @NotNull [] lowerBound; private final RoomLayout layout; - + /** + * LEGACY SHIT. Disorganised nonsense from a bygone era + */ + private final HashSet pathGens = new HashSet<>(); + private final HashSet pathPopulators = new HashSet<>(); + private final ArrayList roomPops = new ArrayList<>(); + public @Nullable RoomCarver roomCarver = null; + /** + * For stupid transitory phase shit + */ + public Material @NotNull [] wallMaterials = new Material[] {Material.CAVE_AIR}; boolean genPaths = true; + boolean allowOverlaps = false; + /** + * Needed for normal function or part of the recode + */ + private PathState pathState; private int numRooms; private int centX; private int centY; private int centZ; private PathPopulatorAbstract pathPop; - public @Nullable RoomCarver roomCarver = null; private int roomMaxHeight = 7; private int roomMinHeight = 5; private int roomMaxX = 15; private int roomMinX = 10; private int roomMaxZ = 15; private int roomMinZ = 10; - // Range refers to the width of the room placement area. // Note that only room central points follow range so it's possible // for a room's area to exceed this range. private int range; - - /** - * For stupid transitory phase shit - */ - public Material @NotNull [] wallMaterials = new Material[]{Material.CAVE_AIR}; - - /** - * LEGACY SHIT. Disorganised nonsense from a bygone era - */ - private final HashSet pathGens = new HashSet<>(); - private final HashSet pathPopulators = new HashSet<>(); - private final ArrayList roomPops = new ArrayList<>(); - boolean allowOverlaps = false; private Random rand; private boolean carveRooms = false; private float xCarveMul = 1.0f; @@ -77,7 +68,14 @@ public class RoomLayoutGenerator { private MazeSpawner mazePathGenerator; private int tile = -1; - public RoomLayoutGenerator(Random random, RoomLayout layout, int numRooms, int centX, int centY, int centZ, int range) { + public RoomLayoutGenerator(Random random, + RoomLayout layout, + int numRooms, + int centX, + int centY, + int centZ, + int range) + { this.numRooms = numRooms; this.layout = layout; this.centX = centX; @@ -89,9 +87,10 @@ public RoomLayoutGenerator(Random random, RoomLayout layout, int numRooms, int c this.lowerBound = new int[] {centX - range / 2, centZ - range / 2}; } - public @NotNull PathState getOrCalculatePathState(@NotNull TerraformWorld tw){ - if(pathState == null) + public @NotNull PathState getOrCalculatePathState(@NotNull TerraformWorld tw) { + if (pathState == null) { pathState = new PathState(this, tw); + } return pathState; } @@ -132,30 +131,38 @@ public void setPyramid(boolean pyramidish) { public @Nullable CubeRoom forceAddRoom(int widthX, int widthZ, int heightY) { if (layout == RoomLayout.RANDOM_BRUTEFORCE) { - CubeRoom room = new CubeRoom(widthX, widthZ, heightY, + CubeRoom room = new CubeRoom(widthX, + widthZ, + heightY, centX + GenUtils.randInt(rand, -range / 2, range / 2), centY, - centZ + GenUtils.randInt(rand, -range / 2, range / 2)); + centZ + GenUtils.randInt(rand, -range / 2, range / 2) + ); boolean canAdd = false; while (!canAdd) { canAdd = true; - if (!allowOverlaps) + if (!allowOverlaps) { for (CubeRoom other : rooms) { if (other.isOverlapping(room)) { canAdd = false; - room = new CubeRoom(widthX, widthZ, heightY, + room = new CubeRoom(widthX, + widthZ, + heightY, centX + GenUtils.randInt(rand, -range / 2, range / 2), centY, - centZ + GenUtils.randInt(rand, -range / 2, range / 2)); + centZ + GenUtils.randInt(rand, -range / 2, range / 2) + ); break; } } + } } rooms.add(room); return room; - } else { + } + else { // Todo: make force spawn for corner budding return null; } @@ -173,40 +180,48 @@ public void calculateRoomPlacement(boolean normalise) { // Normalise room sizes to prevent strange shapes (Like narrow & tall etc) if (normalise) { - if (widthX < widthZ / 2) widthX = widthZ + GenUtils.randInt(rand, -2, 2); - if (widthZ < widthX / 2) widthZ = widthX + GenUtils.randInt(rand, -2, 2); + if (widthX < widthZ / 2) { + widthX = widthZ + GenUtils.randInt(rand, -2, 2); + } + if (widthZ < widthX / 2) { + widthZ = widthX + GenUtils.randInt(rand, -2, 2); + } } int heightY = GenUtils.randInt(rand, roomMinHeight, roomMaxHeight); if (pyramidish) { double heightRange = 1 - ((Math.pow(nx, 2) + Math.pow(nz, 2)) / Math.pow(range / 2f, 2)); - if (heightRange * roomMaxHeight < roomMinHeight) heightRange = roomMinHeight / (float) roomMaxHeight; + if (heightRange * roomMaxHeight < roomMinHeight) { + heightRange = roomMinHeight / (float) roomMaxHeight; + } // TerraformGeneratorPlugin.logger.info("Original h: " + heightY + "; heightRange: " + heightRange); - heightY = GenUtils.randInt(rand, - roomMinHeight, - (int) (roomMaxHeight * heightRange)); + heightY = GenUtils.randInt(rand, roomMinHeight, (int) (roomMaxHeight * heightRange)); } if (normalise) { - if (heightY > widthX) heightY = widthX + GenUtils.randInt(rand, -2, 2); - if (heightY < widthX / 3) heightY = widthX / 3 + GenUtils.randInt(rand, -2, 2); + if (heightY > widthX) { + heightY = widthX + GenUtils.randInt(rand, -2, 2); + } + if (heightY < widthX / 3) { + heightY = widthX / 3 + GenUtils.randInt(rand, -2, 2); + } } - CubeRoom room = new CubeRoom(widthX, widthZ, heightY, - nx + centX, - centY, - nz + centZ); + CubeRoom room = new CubeRoom(widthX, widthZ, heightY, nx + centX, centY, nz + centZ); if (layout == RoomLayout.RANDOM_BRUTEFORCE) { boolean canAdd = true; - if (!allowOverlaps) + if (!allowOverlaps) { for (CubeRoom other : rooms) { if (other.isOverlapping(room)) { canAdd = false; break; } } - if (canAdd) + } + if (canAdd) { rooms.add(room); - } else if (layout == RoomLayout.OVERLAP_CONNECTED) { + } + } + else if (layout == RoomLayout.OVERLAP_CONNECTED) { room.setX(centX + GenUtils.randInt(rand, -4, 4)); room.setZ(centZ + GenUtils.randInt(rand, -4, 4)); @@ -224,19 +239,25 @@ public void calculateRoomPlacement(boolean normalise) { break; } } - if (canAdd) + if (canAdd) { rooms.add(room); + } } } } public boolean anyOverlaps() { - if (allowOverlaps) return false; + if (allowOverlaps) { + return false; + } for (CubeRoom room : rooms) { for (CubeRoom other : rooms) { - if (other.isClone(room)) continue; - if (room.isOverlapping(other)) + if (other.isClone(room)) { + continue; + } + if (room.isOverlapping(other)) { return true; + } } } return false; @@ -247,8 +268,9 @@ public boolean anyOverlaps() { */ public boolean isInRoom(int @NotNull [] coords) { for (CubeRoom room : rooms) { - if (room.isPointInside(coords)) + if (room.isPointInside(coords)) { return true; + } } return false; } @@ -273,14 +295,18 @@ public void calculateRoomPopulators(@NotNull TerraformWorld tw) if (room.pop == null && pops.canPopulate(room)) { // TerraformGeneratorPlugin.logger.info("Set down forced populator of " + pops.getClass().getName()); room.setRoomPopulator(pops); - if (pops.isUnique()) it.remove(); + if (pops.isUnique()) { + it.remove(); + } break; } } } } - if (roomPops.isEmpty()) return; + if (roomPops.isEmpty()) { + return; + } // Allocate randomly placed room populators for (CubeRoom room : rooms) { @@ -300,9 +326,30 @@ public void calculateRoomPopulators(@NotNull TerraformWorld tw) } } if (room.pop != null) { - TerraformGeneratorPlugin.logger.info("Registered: " + room.pop.getClass().getName() + " at " + room.getX() + " " + room.getY() + " " + room.getZ() + " in a room of size " + room.getWidthX() + "x" + room.getWidthZ()); - } else { - TerraformGeneratorPlugin.logger.info("Registered: plain room at " + room.getX() + " " + room.getY() + " " + room.getZ() + " in a room of size " + room.getWidthX() + "x" + room.getWidthZ()); + TerraformGeneratorPlugin.logger.info("Registered: " + + room.pop.getClass().getName() + + " at " + + room.getX() + + " " + + room.getY() + + " " + + room.getZ() + + " in a room of size " + + room.getWidthX() + + "x" + + room.getWidthZ()); + } + else { + TerraformGeneratorPlugin.logger.info("Registered: plain room at " + + room.getX() + + " " + + room.getY() + + " " + + room.getZ() + + " in a room of size " + + room.getWidthX() + + "x" + + room.getWidthZ()); } } } @@ -311,17 +358,20 @@ public void calculateRoomPopulators(@NotNull TerraformWorld tw) * @Deprecated don't use this for new structures. Use the new jigsaw system */ @Deprecated - public void runRoomPopulators(PopulatorDataAbstract data, @NotNull TerraformWorld tw) { - // Allocate room populators + public void runRoomPopulators(PopulatorDataAbstract data, @NotNull TerraformWorld tw) { + // Allocate room populators calculateRoomPopulators(tw); - if (roomPops.isEmpty()) return; + if (roomPops.isEmpty()) { + return; + } - rooms.forEach((room)->room.populate(data)); + rooms.forEach((room) -> room.populate(data)); } /** * Links room populators to empty rooms and applies paths and room to the actual world. + * * @param mat Material to use for lining room walls. */ public void fill(@NotNull PopulatorDataAbstract data, @NotNull TerraformWorld tw, Material... mat) { @@ -340,88 +390,109 @@ public void fill(@NotNull PopulatorDataAbstract data, @NotNull TerraformWorld tw } mazePathGenerator.prepareMaze(); mazePathGenerator.carveMaze(false, mat); - } else + } + else { for (CubeRoom room : rooms) { - SimpleBlock base = new SimpleBlock( - data, - room.getX() + room.getX() % (pathPop.getPathWidth()*2+1), - room.getY(), - room.getZ() + room.getZ() % (pathPop.getPathWidth()*2+1) - ); - LegacyPathGenerator gen = new LegacyPathGenerator(base, mat, rand, upperBound, lowerBound, pathPop.getPathMaxBend()); - if (pathPop != null) gen.setPopulator(pathPop); + SimpleBlock base = new SimpleBlock(data, + room.getX() + room.getX() % (pathPop.getPathWidth() * 2 + 1), + room.getY(), + room.getZ() + room.getZ() % (pathPop.getPathWidth() * 2 + 1) + ); + LegacyPathGenerator gen = new LegacyPathGenerator(base, + mat, + rand, + upperBound, + lowerBound, + pathPop.getPathMaxBend() + ); + if (pathPop != null) { + gen.setPopulator(pathPop); + } while (!gen.isDead()) { gen.placeNext(); } pathGens.add(gen); } + } } // Create empty rooms for (CubeRoom room : rooms) { if (carveRooms) { - room = new CarvedRoom(room); - // TerraformGeneratorPlugin.logger.info("Vol: " + (room.getWidthX() * room.getWidthZ() * room.getHeight())); - if(room.largerThanVolume(40000)) { - // TerraformGeneratorPlugin.logger.info("Larger Room Invoked"); - ((CarvedRoom) room).setFrequency(0.03f); - } - ((CarvedRoom) room).setxMultiplier(this.xCarveMul); - ((CarvedRoom) room).setyMultiplier(this.yCarveMul); - ((CarvedRoom) room).setzMultiplier(this.zCarveMul); + room = new CarvedRoom(room); + // TerraformGeneratorPlugin.logger.info("Vol: " + (room.getWidthX() * room.getWidthZ() * room.getHeight())); + if (room.largerThanVolume(40000)) { + // TerraformGeneratorPlugin.logger.info("Larger Room Invoked"); + ((CarvedRoom) room).setFrequency(0.03f); + } + ((CarvedRoom) room).setxMultiplier(this.xCarveMul); + ((CarvedRoom) room).setyMultiplier(this.yCarveMul); + ((CarvedRoom) room).setzMultiplier(this.zCarveMul); } - if (allowOverlaps) + if (allowOverlaps) { room.fillRoom(data, tile, mat, Material.CAVE_AIR); - else + } + else { room.fillRoom(data, tile, mat, Material.AIR); + } } // Populate pathways if (mazePathGenerator != null && this.pathPop != null) { for (PathPopulatorData pPData : mazePathGenerator.pathPopDatas) { - if (!this.isInRoom(new int[]{pPData.base.getX(), pPData.base.getZ()})) + if (!this.isInRoom(new int[] {pPData.base.getX(), pPData.base.getZ()})) { this.pathPop.populate(pPData); + } } - } else { + } + else { for (LegacyPathGenerator pGen : pathGens) { - // TerraformGeneratorPlugin.logger.info("pathgen"); + // TerraformGeneratorPlugin.logger.info("pathgen"); pGen.populate(); } } - if (roomPops.isEmpty()) return; + if (roomPops.isEmpty()) { + return; + } runRoomPopulators(data, tw); } public void carveRoomsOnly(@NotNull PopulatorDataAbstract data, TerraformWorld tw, Material... mat) { - // Create empty rooms + // Create empty rooms for (CubeRoom room : rooms) { if (carveRooms) { - room = new CarvedRoom(room); - if(room.largerThanVolume(40000)) - ((CarvedRoom) room).setFrequency(0.03f); - ((CarvedRoom) room).setxMultiplier(this.xCarveMul); - ((CarvedRoom) room).setyMultiplier(this.yCarveMul); - ((CarvedRoom) room).setzMultiplier(this.zCarveMul); + room = new CarvedRoom(room); + if (room.largerThanVolume(40000)) { + ((CarvedRoom) room).setFrequency(0.03f); + } + ((CarvedRoom) room).setxMultiplier(this.xCarveMul); + ((CarvedRoom) room).setyMultiplier(this.yCarveMul); + ((CarvedRoom) room).setzMultiplier(this.zCarveMul); } - if (allowOverlaps) + if (allowOverlaps) { room.fillRoom(data, tile, mat, Material.CAVE_AIR); - else + } + else { room.fillRoom(data, tile, mat, Material.AIR); + } } } /** + * */ public void fillRoomsOnly(@NotNull PopulatorDataAbstract data, @NotNull TerraformWorld tw, Material... mat) { - carveRoomsOnly(data,tw,mat); + carveRoomsOnly(data, tw, mat); - if (roomPops.isEmpty()) return; + if (roomPops.isEmpty()) { + return; + } runRoomPopulators(data, tw); @@ -429,16 +500,25 @@ public void fillRoomsOnly(@NotNull PopulatorDataAbstract data, @NotNull Terrafor public void carvePathsOnly(@NotNull PopulatorDataAbstract data, TerraformWorld tw, Material... mat) { // ArrayList pathGens = new ArrayList<>(); - if (genPaths) + if (genPaths) { for (CubeRoom room : rooms) { SimpleBlock base = new SimpleBlock(data, room.getX(), room.getY(), room.getZ()); - LegacyPathGenerator gen = new LegacyPathGenerator(base, mat, rand, upperBound, lowerBound, pathPop.getPathMaxBend()); - if (pathPop != null) gen.setPopulator(pathPop); + LegacyPathGenerator gen = new LegacyPathGenerator(base, + mat, + rand, + upperBound, + lowerBound, + pathPop.getPathMaxBend() + ); + if (pathPop != null) { + gen.setPopulator(pathPop); + } while (!gen.isDead()) { gen.placeNext(); } pathGens.add(gen); } + } } @@ -454,7 +534,7 @@ public void populatePathsOnly() { } public void fillPathsOnly(@NotNull PopulatorDataAbstract data, TerraformWorld tw, Material... mat) { - carvePathsOnly(data,tw,mat); + carvePathsOnly(data, tw, mat); populatePathsOnly(); } @@ -649,30 +729,39 @@ public void setMazePathGenerator(MazeSpawner mazePathGenerator) { this.mazePathGenerator = mazePathGenerator; } - public @NotNull HashSet getPathPopulators(){ - if(this.pathPopulators.isEmpty()) { - for(LegacyPathGenerator pGen:this.pathGens) { - this.pathPopulators.addAll(pGen.path); - } - } - return this.pathPopulators; + public @NotNull HashSet getPathPopulators() { + if (this.pathPopulators.isEmpty()) { + for (LegacyPathGenerator pGen : this.pathGens) { + this.pathPopulators.addAll(pGen.path); + } + } + return this.pathPopulators; } public boolean isPointInPath(@NotNull Wall w, int rearOffset, int includeWidth) { - if(getPathPopulators().contains(new PathPopulatorData(w.getRear(rearOffset).getAtY(centY), 3))) - return true; - if(includeWidth != 0) - for(int i = 1; i < includeWidth; i++) { - if(getPathPopulators().contains(new PathPopulatorData( - w.getRear(rearOffset).getLeft(i).getAtY(centY), 3))) - return true; - - if(getPathPopulators().contains(new PathPopulatorData( - w.getRear(rearOffset).getRight(i).getAtY(centY), 3))) - return true; - } - return false; + if (getPathPopulators().contains(new PathPopulatorData(w.getRear(rearOffset).getAtY(centY), 3))) { + return true; + } + if (includeWidth != 0) { + for (int i = 1; i < includeWidth; i++) { + if (getPathPopulators().contains(new PathPopulatorData(w.getRear(rearOffset).getLeft(i).getAtY(centY), + 3 + ))) + { + return true; + } + + if (getPathPopulators().contains(new PathPopulatorData(w.getRear(rearOffset).getRight(i).getAtY(centY), + 3 + ))) + { + return true; + } + } + } + return false; } + public boolean genPaths() { return genPaths; } diff --git a/common/src/main/java/org/terraform/structure/room/RoomPopulatorAbstract.java b/common/src/main/java/org/terraform/structure/room/RoomPopulatorAbstract.java index d80c7c65..fe0f71bb 100644 --- a/common/src/main/java/org/terraform/structure/room/RoomPopulatorAbstract.java +++ b/common/src/main/java/org/terraform/structure/room/RoomPopulatorAbstract.java @@ -1,13 +1,13 @@ package org.terraform.structure.room; -import java.util.Random; - import org.terraform.coregen.populatordata.PopulatorDataAbstract; +import java.util.Random; + public abstract class RoomPopulatorAbstract { + public final Random rand; private final boolean forceSpawn; private final boolean unique; - public final Random rand; public RoomPopulatorAbstract(Random rand, boolean forceSpawn, boolean unique) { this.rand = rand; @@ -17,7 +17,9 @@ public RoomPopulatorAbstract(Random rand, boolean forceSpawn, boolean unique) { protected static int getNextIndex(int bfIndex) { bfIndex++; - if (bfIndex >= 8) bfIndex = 0; + if (bfIndex >= 8) { + bfIndex = 0; + } return bfIndex; } diff --git a/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java b/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java index ab0b704b..ec5aa979 100644 --- a/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java +++ b/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java @@ -7,16 +7,23 @@ import org.terraform.structure.room.CubeRoom; import org.terraform.utils.BlockUtils; -public class CaveRoomCarver extends RoomCarver{ +public class CaveRoomCarver extends RoomCarver { private float xMultiplier = 1.0f; private float yMultiplier = 1.0f; private float zMultiplier = 1.0f; private float frequency = 0.09f; private float largeRoomFrequency = 0.03f; - public CaveRoomCarver(){} - public CaveRoomCarver(float xMultiplier, float yMultiplier, float zMultiplier, float frequency, float largeRoomFrequency) { + public CaveRoomCarver() { + } + + public CaveRoomCarver(float xMultiplier, + float yMultiplier, + float zMultiplier, + float frequency, + float largeRoomFrequency) + { this.xMultiplier = xMultiplier; this.yMultiplier = yMultiplier; this.zMultiplier = zMultiplier; @@ -27,13 +34,17 @@ public CaveRoomCarver(float xMultiplier, float yMultiplier, float zMultiplier, f @Override public void carveRoom(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room, Material... wallMaterial) { int heightOffset = room.getHeight() - (2 * room.getHeight() / 3); - BlockUtils.carveCaveAir(data.getTerraformWorld().getHashedRand(room.getX(), room.getY(), room.getZ()).nextInt(9999291), - xMultiplier*(room.getWidthX() / 2f), - yMultiplier*(2 * room.getHeight() / 3f), - zMultiplier*(room.getWidthZ() / 2f), + BlockUtils.carveCaveAir(data.getTerraformWorld() + .getHashedRand(room.getX(), room.getY(), room.getZ()) + .nextInt(9999291), + xMultiplier * (room.getWidthX() / 2f), + yMultiplier * (2 * room.getHeight() / 3f), + zMultiplier * (room.getWidthZ() / 2f), room.largerThanVolume(40000) ? largeRoomFrequency : frequency, new SimpleBlock(data, room.getX(), room.getY() + heightOffset, room.getZ()), true, - true, BlockUtils.caveCarveReplace); + true, + BlockUtils.caveCarveReplace + ); } } diff --git a/common/src/main/java/org/terraform/structure/room/carver/StandardRoomCarver.java b/common/src/main/java/org/terraform/structure/room/carver/StandardRoomCarver.java index c5410b02..2ebe800c 100644 --- a/common/src/main/java/org/terraform/structure/room/carver/StandardRoomCarver.java +++ b/common/src/main/java/org/terraform/structure/room/carver/StandardRoomCarver.java @@ -9,7 +9,7 @@ /** * This one will carve a cube room with the specified wall material */ -public class StandardRoomCarver extends RoomCarver{ +public class StandardRoomCarver extends RoomCarver { final int tile; final Material fillMat; @@ -23,26 +23,41 @@ public void carveRoom(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom roo // 30/1/2024 God you really were a shit programmer what the fuck is this int tileIndex = 0; if (mat[0] != Material.BARRIER) - // Create a solid block with the specified width + // Create a solid block with the specified width + { for (int nx = room.getX() - room.getWidthX() / 2; nx <= room.getX() + room.getWidthX() / 2; nx++) { for (int ny = room.getY(); ny <= room.getY() + room.getHeight(); ny++) { for (int nz = room.getZ() - room.getWidthZ() / 2; nz <= room.getZ() + room.getWidthZ() / 2; nz++) { - if (data.getType(nx, ny, nz) == Material.CAVE_AIR) + if (data.getType(nx, ny, nz) == Material.CAVE_AIR) { continue; - if (tile == -1) data.setType(nx, ny, nz, GenUtils.randChoice(mat)); + } + if (tile == -1) { + data.setType(nx, ny, nz, GenUtils.randChoice(mat)); + } else { - data.setType(nx, ny, nz, mat[(Math.abs(nz + room.getWidthZ() / 2 + ny + nx + room.getWidthX() / 2 - tileIndex)) % mat.length]); + data.setType( + nx, + ny, + nz, + mat[(Math.abs(nz + room.getWidthZ() / 2 + ny + nx + room.getWidthX() / 2 + - tileIndex)) % mat.length] + ); tileIndex += 1; - if (tileIndex == 2) tileIndex = 0; + if (tileIndex == 2) { + tileIndex = 0; + } } } } } + } // Hollow out the room for (int nx = room.getX() - room.getWidthX() / 2 + 1; nx <= room.getX() + room.getWidthX() / 2 - 1; nx++) { for (int ny = room.getY() + 1; ny <= room.getY() + room.getHeight() - 1; ny++) { - for (int nz = room.getZ() - room.getWidthZ() / 2 + 1; nz <= room.getZ() + room.getWidthZ() / 2 - 1; nz++) { + for (int nz = room.getZ() - room.getWidthZ() / 2 + 1; + nz <= room.getZ() + room.getWidthZ() / 2 - 1; + nz++) { data.setType(nx, ny, nz, fillMat); } } diff --git a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawBuilder.java b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawBuilder.java index 02f8a018..68d95a6c 100644 --- a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawBuilder.java @@ -8,16 +8,10 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Random; -import java.util.Stack; +import java.util.*; /** * This class has nothing to do with the new system @@ -28,19 +22,19 @@ public class JigsawBuilder { protected final int @NotNull [] lowerBounds = new int[2]; protected final int @NotNull [] upperBounds = new int[2]; protected final int maxDepth = 5; // The amount of pieces before an end piece is forced. + protected final SimpleBlock core; + protected final @NotNull Stack traverseStack = new Stack<>(); + protected final @NotNull HashMap pieces = new HashMap<>(); + protected final @NotNull ArrayList overlapperPieces = new ArrayList<>(); protected int chanceToAddNewPiece = 60; protected int minimumPieces = 0; protected int pieceWidth = 5; - protected final SimpleBlock core; protected @Nullable JigsawStructurePiece center; protected Wall entranceBlock; - protected final @NotNull Stack traverseStack = new Stack<>(); - protected final @NotNull HashMap pieces = new HashMap<>(); - protected final @NotNull ArrayList overlapperPieces = new ArrayList<>(); protected JigsawStructurePiece[] pieceRegistry; protected BlockFace entranceDir; - int traversalIndex = 0; protected boolean hasPlacedEntrance = false; + int traversalIndex = 0; public JigsawBuilder(int widthX, int widthZ, @NotNull PopulatorDataAbstract data, int x, int y, int z) { this.widthX = widthX; @@ -56,9 +50,9 @@ public JigsawBuilder(int widthX, int widthZ, @NotNull PopulatorDataAbstract data public void forceEntranceDirection(BlockFace face) { entranceDir = face; } - + public BlockFace getEntranceDirection() { - return entranceDir; + return entranceDir; } public @Nullable JigsawStructurePiece getFirstPiece(@NotNull Random random) { @@ -73,43 +67,49 @@ public void generate(@NotNull Random random) { center.getRoom().setZ(core.getZ()); pieces.put(new SimpleLocation(core.getX(), core.getY(), core.getZ()), center); traverseStack.push(center); - while (!areAllPiecesCovered()) - if (!traverseAndPopulatePieces(random)) break; - + while (!areAllPiecesCovered()) { + if (!traverseAndPopulatePieces(random)) { + break; + } + } + // MAKE SURE NO CELL HAS 4 WALLS. Remove all 4 walls and // replace it with a room. ArrayList problemCells = new ArrayList<>(); HashMap map = new HashMap<>(); - for(JigsawStructurePiece piece:overlapperPieces) { - if(map.containsKey(piece.getRoom().getSimpleLocation())) { - map.put(piece.getRoom().getSimpleLocation(), map.get(piece.getRoom().getSimpleLocation())+1); - }else { - map.put(piece.getRoom().getSimpleLocation(), 1); - } - if(map.get(piece.getRoom().getSimpleLocation()) >= 4) { - // 4 wall thing spotted. That's bad. Try to replace it. - problemCells.add(piece.getRoom().getSimpleLocation()); - TerraformGeneratorPlugin.logger.info("Found problem piece. Attempting to replace with room."); - } + for (JigsawStructurePiece piece : overlapperPieces) { + if (map.containsKey(piece.getRoom().getSimpleLocation())) { + map.put(piece.getRoom().getSimpleLocation(), map.get(piece.getRoom().getSimpleLocation()) + 1); + } + else { + map.put(piece.getRoom().getSimpleLocation(), 1); + } + if (map.get(piece.getRoom().getSimpleLocation()) >= 4) { + // 4 wall thing spotted. That's bad. Try to replace it. + problemCells.add(piece.getRoom().getSimpleLocation()); + TerraformGeneratorPlugin.logger.info("Found problem piece. Attempting to replace with room."); + } } - if(!problemCells.isEmpty()) { + if (!problemCells.isEmpty()) { overlapperPieces.removeIf(piece -> problemCells.contains(piece.getRoom().getSimpleLocation())); - - for(SimpleLocation loc:problemCells) { - - JigsawStructurePiece toAdd = getPiece(pieceRegistry, JigsawType.STANDARD, random) - .getInstance(random, 0); - - toAdd.getRoom().setX(loc.getX()); - toAdd.getRoom().setY(loc.getY()); - toAdd.getRoom().setZ(loc.getZ()); - - toAdd.setPopulated(BlockFace.NORTH); - toAdd.setPopulated(BlockFace.SOUTH); - toAdd.setPopulated(BlockFace.EAST); - toAdd.setPopulated(BlockFace.WEST); - pieces.put(loc, toAdd); - TerraformGeneratorPlugin.logger.info("Patched problem piece with new room."); + + for (SimpleLocation loc : problemCells) { + + JigsawStructurePiece toAdd = getPiece(pieceRegistry, JigsawType.STANDARD, random).getInstance( + random, + 0 + ); + + toAdd.getRoom().setX(loc.getX()); + toAdd.getRoom().setY(loc.getY()); + toAdd.getRoom().setZ(loc.getZ()); + + toAdd.setPopulated(BlockFace.NORTH); + toAdd.setPopulated(BlockFace.SOUTH); + toAdd.setPopulated(BlockFace.EAST); + toAdd.setPopulated(BlockFace.WEST); + pieces.put(loc, toAdd); + TerraformGeneratorPlugin.logger.info("Patched problem piece with new room."); } } } @@ -118,7 +118,7 @@ public boolean traverseAndPopulatePieces(@NotNull Random random) { if (traverseStack.isEmpty()) { TerraformGeneratorPlugin.logger.info("Jigsaw stack size empty!"); return false; - } + } JigsawStructurePiece current = traverseStack.peek(); // TerraformGeneratorPlugin.logger.info("Traversal Index " + traversalIndex + ", on: " + current.toString()); traversalIndex++; @@ -136,32 +136,49 @@ public boolean traverseAndPopulatePieces(@NotNull Random random) { if (!pieces.containsKey(newLoc)) { if (dir == BlockFace.UP) { // Place an upper connector piece - toAdd = getRelativePiece(current, JigsawType.UPPERCONNECTOR, random) - .getInstance(random, current.getDepth() + 1); + toAdd = getRelativePiece(current, JigsawType.UPPERCONNECTOR, random).getInstance( + random, + current.getDepth() + 1 + ); toAdd.setRotation(BlockUtils.getDirectBlockFace(random)); toAdd.setElevation(current.getElevation() + 1); - } else { + } + else { // Depth is too high (prevent recursion) if (current.getDepth() >= maxDepth) { // Place an end - toAdd = getRelativePiece(current, JigsawType.END, random) - .getInstance(random, current.getDepth() + 1); + toAdd = getRelativePiece(current, JigsawType.END, random).getInstance( + random, + current.getDepth() + 1 + ); toAdd.setRotation(dir); - } else { - if (toAddX - pieceWidth / 2 < lowerBounds[0] || toAddX + pieceWidth / 2 > upperBounds[0] - || toAddZ - pieceWidth / 2 < lowerBounds[1] || toAddZ + pieceWidth / 2 > upperBounds[1]) { + } + else { + if (toAddX - pieceWidth / 2 < lowerBounds[0] + || toAddX + pieceWidth / 2 > upperBounds[0] + || toAddZ - pieceWidth / 2 < lowerBounds[1] + || toAddZ + pieceWidth / 2 > upperBounds[1]) + { // If outside of bounding box, just force an end piece. - toAdd = getRelativePiece(current, JigsawType.END, random) - .getInstance(random, current.getDepth() + 1); + toAdd = getRelativePiece(current, JigsawType.END, random).getInstance( + random, + current.getDepth() + 1 + ); toAdd.setRotation(dir); - } else if (pieces.size() > minimumPieces && !GenUtils.chance(random, chanceToAddNewPiece, 100)) { + } + else if (pieces.size() > minimumPieces && !GenUtils.chance(random, chanceToAddNewPiece, 100)) { // Failed chance to add. Force wall. - toAdd = getRelativePiece(current, JigsawType.END, random) - .getInstance(random, current.getDepth() + 1); + toAdd = getRelativePiece(current, JigsawType.END, random).getInstance( + random, + current.getDepth() + 1 + ); toAdd.setRotation(dir); - } else { + } + else { // Place a standard piece - toAdd = getRelativePiece(current, JigsawType.STANDARD, random) - .getInstance(random, current.getDepth() + 1); + toAdd = getRelativePiece(current, JigsawType.STANDARD, random).getInstance( + random, + current.getDepth() + 1 + ); } } } @@ -176,20 +193,23 @@ public boolean traverseAndPopulatePieces(@NotNull Random random) { // TerraformGeneratorPlugin.logger.info("New location: " + new SimpleLocation(toAddX, toAddY, toAddZ)); - if (toAdd.getType() == JigsawType.END) + if (toAdd.getType() == JigsawType.END) { overlapperPieces.add(toAdd); + } if (toAdd.getType() != JigsawType.END) { pieces.put(newLoc, toAdd); traverseStack.push(toAdd); } - } else { // The location exists in the map already + } + else { // The location exists in the map already JigsawStructurePiece other = pieces.get(newLoc); current.setPopulated(dir); other.setPopulated(dir.getOppositeFace()); } - } else { + } + else { traverseStack.pop(); // Go to the previous piece to continue populating } return true; @@ -198,8 +218,9 @@ public boolean traverseAndPopulatePieces(@NotNull Random random) { public boolean areAllPiecesCovered() { for (JigsawStructurePiece piece : pieces.values()) { // TerraformGeneratorPlugin.logger.info("Checking " + piece.toString()); - if (piece.hasUnpopulatedDirections()) + if (piece.hasUnpopulatedDirections()) { return false; + } } return true; } @@ -215,9 +236,9 @@ public SimpleBlock getCore() { public void build(@NotNull Random random) { for (JigsawStructurePiece piece : pieces.values()) { - // Force room to be air first + // Force room to be air first piece.getRoom().purgeRoomContents(core.getPopData(), 0); - + // Build room piece.build(core.getPopData(), random); } @@ -228,105 +249,119 @@ public void build(@NotNull Random random) { Collections.shuffle(overlapperPieces); for (JigsawStructurePiece piece : overlapperPieces) { // Don't place overlapper objects where rooms have been placed. - SimpleLocation pieceLoc = new SimpleLocation(piece.getRoom().getX(), piece.getRoom().getY(), piece.getRoom().getZ()); + SimpleLocation pieceLoc = new SimpleLocation( + piece.getRoom().getX(), + piece.getRoom().getY(), + piece.getRoom().getZ() + ); if (pieces.containsKey(pieceLoc)) { toRemove.add(piece); continue; } if (!hasPlacedEntrance) { if (entranceDir == null // Random block face direction - || (piece.getRotation() == entranceDir)) // Forced entrance direction + || (piece.getRotation() == entranceDir)) // Forced entrance direction { - // This check is to ensure that entrances aren't walled up in 4 sides. - if(canPlaceEntrance(pieceLoc)) { - // Place an entrance if none was placed before. - hasPlacedEntrance = true; - entrance = getPiece(pieceRegistry, JigsawType.ENTRANCE, random) - .getInstance(random, piece.getDepth()); - entrance.getRoom().setX(piece.getRoom().getX()); - entrance.getRoom().setY(piece.getRoom().getY()); - entrance.getRoom().setZ(piece.getRoom().getZ()); - entrance.setRotation(piece.getRotation()); - entranceBlock = new Wall( - new SimpleBlock( - core.getPopData(), - piece.getRoom().getX(), - piece.getRoom().getY(), - piece.getRoom().getZ()), - piece.getRotation()); - piece = entrance; - } + // This check is to ensure that entrances aren't walled up in 4 sides. + if (canPlaceEntrance(pieceLoc)) { + // Place an entrance if none was placed before. + hasPlacedEntrance = true; + entrance = getPiece(pieceRegistry, JigsawType.ENTRANCE, random).getInstance( + random, + piece.getDepth() + ); + entrance.getRoom().setX(piece.getRoom().getX()); + entrance.getRoom().setY(piece.getRoom().getY()); + entrance.getRoom().setZ(piece.getRoom().getZ()); + entrance.setRotation(piece.getRotation()); + entranceBlock = new Wall(new SimpleBlock(core.getPopData(), + piece.getRoom().getX(), + piece.getRoom().getY(), + piece.getRoom().getZ() + ), piece.getRotation()); + piece = entrance; + } } } JigsawStructurePiece host = getAdjacentPiece(pieceLoc, piece.getRotation().getOppositeFace()); - if (host != null) + if (host != null) { host.getWalledFaces().add(piece.getRotation()); + } // TerraformGeneratorPlugin.logger.info("Populating at " + piece.getClass().getSimpleName() + "::" + piece.getRoom().getX() + "," + piece.getRoom().getZ() + "," + piece.getRotation()); piece.build(core.getPopData(), random); } // Remove pieces that weren't placed and replace the unused wall with the entrance. Iterator it = overlapperPieces.iterator(); - while(it.hasNext()) { - JigsawStructurePiece piece = it.next(); - if(toRemove.contains(piece)) - it.remove(); - else if(piece.getRoom().getSimpleLocation().equals(entrance.getRoom().getSimpleLocation()) - && piece.getRotation() == entrance.getRotation()) - it.remove(); + while (it.hasNext()) { + JigsawStructurePiece piece = it.next(); + if (toRemove.contains(piece)) { + it.remove(); + } + else if (piece.getRoom().getSimpleLocation().equals(entrance.getRoom().getSimpleLocation()) + && piece.getRotation() == entrance.getRotation()) + { + it.remove(); + } } overlapperPieces.add(entrance); } - + public boolean canPlaceEntrance(SimpleLocation pieceLoc) { - return this.countOverlappingPiecesAtLocation(pieceLoc) != 4; - } - - public int countOverlappingPiecesAtLocation(SimpleLocation loc) { - int count = 0; - for(JigsawStructurePiece wall:overlapperPieces) - if(wall.getRoom().getSimpleLocation().equals(loc)) - count++; - return count; + return this.countOverlappingPiecesAtLocation(pieceLoc) != 4; + } + + public int countOverlappingPiecesAtLocation(SimpleLocation loc) { + int count = 0; + for (JigsawStructurePiece wall : overlapperPieces) { + if (wall.getRoom().getSimpleLocation().equals(loc)) { + count++; + } + } + return count; } public JigsawStructurePiece getAdjacentPiece(@NotNull SimpleLocation loc, @NotNull BlockFace face) { - SimpleLocation other = new SimpleLocation( - loc.getX() + face.getModX() * pieceWidth, + SimpleLocation other = new SimpleLocation(loc.getX() + face.getModX() * pieceWidth, loc.getY() + face.getModY() * pieceWidth, - loc.getZ() + face.getModZ() * pieceWidth); + loc.getZ() + face.getModZ() * pieceWidth + ); return pieces.get(other); } - + public @Nullable JigsawStructurePiece getAdjacentWall(@NotNull SimpleLocation loc, @NotNull BlockFace face) { - SimpleLocation other = new SimpleLocation( - loc.getX() + face.getModX() * pieceWidth, + SimpleLocation other = new SimpleLocation(loc.getX() + face.getModX() * pieceWidth, loc.getY() + face.getModY() * pieceWidth, - loc.getZ() + face.getModZ() * pieceWidth); - for(JigsawStructurePiece wall:overlapperPieces) { - if(wall.getRotation() == face && wall.getRoom().getSimpleLocation().equals(other)) { - return wall; - } + loc.getZ() + face.getModZ() * pieceWidth + ); + for (JigsawStructurePiece wall : overlapperPieces) { + if (wall.getRotation() == face && wall.getRoom().getSimpleLocation().equals(other)) { + return wall; + } } return null; } - public @Nullable JigsawStructurePiece getPiece(JigsawStructurePiece[] registry, JigsawType type, @NotNull Random rand) { + public @Nullable JigsawStructurePiece getPiece(JigsawStructurePiece[] registry, + JigsawType type, + @NotNull Random rand) + { ArrayList validPieces = new ArrayList<>(); for (JigsawStructurePiece piece : pieceRegistry) { - boolean dontPlace = false; + boolean dontPlace = false; if (piece.getType() == type) { - if(piece.isUnique()) { - for(JigsawStructurePiece present : this.pieces.values()) { - - if(present.getClass().equals(piece.getClass())) { - dontPlace = true; - break; - } - } - } - if(!dontPlace) - validPieces.add(piece); + if (piece.isUnique()) { + for (JigsawStructurePiece present : this.pieces.values()) { + + if (present.getClass().equals(piece.getClass())) { + dontPlace = true; + break; + } + } + } + if (!dontPlace) { + validPieces.add(piece); + } } } if (validPieces.isEmpty()) { @@ -337,10 +372,14 @@ public JigsawStructurePiece getAdjacentPiece(@NotNull SimpleLocation loc, @NotNu return validPieces.get(rand.nextInt(validPieces.size())); } - public @Nullable JigsawStructurePiece getRelativePiece(@Nullable JigsawStructurePiece current, JigsawType type, @NotNull Random random) { + public @Nullable JigsawStructurePiece getRelativePiece(@Nullable JigsawStructurePiece current, + JigsawType type, + @NotNull Random random) + { if (current == null || (current.getAllowedPieces() != null && current.getAllowedPieces().length == 0)) { return getPiece(pieceRegistry, type, random); - } else { + } + else { return getPiece(current.getAllowedPieces(), type, random); } } @@ -353,7 +392,7 @@ public Wall getEntranceBlock() { return entranceBlock; } - public @NotNull ArrayList getOverlapperPieces() { - return overlapperPieces; - } + public @NotNull ArrayList getOverlapperPieces() { + return overlapperPieces; + } } diff --git a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawStructurePiece.java b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawStructurePiece.java index 1d22b617..3fe1af01 100644 --- a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawStructurePiece.java +++ b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawStructurePiece.java @@ -17,32 +17,41 @@ * This class has nothing to do with the new system */ public abstract class JigsawStructurePiece implements Cloneable { + protected final JigsawType type; protected CubeRoom room; protected HashMap validDirections = new HashMap<>(); protected ArrayList walledFaces = new ArrayList<>(); protected JigsawStructurePiece[] allowedPieces; - protected final JigsawType type; protected int depth = 0; protected BlockFace rotation = BlockFace.NORTH; protected boolean unique = false; protected int elevation = 0; // elevation of 0 is ground level. - public JigsawStructurePiece(int widthX, int height, int widthZ, JigsawType type, boolean unique, BlockFace @NotNull ... validDirs) { + public JigsawStructurePiece(int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + BlockFace @NotNull ... validDirs) + { this.room = new CubeRoom(widthX, widthZ, height, 0, 0, 0); this.type = type; this.unique = unique; - for (BlockFace face : validDirs) + for (BlockFace face : validDirs) { validDirections.put(face, false); + } } - + public JigsawStructurePiece(int widthX, int height, int widthZ, JigsawType type, BlockFace @NotNull ... validDirs) { this.room = new CubeRoom(widthX, widthZ, height, 0, 0, 0); this.type = type; - for (BlockFace face : validDirs) + for (BlockFace face : validDirs) { validDirections.put(face, false); + } } - public void postBuildDecoration(Random random, PopulatorDataAbstract data) {} + public void postBuildDecoration(Random random, PopulatorDataAbstract data) { + } @SuppressWarnings("unchecked") public @Nullable JigsawStructurePiece getInstance(@NotNull Random rand, int depth) { @@ -60,7 +69,8 @@ public void postBuildDecoration(Random random, PopulatorDataAbstract data) {} clone.elevation = 0; clone.setDepth(depth); return clone; - } catch (CloneNotSupportedException e) { + } + catch (CloneNotSupportedException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } return null; @@ -70,8 +80,9 @@ public void postBuildDecoration(Random random, PopulatorDataAbstract data) {} public @Nullable BlockFace getNextUnpopulatedBlockFace() { for (Entry entry : validDirections.entrySet()) { - if (!entry.getValue()) + if (!entry.getValue()) { return entry.getKey(); + } } TerraformGeneratorPlugin.logger.error("Tried to get unpopulated block face when there aren't any left!"); @@ -79,17 +90,24 @@ public void postBuildDecoration(Random random, PopulatorDataAbstract data) {} } public void setPopulated(BlockFace face) { - if (this.type == JigsawType.END) return; - if (!validDirections.containsKey(face)) + if (this.type == JigsawType.END) { + return; + } + if (!validDirections.containsKey(face)) { TerraformGeneratorPlugin.logger.error("Tried to set an invalid blockface as populated for a jigsaw piece."); + } validDirections.put(face, true); } public boolean hasUnpopulatedDirections() { - if (this.type == JigsawType.END) return false; + if (this.type == JigsawType.END) { + return false; + } for (Boolean populated : validDirections.values()) { - if (!populated) return true; + if (!populated) { + return true; + } } return false; } @@ -99,7 +117,9 @@ public CubeRoom getRoom() { } public HashMap getValidDirections() { - if (type == JigsawType.END) return new HashMap<>(); + if (type == JigsawType.END) { + return new HashMap<>(); + } return validDirections; } @@ -134,21 +154,24 @@ public BlockFace getRotation() { public void setRotation(BlockFace rotation) { this.rotation = rotation; } - + /** - * * @return If the structure piece has at least 1 walled face, return * a larger room with bigger widthX and widthZ (same height) */ public CubeRoom getExtendedRoom(int extraSize) { - if(this.walledFaces.isEmpty()) { - return this.room; - }else { - return new CubeRoom( - this.room.getWidthX()+extraSize*2, this.room.getWidthZ()+extraSize*2, this.room.getHeight(), - this.room.getX(), this.room.getY(), this.room.getZ() - ); - } + if (this.walledFaces.isEmpty()) { + return this.room; + } + else { + return new CubeRoom(this.room.getWidthX() + extraSize * 2, + this.room.getWidthZ() + extraSize * 2, + this.room.getHeight(), + this.room.getX(), + this.room.getY(), + this.room.getZ() + ); + } } @Override @@ -158,8 +181,16 @@ public CubeRoom getExtendedRoom(int extraSize) { directions.append(face).append(","); } return this.getClass().getSimpleName() - + "::" + room.getX() + "," + room.getY() + "," + room.getZ() - + "::" + this.hasUnpopulatedDirections() + "::" + directions; + + "::" + + room.getX() + + "," + + room.getY() + + "," + + room.getZ() + + "::" + + this.hasUnpopulatedDirections() + + "::" + + directions; } public boolean isUnique() { diff --git a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawType.java b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawType.java index cf309222..be798575 100644 --- a/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawType.java +++ b/common/src/main/java/org/terraform/structure/room/jigsaw/JigsawType.java @@ -5,10 +5,7 @@ */ public enum JigsawType { - STANDARD, - END, - UPPERCONNECTOR, - // LOWERCONNECTOR, Lower connectors are considered standard. + STANDARD, END, UPPERCONNECTOR, // LOWERCONNECTOR, Lower connectors are considered standard. ENTRANCE } diff --git a/common/src/main/java/org/terraform/structure/room/path/CavePathWriter.java b/common/src/main/java/org/terraform/structure/room/path/CavePathWriter.java index 77adcdb3..ac978087 100644 --- a/common/src/main/java/org/terraform/structure/room/path/CavePathWriter.java +++ b/common/src/main/java/org/terraform/structure/room/path/CavePathWriter.java @@ -6,7 +6,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.utils.BlockUtils; -public class CavePathWriter extends PathWriter{ +public class CavePathWriter extends PathWriter { private final float rXMod; private final float rYMod; private final float rZMod; @@ -24,10 +24,18 @@ public CavePathWriter(float rXMod, float rYMod, float rZMod, int xOff, int yOff, } @Override - public void apply(@NotNull PopulatorDataAbstract popData, @NotNull TerraformWorld tw, PathState.@NotNull PathNode node) { - BlockUtils.carveCaveAir((int) (node.center.hashCode() * tw.getSeed()), - node.pathWidth+rXMod, node.pathWidth+rYMod, node.pathWidth+rZMod, - new SimpleBlock(popData, node.center.getRelative(xOff,yOff,zOff)), false, - BlockUtils.caveCarveReplace); + public void apply(@NotNull PopulatorDataAbstract popData, + @NotNull TerraformWorld tw, + PathState.@NotNull PathNode node) + { + BlockUtils.carveCaveAir( + (int) (node.center.hashCode() * tw.getSeed()), + node.pathWidth + rXMod, + node.pathWidth + rYMod, + node.pathWidth + rZMod, + new SimpleBlock(popData, node.center.getRelative(xOff, yOff, zOff)), + false, + BlockUtils.caveCarveReplace + ); } } diff --git a/common/src/main/java/org/terraform/structure/room/path/PathState.java b/common/src/main/java/org/terraform/structure/room/path/PathState.java index bf16078c..5f0fa87f 100644 --- a/common/src/main/java/org/terraform/structure/room/path/PathState.java +++ b/common/src/main/java/org/terraform/structure/room/path/PathState.java @@ -25,56 +25,63 @@ public class PathState { // This will contain some path nodes public final @NotNull HashSet nodes = new HashSet<>(); - + // If the path generator is not to run while inside room areas, + // then set this to true. + private final boolean ignoreWithinRooms = true; + private final @NotNull RoomLayoutGenerator generator; /* /* General settings */ - public @NotNull PathWriter writer = new CavePathWriter(0,0,0,0,0,0); + public @NotNull PathWriter writer = new CavePathWriter(0, 0, 0, 0, 0, 0); private int pathWidth = 3; private int pathHeight = 3; private int maxBend = -1; - // If the path generator is not to run while inside room areas, - // then set this to true. - private final boolean ignoreWithinRooms = true; - private final @NotNull RoomLayoutGenerator generator; public PathState(@NotNull RoomLayoutGenerator generator, @NotNull TerraformWorld tw) { this.generator = generator; - if(!generator.genPaths()) return; + if (!generator.genPaths()) { + return; + } PathNode[] baseNodes = new PathNode[generator.getRooms().size()]; ArrayList rooms = new ArrayList<>(generator.getRooms()); // One starting node for each room - for(int i = 0; i < generator.getRooms().size(); i++) { + for (int i = 0; i < generator.getRooms().size(); i++) { CubeRoom room = rooms.get(i); - baseNodes[i] = new PathNode(new SimpleLocation(room.getX(), room.getY(), room.getZ()), pathWidth, generator.getPathPop()); + baseNodes[i] = new PathNode( + new SimpleLocation(room.getX(), room.getY(), room.getZ()), + pathWidth, + generator.getPathPop() + ); } // For every node, connect it to the next node // With a poor correlation between array order and // actual XZ position, this would look random. - assert(baseNodes.length >= 2); - for(int i = 0; i < baseNodes.length-1; i++) - connectNodes(baseNodes[i], baseNodes[i+1], tw, nodes); + assert (baseNodes.length >= 2); + for (int i = 0; i < baseNodes.length - 1; i++) { + connectNodes(baseNodes[i], baseNodes[i + 1], tw, nodes); + } nodes.addAll(Arrays.asList(baseNodes)); } // Connects the two nodes with new nodes added to toAdd - private void connectNodes(@NotNull PathNode one, @NotNull PathNode two, @NotNull TerraformWorld tw, @NotNull HashSet toAdd) + private void connectNodes(@NotNull PathNode one, + @NotNull PathNode two, + @NotNull TerraformWorld tw, + @NotNull HashSet toAdd) { BlockFace oneConn; // Set connected state - if(one.center.getX() - two.center.getX() == 0) - { + if (one.center.getX() - two.center.getX() == 0) { oneConn = one.center.getZ() > two.center.getZ() ? BlockFace.NORTH : BlockFace.SOUTH; one.connected.add(oneConn); two.connected.add(oneConn.getOppositeFace()); } - else if(one.center.getZ() - two.center.getZ() == 0) - { + else if (one.center.getZ() - two.center.getZ() == 0) { oneConn = one.center.getX() > two.center.getX() ? BlockFace.WEST : BlockFace.EAST; one.connected.add(oneConn); two.connected.add(oneConn.getOppositeFace()); @@ -83,9 +90,15 @@ else if(one.center.getZ() - two.center.getZ() == 0) { // Either add a node varying the X of one or the Z of two PathNode newNode = new PathNode( - tw.getHashedRand(one.center.getX(), two.center.getZ(), 1890341).nextBoolean() ? - new SimpleLocation(one.center.getX(),one.center.getY(),two.center.getZ()) - : new SimpleLocation(two.center.getX(),one.center.getY(), one.center.getZ()), pathWidth, generator.getPathPop()); + tw.getHashedRand(one.center.getX(), two.center.getZ(), 1890341) + .nextBoolean() + ? new SimpleLocation(one.center.getX(), + one.center.getY(), + two.center.getZ()) + : new SimpleLocation(two.center.getX(), one.center.getY(), one.center.getZ()), + pathWidth, + generator.getPathPop() + ); toAdd.add(newNode); connectNodes(newNode, one, tw, toAdd); connectNodes(newNode, two, tw, toAdd); @@ -93,8 +106,7 @@ else if(one.center.getZ() - two.center.getZ() == 0) } // Add path nodes that lead from one to two - for(int i = pathWidth; i < one.center.distance(two.center); i++) - { + for (int i = pathWidth; i < one.center.distance(two.center); i++) { toAdd.add(new PathNode(one.center.getRelative(oneConn, i), pathWidth, generator.getPathPop(), oneConn)); } } @@ -123,31 +135,37 @@ public void setMaxBend(int maxBend) { this.maxBend = maxBend; } - public static class PathNode{ + public static class PathNode { public final int pathWidth; public final @NotNull SimpleLocation center; public final PathPopulatorAbstract populator; public final HashSet connected = new HashSet<>(); + // Assumes input is new - public PathNode(@NotNull SimpleLocation center, int pathWidth, PathPopulatorAbstract populator, BlockFace... connections) { + public PathNode(@NotNull SimpleLocation center, + int pathWidth, + PathPopulatorAbstract populator, + BlockFace... connections) + { this.pathWidth = pathWidth; this.center = center; // Lock path nodes to a grid-like structure which will allow // path nodes to be spaced properly - this.center.setX((center.getX() / pathWidth)*pathWidth); - this.center.setZ((center.getZ() / pathWidth)*pathWidth); + this.center.setX((center.getX() / pathWidth) * pathWidth); + this.center.setZ((center.getZ() / pathWidth) * pathWidth); Collections.addAll(connected, connections); this.populator = populator; } // Equality is based on the simple location - public boolean equals(Object o){ - if(o instanceof PathNode pn) + public boolean equals(Object o) { + if (o instanceof PathNode pn) { return pn.center.equals(center); + } return false; } - public int hashCode(){ + public int hashCode() { return center.hashCode(); } } diff --git a/common/src/main/java/org/terraform/structure/room/path/PathWriter.java b/common/src/main/java/org/terraform/structure/room/path/PathWriter.java index 54993047..d2169dc5 100644 --- a/common/src/main/java/org/terraform/structure/room/path/PathWriter.java +++ b/common/src/main/java/org/terraform/structure/room/path/PathWriter.java @@ -6,9 +6,9 @@ public abstract class PathWriter { /** - * Contains instructions on how to carve a specific path. + * Contains instructions on how to carve a specific path. * I.e. how to draw the walls and handle turns, or if * a cave is to be carved, how it would be carved. - */ + */ public abstract void apply(PopulatorDataAbstract popData, TerraformWorld tw, PathState.PathNode node); } diff --git a/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java b/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java index 95a9cf4f..fa33f016 100644 --- a/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java @@ -32,22 +32,31 @@ public class DesertWellPopulator extends MultiMegaChunkStructurePopulator { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { int x = coords[0]; int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { continue; + } int height = GenUtils.getHighestGround(data, x, z); - spawnDesertWell(tw, random, data, x, height, z, tw.getBiomeBank(x,z) == BiomeBank.BADLANDS); + spawnDesertWell(tw, random, data, x, height, z, tw.getBiomeBank(x, z) == BiomeBank.BADLANDS); } } - public void spawnDesertWell(TerraformWorld tw, @NotNull Random random, - @NotNull PopulatorDataAbstract data, int x, int y, int z, boolean badlandsWell) { + public void spawnDesertWell(TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + boolean badlandsWell) + { SimpleBlock core = new SimpleBlock(data, x, y, z); TerraformGeneratorPlugin.logger.info("Spawning Desert Well at " + core.getCoords()); @@ -63,26 +72,44 @@ public void spawnDesertWell(TerraformWorld tw, @NotNull Random random, // Make sure the well is standing on a stable base for (int nx = -3; nx <= 3; nx++) { for (int nz = -3; nz <= 3; nz++) { - if (!badlandsWell) - new Wall(core.getRelative(nx, -1, nz)).downLPillar(random, 10, Material.SANDSTONE, Material.CHISELED_SANDSTONE, Material.CUT_SANDSTONE, - Material.SMOOTH_SANDSTONE); - else - new Wall(core.getRelative(nx, -1, nz)).downLPillar(random, 10, Material.RED_SANDSTONE, Material.CHISELED_RED_SANDSTONE, Material.CUT_RED_SANDSTONE, - Material.SMOOTH_RED_SANDSTONE); + if (!badlandsWell) { + new Wall(core.getRelative(nx, -1, nz)).downLPillar( + random, + 10, + Material.SANDSTONE, + Material.CHISELED_SANDSTONE, + Material.CUT_SANDSTONE, + Material.SMOOTH_SANDSTONE + ); + } + else { + new Wall(core.getRelative(nx, -1, nz)).downLPillar( + random, + 10, + Material.RED_SANDSTONE, + Material.CHISELED_RED_SANDSTONE, + Material.CUT_RED_SANDSTONE, + Material.SMOOTH_RED_SANDSTONE + ); + } } } // Drill hole down int depth = GenUtils.randInt(random, 5, 10); - if(core.getUp().getType() != Material.WATER) + if (core.getUp().getType() != Material.WATER) { for (int i = 0; i < depth; i++) { - if (i < depth - 3) + if (i < depth - 3) { core.getRelative(0, -i, 0).setType(Material.CAVE_AIR); - else + } + else { core.getRelative(0, -i, 0).setType(Material.WATER); + } } + } - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } @@ -90,24 +117,31 @@ public void spawnDesertWell(TerraformWorld tw, @NotNull Random random, private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 8291374), - (int) (TConfigOption.STRUCTURES_DESERTWELL_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_DESERTWELL_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } + @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); int[][] allCoords = getCoordsFromMegaChunk(tw, mc); for (int[] coords : allCoords) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); - for(BiomeBank b:biomes) { - if(b.getClimate() != BiomeClimate.HOT_BARREN) return false; - if(b.getType() != BiomeType.FLAT) return false; + for (BiomeBank b : biomes) { + if (b.getClimate() != BiomeClimate.HOT_BARREN) { + return false; + } + if (b.getType() != BiomeType.FLAT) { + return false; + } } - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -117,8 +151,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int num = TConfigOption.STRUCTURES_DESERTWELL_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227 * (1 + i))); + } return coords; } @@ -144,9 +179,9 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() - && TConfigOption.STRUCTURES_DESERTWELL_ENABLED.getBoolean() - && (TConfigOption.BIOME_DESERT_WEIGHT.getInt() > 0 || TConfigOption.BIOME_BADLANDS_WEIGHT.getInt() > 0); + return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_DESERTWELL_ENABLED.getBoolean() && ( + TConfigOption.BIOME_DESERT_WEIGHT.getInt() > 0 + || TConfigOption.BIOME_BADLANDS_WEIGHT.getInt() > 0); } @Override @@ -154,6 +189,11 @@ public boolean isEnabled() { return world.getHashedRand(189821, chunkX, chunkZ); } + @Override + public int getChunkBufferDistance() { + return 1; + } + private static class DesertWellSchematicParser extends SchematicParser { private final Random rand; // private final PopulatorDataAbstract pop; @@ -170,13 +210,7 @@ public DesertWellSchematicParser(Random rand, boolean badlandsWell, int baseY) { public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (this.badlandsWell) { - data = Bukkit.createBlockData( - StringUtils.replace( - data.getAsString(), - "sandstone", - "red_sandstone" - ) - ); + data = Bukkit.createBlockData(StringUtils.replace(data.getAsString(), "sandstone", "red_sandstone")); if (data.getMaterial() == Material.RED_SANDSTONE && rand.nextInt(5) == 0) { data = Bukkit.createBlockData(Material.CHISELED_RED_SANDSTONE); super.applyData(block, data); @@ -184,69 +218,67 @@ public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { } if (data.getMaterial() != Material.RED_SANDSTONE_STAIRS - && data.getMaterial() != Material.RED_SANDSTONE_WALL - && data.getMaterial().toString().contains("RED_SANDSTONE")) { - data = Bukkit.createBlockData( - StringUtils.replace( - data.getAsString(), - "red_sandstone", - GenUtils.randChoice( - rand, - Material.RED_SANDSTONE, - Material.SMOOTH_RED_SANDSTONE, - Material.CUT_RED_SANDSTONE - ).name().toLowerCase(Locale.ENGLISH) - ) - ); + && data.getMaterial() != Material.RED_SANDSTONE_WALL + && data.getMaterial().toString().contains("RED_SANDSTONE")) + { + data = Bukkit.createBlockData(StringUtils.replace(data.getAsString(), + "red_sandstone", + GenUtils.randChoice(rand, + Material.RED_SANDSTONE, + Material.SMOOTH_RED_SANDSTONE, + Material.CUT_RED_SANDSTONE + ).name().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } else + } + else { super.applyData(block, data); + } return; - } else { + } + else { if (data.getMaterial() == Material.SANDSTONE) { - if(rand.nextInt(5) == 0) - { + if (rand.nextInt(5) == 0) { data = Bukkit.createBlockData(Material.CHISELED_SANDSTONE); super.applyData(block, data); return; } - else if(Version.isAtLeast(20) - && block.getY() == baseY - && GenUtils.chance(rand, 1, 20)) - { + else if (Version.isAtLeast(20) && block.getY() == baseY && GenUtils.chance(rand, 1, 20)) { data = Bukkit.createBlockData(OneTwentyBlockHandler.SUSPICIOUS_SAND); - super.applyData(block,data); - block.getPopData().lootTableChest(block.getX(),block.getY(),block.getZ(), TerraLootTable.DESERT_WELL_ARCHAEOLOGY); + super.applyData(block, data); + block.getPopData() + .lootTableChest( + block.getX(), + block.getY(), + block.getZ(), + TerraLootTable.DESERT_WELL_ARCHAEOLOGY + ); return; } } if (data.getMaterial() != Material.SANDSTONE_STAIRS - && data.getMaterial() != Material.SANDSTONE_WALL - && data.getMaterial().toString().contains("SANDSTONE")) { - data = Bukkit.createBlockData( - StringUtils.replace( - data.getAsString(), - "sandstone", - GenUtils.randChoice( - rand, + && data.getMaterial() != Material.SANDSTONE_WALL + && data.getMaterial().toString().contains("SANDSTONE")) + { + data = Bukkit.createBlockData(StringUtils.replace(data.getAsString(), + "sandstone", + GenUtils.randChoice(rand, Material.SANDSTONE, Material.SMOOTH_SANDSTONE, Material.CUT_SANDSTONE - ).name().toLowerCase(Locale.ENGLISH) - ) - ); + ) + .name() + .toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } else + } + else { super.applyData(block, data); + } } } } - - @Override - public int getChunkBufferDistance() { - return 1; - } } diff --git a/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java b/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java index 602ab400..c6220c2f 100644 --- a/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java @@ -16,9 +16,13 @@ public class GiantPumpkinPopulator { public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if ( !TConfigOption.areStructuresEnabled() ) return; + if (!TConfigOption.areStructuresEnabled()) { + return; + } - if (!TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean()) return; + if (!TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean()) { + return; + } int x = data.getChunkX() * 16 + random.nextInt(16); int z = data.getChunkZ() * 16 + random.nextInt(16); int height = GenUtils.getHighestGround(data, x, z); @@ -26,10 +30,15 @@ public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNul spawnGiantPumpkin(tw, random, data, x, height, z); } - public void spawnGiantPumpkin(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnGiantPumpkin(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { // Spawn the biggest pumpkin - new FractalTreeBuilder(FractalTypes.Tree.GIANT_PUMPKIN) - .build(tw, data, x, y + 1, z); + new FractalTreeBuilder(FractalTypes.Tree.GIANT_PUMPKIN).build(tw, data, x, y + 1, z); // Spawn small pumpkins for (int i = 0; i < GenUtils.randInt(random, 15, 30); i++) { @@ -50,13 +59,20 @@ public void spawnGiantPumpkin(@NotNull TerraformWorld tw, @NotNull Random random } // Spawn big bushes - if ( TConfigOption.arePlantsEnabled() ) { - for(int i = 0; i < GenUtils.randInt(random, 4, 6); i++) { + if (TConfigOption.arePlantsEnabled()) { + for (int i = 0; i < GenUtils.randInt(random, 4, 6); i++) { int nx = x + GenUtils.getSign(random) * GenUtils.randInt(4, 6); int nz = z + GenUtils.getSign(random) * GenUtils.randInt(4, 6); int ny = GenUtils.getHighestGround(data, nx, nz); - BlockUtils.replaceSphere(random.nextInt(9992), - 3, 6, 3, new SimpleBlock(data, nx, ny, nz), false, Material.ACACIA_LEAVES); + BlockUtils.replaceSphere( + random.nextInt(9992), + 3, + 6, + 3, + new SimpleBlock(data, nx, ny, nz), + false, + Material.ACACIA_LEAVES + ); } } } diff --git a/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java b/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java index 2ba5ab1a..93d3edcd 100644 --- a/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java @@ -32,26 +32,36 @@ public class WitchHutPopulator extends MultiMegaChunkStructurePopulator { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { int x = coords[0]; int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { continue; + } int height = GenUtils.getHighestGround(data, x, z); if (height < TerraformGenerator.seaLevel) { // Assume. it's on water height = TerraformGenerator.seaLevel + GenUtils.randInt(random, 2, 3); - } else + } + else { height += GenUtils.randInt(random, 2, 3); + } spawnSwampHut(tw, random, data, x, height, z); } } - public void spawnSwampHut(TerraformWorld tw, @NotNull Random random, - @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnSwampHut(TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { // Refers to center of hut, above the water. SimpleBlock core = new SimpleBlock(data, x, y, z); @@ -74,7 +84,8 @@ public void spawnSwampHut(TerraformWorld tw, @NotNull Random random, z = w.getRear(2).get().getZ(); data.addEntity(x, y + 1, z, EntityType.WITCH); data.addEntity(x, y + 1, z, EntityType.CAT); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } @@ -82,24 +93,28 @@ public void spawnSwampHut(TerraformWorld tw, @NotNull Random random, private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 8242112), - (int) (TConfigOption.STRUCTURES_SWAMPHUT_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_SWAMPHUT_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } + @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); int[][] allCoords = getCoordsFromMegaChunk(tw, mc); for (int[] coords : allCoords) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); - for(BiomeBank b:biomes) { - if(b != BiomeBank.SWAMP && b != BiomeBank.MANGROVE) + for (BiomeBank b : biomes) { + if (b != BiomeBank.SWAMP && b != BiomeBank.MANGROVE) { return false; + } } - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -109,8 +124,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int num = TConfigOption.STRUCTURES_SWAMPHUT_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227 * (1 + i))); + } return coords; } @@ -136,9 +152,9 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean() - && (TConfigOption.BIOME_SWAMP_WEIGHT.getInt() > 0|| - TConfigOption.BIOME_MANGROVE_WEIGHT.getInt() > 0); + return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean() && ( + TConfigOption.BIOME_SWAMP_WEIGHT.getInt() > 0 + || TConfigOption.BIOME_MANGROVE_WEIGHT.getInt() > 0); } @Override @@ -146,12 +162,16 @@ public boolean isEnabled() { return world.getHashedRand(1211221, chunkX, chunkZ); } + @Override + public int getChunkBufferDistance() { + return 1; + } + private static class WitchHutSchematicParser extends SchematicParser { private final Random rand; private final PopulatorDataAbstract pop; - public WitchHutSchematicParser(Random rand, - PopulatorDataAbstract pop) { + public WitchHutSchematicParser(Random rand, PopulatorDataAbstract pop) { this.rand = rand; this.pop = pop; } @@ -159,29 +179,38 @@ public WitchHutSchematicParser(Random rand, @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - StringUtils.replace(data.getAsString(), "cobblestone", GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, - Material.MOSSY_COBBLESTONE).name().toLowerCase(Locale.ENGLISH)) - ); + data = Bukkit.createBlockData(StringUtils.replace( + data.getAsString(), + "cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).name().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - if (GenUtils.chance(1, 5)) BlockUtils.vineUp(block, 2); - } else if (data.getMaterial().toString().startsWith("OAK")) { + if (GenUtils.chance(1, 5)) { + BlockUtils.vineUp(block, 2); + } + } + else if (data.getMaterial().toString().startsWith("OAK")) { super.applyData(block, data); if (data.getMaterial().toString().endsWith("LOG")) { - if (GenUtils.chance(1, 5)) BlockUtils.vineUp(block, 2); + if (GenUtils.chance(1, 5)) { + BlockUtils.vineUp(block, 2); + } } super.applyData(block, data); - } else if (data.getMaterial() == Material.CHEST) { + } + else if (data.getMaterial() == Material.CHEST) { super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_TEMPLE); - } else { + } + else { super.applyData(block, data); } } } - @Override - public int getChunkBufferDistance() { - return 1; - } } diff --git a/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java b/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java index de357188..f485efa0 100644 --- a/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java +++ b/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java @@ -1,8 +1,5 @@ package org.terraform.structure.small.buriedtreasure; -import java.util.EnumSet; -import java.util.Random; - import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.terraform.biome.BiomeBank; @@ -18,101 +15,109 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.ChestBuilder; -public class BuriedTreasurePopulator extends MultiMegaChunkStructurePopulator{ - - @Override - public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) - return; - - Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); - MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); - for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { - int x = coords[0]; - int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) - continue; - - int height = GenUtils.getHighestGround(data, x, z); - height -= GenUtils.randInt(random, 3, 10); - - SimpleBlock chest = new SimpleBlock(data, x,height,z); - new ChestBuilder(Material.CHEST) - .setFacing(BlockUtils.getDirectBlockFace(random)) - .setLootTable(TerraLootTable.BURIED_TREASURE) - .apply(chest); - } - } - - @Override - public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK.getInt(); - int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 87464*(1+i))); - return coords; - } - - public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { - MegaChunk mc = new MegaChunk(rawX, 0, rawZ); - - double minDistanceSquared = Integer.MAX_VALUE; - int[] min = null; - for (int nx = -1; nx <= 1; nx++) { - for (int nz = -1; nz <= 1; nz++) { - for (int[] loc : getCoordsFromMegaChunk(tw, mc)) { - double distSqr = Math.pow(loc[0] - rawX, 2) + Math.pow(loc[1] - rawZ, 2); - if (distSqr < minDistanceSquared) { - minDistanceSquared = distSqr; - min = loc; - } - } - } - } - return min; - } - - - private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_BURIEDTREASURE_SPAWNRATIO - .getDouble() * 10000), - 10000); - } - - @Override - public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, - int chunkZ) { - if (!isEnabled()) return false; - - MegaChunk mc = new MegaChunk(chunkX, chunkZ); - for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { - if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); - double numBeach = 0; - for(BiomeBank b:biomes) - if(b.getType() == BiomeType.BEACH) - numBeach++; - - return (numBeach > 0) && rollSpawnRatio(tw,chunkX,chunkZ); - } - } - return false; - } - - @Override - public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { - return world.getHashedRand(82736921, chunkX, chunkZ); - } - - @Override - public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() - && TConfigOption.STRUCTURES_BURIEDTREASURE_ENABLED.getBoolean(); - } - - @Override - public int getChunkBufferDistance() { - return 0; - } +import java.util.EnumSet; +import java.util.Random; + +public class BuriedTreasurePopulator extends MultiMegaChunkStructurePopulator { + + @Override + public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { + if (!isEnabled()) { + return; + } + + Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); + MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); + for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { + int x = coords[0]; + int z = coords[1]; + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { + continue; + } + + int height = GenUtils.getHighestGround(data, x, z); + height -= GenUtils.randInt(random, 3, 10); + + SimpleBlock chest = new SimpleBlock(data, x, height, z); + new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getDirectBlockFace(random)) + .setLootTable(TerraLootTable.BURIED_TREASURE) + .apply(chest); + } + } + + @Override + public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { + int num = TConfigOption.STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK.getInt(); + int[][] coords = new int[num][2]; + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 87464 * (1 + i))); + } + return coords; + } + + public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { + MegaChunk mc = new MegaChunk(rawX, 0, rawZ); + + double minDistanceSquared = Integer.MAX_VALUE; + int[] min = null; + for (int nx = -1; nx <= 1; nx++) { + for (int nz = -1; nz <= 1; nz++) { + for (int[] loc : getCoordsFromMegaChunk(tw, mc)) { + double distSqr = Math.pow(loc[0] - rawX, 2) + Math.pow(loc[1] - rawZ, 2); + if (distSqr < minDistanceSquared) { + minDistanceSquared = distSqr; + min = loc; + } + } + } + } + return min; + } + + + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + return GenUtils.chance( + tw.getHashedRand(chunkX, chunkZ, 12422), + (int) (TConfigOption.STRUCTURES_BURIEDTREASURE_SPAWNRATIO.getDouble() * 10000), + 10000 + ); + } + + @Override + public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + if (!isEnabled()) { + return false; + } + + MegaChunk mc = new MegaChunk(chunkX, chunkZ); + for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { + if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { + EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); + double numBeach = 0; + for (BiomeBank b : biomes) { + if (b.getType() == BiomeType.BEACH) { + numBeach++; + } + } + + return (numBeach > 0) && rollSpawnRatio(tw, chunkX, chunkZ); + } + } + return false; + } + + @Override + public @NotNull Random getHashedRandom(@NotNull TerraformWorld world, int chunkX, int chunkZ) { + return world.getHashedRand(82736921, chunkX, chunkZ); + } + + @Override + public boolean isEnabled() { + return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_BURIEDTREASURE_ENABLED.getBoolean(); + } + + @Override + public int getChunkBufferDistance() { + return 0; + } } diff --git a/common/src/main/java/org/terraform/structure/small/dungeon/DrownedDungeonPopulator.java b/common/src/main/java/org/terraform/structure/small/dungeon/DrownedDungeonPopulator.java index bd45ea4c..99d382ab 100644 --- a/common/src/main/java/org/terraform/structure/small/dungeon/DrownedDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/dungeon/DrownedDungeonPopulator.java @@ -21,7 +21,12 @@ import java.util.Random; public class DrownedDungeonPopulator extends SmallDungeonPopulator { - private static final Material[] cobbleSet = {Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL}; + private static final Material[] cobbleSet = { + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + }; private static final Material[] graniteSet = {Material.GRANITE, Material.GRANITE_WALL}; private static final Material[] dioriteSet = {Material.DIORITE, Material.DIORITE_WALL}; private static final Material[] andesiteSet = {Material.ANDESITE, Material.ANDESITE_WALL}; @@ -51,8 +56,12 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract spawnDungeonRoom(x, z, tw, rand, data); } - public void spawnDungeonRoom(int x, int z, TerraformWorld tw, @NotNull Random rand, - @NotNull PopulatorDataAbstract data) { + public void spawnDungeonRoom(int x, + int z, + TerraformWorld tw, + @NotNull Random rand, + @NotNull PopulatorDataAbstract data) + { TerraformGeneratorPlugin.logger.info("Spawning Drowned Dungeon at " + x + "," + z); int setIndex = rand.nextInt(sets.length); Material[] set = sets[setIndex]; @@ -61,8 +70,9 @@ public void spawnDungeonRoom(int x, int z, TerraformWorld tw, @NotNull Random ra // First Round for (int nx = -radius; nx <= radius; nx++) { for (int nz = -radius; nz <= radius; nz++) { - if (nx * nx + nz * nz > radius * radius + GenUtils.randInt(rand, -10, 10)) + if (nx * nx + nz * nz > radius * radius + GenUtils.randInt(rand, -10, 10)) { continue; + } int y = HeightMap.getBlockHeight(tw, x, z);// GenUtils.getHighestGround(data, nx + x, nz + z); @@ -76,17 +86,22 @@ public void spawnDungeonRoom(int x, int z, TerraformWorld tw, @NotNull Random ra if (GenUtils.chance(rand, 1, 10)) { Wall w = new Wall(new SimpleBlock(data, nx + x, y + 1, nz + z), BlockFace.NORTH); w.LPillar(GenUtils.randInt(1, 7), rand, set); - } else if (GenUtils.chance(rand, 1, 70)) { + } + else if (GenUtils.chance(rand, 1, 70)) { Directional dir = (Directional) Bukkit.createBlockData(Material.CHEST); dir.setFacing(BlockUtils.getDirectBlockFace(rand)); data.setBlockData(x + nx, y + 1, z + nz, dir); - if (radius < 7) + if (radius < 7) { data.lootTableChest(x + nx, y + 1, z + nz, TerraLootTable.UNDERWATER_RUIN_SMALL); - else + } + else { data.lootTableChest(x + nx, y + 1, z + nz, TerraLootTable.UNDERWATER_RUIN_BIG); - } else if (GenUtils.chance(rand, 1, 10)) { + } + } + else if (GenUtils.chance(rand, 1, 10)) { CoralGenerator.generateKelpGrowth(data, nx + x, y + 1, nz + z); - } else if (GenUtils.chance(rand, 1, 10)) { + } + else if (GenUtils.chance(rand, 1, 10)) { data.setType(x + nx, y, z + nz, Material.MAGMA_BLOCK); } } @@ -98,7 +113,8 @@ public void spawnDungeonRoom(int x, int z, TerraformWorld tw, @NotNull Random ra int y = GenUtils.getHighestGround(data, nx + x, nz + z); if (GenUtils.chance(rand, 1, 15)) { CoralGenerator.generateSingleCoral(data, nx + x, y, nz + z); - } else if (GenUtils.chance(rand, 1, 10)) { + } + else if (GenUtils.chance(rand, 1, 10)) { data.setType(x + nx, y + 1, z + nz, Material.SEAGRASS); } } diff --git a/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java b/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java index a1c6b621..9b19643f 100644 --- a/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java @@ -14,7 +14,9 @@ public class SmallDungeonPopulator extends MultiMegaChunkStructurePopulator { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !isEnabled() ) return; + if (!isEnabled()) { + return; + } int totalHeight = 0; for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) { @@ -24,34 +26,44 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract } if (totalHeight / 256 <= TConfigOption.STRUCTURES_DROWNEDDUNGEON_MIN_DEPTH.getInt() - && GenUtils.chance(tw.getHashedRand(1223, data.getChunkX(), data.getChunkZ()), TConfigOption.STRUCTURES_DROWNEDDUNGEON_CHANCE.getInt(), 1000)) { + && GenUtils.chance( + tw.getHashedRand(1223, data.getChunkX(), data.getChunkZ()), + TConfigOption.STRUCTURES_DROWNEDDUNGEON_CHANCE.getInt(), + 1000 + )) + { // Only spawn these in full oceans - if (!TConfigOption.STRUCTURES_DROWNEDDUNGEON_ENABLED.getBoolean()) + if (!TConfigOption.STRUCTURES_DROWNEDDUNGEON_ENABLED.getBoolean()) { return; + } new DrownedDungeonPopulator().populate(tw, data); - } else { - if (!TConfigOption.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED.getBoolean()) + } + else { + if (!TConfigOption.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED.getBoolean()) { return; + } new UndergroundDungeonPopulator().populate(tw, data); } } - + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_DUNGEONS_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_DUNGEONS_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); int[][] allCoords = getCoordsFromMegaChunk(tw, mc); for (int[] coords : allCoords) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -60,10 +72,11 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { // Each mega chunk has config option dungeons @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfigOption.STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 1317324*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 1317324 * (1 + i))); + } return coords; } diff --git a/common/src/main/java/org/terraform/structure/small/dungeon/UndergroundDungeonPopulator.java b/common/src/main/java/org/terraform/structure/small/dungeon/UndergroundDungeonPopulator.java index 1dd9948f..4a993a03 100644 --- a/common/src/main/java/org/terraform/structure/small/dungeon/UndergroundDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/dungeon/UndergroundDungeonPopulator.java @@ -34,7 +34,9 @@ private static void dropDownBlock(@NotNull SimpleBlock block, @NotNull Material while (!block.isSolid()) { block = block.getDown(); depth++; - if (depth > 50) return; + if (depth > 50) { + return; + } } block.getUp().setType(type); @@ -58,9 +60,15 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int z = spawnCoords[1];// data.getChunkZ()*16 + random.nextInt(16); Random rand = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); - int y = HeightMap.getBlockHeight(tw, x, z) - GenUtils.randInt(rand, 15, 50);// GenUtils.getHighestGround(data, x, z) + int y = HeightMap.getBlockHeight(tw, x, z) - GenUtils.randInt( + rand, + 15, + 50 + );// GenUtils.getHighestGround(data, x, z) - if (y < 10) y = 10; + if (y < 10) { + y = 10; + } while (!data.getType(x, y, z).isSolid()) { y--; @@ -69,39 +77,46 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract spawnDungeonRoom(x, y, z, tw, rand, data); } - public void spawnDungeonRoom(int x, int y, int z, TerraformWorld tw, @NotNull Random rand, - @NotNull PopulatorDataAbstract data) { + public void spawnDungeonRoom(int x, + int y, + int z, + TerraformWorld tw, + @NotNull Random rand, + @NotNull PopulatorDataAbstract data) + { TerraformGeneratorPlugin.logger.info("Spawning Underground Dungeon at " + x + "," + y + "," + z); CubeRoom room = new CubeRoom(GenUtils.randOddInt(rand, 9, 15), GenUtils.randOddInt(rand, 9, 15), GenUtils.randInt(rand, 5, 7), - x, y, z); + x, + y, + z + ); boolean isWet = false; - + Material fluid = Material.CAVE_AIR; - + SimpleBlock center = room.getCenterSimpleBlock(data); - if(BlockUtils.isWet(center.getUp())) - { - fluid = Material.WATER; - isWet = true; + if (BlockUtils.isWet(center.getUp())) { + fluid = Material.WATER; + isWet = true; } // Fill with water if the room is wet. If not, use cave air. - room.fillRoom(data, -1, new Material[]{ - Material.COBBLESTONE, - Material.MOSSY_COBBLESTONE}, - fluid); + room.fillRoom(data, -1, new Material[] { + Material.COBBLESTONE, Material.MOSSY_COBBLESTONE + }, fluid); // Make some fence pattern. for (Entry entry : room.getFourWalls(data, 0).entrySet()) { Wall w = entry.getKey().getUp(); int length = entry.getValue(); while (length >= 0) { - if(length % 2 != 0 && length != entry.getValue()) { + if (length % 2 != 0 && length != entry.getValue()) { w.CAPillar(room.getHeight() - 3, rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); - if(isWet) - w.waterlog(room.getHeight()-3); + if (isWet) { + w.waterlog(room.getHeight() - 3); + } } for (int h = 0; h < room.getHeight() - 3; h++) { @@ -119,14 +134,22 @@ public void spawnDungeonRoom(int x, int y, int z, TerraformWorld tw, @NotNull Ra int nX = coords[0]; int nY = coords[1]; int nZ = coords[2]; - BlockUtils.replaceSphere(rand.nextInt(992), GenUtils.randInt(rand, 1, 3), new SimpleBlock(data, nX, nY, nZ), true, fluid); + BlockUtils.replaceSphere( + rand.nextInt(992), + GenUtils.randInt(rand, 1, 3), + new SimpleBlock(data, nX, nY, nZ), + true, + fluid + ); } // Dropdown blocks for (int nx = -room.getWidthX() / 2; nx < room.getWidthX() / 2; nx++) { for (int nz = -room.getWidthZ() / 2; nz < room.getWidthZ() / 2; nz++) { int ny = room.getHeight(); - if (GenUtils.chance(10, 13)) continue; + if (GenUtils.chance(10, 13)) { + continue; + } dropDownBlock(new SimpleBlock(data, x + nx, y + ny, z + nz), fluid); } } @@ -135,10 +158,15 @@ public void spawnDungeonRoom(int x, int y, int z, TerraformWorld tw, @NotNull Ra for (int nx = -room.getWidthX() / 2; nx < room.getWidthX() / 2; nx++) { for (int nz = -room.getWidthZ() / 2; nz < room.getWidthZ() / 2; nz++) { int ny = room.getHeight() - 1; - if (GenUtils.chance(9, 10)) continue; + if (GenUtils.chance(9, 10)) { + continue; + } for (int i = 0; i < GenUtils.randInt(rand, 1, room.getHeight() - 3); i++) { - data.setType(x + nx, y + ny, z + nz, GenUtils.randChoice(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE_WALL, - Material.MOSSY_COBBLESTONE_WALL)); + data.setType(x + nx, y + ny, z + nz, GenUtils.randChoice(Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + )); BlockUtils.correctSurroundingMultifacingData(new SimpleBlock(data, x + nx, y + ny, z + nz)); } } @@ -147,24 +175,35 @@ public void spawnDungeonRoom(int x, int y, int z, TerraformWorld tw, @NotNull Ra // Make spikes on the floor for (int nx = -room.getWidthX() / 2; nx < room.getWidthX() / 2; nx++) { for (int nz = -room.getWidthZ() / 2; nz < room.getWidthZ() / 2; nz++) { - if (GenUtils.chance(9, 10)) continue; + if (GenUtils.chance(9, 10)) { + continue; + } for (int i = 0; i < GenUtils.randInt(rand, 1, room.getHeight() - 3); i++) { Wall w = new Wall(new SimpleBlock(data, x + nx, y + 1, z + nz), BlockFace.NORTH); - w.LPillar(room.getHeight() - 2, rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); + w.LPillar( + room.getHeight() - 2, + rand, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + ); BlockUtils.correctSurroundingMultifacingData(w.get()); } } } // Place Spawner - EntityType type = switch(rand.nextInt(3)) { + EntityType type = switch (rand.nextInt(3)) { case (0) -> EntityType.ZOMBIE; case (1) -> EntityType.SKELETON; case (2) -> EntityType.SPIDER; default -> null; }; - if(isWet) type = EntityType.DROWNED; - + if (isWet) { + type = EntityType.DROWNED; + } + data.setSpawner(x, y + 1, z, type); // Spawn chests @@ -184,10 +223,11 @@ public void spawnDungeonRoom(int x, int y, int z, TerraformWorld tw, @NotNull Ra if (length == chest) { Directional dir = (Directional) Bukkit.createBlockData(Material.CHEST); dir.setFacing(w.getDirection()); - - if(isWet && dir instanceof Waterlogged) - ((Waterlogged) dir).setWaterlogged(true); - + + if (isWet && dir instanceof Waterlogged) { + ((Waterlogged) dir).setWaterlogged(true); + } + w.setBlockData(dir); data.lootTableChest(w.get().getX(), w.get().getY(), w.get().getZ(), TerraLootTable.SIMPLE_DUNGEON); } diff --git a/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java b/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java index 77ed6ec7..3818037c 100644 --- a/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java @@ -1,8 +1,5 @@ package org.terraform.structure.small.igloo; -import java.util.EnumSet; -import java.util.Random; - import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.BlockFace; @@ -22,345 +19,361 @@ import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.main.config.TConfigOption; import org.terraform.structure.MultiMegaChunkStructurePopulator; -import org.terraform.utils.BlockUtils; -import org.terraform.utils.CylinderBuilder; -import org.terraform.utils.GenUtils; -import org.terraform.utils.SphereBuilder; -import org.terraform.utils.StairwayBuilder; +import org.terraform.utils.*; import org.terraform.utils.SphereBuilder.SphereType; -import org.terraform.utils.blockdata.BarrelBuilder; -import org.terraform.utils.blockdata.DirectionalBuilder; -import org.terraform.utils.blockdata.OrientableBuilder; -import org.terraform.utils.blockdata.SlabBuilder; -import org.terraform.utils.blockdata.StairBuilder; -import org.terraform.utils.blockdata.TrapdoorBuilder; +import org.terraform.utils.blockdata.*; + +import java.util.EnumSet; +import java.util.Random; public class IglooPopulator extends MultiMegaChunkStructurePopulator { - + @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !isEnabled() ) return; + if (!isEnabled()) { + return; + } Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { int x = coords[0]; int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) - continue; + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { + continue; + } int height = GenUtils.getHighestGround(data, x, z); - + spawnIgloo(tw, random, data, x, height + 1, z); } } - public void spawnIgloo(TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - Wall core = new Wall(data,x,y,z,BlockUtils.getDirectBlockFace(random)); - - int size = GenUtils.randInt(random, 4, 7); - TerraformGeneratorPlugin.logger.info("Placing igloo of size " + size); - new CylinderBuilder(random, core.getDown(), Material.SPRUCE_PLANKS) - .setHardReplace(false) - .setRX(size*1.5f).setRY(0.5f).setRZ(size*1.5f) - .setMinRadius(1.0f) - .setSingleBlockY(true) - .build(); - - // - new SphereBuilder(random, core, Material.SNOW_BLOCK) - .setSphereType(SphereType.UPPER_SEMISPHERE) - .setRadius(size) - .setSmooth(true) - .build(); - new SphereBuilder(random, core, Material.AIR) - .setSphereType(SphereType.UPPER_SEMISPHERE) - .setRadius(size-1) - .setSmooth(true) - .setHardReplace(true) - .build(); - - spawnSpire(core.getRelative(size-1,0,size-1)); - spawnSpire(core.getRelative(-size+1,0,size-1)); - spawnSpire(core.getRelative(-size+1,0,-size+1)); - spawnSpire(core.getRelative(size-1,0,-size+1)); - - core.getUp(size+1).setType(Material.SPRUCE_SLAB); - - // Side Decorations - spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.NORTH), size); - spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.SOUTH), size); - spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.EAST), size); - spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.WEST), size); - - // Entrance - core.getFront(size+1).getUp().setType(Material.AIR); - core.getFront(size+1).setType(Material.AIR); - core.getFront(size).setType(Material.AIR); - core.getFront(size).getUp().setType(Material.AIR); - - core.getFront(size-1).setType(Material.AIR); - core.getFront(size-1).getUp().setType(Material.AIR); - BlockUtils.placeDoor(data, Material.SPRUCE_DOOR, - core.getFront(size-1)); - - Wall entranceCore = core.getFront(size); - entranceCore.getLeft().Pillar(2, Material.SPRUCE_LOG); - entranceCore.getRight().Pillar(2, Material.SPRUCE_LOG); - entranceCore.getFront().getLeft().setType(Material.SPRUCE_PLANKS); - entranceCore.getFront().getRight().setType(Material.SPRUCE_PLANKS); - - new OrientableBuilder(Material.SPRUCE_LOG) - .setAxis(BlockUtils.getAxisFromBlockFace(core.getDirection())) - .apply(entranceCore.getUp(2)); - - new StairBuilder(Material.SPRUCE_STAIRS) - .setFacing(core.getDirection().getOppositeFace()) - .apply(entranceCore.getFront().getLeft().getUp()) - .apply(entranceCore.getFront().getRight().getUp()) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(entranceCore.getRight().getUp(2)) - .setFacing(BlockUtils.getRight(core.getDirection())) - .apply(entranceCore.getLeft().getUp(2)); - - new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR) - .setOpen(true) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(entranceCore.getLeft(2)) - .apply(entranceCore.getLeft(2).getUp()) - .setFacing(BlockUtils.getRight(core.getDirection())) - .apply(entranceCore.getRight(2)) - .apply(entranceCore.getRight(2).getUp()); - - // Stairway out the entrance. - - if(entranceCore.getFront(2).isSolid()) { - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .setStairwayDirection(BlockFace.UP) - .build(entranceCore.getFront(4)); - entranceCore.getFront(2).Pillar(2, new Random(), Material.AIR); - entranceCore.getFront(3).Pillar(2, new Random(), Material.AIR); - }else - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .build(entranceCore.getFront(2).getDown()); - - // By this point, the entire exterior of the igloo has been placed. - // The below area handles interior placement - - // Pick a random corner to place a chimney - int offset = size/2; - BlockFace offsetDir = BlockUtils.xzDiagonalPlaneBlockFaces[random.nextInt(BlockUtils.xzDiagonalPlaneBlockFaces.length)]; - SimpleBlock chimneyCore = core - .getRelative(offsetDir,offset); - chimneyCore.getDown().setType(Material.HAY_BLOCK); - chimneyCore.setType(Material.CAMPFIRE); - - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - if(face.getModX() == offsetDir.getModX() || face.getModZ() == offsetDir.getModZ()) - for(int depth = 1; depth <= 2; depth++) { - if(chimneyCore.getRelative(face,depth).distanceSquared(core) < size*size) - chimneyCore.getRelative(face,depth).LPillar(size, new Random(), Material.STONE, Material.COBBLESTONE); + public void spawnIgloo(TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + Wall core = new Wall(data, x, y, z, BlockUtils.getDirectBlockFace(random)); + + int size = GenUtils.randInt(random, 4, 7); + TerraformGeneratorPlugin.logger.info("Placing igloo of size " + size); + new CylinderBuilder(random, core.getDown(), Material.SPRUCE_PLANKS).setHardReplace(false) + .setRX(size * 1.5f) + .setRY(0.5f) + .setRZ(size * 1.5f) + .setMinRadius(1.0f) + .setSingleBlockY(true) + .build(); + + // + new SphereBuilder(random, core, Material.SNOW_BLOCK).setSphereType(SphereType.UPPER_SEMISPHERE) + .setRadius(size) + .setSmooth(true) + .build(); + new SphereBuilder(random, core, Material.AIR).setSphereType(SphereType.UPPER_SEMISPHERE) + .setRadius(size - 1) + .setSmooth(true) + .setHardReplace(true) + .build(); + + spawnSpire(core.getRelative(size - 1, 0, size - 1)); + spawnSpire(core.getRelative(-size + 1, 0, size - 1)); + spawnSpire(core.getRelative(-size + 1, 0, -size + 1)); + spawnSpire(core.getRelative(size - 1, 0, -size + 1)); + + core.getUp(size + 1).setType(Material.SPRUCE_SLAB); + + // Side Decorations + spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.NORTH), size); + spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.SOUTH), size); + spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.EAST), size); + spawnTrapdoorDecors(new Wall(core.getUp(size), BlockFace.WEST), size); + + // Entrance + core.getFront(size + 1).getUp().setType(Material.AIR); + core.getFront(size + 1).setType(Material.AIR); + core.getFront(size).setType(Material.AIR); + core.getFront(size).getUp().setType(Material.AIR); + + core.getFront(size - 1).setType(Material.AIR); + core.getFront(size - 1).getUp().setType(Material.AIR); + BlockUtils.placeDoor(data, Material.SPRUCE_DOOR, core.getFront(size - 1)); + + Wall entranceCore = core.getFront(size); + entranceCore.getLeft().Pillar(2, Material.SPRUCE_LOG); + entranceCore.getRight().Pillar(2, Material.SPRUCE_LOG); + entranceCore.getFront().getLeft().setType(Material.SPRUCE_PLANKS); + entranceCore.getFront().getRight().setType(Material.SPRUCE_PLANKS); + + new OrientableBuilder(Material.SPRUCE_LOG).setAxis(BlockUtils.getAxisFromBlockFace(core.getDirection())) + .apply(entranceCore.getUp(2)); + + new StairBuilder(Material.SPRUCE_STAIRS).setFacing(core.getDirection().getOppositeFace()) + .apply(entranceCore.getFront().getLeft().getUp()) + .apply(entranceCore.getFront().getRight().getUp()) + .setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(entranceCore.getRight().getUp(2)) + .setFacing(BlockUtils.getRight(core.getDirection())) + .apply(entranceCore.getLeft().getUp(2)); + + new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR).setOpen(true) + .setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(entranceCore.getLeft(2)) + .apply(entranceCore.getLeft(2).getUp()) + .setFacing(BlockUtils.getRight(core.getDirection())) + .apply(entranceCore.getRight(2)) + .apply(entranceCore.getRight(2).getUp()); + + // Stairway out the entrance. + + if (entranceCore.getFront(2).isSolid()) { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .setStairwayDirection( + BlockFace.UP) + .build(entranceCore.getFront( + 4)); + entranceCore.getFront(2).Pillar(2, new Random(), Material.AIR); + entranceCore.getFront(3).Pillar(2, new Random(), Material.AIR); + } + else { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .build(entranceCore.getFront( + 2).getDown()); + } + + // By this point, the entire exterior of the igloo has been placed. + // The below area handles interior placement + + // Pick a random corner to place a chimney + int offset = size / 2; + BlockFace offsetDir = BlockUtils.xzDiagonalPlaneBlockFaces[random.nextInt(BlockUtils.xzDiagonalPlaneBlockFaces.length)]; + SimpleBlock chimneyCore = core.getRelative(offsetDir, offset); + chimneyCore.getDown().setType(Material.HAY_BLOCK); + chimneyCore.setType(Material.CAMPFIRE); + + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + if (face.getModX() == offsetDir.getModX() || face.getModZ() == offsetDir.getModZ()) { + for (int depth = 1; depth <= 2; depth++) { + if (chimneyCore.getRelative(face, depth).distanceSquared(core) < size * size) { + chimneyCore.getRelative(face, depth) + .LPillar(size, new Random(), Material.STONE, Material.COBBLESTONE); + } } - } - - // dril chimney - chimneyCore.getUp().Pillar(size+10, Material.AIR); - - // Create the actual chimney (drill air and make the chimney out of trapdoor) - for(BlockFace face:BlockUtils.directBlockFaces) { - for(int ry = size+1; ry > 0; ry--) { - SimpleBlock target = chimneyCore.getUp(ry).getRelative(face); - if(target.getDown().getType() == Material.SNOW_BLOCK) { - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(target); - break; - } - else - new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR) - .setFacing(face) - .setOpen(true) - .apply(target); - } - } - - // On all four corners except the entrance, place some stuff - for(BlockFace face:BlockUtils.directBlockFaces) { - if(face == core.getDirection()) continue; - - // find the igloo wall. It will be spruce log, so get the one in front of it. - Wall wall = new Wall(core, face.getOppositeFace()); - - int threshold = size+1; - boolean found = false; - while(threshold >= 0) { - if(wall.getType() == Material.SPRUCE_LOG) { - found = true; - break; - } - wall = wall.getRear(); - threshold--; - } - // Only operate on the wall if a wall is found. - if(found) { - wall = wall.getFront(2); - for(BlockFace side:BlockUtils.getAdjacentFaces(wall.getDirection())) { - Wall decoCore = wall.getRelative(side); - // That's the chimney - if(BlockUtils.isStoneLike(decoCore.getType()) || - BlockUtils.isStoneLike(decoCore.getRelative(side).getType())) - continue; - - switch(random.nextInt(6)) { - case 0: // Bed - case 1: - BlockUtils.placeBed(decoCore, BlockUtils.pickBed(), decoCore.getDirection()); - decoCore.getRelative(side).lsetType(Material.SPRUCE_LOG); - decoCore.getRelative(side).getUp().lsetType(Material.POTTED_SPRUCE_SAPLING); - break; - case 2: - case 3: // Solid interactable blocks and tables - for(int i = 0; i < 5; i++) { - if(decoCore.getRelative(side,i).isSolid()) - break; - - switch(random.nextInt(3)) { - case 0: // Directional deco - new DirectionalBuilder(Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER, Material.ANVIL) - .setFacing(decoCore.getDirection()) - .apply(decoCore.getRelative(side,i)); - break; - case 1: // Static deco - decoCore.getRelative(side,i).setType(Material.CRAFTING_TABLE, Material.FLETCHING_TABLE); - break; - default: // Table - new SlabBuilder(Material.SPRUCE_SLAB, Material.DIORITE_SLAB, Material.ANDESITE_SLAB, Material.COBBLESTONE_SLAB) - .setType(Slab.Type.TOP) - .apply(decoCore.getRelative(side,i)); - break; - - } - - // Place stuff on top of whatever was placed. - decoCore.getRelative(side,i).getUp().setType(Material.TURTLE_EGG, - Material.AIR, Material.AIR, - Material.AIR, Material.AIR, - Material.AIR, Material.AIR, - Material.TORCH, Material.TORCH, - Material.LANTERN, Material.LANTERN, - Material.POTTED_SPRUCE_SAPLING, Material.POTTED_POPPY, - Material.POTTED_FERN); - } - break; - default: // Barrels of stuff - for(int i = 0; i < 5; i++) { - if(decoCore.getRelative(side,i).isSolid()) break; - if(random.nextBoolean()) continue; - new BarrelBuilder() - .setFacing(BlockUtils.getSixBlockFace(random)) - .setLootTable(TerraLootTable.IGLOO_CHEST) - .apply(decoCore.getRelative(side,i)); - } - break; - } - } - } - } - - // Place carpet on the ground in the middle. - core.setType(Material.RED_CARPET); - - // Pick a color and set the larger radius. - Material carpet = BlockUtils.pickCarpet(); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - core.getRelative(face).lsetType(carpet); - } - if(size > 5) - for(BlockFace face:BlockUtils.directBlockFaces) { - core.getRelative(face,2).setType(carpet); - } - - // Spawn a villager. - core.getUp().addEntity(EntityType.VILLAGER); + } + } + + // dril chimney + chimneyCore.getUp().Pillar(size + 10, Material.AIR); + + // Create the actual chimney (drill air and make the chimney out of trapdoor) + for (BlockFace face : BlockUtils.directBlockFaces) { + for (int ry = size + 1; ry > 0; ry--) { + SimpleBlock target = chimneyCore.getUp(ry).getRelative(face); + if (target.getDown().getType() == Material.SNOW_BLOCK) { + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(face.getOppositeFace()).apply(target); + break; + } + else { + new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR).setFacing(face).setOpen(true).apply(target); + } + } + } + + // On all four corners except the entrance, place some stuff + for (BlockFace face : BlockUtils.directBlockFaces) { + if (face == core.getDirection()) { + continue; + } + + // find the igloo wall. It will be spruce log, so get the one in front of it. + Wall wall = new Wall(core, face.getOppositeFace()); + + int threshold = size + 1; + boolean found = false; + while (threshold >= 0) { + if (wall.getType() == Material.SPRUCE_LOG) { + found = true; + break; + } + wall = wall.getRear(); + threshold--; + } + // Only operate on the wall if a wall is found. + if (found) { + wall = wall.getFront(2); + for (BlockFace side : BlockUtils.getAdjacentFaces(wall.getDirection())) { + Wall decoCore = wall.getRelative(side); + // That's the chimney + if (BlockUtils.isStoneLike(decoCore.getType()) || BlockUtils.isStoneLike(decoCore.getRelative(side) + .getType())) + { + continue; + } + + switch (random.nextInt(6)) { + case 0: // Bed + case 1: + BlockUtils.placeBed(decoCore, BlockUtils.pickBed(), decoCore.getDirection()); + decoCore.getRelative(side).lsetType(Material.SPRUCE_LOG); + decoCore.getRelative(side).getUp().lsetType(Material.POTTED_SPRUCE_SAPLING); + break; + case 2: + case 3: // Solid interactable blocks and tables + for (int i = 0; i < 5; i++) { + if (decoCore.getRelative(side, i).isSolid()) { + break; + } + + switch (random.nextInt(3)) { + case 0: // Directional deco + new DirectionalBuilder( + Material.FURNACE, + Material.BLAST_FURNACE, + Material.SMOKER, + Material.ANVIL + ).setFacing(decoCore.getDirection()).apply(decoCore.getRelative(side, i)); + break; + case 1: // Static deco + decoCore.getRelative(side, i) + .setType(Material.CRAFTING_TABLE, Material.FLETCHING_TABLE); + break; + default: // Table + new SlabBuilder( + Material.SPRUCE_SLAB, + Material.DIORITE_SLAB, + Material.ANDESITE_SLAB, + Material.COBBLESTONE_SLAB + ).setType(Slab.Type.TOP).apply(decoCore.getRelative(side, i)); + break; + + } + + // Place stuff on top of whatever was placed. + decoCore.getRelative(side, i).getUp().setType(Material.TURTLE_EGG, + Material.AIR, + Material.AIR, + Material.AIR, + Material.AIR, + Material.AIR, + Material.AIR, + Material.TORCH, + Material.TORCH, + Material.LANTERN, + Material.LANTERN, + Material.POTTED_SPRUCE_SAPLING, + Material.POTTED_POPPY, + Material.POTTED_FERN + ); + } + break; + default: // Barrels of stuff + for (int i = 0; i < 5; i++) { + if (decoCore.getRelative(side, i).isSolid()) { + break; + } + if (random.nextBoolean()) { + continue; + } + new BarrelBuilder().setFacing(BlockUtils.getSixBlockFace(random)) + .setLootTable(TerraLootTable.IGLOO_CHEST) + .apply(decoCore.getRelative(side, i)); + } + break; + } + } + } + } + + // Place carpet on the ground in the middle. + core.setType(Material.RED_CARPET); + + // Pick a color and set the larger radius. + Material carpet = BlockUtils.pickCarpet(); + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + core.getRelative(face).lsetType(carpet); + } + if (size > 5) { + for (BlockFace face : BlockUtils.directBlockFaces) { + core.getRelative(face, 2).setType(carpet); + } + } + + // Spawn a villager. + core.getUp().addEntity(EntityType.VILLAGER); } - + private void spawnTrapdoorDecors(@NotNull Wall w, int size) { - int lowest = 9999; - for(int i = 1; i < size; i++) { - Wall target = w.getFront(i); - if(i <= 2) { - target.setType(Material.SNOW_BLOCK); - if(i == 1) { - target.getLeft().setType(Material.SNOW_BLOCK); - target.getRight().setType(Material.SNOW_BLOCK); - } - new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR) - .setFacing(w.getDirection()).apply(target.getUp()); - continue; - } - - target = target.getDown(i-3); - if(!target.isSolid()) { - new StairBuilder(Material.SPRUCE_STAIRS) - .setFacing(target.getDirection().getOppositeFace()) - .apply(target); - target.getDown().lsetType(Material.SNOW_BLOCK); - } - if(target.getY() < lowest) lowest = target.getY(); - } - - int y = w.getDown(size).getY(); - - while(y <= lowest) { - Wall target = w.getFront(size).getAtY(y); - new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR) - .setOpen(true) - .setFacing(w.getDirection()) - .lapply(target); - if(target.getType() == Material.SNOW_BLOCK) { - target.setType(Material.SPRUCE_LOG); - target.getUp().setType(Material.SPRUCE_LOG); - - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lantern.setHanging(true); - target.getUp().getRear().setBlockData(lantern); - - new StairBuilder(Material.SPRUCE_STAIRS) - .setFacing(target.getDirection().getOppositeFace()) - .apply(target.getUp(2)) - .apply(target.getFront()); - } - y++; - } - + int lowest = 9999; + for (int i = 1; i < size; i++) { + Wall target = w.getFront(i); + if (i <= 2) { + target.setType(Material.SNOW_BLOCK); + if (i == 1) { + target.getLeft().setType(Material.SNOW_BLOCK); + target.getRight().setType(Material.SNOW_BLOCK); + } + new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR).setFacing(w.getDirection()).apply(target.getUp()); + continue; + } + + target = target.getDown(i - 3); + if (!target.isSolid()) { + new StairBuilder(Material.SPRUCE_STAIRS).setFacing(target.getDirection().getOppositeFace()) + .apply(target); + target.getDown().lsetType(Material.SNOW_BLOCK); + } + if (target.getY() < lowest) { + lowest = target.getY(); + } + } + + int y = w.getDown(size).getY(); + + while (y <= lowest) { + Wall target = w.getFront(size).getAtY(y); + new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR).setOpen(true).setFacing(w.getDirection()).lapply(target); + if (target.getType() == Material.SNOW_BLOCK) { + target.setType(Material.SPRUCE_LOG); + target.getUp().setType(Material.SPRUCE_LOG); + + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lantern.setHanging(true); + target.getUp().getRear().setBlockData(lantern); + + new StairBuilder(Material.SPRUCE_STAIRS).setFacing(target.getDirection().getOppositeFace()) + .apply(target.getUp(2)) + .apply(target.getFront()); + } + y++; + } + } - + private void spawnSpire(@NotNull SimpleBlock block) { - block.Pillar(3, Material.SPRUCE_LOG); - block.getUp(3).setType(Material.COBBLESTONE_WALL); - block.getUp(4).setType(Material.SPRUCE_FENCE); - for(BlockFace face:BlockUtils.directBlockFaces) { - new StairBuilder(Material.SPRUCE_STAIRS) - .setFacing(face.getOppositeFace()) - .lapply(block.getRelative(face)); - - new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR) - .setFacing(face) - .setOpen(true) - .apply(block.getUp(2).getRelative(face)); - } - + block.Pillar(3, Material.SPRUCE_LOG); + block.getUp(3).setType(Material.COBBLESTONE_WALL); + block.getUp(4).setType(Material.SPRUCE_FENCE); + for (BlockFace face : BlockUtils.directBlockFaces) { + new StairBuilder(Material.SPRUCE_STAIRS).setFacing(face.getOppositeFace()).lapply(block.getRelative(face)); + + new TrapdoorBuilder(Material.SPRUCE_TRAPDOOR).setFacing(face) + .setOpen(true) + .apply(block.getUp(2).getRelative(face)); + } + } - + @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int num = TConfigOption.STRUCTURES_IGLOO_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCenterChunkBlockCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 992722*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCenterChunkBlockCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 992722 * (1 + i))); + } return coords; } @@ -386,30 +399,33 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 976123), - (int) (TConfigOption.STRUCTURES_IGLOO_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_IGLOO_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } - + @Override - public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, - int chunkZ) { - if ( !isEnabled() ) return false; + public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); + EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); double suitable = 0; double notsuitable = 0; - for(BiomeBank b:biomes) - if((b.getClimate() != BiomeClimate.SNOWY) - || b.getType() != BiomeType.FLAT) - notsuitable++; - else - suitable++; - - return (suitable/(suitable+notsuitable)) > 0.5 && rollSpawnRatio(tw,chunkX,chunkZ); + for (BiomeBank b : biomes) { + if ((b.getClimate() != BiomeClimate.SNOWY) || b.getType() != BiomeType.FLAT) { + notsuitable++; + } + else { + suitable++; + } + } + + return (suitable / (suitable + notsuitable)) > 0.5 && rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -424,9 +440,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_IGLOO_ENABLED.getBoolean(); } - + @Override public int getChunkBufferDistance() { - return 1; + return 1; } } diff --git a/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java b/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java index 550e7be0..0cd31b6b 100644 --- a/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java @@ -1,9 +1,5 @@ package org.terraform.structure.small.ruinedportal; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.NotNull; @@ -28,260 +24,318 @@ import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Random; + public class RuinedPortalPopulator extends MultiMegaChunkStructurePopulator { - private static final Material[] portalBlocks = new Material[] {Material.OBSIDIAN, Material.CRYING_OBSIDIAN}; + private static final Material[] portalBlocks = new Material[] {Material.OBSIDIAN, Material.CRYING_OBSIDIAN}; @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { int x = coords[0]; int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) - continue; + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { + continue; + } int height = GenUtils.getHighestGround(data, x, z); - + spawnRuinedPortal(tw, random, data, x, height + 1, z); } } - public void spawnRuinedPortal(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - SimpleBlock core = new SimpleBlock(data, x, y, z); - BiomeBank biome = tw.getBiomeBank(x, z); - boolean overgrown = biome.getClimate() == BiomeClimate.HUMID_VEGETATION; - boolean snowy = biome.getClimate() == BiomeClimate.SNOWY; - int mossiness = 0; - - if(biome.getClimate() == BiomeClimate.HUMID_VEGETATION) - mossiness = 2; - else if(biome.getClimate() == BiomeClimate.DRY_VEGETATION||biome.getClimate() == BiomeClimate.TRANSITION) - mossiness = 1; - - - spawnRuinedPortal(tw,random,core.getUp(), mossiness, overgrown, snowy); + public void spawnRuinedPortal(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + SimpleBlock core = new SimpleBlock(data, x, y, z); + BiomeBank biome = tw.getBiomeBank(x, z); + boolean overgrown = biome.getClimate() == BiomeClimate.HUMID_VEGETATION; + boolean snowy = biome.getClimate() == BiomeClimate.SNOWY; + int mossiness = 0; + + if (biome.getClimate() == BiomeClimate.HUMID_VEGETATION) { + mossiness = 2; + } + else if (biome.getClimate() == BiomeClimate.DRY_VEGETATION || biome.getClimate() == BiomeClimate.TRANSITION) { + mossiness = 1; + } + + + spawnRuinedPortal(tw, random, core.getUp(), mossiness, overgrown, snowy); } - + /** * Underwater checks are done here, as the portal being underwater will * override all these vegetation settings. */ - public void spawnRuinedPortal(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock core, - int mossiness, boolean overgrown, boolean snowy) { - int horRadius = GenUtils.randInt(random, 2, 4); // ALWAYS EVEN - int vertHeight = 1+horRadius*2; // Can be odd - BlockFace facing = BlockUtils.getDirectBlockFace(random); - Wall w = new Wall(core, facing); - // Material fluid = Material.AIR; - Material lavaFluid = Material.LAVA; - - // Replace lava when overgrown to prevent forest fires - if(BlockUtils.isWet(core) || snowy || overgrown) lavaFluid = Material.MAGMA_BLOCK; - - // Nether-rize the land around the portal - BlockUtils.replaceCircularPatch(random.nextInt(99999), horRadius*2.5f, core.getDown(), - snowy, Material.NETHERRACK); - - // Flatten land below the portal - Material[] stoneBricks = BlockUtils.stoneBricks; - if(mossiness == 0) stoneBricks = new Material[] {Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; - if(mossiness > 1) stoneBricks = new Material[] {Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.MOSSY_STONE_BRICKS}; - new CylinderBuilder(random, w.getDown(), stoneBricks) - .setRadius(horRadius+1) - .setRY(1) - .setHardReplace(false) - .build(); - - // [Side decorations]============================ - Wall effectiveGround = w.getRight(horRadius).findFloor(10); - int heightCorrection = vertHeight; - if(effectiveGround != null) { - if(effectiveGround.getY() >= w.getY()-2) - effectiveGround = effectiveGround.getAtY(w.getY() - 2); - else { - heightCorrection = vertHeight + (w.getY() - 2 - effectiveGround.getY()); - } - new StalactiteBuilder(portalBlocks) - .setVerticalSpace(Math.round(2.5f*heightCorrection*1.5f)) - .setFacingUp(true) - .setSolidBlockType(portalBlocks) - .setMinRadius(2) - .build(random, effectiveGround); - } - effectiveGround = w.getLeft(horRadius+1).findFloor(10); - heightCorrection = vertHeight; - if(effectiveGround != null) { - if(effectiveGround.getY() >= w.getY()-2) - effectiveGround = effectiveGround.getAtY(w.getY() - 2); - else { - heightCorrection = vertHeight + (w.getY() - 2 - effectiveGround.getY()); - } - new StalactiteBuilder(portalBlocks) - .setVerticalSpace(Math.round(2.5f*heightCorrection*1.5f)) - .setFacingUp(true) - .setSolidBlockType(portalBlocks) - .setMinRadius(2) - .build(random, effectiveGround); - } - - // [End side decorations]======================== - - // Build the core portal - for(int left = 0; left < horRadius; left++) { - w.getLeft(left).setType(portalBlocks); - - // Empty center of portal - for(int depth = -3; depth <= 3; depth++) // depth is the horizontal depth - for(int height = 0; height < vertHeight - 2; height++) // Height is vertical height - { - Wall target = w.getFront(depth).getLeft(left).getUp(1 + height); - target.setType(getFluid(target)); - } - - - w.getUp(vertHeight).getLeft(left).setType(portalBlocks); - w.getUp(vertHeight+1).getLeft(left).setType(Material.STONE_BRICK_SLAB, getFluid(w.getUp(vertHeight+1).getLeft(left))); - } - for(int right = 1; right < horRadius-1; right++) { - w.getRight(right).setType(portalBlocks); - for(int depth = -3; depth <= 3; depth++) // depth is the horizontal depth - for(int height = 0; height < vertHeight - 2; height++) // Height is vertical height - { - Wall target = w.getFront(depth).getRight(right).getUp(1+height); - target.setType(getFluid(target)); - } - - - w.getUp(vertHeight).getRight(right).setType(portalBlocks); - w.getUp(vertHeight+1).getRight(right).setType(Material.STONE_BRICK_SLAB, getFluid(w.getUp(vertHeight+1).getRight(right))); - } - - w.getLeft(horRadius).Pillar(1+vertHeight, portalBlocks); - w.getRight(horRadius - 1).Pillar(1+vertHeight, portalBlocks); - - Wall rightCorner = w.getUp(vertHeight).getRight(horRadius - 1); - Wall leftCorner = w.getUp(vertHeight).getLeft(horRadius); - - // [Carve out a lava fissure]================= - FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_RUINEDPORTAL_FISSURES, world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.PerlinFractal); - n.SetFrequency(0.035f); - n.SetFractalOctaves(5); - return n; - }); - - HashMap lavaLocs = new HashMap<>(); - int lowestY = 9999; - for(int relx = - horRadius*3; relx < horRadius*3; relx++) { - for(int relz = - horRadius*3; relz < horRadius*3; relz++) { - double fissureNoise = (3 - 100 * Math.abs(noise.GetNoise(relx+core.getX(), relz + core.getZ()))); - if(fissureNoise > 0) { - SimpleBlock target = core.getRelative(relx,0,relz).getGround(); - fissureNoise = (1.0-Math.min(1.0f,target.distance(core)/(horRadius*3)))*fissureNoise; - lavaLocs.put(target, (int) Math.round(fissureNoise)); - if(lowestY > target.getY()) lowestY = target.getY(); - } - } - } - - for(Entry entry:lavaLocs.entrySet()) { - SimpleBlock target = entry.getKey(); - int depth = entry.getValue(); - int tempY = target.getY(); - target = target.getAtY(lowestY); - for(int i = target.getY(); i <= tempY; i++) { - target.getAtY(i).setType(getFluid(target.getAtY(i))); - } - for(int i = 0; i <= depth; i++) { - target.getDown(i).setType(lavaFluid); - } - } - // [End carve lava fissure]====================== - - // [Break one of the corners]================== - - // Break right corner - if(random.nextBoolean()) { - for(int i = 0; i < GenUtils.randInt(1,3); i++) { - rightCorner.getDown(i).setType(getFluid(rightCorner.getDown(i))); - } - BlockUtils.dropDownBlock(rightCorner.getUp(), getFluid(rightCorner.getUp())); - - for(int i = 1; i < GenUtils.randInt(random, 2, horRadius + 2); i++) { - rightCorner.getLeft(i).setType(getFluid(rightCorner.getLeft(i))); - BlockUtils.dropDownBlock(rightCorner.getLeft(i).getUp(), getFluid(rightCorner.getLeft(i).getUp())); - } - if(overgrown && TConfigOption.arePlantsEnabled() && leftCorner.getRight().isSolid()) { - leftCorner.getRight().getRear().downLPillar(random, GenUtils.randInt(vertHeight/2,vertHeight-1), Material.OAK_LEAVES); - leftCorner.getRight().getFront().downLPillar(random, GenUtils.randInt(vertHeight/2,vertHeight-1), Material.OAK_LEAVES); - } - // Break left corner - }else{ - for(int i = 0; i < GenUtils.randInt(1,3); i++) { - leftCorner.getDown(i).setType(getFluid(leftCorner.getDown(i))); - } - BlockUtils.dropDownBlock(leftCorner.getUp(), getFluid(leftCorner.getUp())); - for(int i = 1; i < GenUtils.randInt(random, 2, horRadius + 2); i++) { - leftCorner.getRight(i).setType(getFluid(leftCorner.getRight(i))); - BlockUtils.dropDownBlock(leftCorner.getRight(i).getUp(), getFluid(leftCorner.getRight(i).getUp())); - } - if(overgrown && TConfigOption.arePlantsEnabled() && rightCorner.getLeft().isSolid()) { - rightCorner.getLeft().getRear().downLPillar(random, GenUtils.randInt(vertHeight/2,vertHeight-1), Material.OAK_LEAVES); - rightCorner.getLeft().getFront().downLPillar(random, GenUtils.randInt(vertHeight/2,vertHeight-1), Material.OAK_LEAVES); - } - } - - // Upper decorations - if(rightCorner.isSolid()) - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(rightCorner.getUp()); - if(leftCorner.isSolid()) - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(leftCorner.getUp()); - - // Gold blocks - if(w.getUp(vertHeight).isSolid()) { - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(2+vertHeight)); - w.getUp(1+vertHeight).setType(Material.GOLD_BLOCK, Material.CHISELED_STONE_BRICKS); - } - - if(w.getLeft().getUp(vertHeight).isSolid()) { - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft().getUp(2+vertHeight)); - w.getLeft().getUp(1+vertHeight).setType(Material.GOLD_BLOCK, Material.CHISELED_STONE_BRICKS); - } - - - // Random chest - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.RUINED_PORTAL) - .apply(w.getFront(GenUtils.randInt(3, (int) (horRadius*1.5f))) - .getRight(GenUtils.randInt(3, (int) (horRadius*1.5f))) - .getGround().getUp()); + public void spawnRuinedPortal(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock core, + int mossiness, + boolean overgrown, + boolean snowy) + { + int horRadius = GenUtils.randInt(random, 2, 4); // ALWAYS EVEN + int vertHeight = 1 + horRadius * 2; // Can be odd + BlockFace facing = BlockUtils.getDirectBlockFace(random); + Wall w = new Wall(core, facing); + // Material fluid = Material.AIR; + Material lavaFluid = Material.LAVA; + + // Replace lava when overgrown to prevent forest fires + if (BlockUtils.isWet(core) || snowy || overgrown) { + lavaFluid = Material.MAGMA_BLOCK; + } + + // Nether-rize the land around the portal + BlockUtils.replaceCircularPatch(random.nextInt(99999), + horRadius * 2.5f, + core.getDown(), + snowy, + Material.NETHERRACK + ); + + // Flatten land below the portal + Material[] stoneBricks = BlockUtils.stoneBricks; + if (mossiness == 0) { + stoneBricks = new Material[] {Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + } + if (mossiness > 1) { + stoneBricks = new Material[] { + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.MOSSY_STONE_BRICKS + }; + } + new CylinderBuilder(random, w.getDown(), stoneBricks).setRadius(horRadius + 1) + .setRY(1) + .setHardReplace(false) + .build(); + + // [Side decorations]============================ + Wall effectiveGround = w.getRight(horRadius).findFloor(10); + int heightCorrection = vertHeight; + if (effectiveGround != null) { + if (effectiveGround.getY() >= w.getY() - 2) { + effectiveGround = effectiveGround.getAtY(w.getY() - 2); + } + else { + heightCorrection = vertHeight + (w.getY() - 2 - effectiveGround.getY()); + } + new StalactiteBuilder(portalBlocks).setVerticalSpace(Math.round(2.5f * heightCorrection * 1.5f)) + .setFacingUp(true) + .setSolidBlockType(portalBlocks) + .setMinRadius(2) + .build(random, effectiveGround); + } + effectiveGround = w.getLeft(horRadius + 1).findFloor(10); + heightCorrection = vertHeight; + if (effectiveGround != null) { + if (effectiveGround.getY() >= w.getY() - 2) { + effectiveGround = effectiveGround.getAtY(w.getY() - 2); + } + else { + heightCorrection = vertHeight + (w.getY() - 2 - effectiveGround.getY()); + } + new StalactiteBuilder(portalBlocks).setVerticalSpace(Math.round(2.5f * heightCorrection * 1.5f)) + .setFacingUp(true) + .setSolidBlockType(portalBlocks) + .setMinRadius(2) + .build(random, effectiveGround); + } + + // [End side decorations]======================== + + // Build the core portal + for (int left = 0; left < horRadius; left++) { + w.getLeft(left).setType(portalBlocks); + + // Empty center of portal + for (int depth = -3; depth <= 3; depth++) // depth is the horizontal depth + { + for (int height = 0; height < vertHeight - 2; height++) // Height is vertical height + { + Wall target = w.getFront(depth).getLeft(left).getUp(1 + height); + target.setType(getFluid(target)); + } + } + + + w.getUp(vertHeight).getLeft(left).setType(portalBlocks); + w.getUp(vertHeight + 1) + .getLeft(left) + .setType(Material.STONE_BRICK_SLAB, getFluid(w.getUp(vertHeight + 1).getLeft(left))); + } + for (int right = 1; right < horRadius - 1; right++) { + w.getRight(right).setType(portalBlocks); + for (int depth = -3; depth <= 3; depth++) // depth is the horizontal depth + { + for (int height = 0; height < vertHeight - 2; height++) // Height is vertical height + { + Wall target = w.getFront(depth).getRight(right).getUp(1 + height); + target.setType(getFluid(target)); + } + } + + + w.getUp(vertHeight).getRight(right).setType(portalBlocks); + w.getUp(vertHeight + 1) + .getRight(right) + .setType(Material.STONE_BRICK_SLAB, getFluid(w.getUp(vertHeight + 1).getRight(right))); + } + + w.getLeft(horRadius).Pillar(1 + vertHeight, portalBlocks); + w.getRight(horRadius - 1).Pillar(1 + vertHeight, portalBlocks); + + Wall rightCorner = w.getUp(vertHeight).getRight(horRadius - 1); + Wall leftCorner = w.getUp(vertHeight).getLeft(horRadius); + + // [Carve out a lava fissure]================= + FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.STRUCTURE_RUINEDPORTAL_FISSURES, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.PerlinFractal); + n.SetFrequency(0.035f); + n.SetFractalOctaves(5); + return n; + }); + + HashMap lavaLocs = new HashMap<>(); + int lowestY = 9999; + for (int relx = -horRadius * 3; relx < horRadius * 3; relx++) { + for (int relz = -horRadius * 3; relz < horRadius * 3; relz++) { + double fissureNoise = (3 - 100 * Math.abs(noise.GetNoise(relx + core.getX(), relz + core.getZ()))); + if (fissureNoise > 0) { + SimpleBlock target = core.getRelative(relx, 0, relz).getGround(); + fissureNoise = (1.0 - Math.min(1.0f, target.distance(core) / (horRadius * 3))) * fissureNoise; + lavaLocs.put(target, (int) Math.round(fissureNoise)); + if (lowestY > target.getY()) { + lowestY = target.getY(); + } + } + } + } + + for (Entry entry : lavaLocs.entrySet()) { + SimpleBlock target = entry.getKey(); + int depth = entry.getValue(); + int tempY = target.getY(); + target = target.getAtY(lowestY); + for (int i = target.getY(); i <= tempY; i++) { + target.getAtY(i).setType(getFluid(target.getAtY(i))); + } + for (int i = 0; i <= depth; i++) { + target.getDown(i).setType(lavaFluid); + } + } + // [End carve lava fissure]====================== + + // [Break one of the corners]================== + + // Break right corner + if (random.nextBoolean()) { + for (int i = 0; i < GenUtils.randInt(1, 3); i++) { + rightCorner.getDown(i).setType(getFluid(rightCorner.getDown(i))); + } + BlockUtils.dropDownBlock(rightCorner.getUp(), getFluid(rightCorner.getUp())); + + for (int i = 1; i < GenUtils.randInt(random, 2, horRadius + 2); i++) { + rightCorner.getLeft(i).setType(getFluid(rightCorner.getLeft(i))); + BlockUtils.dropDownBlock(rightCorner.getLeft(i).getUp(), getFluid(rightCorner.getLeft(i).getUp())); + } + if (overgrown && TConfigOption.arePlantsEnabled() && leftCorner.getRight().isSolid()) { + leftCorner.getRight() + .getRear() + .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); + leftCorner.getRight() + .getFront() + .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); + } + // Break left corner + } + else { + for (int i = 0; i < GenUtils.randInt(1, 3); i++) { + leftCorner.getDown(i).setType(getFluid(leftCorner.getDown(i))); + } + BlockUtils.dropDownBlock(leftCorner.getUp(), getFluid(leftCorner.getUp())); + for (int i = 1; i < GenUtils.randInt(random, 2, horRadius + 2); i++) { + leftCorner.getRight(i).setType(getFluid(leftCorner.getRight(i))); + BlockUtils.dropDownBlock(leftCorner.getRight(i).getUp(), getFluid(leftCorner.getRight(i).getUp())); + } + if (overgrown && TConfigOption.arePlantsEnabled() && rightCorner.getLeft().isSolid()) { + rightCorner.getLeft() + .getRear() + .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); + rightCorner.getLeft() + .getFront() + .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); + } + } + + // Upper decorations + if (rightCorner.isSolid()) { + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(rightCorner.getUp()); + } + if (leftCorner.isSolid()) { + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(leftCorner.getUp()); + } + + // Gold blocks + if (w.getUp(vertHeight).isSolid()) { + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(2 + vertHeight)); + w.getUp(1 + vertHeight).setType(Material.GOLD_BLOCK, Material.CHISELED_STONE_BRICKS); + } + + if (w.getLeft().getUp(vertHeight).isSolid()) { + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getLeft().getUp(2 + vertHeight)); + w.getLeft().getUp(1 + vertHeight).setType(Material.GOLD_BLOCK, Material.CHISELED_STONE_BRICKS); + } + + + // Random chest + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.RUINED_PORTAL) + .apply(w.getFront(GenUtils.randInt(3, (int) (horRadius * 1.5f))) + .getRight(GenUtils.randInt(3, (int) (horRadius * 1.5f))) + .getGround() + .getUp()); } - + private @NotNull Material getFluid(@NotNull SimpleBlock block) { - if(BlockUtils.isWet(block)) return Material.WATER; - for(BlockFace face:BlockUtils.directBlockFaces) - if(BlockUtils.isWet(block.getRelative(face))) return Material.WATER; - return Material.AIR; + if (BlockUtils.isWet(block)) { + return Material.WATER; + } + for (BlockFace face : BlockUtils.directBlockFaces) { + if (BlockUtils.isWet(block.getRelative(face))) { + return Material.WATER; + } + } + return Material.AIR; } - + @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int num = TConfigOption.STRUCTURES_RUINEDPORTAL_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 4363463*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 4363463 * (1 + i))); + } return coords; } @@ -307,20 +361,21 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 976123), - (int) (TConfigOption.STRUCTURES_RUINEDPORTAL_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_RUINEDPORTAL_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } - + @Override - public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, - int chunkZ) { - if ( !isEnabled() ) return false; + public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - return rollSpawnRatio(tw,chunkX,chunkZ); + return rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -335,9 +390,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_RUINEDPORTAL_ENABLED.getBoolean(); } - + @Override public int getChunkBufferDistance() { - return 1; + return 1; } } diff --git a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java index 3f151105..2f83afa1 100644 --- a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java @@ -19,19 +19,24 @@ import java.util.Random; public class ShipwreckPopulator extends MultiMegaChunkStructurePopulator { - private static final String[] SCHEMATICS = {"upright-shipwreck-1", - "tilted-shipwreck-1"}; + private static final String[] SCHEMATICS = { + "upright-shipwreck-1", "tilted-shipwreck-1" + }; private static void dropDownBlock(@NotNull SimpleBlock block) { if (block.isSolid()) { Material type = block.getType(); - if (type == Material.CHEST) return; + if (type == Material.CHEST) { + return; + } block.setType(Material.WATER); int depth = 0; while (!block.isSolid()) { block = block.getDown(); depth++; - if (depth > 50) return; + if (depth > 50) { + return; + } } block.getUp().setType(type); @@ -40,41 +45,64 @@ private static void dropDownBlock(@NotNull SimpleBlock block) { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { int x = coords[0]; int z = coords[1]; - if(x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) - continue; + if (x >> 4 != data.getChunkX() || z >> 4 != data.getChunkZ()) { + continue; + } int height = GenUtils.getHighestGround(data, x, z) - 1 - random.nextInt(5); - + spawnShipwreck(tw, random, data, x, height + 1, z); } } - public void spawnShipwreck(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnShipwreck(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { try { - // If the ground is dry, force the whole ship down into the ground to bury it. - if(!BlockUtils.isWet(new SimpleBlock(data,x,0,z).getGround().getUp())) { - y -= GenUtils.randInt(random, 4, 7); - } + // If the ground is dry, force the whole ship down into the ground to bury it. + if (!BlockUtils.isWet(new SimpleBlock(data, x, 0, z).getGround().getUp())) { + y -= GenUtils.randInt(random, 4, 7); + } y += GenUtils.randInt(random, -1, 1); - TerraSchematic shipwreck = TerraSchematic.load(SCHEMATICS[random.nextInt(SCHEMATICS.length)], new SimpleBlock(data, x, y, z)); + TerraSchematic shipwreck = TerraSchematic.load( + SCHEMATICS[random.nextInt(SCHEMATICS.length)], + new SimpleBlock(data, x, y, z) + ); shipwreck.parser = new ShipwreckSchematicParser(tw.getBiomeBank(x, z), random, data); shipwreck.setFace(BlockUtils.getDirectBlockFace(random)); shipwreck.apply(); - TerraformGeneratorPlugin.logger.info("Spawning shipwreck at " + x + ", " + y + ", " + z + " with rotation of " + shipwreck.getFace()); + TerraformGeneratorPlugin.logger.info("Spawning shipwreck at " + + x + + ", " + + y + + ", " + + z + + " with rotation of " + + shipwreck.getFace()); // Generate holes and damage for (int i = 0; i < GenUtils.randInt(random, 0, 3); i++) { int nx = x + GenUtils.randInt(random, -8, 8); int nz = z + GenUtils.randInt(random, -8, 8); int ny = y + GenUtils.randInt(random, 0, 5); - BlockUtils.replaceWaterSphere(nx * 7 * ny * 23 * nz, GenUtils.randInt(1, 3), new SimpleBlock(data, nx, ny, nz)); + BlockUtils.replaceWaterSphere( + nx * 7 * ny * 23 * nz, + GenUtils.randInt(1, 3), + new SimpleBlock(data, nx, ny, nz) + ); } // Dropdown blocks @@ -89,8 +117,14 @@ public void spawnShipwreck(@NotNull TerraformWorld tw, @NotNull Random random, @ data.addEntity(x, y + 15, z, EntityType.DROWNED); - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place shipwreck at " + x + ", " + y + ", " + z); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place shipwreck at " + + x + + ", " + + y + + ", " + + z); TerraformGeneratorPlugin.logger.stackTrace(e); } } @@ -99,8 +133,9 @@ public void spawnShipwreck(@NotNull TerraformWorld tw, @NotNull Random random, @ public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int num = TConfigOption.STRUCTURES_SHIPWRECK_COUNT_PER_MEGACHUNK.getInt(); int[][] coords = new int[num][2]; - for (int i = 0; i < num; i++) - coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 191921*(1+i))); + for (int i = 0; i < num; i++) { + coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 191921 * (1 + i))); + } return coords; } @@ -127,29 +162,33 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_SHIPWRECK_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_SHIPWRECK_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } - + @Override - public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, - int chunkZ) { - if ( !isEnabled() ) return false; + public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); for (int[] coords : getCoordsFromMegaChunk(tw, mc)) { if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); + EnumSet biomes = GenUtils.getBiomesInChunk(tw, chunkX, chunkZ); double numWet = 0; double numDry = 0; - for(BiomeBank b:biomes) - if(b.isDry()) - numDry++; - else - numWet++; - - return (numWet/(numWet+numDry)) > 0.5 && rollSpawnRatio(tw,chunkX,chunkZ); + for (BiomeBank b : biomes) { + if (b.isDry()) { + numDry++; + } + else { + numWet++; + } + } + + return (numWet / (numWet + numDry)) > 0.5 && rollSpawnRatio(tw, chunkX, chunkZ); } } return false; @@ -164,9 +203,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_SHIPWRECK_ENABLED.getBoolean(); } - + @Override public int getChunkBufferDistance() { - return 1; + return 1; } } diff --git a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckSchematicParser.java b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckSchematicParser.java index 95a80a1e..931fb833 100644 --- a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckSchematicParser.java @@ -21,21 +21,14 @@ public class ShipwreckSchematicParser extends SchematicParser { private static final String[] WOODS = { - "OAK", - "ACACIA", - "BIRCH", - "SPRUCE", - "DARK_OAK", - "SPRUCE", - "JUNGLE" + "OAK", "ACACIA", "BIRCH", "SPRUCE", "DARK_OAK", "SPRUCE", "JUNGLE" }; + final String woodType; private final BiomeBank biome; private final @NotNull Random rand; private final PopulatorDataAbstract pop; - final String woodType; - public ShipwreckSchematicParser(BiomeBank biome, @NotNull Random rand, - PopulatorDataAbstract pop) { + public ShipwreckSchematicParser(BiomeBank biome, @NotNull Random rand, PopulatorDataAbstract pop) { this.biome = biome; this.rand = rand; this.pop = pop; @@ -52,73 +45,74 @@ public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { // Mossy cobble if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - StringUtils.replace(data.getAsString(), "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .name().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(StringUtils.replace(data.getAsString(), + "cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).name().toLowerCase(Locale.ENGLISH) + )); } // Holes if (GenUtils.chance(rand, 1, 30)) { - if (block.getY() <= TerraformGenerator.seaLevel) + if (block.getY() <= TerraformGenerator.seaLevel) { data = Bukkit.createBlockData(Material.WATER); - else + } + else { data = Bukkit.createBlockData(Material.AIR); + } super.applyData(block, data); return; } - if (data.getMaterial().toString().startsWith("OAK") || - data.getMaterial().toString().startsWith("STRIPPED_OAK")) { + if (data.getMaterial().toString().startsWith("OAK") || data.getMaterial() + .toString() + .startsWith("STRIPPED_OAK")) + { data = Bukkit.createBlockData(data.getAsString().replace("OAK", woodType)); } if (data.getMaterial() == Material.CHEST) { if (GenUtils.chance(rand, 4, 5)) { - if (block.getY() <= TerraformGenerator.seaLevel) + if (block.getY() <= TerraformGenerator.seaLevel) { data = Bukkit.createBlockData(Material.WATER); - else + } + else { data = Bukkit.createBlockData(Material.AIR); + } super.applyData(block, data); return; } super.applyData(block, data); - switch(rand.nextInt(3)) { - case 0: - pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.SHIPWRECK_TREASURE); - break; - case 1: - pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.SHIPWRECK_SUPPLY); - break; - case 2: - default: - pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.SHIPWRECK_MAP); - break; + switch (rand.nextInt(3)) { + case 0: + pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.SHIPWRECK_TREASURE); + break; + case 1: + pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.SHIPWRECK_SUPPLY); + break; + case 2: + default: + pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.SHIPWRECK_MAP); + break; } return; } if (data.getMaterial().isBlock() && data.getMaterial().isSolid()) { - if (GenUtils.chance(rand, 1, 60) - && !biome.toString().contains("COLD") // Dont spawn these in cold places. - && !biome.toString().contains("FROZEN")) { // Corals - CoralGenerator.generateCoral(block.getPopData(), - block.getX(), - block.getY(), - block.getZ()); - } else if (GenUtils.chance(rand, 1, 40)) { // kelp n stuff - CoralGenerator.generateKelpGrowth(block.getPopData(), - block.getX(), - block.getY() + 1, - block.getZ()); + if (GenUtils.chance(rand, 1, 60) && !biome.toString().contains("COLD") // Dont spawn these in cold places. + && !biome.toString().contains("FROZEN")) + { // Corals + CoralGenerator.generateCoral(block.getPopData(), block.getX(), block.getY(), block.getZ()); + } + else if (GenUtils.chance(rand, 1, 40)) { // kelp n stuff + CoralGenerator.generateKelpGrowth(block.getPopData(), block.getX(), block.getY() + 1, block.getZ()); } } diff --git a/common/src/main/java/org/terraform/structure/stronghold/HallwayPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/HallwayPopulator.java index 9ca2d71d..34ca8bef 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/HallwayPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/HallwayPopulator.java @@ -34,15 +34,17 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall w = entry.getKey(); boolean wasAir = false; for (int i = 0; i < entry.getValue(); i++) { - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Bisected.Half.TOP) - .apply(w.getUp(4)); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(w.getDirection().getOppositeFace()).setHalf(Bisected.Half.TOP).apply(w.getUp(4)); w.getUp(5).LPillar(room.getHeight(), rand, BlockUtils.stoneBricks); if (!w.getRear().getUp().isSolid()) { wasAir = true; - w.getUp(5).setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); - } else { + w.getUp(5) + .setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); + } + else { // Right or left wall is part of an entrance if (wasAir || !w.getLeft().getRear().getUp().isSolid()) { w.getRear().Pillar(5, rand, Material.STONE, Material.SMOOTH_STONE); @@ -57,10 +59,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (Entry entry : room.getFourWalls(data, 1).entrySet()) { Wall w = entry.getKey().getRelative(0, room.getHeight() - 1, 0); for (int i = 0; i < entry.getValue(); i++) { - new StairBuilder(Material.ANDESITE_STAIRS, Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Bisected.Half.TOP) - .apply(w); + new StairBuilder( + Material.ANDESITE_STAIRS, + Material.STONE_BRICK_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(w.getDirection().getOppositeFace()).setHalf(Bisected.Half.TOP).apply(w); w = w.getLeft(); } @@ -68,8 +71,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Corner Walls for (int[] coords : room.getAllCorners(1)) { - new Wall(new SimpleBlock(data, coords[0], room.getY() + 1, coords[1])) - .Pillar(room.getHeight() - 1, rand, BlockUtils.stoneBricks); + new Wall(new SimpleBlock(data, coords[0], room.getY() + 1, coords[1])).Pillar( + room.getHeight() - 1, + rand, + BlockUtils.stoneBricks + ); } for (int i = 0; i < GenUtils.randInt(rand, room.getWidthX(), room.getWidthX() * room.getWidthZ() / 10); i++) { @@ -89,9 +95,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int j = 0; j < GenUtils.randInt(rand, 0, 3); j++) { BlockFace face = CoralGenerator.getRandomBlockFace(); - if (face == BlockFace.UP) face = BlockFace.SELF; - if (!webBase.getRelative(face).isSolid()) + if (face == BlockFace.UP) { + face = BlockFace.SELF; + } + if (!webBase.getRelative(face).isSolid()) { webBase.getRelative(face).setType(Material.COBWEB); + } } } } @@ -106,18 +115,22 @@ private void dropDownBlock(@NotNull SimpleBlock block) { while (!block.isSolid()) { block = block.getDown(); depth++; - if (depth > 50) return; + if (depth > 50) { + return; + } } if (type instanceof Slab) { ((Slab) type).setType(Slab.Type.BOTTOM); - } else if (type instanceof Stairs) { + } + else if (type instanceof Stairs) { ((Stairs) type).setHalf(Half.BOTTOM); } if (GenUtils.chance(1, 3)) { block.getUp().setBlockData(BlockUtils.infestStone(type)); - } else { + } + else { block.getUp().setBlockData(type); } } @@ -126,9 +139,7 @@ private void dropDownBlock(@NotNull SimpleBlock block) { @Override public boolean canPopulate(@NotNull CubeRoom room) { // Don't override prisons: Hallways are bloody dull. - return !new PrisonRoomPopulator(new Random(), false, false).canPopulate(room) - && room.isBig() - && !room.isHuge(); + return !new PrisonRoomPopulator(new Random(), false, false).canPopulate(room) && room.isBig() && !room.isHuge(); } diff --git a/common/src/main/java/org/terraform/structure/stronghold/LibraryRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/LibraryRoomPopulator.java index 5135b4f5..9175325e 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/LibraryRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/LibraryRoomPopulator.java @@ -45,21 +45,25 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall temp = wall.getUp(); for (int t = 0; t < room.getHeight(); t++) { temp = temp.getUp(); - if (temp.getRear().get().getType().toString().endsWith("STONE_BRICKS")) + if (temp.getRear().get().getType().toString().endsWith("STONE_BRICKS")) { break; + } } temp.setType(Material.CHISELED_STONE_BRICKS); temp.getUp().LPillar(room.getHeight(), rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - } else { // If it isn't an entrance, make bookshelves + } + else { // If it isn't an entrance, make bookshelves if (other <= 2) { wall.LPillar(room.getHeight(), rand, Material.BOOKSHELF); other++; - } else { + } + else { other = 0; wall.LPillar(room.getHeight(), rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - wall.getFront().LPillar(room.getHeight(), rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + wall.getFront() + .LPillar(room.getHeight(), rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); } } wall = wall.getLeft(); @@ -84,17 +88,24 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room front.setBlockData(o); } } - } else { + } + else { // Spawn loot chest if (GenUtils.chance(rand, 5, 100)) { SimpleBlock cBlock = pWall.getUp().get(); cBlock.setType(Material.CHEST); - org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData(Material.CHEST); + org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData( + Material.CHEST); chest.setFacing(pWall.getDirection()); cBlock.setBlockData(chest); - data.lootTableChest(cBlock.getX(), cBlock.getY(), cBlock.getZ(), TerraLootTable.STRONGHOLD_LIBRARY); + data.lootTableChest( + cBlock.getX(), + cBlock.getY(), + cBlock.getZ(), + TerraLootTable.STRONGHOLD_LIBRARY + ); } // Place slabs for (int i = 0; i < 3; i++) { @@ -123,8 +134,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int l = 0; l < entry.getValue(); l++) { wall.setType(Material.OAK_FENCE); BlockUtils.correctSurroundingMultifacingData(wall.get()); - if (GenUtils.chance(rand, 1, 10)) + if (GenUtils.chance(rand, 1, 10)) { wall.getUp().setType(Material.TORCH); + } wall = wall.getLeft(); } } @@ -132,18 +144,30 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Stairway generation // Wall object, to the length of the wall ArrayList stairWalls = new ArrayList<>(); - Wall stairWallOne = new Wall( - new SimpleBlock(data, lowerBounds[0] + 5, room.getY() + pHeight, upperBounds[1] - 5) - , BlockFace.NORTH); - Wall stairWallTwo = new Wall( - new SimpleBlock(data, upperBounds[0] - 5, room.getY() + pHeight, lowerBounds[1] + 5) - , BlockFace.SOUTH); - Wall stairWallThree = new Wall( - new SimpleBlock(data, lowerBounds[0] + 5, room.getY() + pHeight, lowerBounds[1] + 5) - , BlockFace.EAST); - Wall stairWallFour = new Wall( - new SimpleBlock(data, upperBounds[0] - 5, room.getY() + pHeight, upperBounds[1] - 5) - , BlockFace.WEST); + Wall stairWallOne = new Wall(new SimpleBlock( + data, + lowerBounds[0] + 5, + room.getY() + pHeight, + upperBounds[1] - 5 + ), BlockFace.NORTH); + Wall stairWallTwo = new Wall(new SimpleBlock( + data, + upperBounds[0] - 5, + room.getY() + pHeight, + lowerBounds[1] + 5 + ), BlockFace.SOUTH); + Wall stairWallThree = new Wall(new SimpleBlock( + data, + lowerBounds[0] + 5, + room.getY() + pHeight, + lowerBounds[1] + 5 + ), BlockFace.EAST); + Wall stairWallFour = new Wall(new SimpleBlock( + data, + upperBounds[0] - 5, + room.getY() + pHeight, + upperBounds[1] - 5 + ), BlockFace.WEST); stairWalls.add(stairWallOne); stairWalls.add(stairWallTwo); @@ -175,21 +199,28 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room SimpleBlock core = new SimpleBlock(data, room.getX(), room.getY() + 1, room.getZ()); // Generate central bookpillar - for (int nx = -1; nx <= 1; nx++) - for (int nz = -1; nz <= 1; nz++) + for (int nx = -1; nx <= 1; nx++) { + for (int nz = -1; nz <= 1; nz++) { for (int ny = 0; ny < room.getHeight() - 1; ny++) { - if (ny == pHeight || - ny == 0 || - ny == room.getHeight() - 2) { + if (ny == pHeight || ny == 0 || ny == room.getHeight() - 2) { core.getRelative(nx, ny, nz).setType(Material.CHISELED_STONE_BRICKS); continue; } core.getRelative(nx, ny, nz).setType(Material.IRON_BARS); BlockUtils.correctSurroundingMultifacingData(core.getRelative(nx, ny, nz)); } + } + } - BlockUtils.spawnPillar(rand, data, room.getX(), room.getY() + 1, room.getZ(), - Material.BOOKSHELF, room.getHeight() - 2, room.getHeight() - 2); + BlockUtils.spawnPillar(rand, + data, + room.getX(), + room.getY() + 1, + room.getZ(), + Material.BOOKSHELF, + room.getHeight() - 2, + room.getHeight() - 2 + ); } @Override diff --git a/common/src/main/java/org/terraform/structure/stronghold/NetherPortalRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/NetherPortalRoomPopulator.java index 1cc69ab1..31ee1ced 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/NetherPortalRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/NetherPortalRoomPopulator.java @@ -39,24 +39,36 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int z = room.getZ(); // Make some nether corruption - BlockUtils.replaceUpperSphere(rand.nextInt(123), rX, rY, rZ, - new SimpleBlock(data, x, y, z), true, + BlockUtils.replaceUpperSphere(rand.nextInt(123), + rX, + rY, + rZ, + new SimpleBlock(data, x, y, z), + true, Material.NETHERRACK, Material.NETHERRACK, Material.SOUL_SAND, Material.NETHERRACK, Material.NETHERRACK, - Material.MAGMA_BLOCK); + Material.MAGMA_BLOCK + ); while (data.getType(x, y, z).isSolid() && y < room.getY() + room.getHeight() - 5) { y++; } y--; - Wall wall = new Wall(new SimpleBlock(data, x, y, z), - BlockUtils.getXZPlaneBlockFace(rand)); + Wall wall = new Wall(new SimpleBlock(data, x, y, z), BlockUtils.getXZPlaneBlockFace(rand)); - Material[] blocks = {Material.OBSIDIAN, Material.OBSIDIAN, Material.OBSIDIAN, Material.OBSIDIAN, Material.OBSIDIAN, Material.OBSIDIAN, Material.OBSIDIAN, - Material.CAVE_AIR}; + Material[] blocks = { + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.OBSIDIAN, + Material.CAVE_AIR + }; // Spawn a nether portal wall.getRight().getRight().Pillar(5, rand, blocks); diff --git a/common/src/main/java/org/terraform/structure/stronghold/PortalRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/PortalRoomPopulator.java index d8912919..f320f925 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/PortalRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/PortalRoomPopulator.java @@ -42,10 +42,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Wall wall = entry.getKey().getUp(3); for (int i = 1; i <= entry.getValue(); i++) { wall.setType(Material.CHISELED_STONE_BRICKS); - if (i % 5 == 2 || i % 5 == 4) + if (i % 5 == 2 || i % 5 == 4) { wall.getUp().Pillar(15 - 7, rand, Material.CHISELED_STONE_BRICKS); - if (i % 5 == 3) + } + if (i % 5 == 3) { wall.getUp().Pillar(15 - 7, rand, Material.COBBLESTONE_WALL); + } for (int h = 1; h < 15 - 7; h++) { BlockUtils.correctSurroundingMultifacingData(wall.getRelative(0, h, 0).get()); @@ -160,7 +162,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (i == 0 || i == 3) { w.getLeft().setType(Material.CHISELED_STONE_BRICKS); w.getRight().setType(Material.CHISELED_STONE_BRICKS); - } else { + } + else { Stairs stairs = (Stairs) Bukkit.createBlockData(Material.POLISHED_ANDESITE_STAIRS); stairs.setFacing(BlockUtils.getAdjacentFaces(w.getDirection())[1]); w.getLeft().setBlockData(stairs); @@ -178,7 +181,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room if (i == 0 || i == 3) { w.getLeft().setType(Material.CHISELED_STONE_BRICKS); w.getRight().setType(Material.CHISELED_STONE_BRICKS); - } else { + } + else { Stairs stairs = (Stairs) Bukkit.createBlockData(Material.POLISHED_ANDESITE_STAIRS); stairs.setFacing(BlockUtils.getAdjacentFaces(w.getDirection())[1]); w.getLeft().setBlockData(stairs); @@ -210,13 +214,20 @@ public void lavaPool(@NotNull PopulatorDataAbstract data, int x, int y, int z, i for (int nx = -1; nx <= 1; nx++) { for (int nz = -1; nz <= 1; nz++) { data.setType(x + nx, y + height, z + nz, Material.CHISELED_STONE_BRICKS); - if (nx == 0 && nz == 0) + if (nx == 0 && nz == 0) { data.setType(x, y + height, z, Material.LAVA); + } } } } - public void decoratedPillar(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, int height) { + public void decoratedPillar(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + int height) + { BlockUtils.spawnPillar(rand, data, x, y, z, Material.CHISELED_STONE_BRICKS, height, height); BlockUtils.spawnPillar(rand, data, x + 1, y, z + 1, Material.COBBLESTONE_WALL, height, height); BlockUtils.spawnPillar(rand, data, x - 1, y, z + 1, Material.COBBLESTONE_WALL, height, height); @@ -262,7 +273,7 @@ private void ceilDecor(@NotNull SimpleBlock ceil) { ceil.getRelative(0, 0, 2).setType(Material.MOSSY_STONE_BRICKS); ceil.getRelative(0, 0, 3).setType(Material.MOSSY_COBBLESTONE); ceil.getRelative(0, 0, 4).setBlockData(randTopSlab()); - for (int i : new int[]{-1, 1}) { + for (int i : new int[] {-1, 1}) { ceil.getRelative(i, 0, -1).setType(Material.MOSSY_STONE_BRICKS); ceil.getRelative(i, 0, 0).setType(Material.MOSSY_STONE_BRICKS); ceil.getRelative(i, 0, 1).setType(Material.MOSSY_STONE_BRICKS); diff --git a/common/src/main/java/org/terraform/structure/stronghold/PrisonRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/PrisonRoomPopulator.java index 15cce050..995d0c0d 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/PrisonRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/PrisonRoomPopulator.java @@ -41,14 +41,14 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int[] upperCorner = room.getUpperCorner(1); // Dangling chains - for (int i = 0; i < GenUtils.randInt(12, 25); i++) - dangleIronBarsDown(rand, - GenUtils.randInt(room.getHeight() / 4 - 1, room.getHeight() / 2), - new SimpleBlock( - data, - GenUtils.randInt(lowerCorner[0], upperCorner[0]), - room.getY() + room.getHeight() - 1, - GenUtils.randInt(lowerCorner[1], upperCorner[1]))); + for (int i = 0; i < GenUtils.randInt(12, 25); i++) { + dangleIronBarsDown(rand, GenUtils.randInt(room.getHeight() / 4 - 1, room.getHeight() / 2), new SimpleBlock( + data, + GenUtils.randInt(lowerCorner[0], upperCorner[0]), + room.getY() + room.getHeight() - 1, + GenUtils.randInt(lowerCorner[1], upperCorner[1]) + )); + } // Spawn platform Material[] slabs = { @@ -60,10 +60,11 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setBlockData(x, room.getY() + room.getHeight() / 2, z, - new SlabBuilder(slabs) - .setType(Type.TOP) - .get()); + data.setBlockData(x, + room.getY() + room.getHeight() / 2, + z, + new SlabBuilder(slabs).setType(Type.TOP).get() + ); } } @@ -78,26 +79,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // 4 pillars for (int[] coords : room.getAllCorners(6)) { - new Wall(new SimpleBlock(data, coords[0], room.getY() + 1, coords[1])) - .Pillar(room.getHeight(), - this.rand, - Material.STONE_BRICKS, - Material.MOSSY_STONE_BRICKS, - Material.CRACKED_STONE_BRICKS); + new Wall(new SimpleBlock(data, coords[0], room.getY() + 1, coords[1])).Pillar(room.getHeight(), + this.rand, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } // Walls for (Entry entry : room.getFourWalls(data, 6).entrySet()) { - Wall w = entry.getKey() - .getRelative(0, room.getHeight() / 2, 0); + Wall w = entry.getKey().getRelative(0, room.getHeight() / 2, 0); for (int i = 0; i < entry.getValue(); i++) { if (!w.isSolid()) { - if (i != entry.getValue() / 2) - w.setType( - Material.COBBLESTONE_WALL, - Material.MOSSY_COBBLESTONE_WALL - ); + if (i != entry.getValue() / 2) { + w.setType(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); + } else { w.setType(slabs); } @@ -111,10 +109,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Stairs leading to the second level BlockFace dir; - if (room.getWidthX() > room.getWidthZ()) - dir = new BlockFace[]{BlockFace.WEST, BlockFace.EAST}[rand.nextInt(1)]; - else - dir = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH}[rand.nextInt(1)]; + if (room.getWidthX() > room.getWidthZ()) { + dir = new BlockFace[] {BlockFace.WEST, BlockFace.EAST}[rand.nextInt(1)]; + } + else { + dir = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}[rand.nextInt(1)]; + } for (int[] corner : room.getCornersAlongFace(dir, 7)) { Wall w = new Wall(new SimpleBlock(data, corner[0], room.getY() + 1, corner[1]), dir.getOppositeFace()); @@ -125,23 +125,24 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int i = 0; i < room.getHeight() / 2; i++) { w.Pillar(room.getHeight() / 2 - i, rand, BlockUtils.stoneBricks); - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(dir) - .apply(w.getRelative(0, room.getHeight() / 2 - i - 1, 0)); + new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS).setFacing(dir) + .apply(w.getRelative(0, + room.getHeight() + / 2 - i - 1, + 0 + )); w = w.getFront(); } } // Prison Cells for (int[] corner : room.getCornersAlongFace(BlockFace.NORTH, 2)) { - placePrisonCell( - new SimpleBlock(data, corner[0], room.getY() + 1 + room.getHeight() / 2, corner[1]), + placePrisonCell(new SimpleBlock(data, corner[0], room.getY() + 1 + room.getHeight() / 2, corner[1]), BlockFace.SOUTH ); } for (int[] corner : room.getCornersAlongFace(BlockFace.SOUTH, 2)) { - placePrisonCell( - new SimpleBlock(data, corner[0], room.getY() + 1 + room.getHeight() / 2, corner[1]), + placePrisonCell(new SimpleBlock(data, corner[0], room.getY() + 1 + room.getHeight() / 2, corner[1]), BlockFace.NORTH ); } @@ -155,21 +156,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room w.getUp(3).LPillar(room.getHeight() / 2 - 2, rand, BlockUtils.stoneBricks); // chance for skeletons - if (rand.nextBoolean()) + if (rand.nextBoolean()) { data.addEntity(w.getX(), w.getY(), w.getZ(), EntityType.SKELETON); + } - } else if (i == entry.getValue() / 2 + 1 || i == entry.getValue() / 2 - 1) { + } + else if (i == entry.getValue() / 2 + 1 || i == entry.getValue() / 2 - 1) { w.LPillar(room.getHeight() / 2, rand, BlockUtils.stoneBricks); - } else { + } + else { w.LPillar(room.getHeight() / 2, rand, Material.IRON_BARS); w.CorrectMultipleFacing(room.getHeight() / 2); } if (GenUtils.chance(rand, 1, 35)) { - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.STRONGHOLD_CORRIDOR) - .apply(w.getRear(3)); + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.STRONGHOLD_CORRIDOR) + .apply(w.getRear(3)); } w = w.getLeft(); } @@ -179,18 +182,23 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room public void placePrisonCell(@NotNull SimpleBlock location, @NotNull BlockFace doorDir) { Wall w = new Wall(location); - Material[] prisonMats = {Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.IRON_BARS}; + Material[] prisonMats = { + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS, + Material.IRON_BARS + }; int width = 2; // Walls - for (int nx : new int[]{-width, width}) { + for (int nx : new int[] {-width, width}) { for (int nz = -width; nz <= width; nz++) { w.getRelative(nx, 0, nz).LPillar(15, rand, prisonMats); } } - for (int nz : new int[]{-width, width}) { + for (int nz : new int[] {-width, width}) { for (int nx = -width; nx <= width; nx++) { w.getRelative(nx, 0, nz).LPillar(15, rand, prisonMats); } @@ -202,9 +210,6 @@ public void placePrisonCell(@NotNull SimpleBlock location, @NotNull BlockFace do @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getHeight() > 8 - && room.getWidthX() > 14 - && room.getWidthZ() > 14 - && !room.isHuge(); + return room.getHeight() > 8 && room.getWidthX() > 14 && room.getWidthZ() > 14 && !room.isHuge(); } } diff --git a/common/src/main/java/org/terraform/structure/stronghold/SilverfishDenPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/SilverfishDenPopulator.java index 203aedc4..70301751 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/SilverfishDenPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/SilverfishDenPopulator.java @@ -24,8 +24,17 @@ public SilverfishDenPopulator(Random rand, boolean forceSpawn, boolean unique) { public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { // Spawn a random sphere of silverfish eggs SimpleBlock base = new SimpleBlock(data, room.getX(), room.getY() + room.getHeight() / 2 - 2, room.getZ()); - BlockUtils.replaceUpperSphere(rand.nextInt(9999), (room.getWidthX() - 2) / 2f, (room.getHeight() - 3), (room.getWidthZ() - 2) / 2f, base, false, Material.INFESTED_STONE, - Material.INFESTED_STONE, Material.CAVE_AIR, Material.STONE); + BlockUtils.replaceUpperSphere(rand.nextInt(9999), + (room.getWidthX() - 2) / 2f, + (room.getHeight() - 3), + (room.getWidthZ() - 2) / 2f, + base, + false, + Material.INFESTED_STONE, + Material.INFESTED_STONE, + Material.CAVE_AIR, + Material.STONE + ); // Silverfish spawner in the middle data.setSpawner(room.getX(), room.getY() + 1, room.getZ(), EntityType.SILVERFISH); @@ -41,7 +50,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room while (data.getType(x, ny, z).isSolid() && ny < room.getHeight() + room.getY()) { ny++; } - if (ny == room.getHeight() + room.getY()) continue; + if (ny == room.getHeight() + room.getY()) { + continue; + } data.setType(x, ny, z, Material.CHEST); org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData(Material.CHEST); diff --git a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPathPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPathPopulator.java index 994f905d..bca1ef27 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPathPopulator.java @@ -39,7 +39,9 @@ public void populate(@NotNull PathPopulatorData ppd) { while (!ceil.isSolid()) { ceil = ceil.getUp(); depth++; - if (depth > 10) return; + if (depth > 10) { + return; + } } @@ -52,12 +54,11 @@ public void populate(@NotNull PathPopulatorData ppd) { // Check for any walls. ArrayList walls = new ArrayList<>(); for (BlockFace face : BlockUtils.directBlockFaces) { - if (ppd.base.getRelative(face.getModX() * 2, 2, face.getModZ() * 2) - .isSolid()) { + if (ppd.base.getRelative(face.getModX() * 2, 2, face.getModZ() * 2).isSolid()) { isCrossroad = false; - walls.add(new Wall( - ppd.base.getRelative(face.getModX() * 2, 1, face.getModZ() * 2), - face.getOppositeFace())); + walls.add(new Wall(ppd.base.getRelative(face.getModX() * 2, 1, face.getModZ() * 2), + face.getOppositeFace() + )); } } @@ -65,10 +66,16 @@ public void populate(@NotNull PathPopulatorData ppd) { if (isCrossroad) { // This is a crossroad (Has 4 pathways) for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { - new Wall(ppd.base.getUp().getRelative(face)) - .LPillar(10, rand, Material.COBBLESTONE_WALL, Material.ANDESITE_WALL, Material.STONE_BRICK_WALL); + new Wall(ppd.base.getUp().getRelative(face)).LPillar( + 10, + rand, + Material.COBBLESTONE_WALL, + Material.ANDESITE_WALL, + Material.STONE_BRICK_WALL + ); } - } else // this is a turn + } + else // this is a turn { // Decorate the walls for (Wall wall : walls) { @@ -78,65 +85,81 @@ public void populate(@NotNull PathPopulatorData ppd) { wall.getUp().getLeft().setType(Material.STONE, Material.SMOOTH_STONE, Material.ANDESITE); wall.getUp().getRight().setType(Material.STONE, Material.SMOOTH_STONE, Material.ANDESITE); - new StairBuilder(Material.ANDESITE_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(wall.getDirection())) - .setHalf(Half.TOP) - .apply(wall.getRight()); - - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(wall.getDirection())) - .setHalf(Half.TOP) - .apply(wall.getLeft()); - - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(wall.getDirection())) - .setHalf(Half.BOTTOM) - .apply(wall.getRight().getUp(2)); - - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(wall.getDirection())) - .setHalf(Half.BOTTOM) - .apply(wall.getLeft().getUp(2)); + new StairBuilder( + Material.ANDESITE_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getLeft(wall.getDirection())).setHalf(Half.TOP).apply(wall.getRight()); + + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getRight(wall.getDirection())).setHalf(Half.TOP).apply(wall.getLeft()); + + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getLeft(wall.getDirection())) + .setHalf(Half.BOTTOM) + .apply(wall.getRight().getUp(2)); + + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getRight(wall.getDirection())) + .setHalf(Half.BOTTOM) + .apply(wall.getLeft().getUp(2)); } } - } else // This is a pathway + } + else // This is a pathway { // Check if the walls present really make it a pathway // 3x4 empty air area. (widthxheight) - if (!verifyPathway(new Wall(ppd.base, ppd.dir))) return; + if (!verifyPathway(new Wall(ppd.base, ppd.dir))) { + return; + } if (ppd.calcRemainder(2) == 0) { // arch decoratePathways(ppd.base, ppd.dir); Wall base = new Wall(ppd.base, ppd.dir); base.getUp().getLeft(2).setType(Material.SMOOTH_STONE, Material.POLISHED_ANDESITE); base.getUp().getRight(2).setType(Material.SMOOTH_STONE, Material.POLISHED_ANDESITE); - base.getUp(2).getLeft(2).setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); - base.getUp(2).getRight(2).setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); + base.getUp(2) + .getLeft(2) + .setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); + base.getUp(2) + .getRight(2) + .setType(Material.CHISELED_STONE_BRICKS, Material.CHISELED_STONE_BRICKS, Material.COBBLESTONE); base.getUp(3).getLeft(2).setType(Material.SMOOTH_STONE, Material.POLISHED_ANDESITE); base.getUp(4).getRight(2).setType(Material.SMOOTH_STONE, Material.POLISHED_ANDESITE); - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS, Material.ANDESITE_STAIRS) - .setFacing(BlockUtils.getLeft(ppd.dir)) - .setHalf(Half.TOP) - .apply(base.getUp(4).getLeft()); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.ANDESITE_STAIRS + ).setFacing(BlockUtils.getLeft(ppd.dir)).setHalf(Half.TOP).apply(base.getUp(4).getLeft()); - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS, Material.ANDESITE_STAIRS) - .setFacing(BlockUtils.getRight(ppd.dir)) - .setHalf(Half.TOP) - .apply(base.getUp(4).getRight()); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.ANDESITE_STAIRS + ).setFacing(BlockUtils.getRight(ppd.dir)).setHalf(Half.TOP).apply(base.getUp(4).getRight()); ceil.setType(Material.CHISELED_STONE_BRICKS); - } else // not-arch + } + else // not-arch { Wall base = new Wall(ppd.base, ppd.dir); - new SlabBuilder(BlockUtils.stoneBrickSlabs) - .setType(Slab.Type.TOP) - .apply(base.getUp(4).getLeft()); + new SlabBuilder(BlockUtils.stoneBrickSlabs).setType(Slab.Type.TOP).apply(base.getUp(4).getLeft()); - new SlabBuilder(BlockUtils.stoneBrickSlabs) - .setType(Slab.Type.TOP) - .apply(base.getUp(4).getRight()); + new SlabBuilder(BlockUtils.stoneBrickSlabs).setType(Slab.Type.TOP).apply(base.getUp(4).getRight()); // Loot chests if (GenUtils.chance(rand, 1, 50)) { @@ -145,22 +168,41 @@ public void populate(@NotNull PathPopulatorData ppd) { Wall w = base.getUp(); depth = 0; while (!w.get().isSolid() && depth < 10) { - if (i == 0) w = w.getLeft(); - if (i == 1) w = w.getRight(); + if (i == 0) { + w = w.getLeft(); + } + if (i == 1) { + w = w.getRight(); + } depth++; } - if (i == 1) w = w.getLeft(); - if (i == 0) w = w.getRight(); + if (i == 1) { + w = w.getLeft(); + } + if (i == 0) { + w = w.getRight(); + } SimpleBlock cBlock = w.get(); cBlock.setType(Material.CHEST); - org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData(Material.CHEST); - if (i == 0) chest.setFacing(BlockUtils.getAdjacentFaces(ppd.dir)[1]); - if (i == 1) chest.setFacing(BlockUtils.getAdjacentFaces(ppd.dir)[0]); + org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData( + Material.CHEST); + if (i == 0) { + chest.setFacing(BlockUtils.getAdjacentFaces(ppd.dir)[1]); + } + if (i == 1) { + chest.setFacing(BlockUtils.getAdjacentFaces(ppd.dir)[0]); + } cBlock.setBlockData(chest); - cBlock.getPopData().lootTableChest(cBlock.getX(), cBlock.getY(), cBlock.getZ(), TerraLootTable.STRONGHOLD_CORRIDOR); - } else if (GenUtils.chance(rand, 4, 25)) { // If a chest spawns, don't overlap it with iron bars + cBlock.getPopData() + .lootTableChest(cBlock.getX(), + cBlock.getY(), + cBlock.getZ(), + TerraLootTable.STRONGHOLD_CORRIDOR + ); + } + else if (GenUtils.chance(rand, 4, 25)) { // If a chest spawns, don't overlap it with iron bars setIronBars(ppd); } } @@ -183,7 +225,9 @@ public void populate(@NotNull PathPopulatorData ppd) { for (int i = 0; i < GenUtils.randInt(rand, 0, 3); i++) { BlockFace face = CoralGenerator.getRandomBlockFace(); - if (face == BlockFace.UP) face = BlockFace.SELF; + if (face == BlockFace.UP) { + face = BlockFace.SELF; + } webBase.getRelative(face).setType(Material.COBWEB); } } @@ -195,15 +239,20 @@ private boolean verifyPathway(@NotNull Wall base) { for (int width = -2; width <= 2; width++) { Wall rel = base.getRelative(0, h, 0); if (h == 0 || h == 5 || width == -2 || width == 2) { - if (!rel.getLeft(width).isSolid()) + if (!rel.getLeft(width).isSolid()) { return false; - if (!rel.getRight(width).isSolid()) + } + if (!rel.getRight(width).isSolid()) { return false; - } else { - if (rel.getLeft(width).isSolid()) + } + } + else { + if (rel.getLeft(width).isSolid()) { return false; - if (rel.getRight(width).isSolid()) + } + if (rel.getRight(width).isSolid()) { return false; + } } } } @@ -217,14 +266,11 @@ private void decorateCrossroads(@NotNull SimpleBlock core, Bisected.@NotNull Hal core.RSolSetType(Material.CHISELED_STONE_BRICKS); for (BlockFace face : BlockUtils.directBlockFaces) { - core.getRelative(face).RSolSetBlockData( - new StairBuilder( - Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS, - Material.MOSSY_STONE_BRICK_STAIRS, Material.ANDESITE_STAIRS) - .setFacing(face) - .setHalf(isCeil) - .get() - ); + core.getRelative(face).RSolSetBlockData(new StairBuilder(Material.STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.ANDESITE_STAIRS + ).setFacing(face).setHalf(isCeil).get()); } } @@ -233,12 +279,12 @@ private void decoratePathways(@NotNull SimpleBlock core, @NotNull BlockFace dir) core.RSolSetType(Material.CHISELED_STONE_BRICKS); for (BlockFace face : BlockUtils.getAdjacentFaces(dir)) { - core.getRelative(face).RSolSetBlockData( - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.COBBLESTONE_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS, Material.ANDESITE_STAIRS) - .setFacing(face) - .setHalf(Half.BOTTOM) - .get() - ); + core.getRelative(face) + .RSolSetBlockData(new StairBuilder(Material.STONE_BRICK_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS, + Material.ANDESITE_STAIRS + ).setFacing(face).setHalf(Half.BOTTOM).get()); } } @@ -269,18 +315,22 @@ private void dropDownBlock(@NotNull SimpleBlock block) { while (!block.isSolid()) { block = block.getDown(); depth++; - if (depth > 50) return; + if (depth > 50) { + return; + } } if (type instanceof Slab) { ((Slab) type).setType(Slab.Type.BOTTOM); - } else if (type instanceof Stairs) { + } + else if (type instanceof Stairs) { ((Stairs) type).setHalf(Half.BOTTOM); } if (GenUtils.chance(1, 3)) { block.getUp().setBlockData(BlockUtils.infestStone(type)); - } else { + } + else { block.getUp().setBlockData(type); } } diff --git a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java index 9ef77431..6b4e534f 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java @@ -29,7 +29,7 @@ private static int[] randomCircleCoords(@NotNull Random rand, int radius) { double angle = rand.nextDouble() * Math.PI * 2; int x = (int) (Math.cos(angle) * radius); int z = (int) (Math.sin(angle) * radius); - return new int[]{x, z}; + return new int[] {x, z}; } private static boolean areCoordsEqual(int @NotNull [] a, int x, int z) { @@ -52,25 +52,39 @@ public int[][] strongholdPositions(@NotNull TerraformWorld tw) { } radius += 3072; // TerraformGeneratorPlugin.logger.debug("sp-1"); - for (int i = 0; i < 6; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 6; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("sp-2"); - for (int i = 0; i < 10; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 10; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("sp-3"); - for (int i = 0; i < 15; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 15; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("s-pop-4"); - for (int i = 0; i < 21; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 21; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("s-pop-5"); - for (int i = 0; i < 28; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 28; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("s-pop-6"); - for (int i = 0; i < 36; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 36; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } radius += 3072; // TerraformGeneratorPlugin.logger.debug("s-pop-7"); - for (int i = 0; i < 9; i++) POSITIONS[pos++] = randomCircleCoords(rand, radius); + for (int i = 0; i < 9; i++) { + POSITIONS[pos++] = randomCircleCoords(rand, radius); + } // TerraformGeneratorPlugin.logger.debug("s-pop-8"); } @@ -79,13 +93,17 @@ public int[][] strongholdPositions(@NotNull TerraformWorld tw) { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } int[][] positions = strongholdPositions(tw); for (int x = chunkX * 16; x < chunkX * 16 + 16; x++) { for (int z = chunkZ * 16; z < chunkZ * 16 + 16; z++) { for (int[] pos : positions) { - if (areCoordsEqual(pos, x, z)) return true; + if (areCoordsEqual(pos, x, z)) { + return true; + } } } } @@ -95,25 +113,39 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, Biom @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } int[][] positions = strongholdPositions(tw); for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) { for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z++) { for (int[] pos : positions) { if (areCoordsEqual(pos, x, z)) { - - // Strongholds no longer calculate from the surface. - // Just pick a directly underground location. - int y = GenUtils.randInt(TConfigOption.STRUCTURES_STRONGHOLD_MIN_Y.getInt(), TConfigOption.STRUCTURES_STRONGHOLD_MAX_Y.getInt()); - + + // Strongholds no longer calculate from the surface. + // Just pick a directly underground location. + int y = GenUtils.randInt( + TConfigOption.STRUCTURES_STRONGHOLD_MIN_Y.getInt(), + TConfigOption.STRUCTURES_STRONGHOLD_MAX_Y.getInt() + ); + // Attempt to force strongholds further underground if // they're above the surface. - if(y + 18 > GenUtils.getHighestGround(data, x, z)) { - if(y > TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt()) y = TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt(); + if (y + 18 > GenUtils.getHighestGround(data, x, z)) { + if (y > TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt()) { + y = TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt(); + } } - - spawnStronghold(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, y, z); + + spawnStronghold( + tw, + this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), + data, + x, + y, + z + ); break; } } @@ -123,7 +155,13 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract } - public void spawnStronghold(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnStronghold(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { // TerraformGeneratorPlugin.logger.info("Spawning stronghold at: " + x + "," + z); int numRooms = 70; @@ -131,7 +169,15 @@ public void spawnStronghold(@NotNull TerraformWorld tw, Random random, @NotNull // Level One Random hashedRand = tw.getHashedRand(x, y, z); - RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); + RoomLayoutGenerator gen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + ); MazeSpawner mazeSpawner = new MazeSpawner(); mazeSpawner.setMazePeriod(10); @@ -157,7 +203,14 @@ public void spawnStronghold(@NotNull TerraformWorld tw, Random random, @NotNull gen.registerRoomPopulator(new TrapChestRoomPopulator(random, false, false)); gen.registerRoomPopulator(new HallwayPopulator(random, false, false)); gen.calculateRoomPlacement(); - gen.fill(data, tw, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.CRACKED_STONE_BRICKS); + gen.fill( + data, + tw, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); gen.reset(); mazeSpawner = new MazeSpawner(); @@ -179,7 +232,14 @@ public void spawnStronghold(@NotNull TerraformWorld tw, Random random, @NotNull stairwayTwo.setRoomPopulator(new StairwayTopPopulator(random, false, false)); gen.getRooms().add(stairwayTwo); gen.calculateRoomPlacement(); - gen.fill(data, tw, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.CRACKED_STONE_BRICKS); + gen.fill( + data, + tw, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } @@ -190,26 +250,27 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { for (int[] loc : strongholdPositions(tw)) { double distSqr = Math.pow(loc[0] - rawX, 2) + Math.pow(loc[1] - rawZ, 2); - if(min == null) { + if (min == null) { minDistanceSquared = distSqr; - min = loc; - continue; - } - + min = loc; + continue; + } + if (distSqr < minDistanceSquared) { minDistanceSquared = distSqr; min = loc; } } - return new int[]{min[0], min[1]}; + return new int[] {min[0], min[1]}; } public int[] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { int[][] positions = strongholdPositions(tw); for (int[] pos : positions) { - if (mc.containsXZBlockCoords(pos[0], pos[1])) + if (mc.containsXZBlockCoords(pos[0], pos[1])) { return pos; + } } return null; @@ -225,9 +286,9 @@ public int[] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChu public boolean isEnabled() { return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_STRONGHOLD_ENABLED.getBoolean(); } - + @Override public int getChunkBufferDistance() { - return 0; + return 0; } } diff --git a/common/src/main/java/org/terraform/structure/stronghold/SupplyRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/SupplyRoomPopulator.java index 8c4875ec..e166307b 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/SupplyRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/SupplyRoomPopulator.java @@ -35,8 +35,12 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int x = GenUtils.randInt(rand, lowerBounds[0] + 1, upperBounds[0] - 1); int z = GenUtils.randInt(rand, lowerBounds[1] + 1, upperBounds[1] - 1); int ny = y + 1; - while (data.getType(x, ny, z).isSolid() && ny < room.getHeight() + room.getY()) ny++; - if (ny == room.getHeight() + room.getY()) continue; + while (data.getType(x, ny, z).isSolid() && ny < room.getHeight() + room.getY()) { + ny++; + } + if (ny == room.getHeight() + room.getY()) { + continue; + } data.setType(x, ny, z, Material.TORCH); } @@ -48,13 +52,15 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room GenUtils.randInt(rand, 1, 3), GenUtils.randInt(rand, 1, 3), GenUtils.randInt(rand, 1, 3), - new SimpleBlock(data, x, y, z), false, + new SimpleBlock(data, x, y, z), + false, GenUtils.randChoice(rand, Material.IRON_ORE, Material.HAY_BLOCK, Material.CHISELED_STONE_BRICKS, Material.COAL_BLOCK, - Material.COAL_ORE) + Material.COAL_ORE + ) ); } @@ -66,23 +72,29 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room while (data.getType(x, ny, z).isSolid() && ny < room.getHeight() + room.getY()) { ny++; } - if (ny == room.getHeight() + room.getY()) continue; + if (ny == room.getHeight() + room.getY()) { + continue; + } - Material type = GenUtils.randChoice(rand, Material.CRAFTING_TABLE, + Material type = GenUtils.randChoice(rand, + Material.CRAFTING_TABLE, Material.ANVIL, Material.CAULDRON, Material.FLETCHING_TABLE, Material.SMITHING_TABLE, Material.CARTOGRAPHY_TABLE, Material.BARREL, - Material.OAK_LOG); + Material.OAK_LOG + ); BlockData typeData = Bukkit.createBlockData(type); if (typeData instanceof Rotatable) { ((Rotatable) typeData).setRotation(BlockUtils.getDirectBlockFace(rand)); - } else if (typeData instanceof Directional) { + } + else if (typeData instanceof Directional) { ((Directional) typeData).setFacing(BlockUtils.getDirectBlockFace(rand)); - } else if (typeData instanceof Orientable) { + } + else if (typeData instanceof Orientable) { ((Orientable) typeData).setAxis(Axis.values()[GenUtils.randInt(rand, 0, 2)]); } data.setBlockData(x, ny, z, typeData); @@ -96,7 +108,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room while (data.getType(x, ny, z).isSolid() && ny < room.getHeight() + room.getY()) { ny++; } - if (ny == room.getHeight() + room.getY()) continue; + if (ny == room.getHeight() + room.getY()) { + continue; + } data.setType(x, ny, z, Material.CHEST); org.bukkit.block.data.type.Chest chest = (org.bukkit.block.data.type.Chest) Bukkit.createBlockData(Material.CHEST); diff --git a/common/src/main/java/org/terraform/structure/stronghold/TrapChestRoomPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/TrapChestRoomPopulator.java index f8b459df..10da4b31 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/TrapChestRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/TrapChestRoomPopulator.java @@ -29,18 +29,21 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int z = room.getZ() + GenUtils.randInt(rand, -room.getWidthZ() / 2, room.getWidthZ() / 2); data.setType(x, room.getY() + 1, z, Material.STONE_PRESSURE_PLATE); - if (GenUtils.chance(rand, 4, 5)) + if (GenUtils.chance(rand, 4, 5)) { data.setType(x, room.getY() - 1, z, Material.TNT); + } } int y = room.getY() + 1; int x = room.getX(); int z = room.getZ(); - if (GenUtils.chance(rand, 1, 2)) + if (GenUtils.chance(rand, 1, 2)) { data.setType(x, y, z, Material.TNT); - else + } + else { data.setType(x, y, z, Material.SMOOTH_STONE); + } SimpleBlock core = new SimpleBlock(data, x, y, z); for (BlockFace face : BlockUtils.directBlockFaces) { diff --git a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsHutRoom.java b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsHutRoom.java index 2bca0728..7e01a001 100644 --- a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsHutRoom.java +++ b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsHutRoom.java @@ -26,42 +26,47 @@ public TrailRuinsHutRoom(Random rand, boolean forceSpawn, boolean unique) { @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { Material terracottaType = GenUtils.randChoice(BlockUtils.TERRACOTTA); - for(Map.Entry entry:room.getFourWalls(data,1).entrySet()) - { + for (Map.Entry entry : room.getFourWalls(data, 1).entrySet()) { Wall w = entry.getKey(); - for(int i = 1; i < entry.getValue()-1; i++) - { - if(w.getDown().isSolid()) - { + for (int i = 1; i < entry.getValue() - 1; i++) { + if (w.getDown().isSolid()) { int h = GenUtils.randInt(rand, 1, 5); - w.Pillar(Math.min(2,h), OneOneNineBlockHandler.MUD_BRICKS); - w.getUp(2).Pillar(Math.min(0,h-2), terracottaType); + w.Pillar(Math.min(2, h), OneOneNineBlockHandler.MUD_BRICKS); + w.getUp(2).Pillar(Math.min(0, h - 2), terracottaType); // If this is inside a jungle, allow jungle chests. - if(data.getBiome(w.getX(),w.getZ()) == Biome.JUNGLE - || data.getBiome(w.getX(),w.getZ()) == Biome.BAMBOO_JUNGLE - // || data.getBiome(w.getX(),w.getZ()) == Biome.SPARSE_JUNGLE - // this biome doesn't exist in 1.16. It's not used anyway, might as well remove the check - ) - if(i > 1 && i < entry.getValue() - 2 - && GenUtils.chance(rand, 1, 9)) - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.JUNGLE_TEMPLE) - .apply(w.getFront().getRight().getUp()); + if (data.getBiome(w.getX(), w.getZ()) == Biome.JUNGLE + || data.getBiome(w.getX(), w.getZ()) == Biome.BAMBOO_JUNGLE + // || data.getBiome(w.getX(),w.getZ()) == Biome.SPARSE_JUNGLE + // this biome doesn't exist in 1.16. It's not used anyway, might as well remove the check + ) + { + if (i > 1 && i < entry.getValue() - 2 && GenUtils.chance(rand, 1, 9)) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.JUNGLE_TEMPLE) + .apply(w.getFront().getRight().getUp()); + } + } } w = w.getLeft(); } } // Suspicious gravel - if(Version.isAtLeast(20)) - for(int i = 0; i < rand.nextInt(4); i++) - { + if (Version.isAtLeast(20)) { + for (int i = 0; i < rand.nextInt(4); i++) { int[] coords = room.randomCoords(rand); - data.setType(coords[0],room.getY(),coords[2], OneTwentyBlockHandler.SUSPICIOUS_GRAVEL); - data.lootTableChest(coords[0],room.getY(),coords[2], GenUtils.chance(rand,1,3) ? TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_RARE: TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_COMMON); + data.setType(coords[0], room.getY(), coords[2], OneTwentyBlockHandler.SUSPICIOUS_GRAVEL); + data.lootTableChest( + coords[0], + room.getY(), + coords[2], + GenUtils.chance(rand, 1, 3) + ? TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_RARE + : TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_COMMON + ); } + } } @Override diff --git a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPathPopulator.java b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPathPopulator.java index f63f125c..dea293a3 100644 --- a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPathPopulator.java @@ -10,14 +10,14 @@ public class TrailRuinsPathPopulator extends PathPopulatorAbstract { - public TrailRuinsPathPopulator(Random rand) { - } + public TrailRuinsPathPopulator(Random rand) { + } @Override public void populate(@NotNull PathPopulatorData ppd) { - for(int i = -1; i <= 1; i++) { + for (int i = -1; i <= 1; i++) { Wall core = new Wall(ppd.base, ppd.dir).getLeft(i); - if(core.getDown(2).isSolid()) { + if (core.getDown(2).isSolid()) { core.setType(Material.STONE, Material.COBBLESTONE, Material.AIR); core.getDown().setType(Material.STONE, Material.COBBLESTONE); } diff --git a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java index 584f41b8..577919b5 100644 --- a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java +++ b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java @@ -18,23 +18,37 @@ public class TrailRuinsPopulator extends SingleMegaChunkStructurePopulator { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if (!isEnabled() ) return false; + if (!isEnabled()) { + return false; + } - if(biome == (BiomeBank.TAIGA) - || biome == (BiomeBank.SNOWY_TAIGA) - || biome == (BiomeBank.JUNGLE)) { - return rollSpawnRatio(tw,chunkX,chunkZ); + if (biome == (BiomeBank.TAIGA) || biome == (BiomeBank.SNOWY_TAIGA) || biome == (BiomeBank.JUNGLE)) { + return rollSpawnRatio(tw, chunkX, chunkZ); } return false; } - public void spawnTrailRuins(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z){ + public void spawnTrailRuins(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { int numRooms = 10; int range = 40; // Level One Random hashedRand = tw.getHashedRand(x, y, z); - RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); + RoomLayoutGenerator gen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + ); gen.setPathPopulator(new TrailRuinsPathPopulator(hashedRand)); gen.setRoomMaxX(10); gen.setRoomMaxZ(10); @@ -42,9 +56,9 @@ public void spawnTrailRuins(@NotNull TerraformWorld tw, Random random, @NotNull gen.setRoomMinZ(6); gen.setRoomMaxHeight(15); gen.setCarveRooms(true); - gen.setCarveRoomsMultiplier(0,0,0); // No carving + gen.setCarveRoomsMultiplier(0, 0, 0); // No carving - CubeRoom towerRoom = new CubeRoom(7,7,7, x,y,z); + CubeRoom towerRoom = new CubeRoom(7, 7, 7, x, y, z); towerRoom.setRoomPopulator(new TrailRuinsTowerRoom(random, false, false)); gen.getRooms().add(towerRoom); @@ -60,20 +74,23 @@ public void spawnTrailRuins(@NotNull TerraformWorld tw, Random random, @NotNull @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); int x = coords[0];// data.getChunkX()*16 + random.nextInt(16); int z = coords[1];// data.getChunkZ()*16 + random.nextInt(16); - int y = GenUtils.getHighestGround(data, x, z) - GenUtils.randInt( - this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), - 10, 15); + int y = GenUtils.getHighestGround(data, x, z) - GenUtils.randInt(this.getHashedRandom( + tw, + data.getChunkX(), + data.getChunkZ() + ), 10, 15); - spawnTrailRuins(tw,this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), - data,x,y,z); + spawnTrailRuins(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, y, z); } @@ -93,8 +110,8 @@ public boolean isEnabled() { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 34122), - (int) (TConfigOption.STRUCTURES_TRAILRUINS_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_TRAILRUINS_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } } diff --git a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsTowerRoom.java b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsTowerRoom.java index 13f3f049..29245db8 100644 --- a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsTowerRoom.java +++ b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsTowerRoom.java @@ -43,7 +43,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room towerTop.setFace(direction); towerTop.apply(); - } catch(FileNotFoundException e) { + } + catch (FileNotFoundException e) { throw new RuntimeException(e); } } @@ -53,18 +54,17 @@ public boolean canPopulate(CubeRoom room) { return false; } - public static class TrailRuinsTowerParser extends SchematicParser{ + public static class TrailRuinsTowerParser extends SchematicParser { + @NotNull + final HashMap newMapping = new HashMap<>(); private final @NotNull SimpleBlock destruction; private final @NotNull Random random; - @NotNull - final - HashMap newMapping = new HashMap<>(); + public TrailRuinsTowerParser(@NotNull SimpleBlock core, @NotNull Random rand) { this.random = rand; - this.destruction = core.getRelative( - GenUtils.getSign(rand)*rand.nextInt(3), - GenUtils.getSign(rand)*rand.nextInt(5), - GenUtils.getSign(rand)*rand.nextInt(3) + this.destruction = core.getRelative(GenUtils.getSign(rand) * rand.nextInt(3), + GenUtils.getSign(rand) * rand.nextInt(5), + GenUtils.getSign(rand) * rand.nextInt(3) ); // Shuffle terracotta types @@ -77,32 +77,42 @@ public TrailRuinsTowerParser(@NotNull SimpleBlock core, @NotNull Random rand) { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { // If within destruction zone, don't place - if(block.distance(destruction) < 3) return; + if (block.distance(destruction) < 3) { + return; + } - if(newMapping.containsKey(data.getMaterial())) { - if(data instanceof Directional) - { + if (newMapping.containsKey(data.getMaterial())) { + if (data instanceof Directional) { BlockFace f = ((Directional) data).getFacing(); data = Bukkit.createBlockData(newMapping.get(data.getMaterial())); ((Directional) data).setFacing(f); } - else data = Bukkit.createBlockData(newMapping.get(data.getMaterial())); + else { + data = Bukkit.createBlockData(newMapping.get(data.getMaterial())); + } } super.applyData(block, data); - for(int i = 1; i < 3; i++) - { - if(GenUtils.chance(random, 1, 4) && BlockUtils.isStoneLike(block.getUp(i).getType())) - { - if(Version.isAtLeast(20) && GenUtils.chance(random, 1, 5)) - { + for (int i = 1; i < 3; i++) { + if (GenUtils.chance(random, 1, 4) && BlockUtils.isStoneLike(block.getUp(i).getType())) { + if (Version.isAtLeast(20) && GenUtils.chance(random, 1, 5)) { block.getUp(i).setType(OneTwentyBlockHandler.SUSPICIOUS_GRAVEL); - block.getPopData().lootTableChest(block.getX(), block.getY()+i, block.getZ(), - GenUtils.chance(random,1,3)? TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_RARE: TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_COMMON); + block.getPopData().lootTableChest( + block.getX(), + block.getY() + i, + block.getZ(), + GenUtils.chance(random, 1, 3) + ? TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_RARE + : TerraLootTable.TRAIL_RUINS_ARCHAEOLOGY_COMMON + ); } - else + else { block.getUp(i).setType(Material.SAND, Material.GRAVEL); - }else break; // Stack up, but break if its no longer stone + } + } + else { + break; // Stack up, but break if its no longer stone + } } } } diff --git a/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java b/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java index 2172f410..d3feb2da 100644 --- a/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java +++ b/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java @@ -17,7 +17,7 @@ public TrialChamberPopulator() { @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - return isEnabled() && rollSpawnRatio(tw,chunkX,chunkZ); + return isEnabled() && rollSpawnRatio(tw, chunkX, chunkZ); } @Override @@ -36,9 +36,10 @@ public boolean isEnabled() { } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 19650), - (int) (TConfigOption.STRUCTURES_TRIALCHAMBER_SPAWNRATIO - .getDouble() * 10000), - 10000); + return GenUtils.chance( + tw.getHashedRand(chunkX, chunkZ, 19650), + (int) (TConfigOption.STRUCTURES_TRIALCHAMBER_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } } diff --git a/common/src/main/java/org/terraform/structure/village/VillagePopulator.java b/common/src/main/java/org/terraform/structure/village/VillagePopulator.java index edb18c7e..6e158c74 100644 --- a/common/src/main/java/org/terraform/structure/village/VillagePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/VillagePopulator.java @@ -17,32 +17,36 @@ public class VillagePopulator extends SingleMegaChunkStructurePopulator { public @NotNull Random getHashedRandom(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return tw.getHashedRand(11111199, chunkX, chunkZ); } - + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_VILLAGE_SPAWNRATIO - .getDouble() * 10000), - 10000); + return GenUtils.chance( + tw.getHashedRand(chunkX, chunkZ, 12422), + (int) (TConfigOption.STRUCTURES_VILLAGE_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if ( !isEnabled()) return false; + if (!isEnabled()) { + return false; + } // MegaChunk mc = new MegaChunk(chunkX, chunkZ); // int[] coords = mc.getCenterBiomeSectionBlockCoords();// getCoordsFromMegaChunk(tw, mc); // If it is below sea level, DON'T SPAWN IT. // if (HeightMap.getBlockHeight(tw, coords[0], coords[1]) > TerraformGenerator.seaLevel) { - - // Height no longer checked in the interest of speed. - - if(biome == (BiomeBank.PLAINS) - || biome == (BiomeBank.FOREST) - || biome == (BiomeBank.SAVANNA) - || biome == (BiomeBank.TAIGA) - || biome == (BiomeBank.SCARLET_FOREST) - || biome == (BiomeBank.CHERRY_GROVE)) { - - return rollSpawnRatio(tw,chunkX,chunkZ); + + // Height no longer checked in the interest of speed. + + if (biome == (BiomeBank.PLAINS) + || biome == (BiomeBank.FOREST) + || biome == (BiomeBank.SAVANNA) + || biome == (BiomeBank.TAIGA) + || biome == (BiomeBank.SCARLET_FOREST) + || biome == (BiomeBank.CHERRY_GROVE)) + { + + return rollSpawnRatio(tw, chunkX, chunkZ); } // } return false; @@ -50,34 +54,36 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, Biom @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !isEnabled()) return; + if (!isEnabled()) { + return; + } - // For now, don't check biomes. There is only plains village. -// EnumSet banks = GenUtils.getBiomesInChunk(tw, data.getChunkX(), data.getChunkZ()); + // For now, don't check biomes. There is only plains village. + // EnumSet banks = GenUtils.getBiomesInChunk(tw, data.getChunkX(), data.getChunkZ()); // MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); // int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); - + // NO HIGHEST GROUND CHECKS IN POPULATE. If canSpawn is true, the structure MUST spawn. // if (GenUtils.getHighestGround(data, coords[0], coords[1]) > TerraformGenerator.seaLevel) { -// if (banks.contains(BiomeBank.PLAINS) -// || banks.contains(BiomeBank.FOREST) -// || banks.contains(BiomeBank.SAVANNA) -// || banks.contains(BiomeBank.TAIGA) -// || banks.contains(BiomeBank.SCARLET_FOREST) -// || banks.contains(BiomeBank.CHERRY_GROVE)) { + // if (banks.contains(BiomeBank.PLAINS) + // || banks.contains(BiomeBank.FOREST) + // || banks.contains(BiomeBank.SAVANNA) + // || banks.contains(BiomeBank.TAIGA) + // || banks.contains(BiomeBank.SCARLET_FOREST) + // || banks.contains(BiomeBank.CHERRY_GROVE)) { new PlainsVillagePopulator().populate(tw, data); -// } + // } // } - + } @Override public int getChunkBufferDistance() { - return TConfigOption.STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE.getInt(); + return TConfigOption.STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE.getInt(); } @Override diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsPathRecursiveSpawner.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsPathRecursiveSpawner.java index 64d165c5..7e82fd44 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsPathRecursiveSpawner.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsPathRecursiveSpawner.java @@ -18,32 +18,25 @@ import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.SlabBuilder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Random; +import java.util.*; public class PlainsPathRecursiveSpawner { private static final int minPathLength = 25; private static final int maxPathLength = 35; private final int range; + private final ArrayList validRooms = new ArrayList<>(); + private final @NotNull SimpleBlock core; + private final HashMap rooms = new HashMap<>(); + private final HashMap path = new HashMap<>(); + private final HashMap crossRoads = new HashMap<>(); private int minRoomWidth = 15; private int maxRoomWidth = 20; - - /** + /** * 1 for max room density, 0 for no rooms. */ private double villageDensity = 1; private PathPopulatorAbstract pathPop; - private final ArrayList validRooms = new ArrayList<>(); - - private final @NotNull SimpleBlock core; - private final HashMap rooms = new HashMap<>(); - private final HashMap path = new HashMap<>(); - private final HashMap crossRoads = new HashMap<>(); public PlainsPathRecursiveSpawner(@NotNull SimpleBlock core, int range, BlockFace... faces) { SimpleLocation start = new SimpleLocation(core.getX(), 0, core.getZ()); @@ -75,21 +68,24 @@ private void advanceCrossRoad(@NotNull Random random, @NotNull CrossRoad target, int minRoomWidth = this.minRoomWidth; int maxRoomWidth = this.maxRoomWidth; int smallRoomChance = 10; - if(GenUtils.chance(random, smallRoomChance, 100)) { + if (GenUtils.chance(random, smallRoomChance, 100)) { minRoomWidth = 7; maxRoomWidth = 10; } - + int roomWidthX = GenUtils.randInt(minRoomWidth, maxRoomWidth); int roomWidthZ = GenUtils.randInt(minRoomWidth, maxRoomWidth); - - DirectionalCubeRoom room = new DirectionalCubeRoom( - rF, roomWidthX, roomWidthZ, 20, - loc.getX() + (adjDir.getModX() * (2 + roomWidthX/2)), + + DirectionalCubeRoom room = new DirectionalCubeRoom(rF, + roomWidthX, + roomWidthZ, + 20, + loc.getX() + (adjDir.getModX() * (2 + roomWidthX / 2)), loc.getY(), - loc.getZ() + (adjDir.getModZ() * (2 + roomWidthZ/2))); + loc.getZ() + (adjDir.getModZ() * (2 + roomWidthZ / 2)) + ); // TerraformGeneratorPlugin.logger.info("ROOM: [" + (loc.getX() + adjDir.getModX()*11) + "] : [" + room.getX() + "], [" + (loc.getZ() + adjDir.getModZ()*11) + "] : [" + room.getZ() + "]"); - + if (!this.registerRoom(room)) { // Roll crossroads if (GenUtils.chance(random, lastCrossroad, 20)) { crossRoads.put(loc, new CrossRoad(loc, BlockUtils.getAdjacentFaces(direction))); @@ -97,26 +93,27 @@ private void advanceCrossRoad(@NotNull Random random, @NotNull CrossRoad target, } } } - } else { + } + else { if (GenUtils.chance(random, lastCrossroad, 20)) { crossRoads.put(loc, new CrossRoad(loc, BlockUtils.getAdjacentFaces(direction))); lastCrossroad = 0; } } loc = loc.getRelative(direction); - }else if(loc.distanceSqr(core.getX(), core.getY(), core.getZ()) > Math.pow(range, 2)) - { - loc = loc.getRelative(direction.getOppositeFace()); - direction = BlockUtils.getTurnBlockFace(random, direction); - loc = loc.getRelative(direction); - edgeTurns++; - if(edgeTurns > 3) { - cull = true; - // TerraformGeneratorPlugin.logger.info("Death by edgeTurns .+ 3"); - } + } + else if (loc.distanceSqr(core.getX(), core.getY(), core.getZ()) > Math.pow(range, 2)) { + loc = loc.getRelative(direction.getOppositeFace()); + direction = BlockUtils.getTurnBlockFace(random, direction); + loc = loc.getRelative(direction); + edgeTurns++; + if (edgeTurns > 3) { + cull = true; + // TerraformGeneratorPlugin.logger.info("Death by edgeTurns .+ 3"); + } } else { - // TerraformGeneratorPlugin.logger.info("Death by "); + // TerraformGeneratorPlugin.logger.info("Death by "); cull = true; } } @@ -130,9 +127,8 @@ public void registerRoomPopulator(RoomPopulatorAbstract roomPop) { validRooms.add(roomPop); } - + /** - * * @return whether or not a location can hold a cuberoom (no overlaps, not too far etc) */ private boolean isLocationValid(@NotNull SimpleLocation loc) { @@ -152,18 +148,26 @@ private boolean isLocationValid(@NotNull SimpleLocation loc) { public boolean registerRoom(@NotNull DirectionalCubeRoom room) { // Cannot be below sea level - if (core.getPopData().getType(room.getX(),GenUtils.getHighestGround(core.getPopData(), room.getX(), room.getZ())+1,room.getZ()) == Material.WATER) { + if (core.getPopData() + .getType(room.getX(), + GenUtils.getHighestGround(core.getPopData(), room.getX(), room.getZ()) + 1, + room.getZ()) == Material.WATER) + { return false; } // Cannot overlap another room for (DirectionalCubeRoom other : rooms.values()) { - if (other.isOverlapping(room)) return false; + if (other.isOverlapping(room)) { + return false; + } } // Don't be inside a pathway for (SimpleLocation loc : path.keySet()) { - if (room.isPointInside(loc)) return false; + if (room.isPointInside(loc)) { + return false; + } } rooms.put(new SimpleLocation(room.getX(), 0, room.getZ()), room); return true; @@ -189,55 +193,62 @@ public void build(@NotNull Random random) { Wall w = new Wall(new SimpleBlock(core.getPopData(), loc.getX(), loc.getY(), loc.getZ()), path.get(loc)); w = w.getGround(); if (BlockUtils.isWet(w.getUp().get())) { - + // Paths underwater are wood planks. - if(BlockUtils.isWet(w.getAtY(TerraformGenerator.seaLevel))) - w = w.getAtY(TerraformGenerator.seaLevel); - else - w = w.getGroundOrDry().getDown(); - - new SlabBuilder(Material.OAK_SLAB) - .setWaterlogged(true).setType(Type.TOP) - .apply(w) - .lapply(w.getRelative(0,0,1)) - .lapply(w.getRelative(0,0,-1)) - .lapply(w.getRelative(1,0,1)) - .lapply(w.getRelative(1,0,-1)) - .lapply(w.getRelative(-1,0,1)) - .lapply(w.getRelative(-1,0,-1)) - .lapply(w.getRelative(1,0,0)) - .lapply(w.getRelative(-1,0,0)) - ; - // Bukkit.getLogger().info("Underwater path at " + w.get().getVector() + " of type " + w.getType().toString()); - + if (BlockUtils.isWet(w.getAtY(TerraformGenerator.seaLevel))) { + w = w.getAtY(TerraformGenerator.seaLevel); + } + else { + w = w.getGroundOrDry().getDown(); + } + + new SlabBuilder(Material.OAK_SLAB).setWaterlogged(true) + .setType(Type.TOP) + .apply(w) + .lapply(w.getRelative(0, 0, 1)) + .lapply(w.getRelative(0, 0, -1)) + .lapply(w.getRelative(1, 0, 1)) + .lapply(w.getRelative(1, 0, -1)) + .lapply(w.getRelative(-1, 0, 1)) + .lapply(w.getRelative(-1, 0, -1)) + .lapply(w.getRelative(1, 0, 0)) + .lapply(w.getRelative(-1, 0, 0)); + // Bukkit.getLogger().info("Underwater path at " + w.get().getVector() + " of type " + w.getType().toString()); + continue; } - + // Remove foilage before placement - if(!w.getUp(2).isSolid() && w.getUp(2).getType() != Material.AIR) - w.getUp(2).setType(Material.AIR); - - if(!w.getUp().isSolid() && w.getUp().getType() != Material.AIR) - w.getUp().setType(Material.AIR); + if (!w.getUp(2).isSolid() && w.getUp(2).getType() != Material.AIR) { + w.getUp(2).setType(Material.AIR); + } + + if (!w.getUp().isSolid() && w.getUp().getType() != Material.AIR) { + w.getUp().setType(Material.AIR); + } + - w.setType(Material.DIRT_PATH); for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { Wall target = w.getRelative(face).getGround(); // Remove foilage before placement if (random.nextInt(3) != 0) { - if(!target.getUp(2).isSolid() && target.getUp(2).getType() != Material.AIR) - target.getUp(2).setType(Material.AIR); - - if(!target.getUp().isSolid() && target.getUp().getType() != Material.AIR) - target.getUp().setType(Material.AIR); + if (!target.getUp(2).isSolid() && target.getUp(2).getType() != Material.AIR) { + target.getUp(2).setType(Material.AIR); + } + + if (!target.getUp().isSolid() && target.getUp().getType() != Material.AIR) { + target.getUp().setType(Material.AIR); + } target.setType(Material.DIRT_PATH); } } } - if (validRooms.isEmpty()) return; + if (validRooms.isEmpty()) { + return; + } // Allocate room populators Iterator it = validRooms.iterator(); @@ -247,14 +258,18 @@ public void build(@NotNull Random random) { for (CubeRoom room : rooms.values()) { if (room.getPop() == null && pops.canPopulate(room)) { room.setRoomPopulator(pops); - if (pops.isUnique()) it.remove(); + if (pops.isUnique()) { + it.remove(); + } break; } } } } - if (validRooms.isEmpty()) return; + if (validRooms.isEmpty()) { + return; + } // Apply room populators for (CubeRoom room : rooms.values()) { @@ -273,8 +288,18 @@ public void build(@NotNull Random random) { } } if (room.getPop() != null) { - TerraformGeneratorPlugin.logger.info("Registered: " + room.getPop().getClass().getName() + " at " + room.getX() + " " + room.getY() + " " + room.getZ() + " in a room of size " - + room.getWidthX() + "x" + room.getWidthZ()); + TerraformGeneratorPlugin.logger.info("Registered: " + + room.getPop().getClass().getName() + + " at " + + room.getX() + + " " + + room.getY() + + " " + + room.getZ() + + " in a room of size " + + room.getWidthX() + + "x" + + room.getWidthZ()); room.populate(core.getPopData()); } } @@ -282,15 +307,23 @@ public void build(@NotNull Random random) { // Populate pathways for (SimpleLocation loc : path.keySet()) { if (pathPop != null) { - pathPop.populate(new PathPopulatorData(new SimpleBlock(core.getPopData(), loc.getX(), loc.getY(), loc.getZ()), path.get(loc), 3, false)); + pathPop.populate(new PathPopulatorData(new SimpleBlock( + core.getPopData(), + loc.getX(), + loc.getY(), + loc.getZ() + ), path.get(loc), 3, false)); } } } private @Nullable CrossRoad getFirstUnsatisfiedCrossRoad() { - for (CrossRoad road : crossRoads.values()) - if (!road.isSatisfied()) return road; + for (CrossRoad road : crossRoads.values()) { + if (!road.isSatisfied()) { + return road; + } + } return null; } @@ -346,8 +379,9 @@ public boolean isSatisfied() { public @Nullable BlockFace getFirstUnsatisfiedDirection() { for (BlockFace face : faces) { - if (!satisfiedFaces.contains(face)) + if (!satisfiedFaces.contains(face)) { return face; + } } return null; } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java index 40761ce1..229f38ea 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java @@ -19,98 +19,95 @@ public abstract class PlainsVillageAbstractRoomPopulator extends RoomPopulatorAbstract { - public PlainsVillageAbstractRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { - super(rand, forceSpawn, unique); - } - + public PlainsVillageAbstractRoomPopulator(Random rand, boolean forceSpawn, boolean unique) { + super(rand, forceSpawn, unique); + } + @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - // Test the center and 4 corners to ensure that the ground is fairly stable - int roomY = this.calculateRoomY(data, room); - - int worldHeight = TerraformGeneratorPlugin.injector.getMaxY()-TerraformGeneratorPlugin.injector.getMinY() + 1; - - for(int[] corner:room.getAllCorners(2)) { - SimpleBlock sb = new SimpleBlock(data,corner[0],roomY,corner[1]); - int lowSb = sb.findFloor(worldHeight).getY(); - if(Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - { - // place platform as uneven ground was detected. - this.placeFixerPlatform(roomY, data, room); - break; - } - } + // Test the center and 4 corners to ensure that the ground is fairly stable + int roomY = this.calculateRoomY(data, room); + + int worldHeight = TerraformGeneratorPlugin.injector.getMaxY() - TerraformGeneratorPlugin.injector.getMinY() + 1; + + for (int[] corner : room.getAllCorners(2)) { + SimpleBlock sb = new SimpleBlock(data, corner[0], roomY, corner[1]); + int lowSb = sb.findFloor(worldHeight).getY(); + if (Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + // place platform as uneven ground was detected. + this.placeFixerPlatform(roomY, data, room); + break; + } + } + } + + public void placeFixerPlatform(int roomY, @NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { + + // Semisphere air and semisphere ground + SimpleBlock core = room.getCenterSimpleBlock(data); + core = core.getAtY(roomY); + // Air + new SphereBuilder(this.rand, core.getUp(), Material.AIR).setRX((float) room.getWidthX() / 2 - 1.5f) + .setRZ((float) room.getWidthZ() / 2 - 1.5f) + .setRY(getRoomRoughNeededHeight()) + .setHardReplace(true) + .setSphereType(SphereType.UPPER_SEMISPHERE) + .build(); + + // Platform + new SphereBuilder(this.rand, core.getDown(), Material.DIRT).setRX(room.getWidthX() / 2f) + .setRZ(room.getWidthZ() / 2f) + .setRY(3) + .setPadding(4) + .setSphereFrequency(0.11f) + .setMinRadius(0.8) + .setHardReplace(false) + .setUpperType(Material.GRASS_BLOCK) + .setSphereType(SphereType.LOWER_SEMISPHERE) + .build(); + + } + + public int getRoomRoughNeededHeight() { + return 12; + } + + protected int calculateRoomY(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { + int centerHeight = GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); + int pathHeight = getPathHeight(data, room); + + if (Math.abs(centerHeight - pathHeight) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + return pathHeight; + } + else { + return centerHeight; + } + } + + protected boolean doesAreaFailTolerance(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { + int roomY = calculateRoomY(data, room); + int worldHeight = TerraformGeneratorPlugin.injector.getMaxY() - TerraformGeneratorPlugin.injector.getMinY() + 1; + for (int[] corner : room.getAllCorners(2)) { + SimpleBlock sb = new SimpleBlock(data, corner[0], roomY, corner[1]); + int lowSb = sb.findFloor(worldHeight).getY(); + if (Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + return true; + } + } + return false; } - public void placeFixerPlatform(int roomY, @NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - - // Semisphere air and semisphere ground - SimpleBlock core = room.getCenterSimpleBlock(data); - core = core.getAtY(roomY); - // Air - new SphereBuilder(this.rand, core.getUp(), Material.AIR) - .setRX((float) room.getWidthX() /2 - 1.5f) - .setRZ((float) room.getWidthZ() /2 - 1.5f) - .setRY(getRoomRoughNeededHeight()) - .setHardReplace(true) - .setSphereType(SphereType.UPPER_SEMISPHERE) - .build(); - - // Platform - new SphereBuilder(this.rand, core.getDown(), Material.DIRT) - .setRX(room.getWidthX()/2f) - .setRZ(room.getWidthZ()/2f) - .setRY(3) - .setPadding(4) - .setSphereFrequency(0.11f) - .setMinRadius(0.8) - .setHardReplace(false) - .setUpperType(Material.GRASS_BLOCK) - .setSphereType(SphereType.LOWER_SEMISPHERE) - .build(); - - } - - public int getRoomRoughNeededHeight() { - return 12; - } - - protected int calculateRoomY(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - int centerHeight = GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); - int pathHeight = getPathHeight(data, room); - - if(Math.abs(centerHeight-pathHeight) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { - return pathHeight; - }else { - return centerHeight; - } - } - - protected boolean doesAreaFailTolerance(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - int roomY = calculateRoomY(data,room); - int worldHeight = TerraformGeneratorPlugin.injector.getMaxY()-TerraformGeneratorPlugin.injector.getMinY() + 1; - for(int[] corner:room.getAllCorners(2)) { - SimpleBlock sb = new SimpleBlock(data,corner[0],roomY,corner[1]); - int lowSb = sb.findFloor(worldHeight).getY(); - if(Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - { - return true; - } - } - return false; - } - - protected int getPathHeight(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - int pathHeight; // This is the entry height for the house/object - + protected int getPathHeight(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { + int pathHeight; // This is the entry height for the house/object + BlockFace dir = ((DirectionalCubeRoom) room).getDirection(); int pad = GenUtils.randInt(1, 3); - - // calculate center height - Entry openingWallSet = room.getWall(data, dir, pad); - pathHeight = openingWallSet.getKey().getLeft(openingWallSet.getValue()/2).getGroundOrSeaLevel().getY(); - return pathHeight; - } - + + // calculate center height + Entry openingWallSet = room.getWall(data, dir, pad); + pathHeight = openingWallSet.getKey().getLeft(openingWallSet.getValue() / 2).getGroundOrSeaLevel().getY(); + return pathHeight; + } + } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java index d8b560b8..e173915a 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java @@ -22,197 +22,219 @@ public class PlainsVillageAnimalPenPopulator extends PlainsVillageAbstractRoomPopulator { private static final EntityType[] farmAnimals = { - EntityType.PIG, - EntityType.SHEEP, - EntityType.COW, - EntityType.HORSE, - EntityType.CHICKEN + EntityType.PIG, EntityType.SHEEP, EntityType.COW, EntityType.HORSE, EntityType.CHICKEN }; - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageAnimalPenPopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageAnimalPenPopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - - // If terrain is adverse, - // just forget it, animal pens don't fare well in hilly terrain. - if(super.doesAreaFailTolerance(data, room)) - return; - - int roomY = super.calculateRoomY(data, room); - - - // For animal farms, they look increasingly stupid when tilted. - // Just give up and place a platform underneath. - // super.placeFixerPlatform(roomY, data, room); - // Maybe this isn't needed as it no longer places when terrain is adverse - - SimpleBlock jobBlock = null; - boolean spawnedWater = false; - // Place fence - for(Entry entry:room.getFourWalls(data, 2).entrySet()) { - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - Wall target = w.getAtY(roomY).findNearestAirPocket(15); - if(target != null) { - if(target.getDown().getType()!=Material.COBBLESTONE_SLAB && - target.getDown().getType()!=plainsVillagePopulator.woodFence) - { - int wallHeight = 3; - if(target.getY() < roomY) - wallHeight = 2 + (roomY - target.getY()); - - if(i % 2 == 0) { - target.Pillar(wallHeight, plainsVillagePopulator.woodLog); - target.getUp(wallHeight).setType(Material.COBBLESTONE_SLAB); - target.getDown(2).getRight().CorrectMultipleFacing(wallHeight+2); - target.getDown(2).getLeft().CorrectMultipleFacing(wallHeight+2); - }else { - target.Pillar(wallHeight, plainsVillagePopulator.woodFence); - target.CorrectMultipleFacing(wallHeight); - } - - } - if(w.getDirection() == ((DirectionalCubeRoom) room).getDirection().getOppositeFace() - && i == entry.getValue()/2) { - jobBlock = target.getRear(); - } - } - w = w.getLeft(); - } - - } - - // Decorations - int[] lowerCorner = room.getLowerCorner(3); - int[] upperCorner = room.getUpperCorner(3); - - // Change the floor - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - - int highest; -// if(!areaFailedTolerance) { - highest = GenUtils.getHighestGroundOrSeaLevel(data, x, z); -// } -// else -// highest = roomY; - - if(Math.abs(highest-roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - continue; - - BlockUtils.setDownUntilSolid(x, highest, z, data, Material.DIRT); - - if(rand.nextBoolean()) { - data.setType(x, highest, z, GenUtils.randChoice(Material.PODZOL, Material.COARSE_DIRT, Material.GRASS_BLOCK)); - }else if(rand.nextBoolean()) { - if(!data.getType(x, highest+1, z).isSolid()) - PlantBuilder.TALL_GRASS.build(data, x, highest+1, z); - } - } - - - lowerCorner = room.getLowerCorner(5); - upperCorner = room.getUpperCorner(5); - // Place objects - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - - if(GenUtils.chance(rand, 1, 70)) { - if(!spawnedWater && rand.nextBoolean()) { // Water - spawnedWater = true; - Wall core = new Wall(new SimpleBlock(data, x,0,z),BlockUtils.getDirectBlockFace(rand)); - -// if(!areaFailedTolerance) { - core = core.getGroundOrSeaLevel().getUp(); -// } -// else -// core.getAtY(roomY+1); - - if(Math.abs(core.getY()-roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - continue; - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setHalf(Half.TOP) - .setFacing(core.getDirection()) - .apply(core.getRear()) - .setFacing(core.getDirection().getOppositeFace()) - .apply(core.getFront(2)) - .setFacing(BlockUtils.getRight(core.getDirection())) - .apply(core.getFront().getLeft()) - .apply(core.getLeft()) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(core.getFront().getRight()) - .apply(core.getRight()); - - new SlabBuilder(Material.COBBLESTONE_SLAB) - .setWaterlogged(true) - .apply(core).apply(core.getFront()); - - core.getDown().downUntilSolid(new Random(),Material.DIRT); - core.getFront().getDown().downUntilSolid(new Random(),Material.DIRT); - break; - } else { // Haybales - SimpleBlock core = new SimpleBlock(data, x, roomY, z).findAirPocket(15); - if(core == null) - continue; - - BlockUtils.replaceUpperSphere(x + 7 * z + 17 * 17, 1.5f, 2.5f, 1.5f, + + // If terrain is adverse, + // just forget it, animal pens don't fare well in hilly terrain. + if (super.doesAreaFailTolerance(data, room)) { + return; + } + + int roomY = super.calculateRoomY(data, room); + + + // For animal farms, they look increasingly stupid when tilted. + // Just give up and place a platform underneath. + // super.placeFixerPlatform(roomY, data, room); + // Maybe this isn't needed as it no longer places when terrain is adverse + + SimpleBlock jobBlock = null; + boolean spawnedWater = false; + // Place fence + for (Entry entry : room.getFourWalls(data, 2).entrySet()) { + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + Wall target = w.getAtY(roomY).findNearestAirPocket(15); + if (target != null) { + if (target.getDown().getType() != Material.COBBLESTONE_SLAB + && target.getDown().getType() != plainsVillagePopulator.woodFence) + { + int wallHeight = 3; + if (target.getY() < roomY) { + wallHeight = 2 + (roomY - target.getY()); + } + + if (i % 2 == 0) { + target.Pillar(wallHeight, plainsVillagePopulator.woodLog); + target.getUp(wallHeight).setType(Material.COBBLESTONE_SLAB); + target.getDown(2).getRight().CorrectMultipleFacing(wallHeight + 2); + target.getDown(2).getLeft().CorrectMultipleFacing(wallHeight + 2); + } + else { + target.Pillar(wallHeight, plainsVillagePopulator.woodFence); + target.CorrectMultipleFacing(wallHeight); + } + + } + if (w.getDirection() == ((DirectionalCubeRoom) room).getDirection().getOppositeFace() + && i == entry.getValue() / 2) + { + jobBlock = target.getRear(); + } + } + w = w.getLeft(); + } + + } + + // Decorations + int[] lowerCorner = room.getLowerCorner(3); + int[] upperCorner = room.getUpperCorner(3); + + // Change the floor + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + + int highest; + // if(!areaFailedTolerance) { + highest = GenUtils.getHighestGroundOrSeaLevel(data, x, z); + // } + // else + // highest = roomY; + + if (Math.abs(highest - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + continue; + } + + BlockUtils.setDownUntilSolid(x, highest, z, data, Material.DIRT); + + if (rand.nextBoolean()) { + data.setType(x, + highest, + z, + GenUtils.randChoice(Material.PODZOL, Material.COARSE_DIRT, Material.GRASS_BLOCK) + ); + } + else if (rand.nextBoolean()) { + if (!data.getType(x, highest + 1, z).isSolid()) { + PlantBuilder.TALL_GRASS.build(data, x, highest + 1, z); + } + } + } + } + + + lowerCorner = room.getLowerCorner(5); + upperCorner = room.getUpperCorner(5); + // Place objects + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + + if (GenUtils.chance(rand, 1, 70)) { + if (!spawnedWater && rand.nextBoolean()) { // Water + spawnedWater = true; + Wall core = new Wall(new SimpleBlock(data, x, 0, z), BlockUtils.getDirectBlockFace(rand)); + + // if(!areaFailedTolerance) { + core = core.getGroundOrSeaLevel().getUp(); + // } + // else + // core.getAtY(roomY+1); + + if (Math.abs(core.getY() - roomY) + > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) + { + continue; + } + + new StairBuilder(Material.COBBLESTONE_STAIRS).setHalf(Half.TOP) + .setFacing(core.getDirection()) + .apply(core.getRear()) + .setFacing(core.getDirection().getOppositeFace()) + .apply(core.getFront(2)) + .setFacing(BlockUtils.getRight(core.getDirection())) + .apply(core.getFront().getLeft()) + .apply(core.getLeft()) + .setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(core.getFront().getRight()) + .apply(core.getRight()); + + new SlabBuilder(Material.COBBLESTONE_SLAB).setWaterlogged(true) + .apply(core) + .apply(core.getFront()); + + core.getDown().downUntilSolid(new Random(), Material.DIRT); + core.getFront().getDown().downUntilSolid(new Random(), Material.DIRT); + break; + } + else { // Haybales + SimpleBlock core = new SimpleBlock(data, x, roomY, z).findAirPocket(15); + if (core == null) { + continue; + } + + BlockUtils.replaceUpperSphere(x + 7 * z + 17 * 17, + 1.5f, + 2.5f, + 1.5f, core, - false, Material.HAY_BLOCK); + false, + Material.HAY_BLOCK + ); break; - } - } - } - - // Spawn animals - EntityType animal = farmAnimals[rand.nextInt(farmAnimals.length)]; + } + } + } + } + // Spawn animals - int[] coords = new int[] {room.getX(),0,room.getZ()}; - - int highest; -// if(!areaFailedTolerance) { - highest = GenUtils.getTrueHighestBlock(data, coords[0], coords[2]); -// } -// else -// highest = roomY; - - int threshold = 0; - while(data.getType(coords[0], highest + 1, coords[2]).isSolid() && - threshold < 6) { - threshold++; - highest++; + EntityType animal = farmAnimals[rand.nextInt(farmAnimals.length)]; + // Spawn animals + int[] coords = new int[] {room.getX(), 0, room.getZ()}; + + int highest; + // if(!areaFailedTolerance) { + highest = GenUtils.getTrueHighestBlock(data, coords[0], coords[2]); + // } + // else + // highest = roomY; + + int threshold = 0; + while (data.getType(coords[0], highest + 1, coords[2]).isSolid() && threshold < 6) { + threshold++; + highest++; + } + if (threshold < 6) { + if (Math.abs(highest - roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + for (int i = 0; i < GenUtils.randInt(3, 7); i++) { + data.addEntity(coords[0], highest + 1, coords[2], animal); + } + } } - if(threshold < 6) { - if(Math.abs(highest-roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - { - for (int i = 0; i < GenUtils.randInt(3, 7); i++) - data.addEntity(coords[0], highest + 1, coords[2], animal); + + if (jobBlock != null) { + switch (animal) { + case PIG: + case CHICKEN: + new DirectionalBuilder(Material.SMOKER).setFacing(((DirectionalCubeRoom) room).getDirection()) + .apply(jobBlock); + break; + case SHEEP: + jobBlock.setType(Material.LOOM); + break; + case COW: + case HORSE: + jobBlock.setType(Material.CAULDRON); + break; + default: + break; } } - - if(jobBlock != null) - switch(animal) { - case PIG: - case CHICKEN: - new DirectionalBuilder(Material.SMOKER) - .setFacing(((DirectionalCubeRoom) room).getDirection()) - .apply(jobBlock); - break; - case SHEEP: - jobBlock.setType(Material.LOOM); - break; - case COW: - case HORSE: - jobBlock.setType(Material.CAULDRON); - break; - default: - break; - } } @Override diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java index e1621f20..b3d36a78 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java @@ -24,7 +24,7 @@ public class PlainsVillageCropFarmPopulator extends PlainsVillageAbstractRoomPopulator { - private static final Material[] crops = { + private static final Material[] crops = { Material.WHEAT, Material.CARROTS, Material.POTATOES, @@ -33,102 +33,113 @@ public class PlainsVillageCropFarmPopulator extends PlainsVillageAbstractRoomPop Material.MELON_STEM }; - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageCropFarmPopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageCropFarmPopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - int roomY = super.calculateRoomY(data, room); - boolean areaFailedTolerance = super.doesAreaFailTolerance(data, room); - - // If terrain is adverse, don't bother. - if(areaFailedTolerance) - return; - - super.populate(data, room); - + int roomY = super.calculateRoomY(data, room); + boolean areaFailedTolerance = super.doesAreaFailTolerance(data, room); + + // If terrain is adverse, don't bother. + if (areaFailedTolerance) { + return; + } + + super.populate(data, room); + BlockFace dir = ((DirectionalCubeRoom) room).getDirection(); boolean hasScareCrow = false; int pad = GenUtils.randInt(1, 3); for (Entry entry : room.getFourWalls(data, pad).entrySet()) { Wall w; - -// if(!areaFailedTolerance) { - w = entry.getKey().getGroundOrSeaLevel().getUp(); -// } -// else - // w = entry.getKey().getAtY(roomY).getUp(); - + + // if(!areaFailedTolerance) { + w = entry.getKey().getGroundOrSeaLevel().getUp(); + // } + // else + // w = entry.getKey().getAtY(roomY).getUp(); + for (int i = 0; i < entry.getValue(); i++) { - // Added height tolerance check. Don't place anything on areas that deviate too far off. - if(Math.abs(w.getY()-roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - if (w.getDirection().getOppositeFace() == dir) { // Entrance - - if (i <= 1 || i >= entry.getValue() - 1) { - w.setType(plainsVillagePopulator.woodLog); - w.getDown().downUntilSolid(rand, plainsVillagePopulator.woodLog); - if (i == 1 || i == entry.getValue() - 1) { - new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor) - .setFacing(dir) - .setOpen(true) - .setHalf(Half.BOTTOM) - .apply(w.getRear()); - - w.getUp().setType(plainsVillagePopulator.woodLeaves); - } - } else if (i == 2 || i == entry.getValue() - 2) { - w.setType(plainsVillagePopulator.woodFence); - - w.getDown().downUntilSolid(rand, plainsVillagePopulator.woodLog); - - w.CorrectMultipleFacing(1); - w.getUp().setType(Material.TORCH); - - } else if (i == entry.getValue() / 2) - w.setType(Material.COMPOSTER); - - - } else { // Farm Walls - w.downUntilSolid(rand, plainsVillagePopulator.woodLog); - if (i % 3 == 0) { - w.getUp().setType(plainsVillagePopulator.woodLeaves); - } else { - w.getUp().setType(plainsVillagePopulator.woodFence); - w.getUp().CorrectMultipleFacing(1); - - // Chance to spawn overhanging lamp - if (i > 1 && i < entry.getValue()-2 && GenUtils.chance(rand, 1, 13)) { - int lampHeight = GenUtils.randInt(rand, 4, 6); - w.getUp(2).Pillar(lampHeight, rand, plainsVillagePopulator.woodFence); - - Wall lampWall = w.getRelative(0, 1 + lampHeight, 0).getFront(); - - for (int j = 0; j < GenUtils.randInt(rand, 1, 2); j++) { - lampWall.setType(plainsVillagePopulator.woodFence); - lampWall.CorrectMultipleFacing(1); - lampWall = lampWall.getFront(); - } - lampWall = lampWall.getRear().getDown(); - - for (int j = 0; j < GenUtils.randInt(rand, 0, 1); j++) { - lampWall.setType(Material.CHAIN); - lampWall = lampWall.getDown(); - } - Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); - lantern.setHanging(true); - lampWall.setBlockData(lantern); - } - } - } - - -// if(!areaFailedTolerance) + // Added height tolerance check. Don't place anything on areas that deviate too far off. + if (Math.abs(w.getY() - roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (w.getDirection().getOppositeFace() == dir) { // Entrance + + if (i <= 1 || i >= entry.getValue() - 1) { + w.setType(plainsVillagePopulator.woodLog); + w.getDown().downUntilSolid(rand, plainsVillagePopulator.woodLog); + if (i == 1 || i == entry.getValue() - 1) { + new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor).setFacing(dir) + .setOpen(true) + .setHalf(Half.BOTTOM) + .apply(w.getRear()); + + w.getUp().setType(plainsVillagePopulator.woodLeaves); + } + } + else if (i == 2 || i == entry.getValue() - 2) { + w.setType(plainsVillagePopulator.woodFence); + + w.getDown().downUntilSolid(rand, plainsVillagePopulator.woodLog); + + w.CorrectMultipleFacing(1); + w.getUp().setType(Material.TORCH); + + } + else if (i == entry.getValue() / 2) { + w.setType(Material.COMPOSTER); + } + + + } + else { // Farm Walls + w.downUntilSolid(rand, plainsVillagePopulator.woodLog); + if (i % 3 == 0) { + w.getUp().setType(plainsVillagePopulator.woodLeaves); + } + else { + w.getUp().setType(plainsVillagePopulator.woodFence); + w.getUp().CorrectMultipleFacing(1); + + // Chance to spawn overhanging lamp + if (i > 1 && i < entry.getValue() - 2 && GenUtils.chance(rand, 1, 13)) { + int lampHeight = GenUtils.randInt(rand, 4, 6); + w.getUp(2).Pillar(lampHeight, rand, plainsVillagePopulator.woodFence); + + Wall lampWall = w.getRelative(0, 1 + lampHeight, 0).getFront(); + + for (int j = 0; j < GenUtils.randInt(rand, 1, 2); j++) { + lampWall.setType(plainsVillagePopulator.woodFence); + lampWall.CorrectMultipleFacing(1); + lampWall = lampWall.getFront(); + } + lampWall = lampWall.getRear().getDown(); + + for (int j = 0; j < GenUtils.randInt(rand, 0, 1); j++) { + lampWall.setType(Material.CHAIN); + lampWall = lampWall.getDown(); + } + Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); + lantern.setHanging(true); + lampWall.setBlockData(lantern); + } + } + } + } + + + // if(!areaFailedTolerance) w = w.getLeft().getGroundOrSeaLevel().getUp(); -// else + // else // w = w.getLeft().getAtY(roomY).getUp(); } } @@ -144,51 +155,68 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { int height; -// if(!areaFailedTolerance) { - height = GenUtils.getHighestGroundOrSeaLevel(data, x, z); - - // Forget populating areas that are too far up/down - if(Math.abs(height-roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - continue; -// } else -// height = roomY; - - BlockUtils.setDownUntilSolid(x, height-1, z, data, Material.DIRT); - + // if(!areaFailedTolerance) { + height = GenUtils.getHighestGroundOrSeaLevel(data, x, z); + + // Forget populating areas that are too far up/down + if (Math.abs(height - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + continue; + } + // } else + // height = roomY; + + BlockUtils.setDownUntilSolid(x, height - 1, z, data, Material.DIRT); + if (x % 4 == 0 && z % 4 == 0) { // Water - for(BlockFace face:BlockUtils.directBlockFaces) { - data.setType(x+face.getModX(), height, z+face.getModZ(), Material.FARMLAND); - BlockUtils.setDownUntilSolid(x+face.getModX(), height-1, z+face.getModZ(), data, Material.DIRT); - } + for (BlockFace face : BlockUtils.directBlockFaces) { + data.setType(x + face.getModX(), height, z + face.getModZ(), Material.FARMLAND); + BlockUtils.setDownUntilSolid( + x + face.getModX(), + height - 1, + z + face.getModZ(), + data, + Material.DIRT + ); + } data.setType(x, height, z, Material.WATER); - } else if ((crop != Material.PUMPKIN_STEM && crop != Material.MELON_STEM) - || GenUtils.chance(rand, 1, 3)) { + } + else if ((crop != Material.PUMPKIN_STEM && crop != Material.MELON_STEM) || GenUtils.chance( + rand, + 1, + 3 + )) + { if (GenUtils.chance(rand, 1, 30) && !hasScareCrow) { // Scarecrows // Ensure enough space - if (x > lowerCorner[0] + 1 && x < upperCorner[0] - 1 && z > lowerCorner[1] + 1 && z < upperCorner[1] - 1) { + if (x > lowerCorner[0] + 1 + && x < upperCorner[0] - 1 + && z > lowerCorner[1] + 1 + && z < upperCorner[1] - 1) + { hasScareCrow = true; setScareCrow(data, x, height + 1, z); } - } else { // Farmlands + } + else { // Farmlands Farmland land = (Farmland) Bukkit.createBlockData(Material.FARMLAND); land.setMoisture(7); data.setBlockData(x, height, z, land); - new AgeableBuilder(crop) - .setRandomAge(rand) - .apply(data, x, height + 1, z); + new AgeableBuilder(crop).setRandomAge(rand).apply(data, x, height + 1, z); } - } else if (GenUtils.chance(rand, 1, 3)) { + } + else if (GenUtils.chance(rand, 1, 3)) { data.setType(x, height, z, Material.DIRT); Material block; Material stem; if (crop == Material.PUMPKIN_STEM) { block = Material.PUMPKIN; stem = Material.ATTACHED_PUMPKIN_STEM; - } else { + } + else { block = Material.MELON; stem = Material.ATTACHED_MELON_STEM; } @@ -197,13 +225,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (BlockFace near : BlockUtils.directBlockFaces) { if (target.getRelative(near).getBlockData() instanceof Ageable) { target.setType(block); - new DirectionalBuilder(stem) - .setFacing(near.getOppositeFace()) - .apply(target.getRelative(near)); + new DirectionalBuilder(stem).setFacing(near.getOppositeFace()) + .apply(target.getRelative(near)); break; } } - } else { + } + else { data.setType(x, height, z, Material.COARSE_DIRT); } @@ -222,9 +250,7 @@ private void setScareCrow(@NotNull PopulatorDataAbstract data, int x, int y, int w.getRight().getUp(2).setType(plainsVillagePopulator.woodFence); w.getUp(2).CorrectMultipleFacing(1); - new DirectionalBuilder(Material.CARVED_PUMPKIN, Material.JACK_O_LANTERN) - .setFacing(facing) - .apply(w.getUp(3)); + new DirectionalBuilder(Material.CARVED_PUMPKIN, Material.JACK_O_LANTERN).setFacing(facing).apply(w.getUp(3)); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageForgePopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageForgePopulator.java index 6601747a..265332d1 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageForgePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageForgePopulator.java @@ -13,26 +13,37 @@ import java.util.Random; public class PlainsVillageForgePopulator extends PlainsVillageAbstractRoomPopulator { - - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageForgePopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageForgePopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); + super.populate(data, room); int height = super.calculateRoomY(data, room); // GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); - + // 1 is added to height because temples need a small bit of elevation to look better PlainsVillageForgeJigsawBuilder builder = new PlainsVillageForgeJigsawBuilder( - plainsVillagePopulator, - room.getWidthX() - 3, room.getWidthZ() - 3, data, room.getX(), height+1, room.getZ() + plainsVillagePopulator, + room.getWidthX() - 3, + room.getWidthZ() - 3, + data, + room.getX(), + height + 1, + room.getZ() ); - if (room instanceof DirectionalCubeRoom) + if (room instanceof DirectionalCubeRoom) { builder.forceEntranceDirection(((DirectionalCubeRoom) room).getDirection()); + } builder.generate(this.rand); builder.build(this.rand); @@ -43,15 +54,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room boolean placedLamp = false; // Connect front to the nearest path. while (entrance.getType() != Material.DIRT_PATH && maxDepth > 0) { - if (BlockUtils.isDirtLike(entrance.getType())) + if (BlockUtils.isDirtLike(entrance.getType())) { entrance.setType(Material.DIRT_PATH); + } if (!placedLamp && GenUtils.chance(this.rand, 3, 5)) { SimpleBlock target; - if (this.rand.nextBoolean()) + if (this.rand.nextBoolean()) { target = entrance.getLeft(2).getGround().getUp().get(); - else + } + else { target = entrance.getRight(2).getGround().getUp().get(); + } if (PlainsVillagePathPopulator.canPlaceLamp(target)) { placedLamp = true; PlainsVillagePathPopulator.placeLamp(rand, target); diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageFountainPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageFountainPopulator.java index ad071ee8..bec8753b 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageFountainPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageFountainPopulator.java @@ -23,69 +23,79 @@ public class PlainsVillageFountainPopulator extends RoomPopulatorAbstract { - private static final String[] villageFountainSchems = new String[] { - "plainsvillage-fountain1", - "plainsvillage-fountain2" - }; + private static final String[] villageFountainSchems = new String[] { + "plainsvillage-fountain1", "plainsvillage-fountain2" + }; - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageFountainPopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageFountainPopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - - int x = room.getX(); + + int x = room.getX(); int z = room.getZ(); int y = GenUtils.getHighestGround(data, x, z); BlockFace roomDir = ((DirectionalCubeRoom) room).getDirection(); - + try { - SimpleBlock core = new SimpleBlock(data, x,y+1,z); - TerraSchematic schem = TerraSchematic.load(villageFountainSchems[rand.nextInt(villageFountainSchems.length)], core.getDown()); - schem.parser = new PlainsVillageFountainSchematicParser(); - schem.apply(); - - for(int nx = -3; nx <= 3; nx++) { - for(int nz = -3; nz <= 3; nz++) { - Wall target = new Wall(core.getRelative(nx,0,nz)); - if(target.getType() == Material.COBBLESTONE - ||target.getType() == Material.MOSSY_COBBLESTONE) { - target.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - }else if(target.getType() == Material.POLISHED_ANDESITE) { - target.getDown().downUntilSolid(rand, Material.POLISHED_ANDESITE); - } - } - } - - Wall w = new Wall(core.getRelative(roomDir,3), roomDir); - - int pathLength = room.getWidthX()/2; - if(BlockUtils.getAxisFromBlockFace(roomDir) == Axis.Z) - pathLength = room.getWidthZ()/2; - - for(int i = 0; i < pathLength-1; i++) { - w.getGround().setType(Material.DIRT_PATH); - w.getLeft().getGround().setType(Material.DIRT_PATH); - w.getRight().getGround().setType(Material.DIRT_PATH); - - if(GenUtils.chance(rand, 1, 10)) { - BlockFace lampFace = BlockUtils.getTurnBlockFace(rand, roomDir); - SimpleBlock target = w.getRelative(lampFace,2).getGround().getUp().get(); - if(target.getDown().getType() != Material.DIRT_PATH - && PlainsVillagePathPopulator.canPlaceLamp(target)) { - PlainsVillagePathPopulator.placeLamp(rand, target); - } - } - - w = w.getRelative(roomDir); - } - - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } + SimpleBlock core = new SimpleBlock(data, x, y + 1, z); + TerraSchematic schem = TerraSchematic.load( + villageFountainSchems[rand.nextInt(villageFountainSchems.length)], + core.getDown() + ); + schem.parser = new PlainsVillageFountainSchematicParser(); + schem.apply(); + + for (int nx = -3; nx <= 3; nx++) { + for (int nz = -3; nz <= 3; nz++) { + Wall target = new Wall(core.getRelative(nx, 0, nz)); + if (target.getType() == Material.COBBLESTONE || target.getType() == Material.MOSSY_COBBLESTONE) { + target.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + else if (target.getType() == Material.POLISHED_ANDESITE) { + target.getDown().downUntilSolid(rand, Material.POLISHED_ANDESITE); + } + } + } + + Wall w = new Wall(core.getRelative(roomDir, 3), roomDir); + + int pathLength = room.getWidthX() / 2; + if (BlockUtils.getAxisFromBlockFace(roomDir) == Axis.Z) { + pathLength = room.getWidthZ() / 2; + } + + for (int i = 0; i < pathLength - 1; i++) { + w.getGround().setType(Material.DIRT_PATH); + w.getLeft().getGround().setType(Material.DIRT_PATH); + w.getRight().getGround().setType(Material.DIRT_PATH); + + if (GenUtils.chance(rand, 1, 10)) { + BlockFace lampFace = BlockUtils.getTurnBlockFace(rand, roomDir); + SimpleBlock target = w.getRelative(lampFace, 2).getGround().getUp().get(); + if (target.getDown().getType() != Material.DIRT_PATH && PlainsVillagePathPopulator.canPlaceLamp( + target)) + { + PlainsVillagePathPopulator.placeLamp(rand, target); + } + } + + w = w.getRelative(roomDir); + } + + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } } @@ -93,28 +103,26 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room public boolean canPopulate(@NotNull CubeRoom room) { return room.getWidthX() <= 10; } - - private class PlainsVillageFountainSchematicParser extends SchematicParser{ + + private class PlainsVillageFountainSchematicParser extends SchematicParser { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } else if(data.getMaterial().toString().startsWith("OAK_")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "oak_", - plainsVillagePopulator.wood - ) - ); + } + else if (data.getMaterial().toString().startsWith("OAK_")) { + data = Bukkit.createBlockData(data.getAsString().replaceAll("oak_", plainsVillagePopulator.wood)); super.applyData(block, data); - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java index f31064d2..f57b2aad 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java @@ -41,101 +41,120 @@ public static void placeLamp(@NotNull Random rand, @NotNull SimpleBlock b) { b.getUp(4).setType(Material.CAMPFIRE); b.getUp(5).setType(GenUtils.randChoice(rand, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS)); for (BlockFace face : BlockUtils.directBlockFaces) { - Slab tSlab = (Slab) Bukkit.createBlockData(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); + Slab tSlab = (Slab) Bukkit.createBlockData(GenUtils.randChoice( + rand, + Material.STONE_BRICK_SLAB, + Material.MOSSY_STONE_BRICK_SLAB + )); tSlab.setType(Type.TOP); b.getRelative(face).getUp(3).setBlockData(tSlab); - b.getRelative(face).getUp(4).setType(GenUtils.randChoice(rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); - b.getRelative(face).getUp(5).setType(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); + b.getRelative(face) + .getUp(4) + .setType(GenUtils.randChoice(rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); + b.getRelative(face) + .getUp(5) + .setType(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); } } - - /** - * Only checks if the target location has enough space to place a lamp, - * and if the lamp is in water. Other - * checks such as ground type etc must be done elsewhere - * @param target the block where the base of the lamp is. - * @return whether or not the lamp has enough space to be placed here. - */ + + /** + * Only checks if the target location has enough space to place a lamp, + * and if the lamp is in water. Other + * checks such as ground type etc must be done elsewhere + * + * @param target the block where the base of the lamp is. + * @return whether or not the lamp has enough space to be placed here. + */ public static boolean canPlaceLamp(@NotNull SimpleBlock target) { - - if(target.getType() == Material.WATER) - return false; + + if (target.getType() == Material.WATER) { + return false; + } for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { - for (int i = 0; i < 6; i++) - if (target.getRelative(face).getRelative(0, i, 0).isSolid()) + for (int i = 0; i < 6; i++) { + if (target.getRelative(face).getRelative(0, i, 0).isSolid()) { return false; + } + } } return true; } - + @Override public void populate(@NotNull PathPopulatorData ppd) { // Find the ground level to place pathways - ppd.base = new SimpleBlock( - ppd.base.getPopData(), + ppd.base = new SimpleBlock(ppd.base.getPopData(), ppd.base.getX(), GenUtils.getHighestGround(ppd.base.getPopData(), ppd.base.getX(), ppd.base.getZ()), - ppd.base.getZ()); + ppd.base.getZ() + ); // Path is on water. Place a solid wooden foundation, and then return. if (BlockUtils.isWet(ppd.base.getUp())) { - - Wall pathCore = new Wall(ppd.base, ppd.dir).getAtY(TerraformGenerator.seaLevel); - - if((BlockUtils.getAxisFromBlockFace(ppd.dir) == Axis.X && ppd.base.getX() % 2 == 0) - || (BlockUtils.getAxisFromBlockFace(ppd.dir) == Axis.Z && ppd.base.getZ() % 2 == 0)) { - pathCore.getDown().downLPillar(random, 50, Material.OAK_LOG); - pathCore.setType(Material.CHISELED_STONE_BRICKS); - } + + Wall pathCore = new Wall(ppd.base, ppd.dir).getAtY(TerraformGenerator.seaLevel); + + if ((BlockUtils.getAxisFromBlockFace(ppd.dir) == Axis.X && ppd.base.getX() % 2 == 0) + || (BlockUtils.getAxisFromBlockFace(ppd.dir) == Axis.Z && ppd.base.getZ() % 2 == 0)) + { + pathCore.getDown().downLPillar(random, 50, Material.OAK_LOG); + pathCore.setType(Material.CHISELED_STONE_BRICKS); + } return; } - + // Decorate the sides of the paths Wall pathCore = new Wall(ppd.base, ppd.dir); - for(BlockFace face:BlockUtils.getAdjacentFaces(ppd.dir)) { - for(int i = 0; i < 4; i++) { - Wall target = pathCore.getRelative(face,i).getGround(); - if(!target.getUp().isSolid() - && target.getUp().getType() != Material.WATER - && BlockUtils.isDirtLike(target.getType()) - && target.getType() != Material.DIRT_PATH) { - if(GenUtils.chance(2,5)) { // Leaves + for (BlockFace face : BlockUtils.getAdjacentFaces(ppd.dir)) { + for (int i = 0; i < 4; i++) { + Wall target = pathCore.getRelative(face, i).getGround(); + if (!target.getUp().isSolid() && target.getUp().getType() != Material.WATER && BlockUtils.isDirtLike( + target.getType()) && target.getType() != Material.DIRT_PATH) + { + if (GenUtils.chance(2, 5)) { // Leaves PlantBuilder.OAK_LEAVES.build(target.getUp()); - }else if(GenUtils.chance(1, 5)) { // Flowers + } + else if (GenUtils.chance(1, 5)) { // Flowers BlockUtils.pickTallFlower().build(target); - }else if(GenUtils.chance(1, 10)) { // Small cobble walls with lanterns - target.getUp().setType(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); - if (TConfigOption.areDecorationsEnabled()) - target.getUp(2).setType(Material.LANTERN); - } - - break; - } - } + } + else if (GenUtils.chance(1, 10)) { // Small cobble walls with lanterns + target.getUp().setType(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); + if (TConfigOption.areDecorationsEnabled()) { + target.getUp(2).setType(Material.LANTERN); + } + } + + break; + } + } } - - + + if (GenUtils.chance(random, 1, 15)) { BlockFace side = BlockUtils.getTurnBlockFace(random, ppd.dir); - SimpleBlock target = new SimpleBlock( - ppd.base.getPopData(), + SimpleBlock target = new SimpleBlock(ppd.base.getPopData(), ppd.base.getX() + side.getModX() * 3, - GenUtils.getHighestGround( - ppd.base.getPopData(), + GenUtils.getHighestGround(ppd.base.getPopData(), ppd.base.getX() + side.getModX() * 3, - ppd.base.getZ() + side.getModZ() * 3), - ppd.base.getZ() + side.getModZ() * 3); - if (target.getType() == Material.DIRT_PATH) return; + ppd.base.getZ() + side.getModZ() * 3 + ), + ppd.base.getZ() + side.getModZ() * 3 + ); + if (target.getType() == Material.DIRT_PATH) { + return; + } for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { - if (target.getRelative(face).getGround().getUp().isSolid()) + if (target.getRelative(face).getGround().getUp().isSolid()) { return; + } } for (CubeRoom room : knownRooms) { - if (room.isPointInside(target)) + if (room.isPointInside(target)) { return; + } } placeLamp(random, target.getUp()); diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java index ed26b6b5..eb7254f3 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java @@ -25,147 +25,202 @@ public PlainsVillagePondPopulator(Random rand, boolean forceSpawn, boolean uniqu @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - - // Check if this area is flat enough to be a pond - int[] lowerCorner = room.getLowerCorner(); - int[] upperCorner = room.getUpperCorner(); - - int lowest = 256; - int highest = -1; - - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - int ground = GenUtils.getHighestGround(data, x, z); - if(ground < lowest) lowest = ground; - if(ground > highest) highest = ground; - } - - // Height difference is too big. Don't bother. - if(highest - lowest >= 5) return; - - SimpleBlock core = new SimpleBlock(data, room.getX(), 0, room.getZ()); - core = core.getGround(); - - // Carve hole in ground - int depth = GenUtils.randInt(3, 5); - BlockUtils.replaceLowerSphere(rand.nextInt(12222), - (room.getWidthX()/2.0f)-1.5f, (float) depth, (room.getWidthZ()/2.0f)-1.5f, - core, true, Material.AIR); - - // Try to replace bottom with water - - // Find lowest ground block in the area - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - int ground = GenUtils.getHighestGround(data, x, z); - if(ground < lowest) lowest = ground; - if(ground > highest) highest = ground; - } - - - ArrayList lakeWaterBlocks = getLakeWaterBlocks(core, lowerCorner, upperCorner, lowest); - - if(lakeWaterBlocks.isEmpty()) return; // Don't bother if the pond is too small; - - int pondSurface = -1; // this variable will now be used to store the water level of the pond. - for(SimpleBlock s:lakeWaterBlocks) { - s.setType(Material.WATER); - if(s.getY() > pondSurface) pondSurface = s.getY(); - } - - boolean placedJobBlock = false; - // Place side decorations - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - SimpleBlock target = new SimpleBlock(core.getPopData(),x,0,z).getGround(); - - // Decorate side of the pond - if(target.getUp().getType() == Material.AIR) { - - // Make sure it's the side of the pond - boolean valid = false; - for(BlockFace face:BlockUtils.directBlockFaces) - if(target.getRelative(face).getType() == Material.WATER) - valid = true; - if(!valid) continue; - - target = target.getUp(); - if(GenUtils.chance(1, 4)) { // Sugar Canes + + // Check if this area is flat enough to be a pond + int[] lowerCorner = room.getLowerCorner(); + int[] upperCorner = room.getUpperCorner(); + + int lowest = 256; + int highest = -1; + + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + int ground = GenUtils.getHighestGround(data, x, z); + if (ground < lowest) { + lowest = ground; + } + if (ground > highest) { + highest = ground; + } + } + } + + // Height difference is too big. Don't bother. + if (highest - lowest >= 5) { + return; + } + + SimpleBlock core = new SimpleBlock(data, room.getX(), 0, room.getZ()); + core = core.getGround(); + + // Carve hole in ground + int depth = GenUtils.randInt(3, 5); + BlockUtils.replaceLowerSphere(rand.nextInt(12222), + (room.getWidthX() / 2.0f) - 1.5f, + (float) depth, + (room.getWidthZ() / 2.0f) - 1.5f, + core, + true, + Material.AIR + ); + + // Try to replace bottom with water + + // Find lowest ground block in the area + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + int ground = GenUtils.getHighestGround(data, x, z); + if (ground < lowest) { + lowest = ground; + } + if (ground > highest) { + highest = ground; + } + } + } + + + ArrayList lakeWaterBlocks = getLakeWaterBlocks(core, lowerCorner, upperCorner, lowest); + + if (lakeWaterBlocks.isEmpty()) { + return; // Don't bother if the pond is too small; + } + + int pondSurface = -1; // this variable will now be used to store the water level of the pond. + for (SimpleBlock s : lakeWaterBlocks) { + s.setType(Material.WATER); + if (s.getY() > pondSurface) { + pondSurface = s.getY(); + } + } + + boolean placedJobBlock = false; + // Place side decorations + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + SimpleBlock target = new SimpleBlock(core.getPopData(), x, 0, z).getGround(); + + // Decorate side of the pond + if (target.getUp().getType() == Material.AIR) { + + // Make sure it's the side of the pond + boolean valid = false; + for (BlockFace face : BlockUtils.directBlockFaces) { + if (target.getRelative(face).getType() == Material.WATER) { + valid = true; + } + } + if (!valid) { + continue; + } + + target = target.getUp(); + if (GenUtils.chance(1, 4)) { // Sugar Canes PlantBuilder.SUGAR_CANE.build(target, rand, 2, 5); - }else if(GenUtils.chance(1, 4)) { // Leaves + } + else if (GenUtils.chance(1, 4)) { // Leaves PlantBuilder.OAK_LEAVES.build(target); - }else if(GenUtils.chance(1, 4)) { // Double Plants - PlantBuilder.build(core.getPopData(), target.getX(), target.getY(), target.getZ(), PlantBuilder.LARGE_FERN, PlantBuilder.TALL_GRASS); - }else if(!placedJobBlock && TConfigOption.areDecorationsEnabled() && GenUtils.chance(2, 5)) { - target.setType(Material.BARREL); - placedJobBlock = true; - } - } - else if(target.getUp().getType() == Material.WATER) // Decorate pond surface and pond floor - { - target = target.getUp(); - if(GenUtils.chance(1,5)) // Lily pads + } + else if (GenUtils.chance(1, 4)) { // Double Plants + PlantBuilder.build( + core.getPopData(), + target.getX(), + target.getY(), + target.getZ(), + PlantBuilder.LARGE_FERN, + PlantBuilder.TALL_GRASS + ); + } + else if (!placedJobBlock && TConfigOption.areDecorationsEnabled() && GenUtils.chance(2, 5)) { + target.setType(Material.BARREL); + placedJobBlock = true; + } + } + else if (target.getUp().getType() == Material.WATER) // Decorate pond surface and pond floor + { + target = target.getUp(); + if (GenUtils.chance(1, 5)) // Lily pads + { PlantBuilder.LILY_PAD.build(target.getAtY(pondSurface).getUp()); - else if(GenUtils.chance(1, 5)) // Kelp growth - CoralGenerator.generateKelpGrowth(data, x, target.getY(), z); - else if(GenUtils.chance(1, 7)) // sea pickle growth - CoralGenerator.generateSeaPickles(data, x, target.getY(), z); - - if(TConfigOption.areAnimalsEnabled() && GenUtils.chance(1,20)) { // spawn fish - core.getPopData().addEntity(target.getX(), target.getY(), target.getZ(), EntityType.TROPICAL_FISH); - } - } - } - - - + } + else if (GenUtils.chance(1, 5)) // Kelp growth + { + CoralGenerator.generateKelpGrowth(data, x, target.getY(), z); + } + else if (GenUtils.chance(1, 7)) // sea pickle growth + { + CoralGenerator.generateSeaPickles(data, x, target.getY(), z); + } + + if (TConfigOption.areAnimalsEnabled() && GenUtils.chance(1, 20)) { // spawn fish + core.getPopData() + .addEntity(target.getX(), target.getY(), target.getZ(), EntityType.TROPICAL_FISH); + } + } + } + } + + } - - private @NotNull ArrayList getLakeWaterBlocks(@NotNull SimpleBlock core, int @NotNull [] lowerCorner, int @NotNull [] upperCorner, int lowestPoint){ - int layer = 0; - ArrayList lakeBlocks = new ArrayList<>(); - while(true) { - boolean layerValid = true; - // Check if the corners are solid. If they aren't this layer isn't valid. - - for(int x:new int[] {lowerCorner[0],upperCorner[0]}) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - if(!core.getPopData().getType(x, lowestPoint+layer, z).isSolid()) { - layerValid = false; - break; - } - if(!layerValid) break; - } - - if(layerValid) - for(int z:new int[] {lowerCorner[1],upperCorner[1]}) - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) { - if(!core.getPopData().getType(x, lowestPoint+layer, z).isSolid()) { - layerValid = false; - break; - } - if(!layerValid) break; - } - - if(!layerValid) - break; - - // Add all airspace simpleblocks to the lake blocks - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - if(!core.getPopData().getType(x, lowestPoint+layer, z).isSolid()) - lakeBlocks.add(new SimpleBlock(core.getPopData(),x,lowestPoint+layer,z)); - } - - layer++; - } - - return lakeBlocks; + + private @NotNull ArrayList getLakeWaterBlocks(@NotNull SimpleBlock core, + int @NotNull [] lowerCorner, + int @NotNull [] upperCorner, + int lowestPoint) + { + int layer = 0; + ArrayList lakeBlocks = new ArrayList<>(); + while (true) { + boolean layerValid = true; + // Check if the corners are solid. If they aren't this layer isn't valid. + + for (int x : new int[] {lowerCorner[0], upperCorner[0]}) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + if (!core.getPopData().getType(x, lowestPoint + layer, z).isSolid()) { + layerValid = false; + break; + } + if (!layerValid) { + break; + } + } + } + + if (layerValid) { + for (int z : new int[] {lowerCorner[1], upperCorner[1]}) { + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + if (!core.getPopData().getType(x, lowestPoint + layer, z).isSolid()) { + layerValid = false; + break; + } + if (!layerValid) { + break; + } + } + } + } + + if (!layerValid) { + break; + } + + // Add all airspace simpleblocks to the lake blocks + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + if (!core.getPopData().getType(x, lowestPoint + layer, z).isSolid()) { + lakeBlocks.add(new SimpleBlock(core.getPopData(), x, lowestPoint + layer, z)); + } + } + } + + layer++; + } + + return lakeBlocks; } @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getWidthX() <= 10 && - (room.getWidthZ() > 5 && room.getWidthX() > 5); + return room.getWidthX() <= 10 && (room.getWidthZ() > 5 && room.getWidthX() > 5); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePopulator.java index 8716f693..522ab70d 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePopulator.java @@ -13,14 +13,27 @@ import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.structure.village.VillagePopulator; import org.terraform.utils.BlockUtils; +import org.terraform.utils.GenUtils; import org.terraform.utils.WoodUtils; import org.terraform.utils.WoodUtils.WoodType; -import org.terraform.utils.GenUtils; import java.util.Locale; import java.util.Random; public class PlainsVillagePopulator extends VillagePopulator { + public @Nullable Material woodSlab = Material.OAK_SLAB; + public @Nullable Material woodPlank = Material.OAK_PLANKS; + public @Nullable Material woodLog = Material.OAK_LOG; + public @Nullable Material woodStrippedLog = Material.STRIPPED_OAK_LOG; + public @Nullable Material woodFence = Material.OAK_FENCE; + public @Nullable Material woodButton = Material.OAK_BUTTON; + public @Nullable Material woodTrapdoor = Material.OAK_TRAPDOOR; + public @Nullable Material woodDoor = Material.OAK_DOOR; + public @Nullable Material woodStairs = Material.OAK_STAIRS; + public @Nullable Material woodLeaves = Material.OAK_LEAVES; + public @Nullable Material woodPressurePlate = Material.OAK_PRESSURE_PLATE; + public @NotNull String wood = "oak_"; + @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); @@ -30,76 +43,75 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // Height set to 50 as plains village will settle its own height. spawnPlainsVillage(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, 50, z); } - + /** * */ - private void ensureFarmHouseEntrance(@NotNull Random rand, @NotNull DirectionalCubeRoom room, @NotNull PopulatorDataAbstract data) { - int frontSpaceGuarantee = 11; - Wall w = new Wall(new SimpleBlock(data,room.getX(),room.getY(),room.getZ()).getGround(), room.getDirection()) - .getUp(4); - - - int elevation = GenUtils.randInt(rand, 2,4); - int max = 30; - while(max > 0 && !isFrontSpaceClear(w,frontSpaceGuarantee)) { - switch(rand.nextInt(2+1)) { - case 0: // Move the house forward - w = w.getFront().getGround().getRelative(0,elevation,0); - break; - case 1: // Turn the house - w = new Wall(w.get(),BlockUtils.getTurnBlockFace(rand, w.getDirection())); - break; - case 2: - elevation+=2; // elevate more - break; - } - max--; - } - - // If the block above is wet, find another area. - Wall temp = w.getGround().getUp(elevation); - while(BlockUtils.isWet(temp) || BlockUtils.isWet(temp.getDown())) { - temp = temp.getUp(); - elevation++; - } - - if(max == 0) { // Maybe it's a mountain or stuck in the middle of eroded plains - TerraformGeneratorPlugin.logger.info("Village at " + w.get().toVector() + " may have a weird spawn."); - } - - room.setX(w.getX()); - room.setY(w.getY()); - room.setZ(w.getZ()); - room.setDirection(w.getDirection()); - ((PlainsVillageTownhallPopulator) room.getPop()).setElevation(elevation); + private void ensureFarmHouseEntrance(@NotNull Random rand, + @NotNull DirectionalCubeRoom room, + @NotNull PopulatorDataAbstract data) + { + int frontSpaceGuarantee = 11; + Wall w = new Wall( + new SimpleBlock(data, room.getX(), room.getY(), room.getZ()).getGround(), + room.getDirection() + ).getUp(4); + + + int elevation = GenUtils.randInt(rand, 2, 4); + int max = 30; + while (max > 0 && !isFrontSpaceClear(w, frontSpaceGuarantee)) { + switch (rand.nextInt(2 + 1)) { + case 0: // Move the house forward + w = w.getFront().getGround().getRelative(0, elevation, 0); + break; + case 1: // Turn the house + w = new Wall(w.get(), BlockUtils.getTurnBlockFace(rand, w.getDirection())); + break; + case 2: + elevation += 2; // elevate more + break; + } + max--; + } + + // If the block above is wet, find another area. + Wall temp = w.getGround().getUp(elevation); + while (BlockUtils.isWet(temp) || BlockUtils.isWet(temp.getDown())) { + temp = temp.getUp(); + elevation++; + } + + if (max == 0) { // Maybe it's a mountain or stuck in the middle of eroded plains + TerraformGeneratorPlugin.logger.info("Village at " + w.get().toVector() + " may have a weird spawn."); + } + + room.setX(w.getX()); + room.setY(w.getY()); + room.setZ(w.getZ()); + room.setDirection(w.getDirection()); + ((PlainsVillageTownhallPopulator) room.getPop()).setElevation(elevation); } - + private boolean isFrontSpaceClear(@NotNull Wall w, int space) { - for(int i = 0; i < space; i++) { - if(w.getFront(i).isSolid()) - return false; - } - return true; + for (int i = 0; i < space; i++) { + if (w.getFront(i).isSolid()) { + return false; + } + } + return true; } - - public @Nullable Material woodSlab = Material.OAK_SLAB; - public @Nullable Material woodPlank = Material.OAK_PLANKS; - public @Nullable Material woodLog = Material.OAK_LOG; - public @Nullable Material woodStrippedLog = Material.STRIPPED_OAK_LOG; - public @Nullable Material woodFence = Material.OAK_FENCE; - public @Nullable Material woodButton = Material.OAK_BUTTON; - public @Nullable Material woodTrapdoor = Material.OAK_TRAPDOOR; - public @Nullable Material woodDoor = Material.OAK_DOOR; - public @Nullable Material woodStairs = Material.OAK_STAIRS; - public @Nullable Material woodLeaves = Material.OAK_LEAVES; - public @Nullable Material woodPressurePlate = Material.OAK_PRESSURE_PLATE; - public @NotNull String wood = "oak_"; - public void spawnPlainsVillage(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - - - BlockFace pathStart = BlockUtils.getDirectBlockFace(random); + public void spawnPlainsVillage(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + + + BlockFace pathStart = BlockUtils.getDirectBlockFace(random); TerraformGeneratorPlugin.logger.info("Spawning plains village at " + x + "," + y + "," + z); DirectionalCubeRoom townHall = new DirectionalCubeRoom(pathStart, 24, 24, 24, x, y, z); PlainsVillageTownhallPopulator townHallPop = new PlainsVillageTownhallPopulator(tw, random, false, false); @@ -107,7 +119,7 @@ public void spawnPlainsVillage(@NotNull TerraformWorld tw, @NotNull Random rando ensureFarmHouseEntrance(random, townHall, data); pathStart = townHall.getDirection(); - + BiomeBank biome = tw.getBiomeBank(townHall.getX(), townHall.getZ()); woodSlab = WoodUtils.getWoodForBiome(biome, WoodType.SLAB); woodPlank = WoodUtils.getWoodForBiome(biome, WoodType.PLANKS); @@ -120,13 +132,16 @@ public void spawnPlainsVillage(@NotNull TerraformWorld tw, @NotNull Random rando woodPressurePlate = WoodUtils.getWoodForBiome(biome, WoodType.PRESSURE_PLATE); woodDoor = WoodUtils.getWoodForBiome(biome, WoodType.DOOR); woodLeaves = WoodUtils.getWoodForBiome(biome, WoodType.LEAVES); - wood = woodLeaves.toString().toLowerCase(Locale.ENGLISH).replace("leaves",""); - + wood = woodLeaves.toString().toLowerCase(Locale.ENGLISH).replace("leaves", ""); + // Re-get x and z because they change after ensureFarmHouseEntrance. // 13 because that's the width of the townhall. - PlainsPathRecursiveSpawner spawner = new PlainsPathRecursiveSpawner( - new SimpleBlock(data, townHall.getX() + pathStart.getModX() * 13, y, townHall.getZ() + pathStart.getModZ() * 13), - 100, BlockUtils.getAdjacentFaces(pathStart)); + PlainsPathRecursiveSpawner spawner = new PlainsPathRecursiveSpawner(new SimpleBlock( + data, + townHall.getX() + pathStart.getModX() * 13, + y, + townHall.getZ() + pathStart.getModZ() * 13 + ), 100, BlockUtils.getAdjacentFaces(pathStart)); spawner.forceRegisterRoom(townHall); spawner.setVillageDensity(0.7); spawner.setPathPop(new PlainsVillagePathPopulator(tw, spawner.getRooms().values(), random)); diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageStandardHousePopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageStandardHousePopulator.java index 74b3b1e3..0ed9ca3c 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageStandardHousePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageStandardHousePopulator.java @@ -13,27 +13,38 @@ import java.util.Random; public class PlainsVillageStandardHousePopulator extends PlainsVillageAbstractRoomPopulator { - - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageStandardHousePopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageStandardHousePopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); + super.populate(data, room); int height = super.calculateRoomY(data, room); // GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); - + // Debug squares PlainsVillageHouseJigsawBuilder builder = new PlainsVillageHouseJigsawBuilder( - plainsVillagePopulator, - room.getWidthX() - 3, room.getWidthZ() - 3, data, room.getX(), height, room.getZ() + plainsVillagePopulator, + room.getWidthX() - 3, + room.getWidthZ() - 3, + data, + room.getX(), + height, + room.getZ() ); - if (room instanceof DirectionalCubeRoom) + if (room instanceof DirectionalCubeRoom) { builder.forceEntranceDirection(((DirectionalCubeRoom) room).getDirection()); + } builder.generate(this.rand); builder.build(this.rand); @@ -44,15 +55,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room boolean placedLamp = false; // Connect front to the nearest path. while (entrance.getType() != Material.DIRT_PATH && maxDepth > 0) { - if (BlockUtils.isDirtLike(entrance.getType())) + if (BlockUtils.isDirtLike(entrance.getType())) { entrance.setType(Material.DIRT_PATH); + } if (!placedLamp && GenUtils.chance(this.rand, 3, 5)) { SimpleBlock target; - if (this.rand.nextBoolean()) + if (this.rand.nextBoolean()) { target = entrance.getLeft(2).getGround().getUp().get(); - else + } + else { target = entrance.getRight(2).getGround().getUp().get(); + } if (PlainsVillagePathPopulator.canPlaceLamp(target)) { placedLamp = true; PlainsVillagePathPopulator.placeLamp(rand, target); diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTemplePopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTemplePopulator.java index 8307b2eb..190088b7 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTemplePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTemplePopulator.java @@ -14,8 +14,13 @@ public class PlainsVillageTemplePopulator extends PlainsVillageAbstractRoomPopulator { - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageTemplePopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageTemplePopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @@ -23,17 +28,23 @@ public PlainsVillageTemplePopulator(PlainsVillagePopulator plainsVillagePopulato @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data, room); + super.populate(data, room); int height = super.calculateRoomY(data, room); // GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); - + // 1 is added to height because temples need a small bit of elevation to look better PlainsVillageTempleJigsawBuilder builder = new PlainsVillageTempleJigsawBuilder( - plainsVillagePopulator, - room.getWidthX() - 3, room.getWidthZ() - 3, data, room.getX(), height+1, room.getZ() + plainsVillagePopulator, + room.getWidthX() - 3, + room.getWidthZ() - 3, + data, + room.getX(), + height + 1, + room.getZ() ); - if (room instanceof DirectionalCubeRoom) + if (room instanceof DirectionalCubeRoom) { builder.forceEntranceDirection(((DirectionalCubeRoom) room).getDirection()); + } builder.generate(this.rand); builder.build(this.rand); @@ -44,15 +55,18 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room boolean placedLamp = false; // Connect front to the nearest path. while (entrance.getType() != Material.DIRT_PATH && maxDepth > 0) { - if (BlockUtils.isDirtLike(entrance.getType())) + if (BlockUtils.isDirtLike(entrance.getType())) { entrance.setType(Material.DIRT_PATH); + } if (!placedLamp && GenUtils.chance(this.rand, 3, 5)) { SimpleBlock target; - if (this.rand.nextBoolean()) + if (this.rand.nextBoolean()) { target = entrance.getLeft(2).getGround().getUp().get(); - else + } + else { target = entrance.getRight(2).getGround().getUp().get(); + } if (PlainsVillagePathPopulator.canPlaceLamp(target)) { placedLamp = true; PlainsVillagePathPopulator.placeLamp(rand, target); diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTownhallPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTownhallPopulator.java index 542e7608..cb1dfd0a 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTownhallPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageTownhallPopulator.java @@ -35,9 +35,9 @@ public PlainsVillageTownhallPopulator(TerraformWorld tw, Random rand, boolean fo this.tw = tw; this.elevation = GenUtils.randInt(this.rand, 2, 4); } - + public void setElevation(int elevation) { - this.elevation = elevation; + this.elevation = elevation; } @Override @@ -48,7 +48,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room try { BiomeBank biome = tw.getBiomeBank(x, z); y += elevation; - TerraSchematic farmHouse = TerraSchematic.load("farmhouse", new SimpleBlock(data,x,y,z)); + TerraSchematic farmHouse = TerraSchematic.load("farmhouse", new SimpleBlock(data, x, y, z)); farmHouse.parser = new FarmhouseSchematicParser(biome, this.rand, data); BlockFace face = BlockUtils.getDirectBlockFace(this.rand); if (room instanceof DirectionalCubeRoom) { @@ -58,7 +58,14 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room farmHouse.setFace(face); farmHouse.apply(); - TerraformGeneratorPlugin.logger.info("Spawning farmhouse at " + x + "," + y + "," + z + " with rotation of " + farmHouse.getFace()); + TerraformGeneratorPlugin.logger.info("Spawning farmhouse at " + + x + + "," + + y + + "," + + z + + " with rotation of " + + farmHouse.getFace()); data.addEntity(x, y + 1, z, EntityType.VILLAGER); // Two villagers data.addEntity(x, y + 1, z, EntityType.VILLAGER); @@ -67,35 +74,61 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Spawn a base on the house to sit on for (int nx = -17 / 2 - 1; nx <= 17 / 2 + 1; nx++) { for (int nz = -17 / 2 - 1; nz <= 17 / 2 + 1; nz++) { - if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") || - data.getType(x + nx, y - 1, z + nz).toString().contains("STONE_BRICKS")) - BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) + if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") || data.getType(x + nx, + y - 1, + z + nz + ).toString().contains("STONE_BRICKS")) + { + BlockUtils.setDownUntilSolid( + x + nx, + y - 2, + z + nz, + data, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ); + } + else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) { BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, data.getType(x + nx, y - 1, z + nz)); + } } } // Spawn a stairway from the house. Wall w = new Wall(new SimpleBlock(data, x, y - 1, z), farmHouse.getFace()).getRight(); - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { w = w.getFront(); + } // while(w.getType() != Material.DIRT){ - while (!w.isSolid() || - w.getType().toString().contains("PLANKS")) { - Stairs stairs = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(this.rand, Material.COBBLESTONE_STAIRS, Material.COBBLESTONE_STAIRS, - Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS)); + while (!w.isSolid() || w.getType().toString().contains("PLANKS")) { + Stairs stairs = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(this.rand, + Material.COBBLESTONE_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_COBBLESTONE_STAIRS + )); stairs.setFacing(w.getDirection().getOppositeFace()); w.getRight().setBlockData(stairs); w.setBlockData(stairs); w.getLeft().setBlockData(stairs); w.getLeft(2).getUp().downUntilSolid(this.rand, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); - w.getLeft(2).getUp(2).setType(GenUtils.randChoice(this.rand, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, - Material.MOSSY_COBBLESTONE_WALL)); + w.getLeft(2).getUp(2).setType(GenUtils.randChoice(this.rand, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + )); w.getRight(2).getUp().downUntilSolid(this.rand, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); - w.getRight(2).getUp(2).setType(GenUtils.randChoice(this.rand, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, - Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); + w.getRight(2).getUp(2).setType(GenUtils.randChoice(this.rand, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + )); w = w.getFront().getDown(); } @@ -111,23 +144,33 @@ else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) // Connect front to the nearest path. while (entrance.getType() != Material.DIRT_PATH && maxDepth > 0) { - if (BlockUtils.isDirtLike(entrance.getType())) + if (BlockUtils.isDirtLike(entrance.getType())) { entrance.setType(Material.DIRT_PATH); + } Wall leftPath = entrance.getLeft().getGround(); Wall rightPath = entrance.getRight().getGround(); - if (BlockUtils.isDirtLike(leftPath.getType())) + if (BlockUtils.isDirtLike(leftPath.getType())) { leftPath.setType(Material.DIRT_PATH); - if (BlockUtils.isDirtLike(rightPath.getType())) + } + if (BlockUtils.isDirtLike(rightPath.getType())) { rightPath.setType(Material.DIRT_PATH); + } entrance = entrance.getFront().getGround(); maxDepth--; } - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + x + "," + y + "," + z + "!"); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + + x + + "," + + y + + "," + + z + + "!"); TerraformGeneratorPlugin.logger.stackTrace(e); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java index e6d0fe84..915ee8e6 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java @@ -24,13 +24,17 @@ public class PlainsVillageWellPopulator extends PlainsVillageAbstractRoomPopulator { - private static final String[] villageWellSchems = new String[] { - "plainsvillage-well1", - "plainsvillage-well2" - }; - - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageWellPopulator(PlainsVillagePopulator plainsVillagePopulator, Random rand, boolean forceSpawn, boolean unique) { + private static final String[] villageWellSchems = new String[] { + "plainsvillage-well1", "plainsvillage-well2" + }; + + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageWellPopulator(PlainsVillagePopulator plainsVillagePopulator, + Random rand, + boolean forceSpawn, + boolean unique) + { super(rand, forceSpawn, unique); this.plainsVillagePopulator = plainsVillagePopulator; } @@ -38,98 +42,110 @@ public PlainsVillageWellPopulator(PlainsVillagePopulator plainsVillagePopulator, @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - // This code is repeated from super, as it must be changed a little + // This code is repeated from super, as it must be changed a little int y = super.calculateRoomY(data, room); - - int worldHeight = TerraformGeneratorPlugin.injector.getMaxY()-TerraformGeneratorPlugin.injector.getMinY() + 1; - - for(int[] corner:room.getAllCorners()) { - SimpleBlock sb = new SimpleBlock(data,corner[0],y,corner[1]); - int lowSb = sb.findFloor(worldHeight).getY(); - if(Math.abs(lowSb - y) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) - { - // place platform as uneven ground was detected. - this.placeFixerPlatform(y, data, room); - break; - } - } - - int x = room.getX(); + + int worldHeight = TerraformGeneratorPlugin.injector.getMaxY() - TerraformGeneratorPlugin.injector.getMinY() + 1; + + for (int[] corner : room.getAllCorners()) { + SimpleBlock sb = new SimpleBlock(data, corner[0], y, corner[1]); + int lowSb = sb.findFloor(worldHeight).getY(); + if (Math.abs(lowSb - y) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + // place platform as uneven ground was detected. + this.placeFixerPlatform(y, data, room); + break; + } + } + + int x = room.getX(); int z = room.getZ(); - SimpleBlock tester = new SimpleBlock(data,x,y+1,z); - if(BlockUtils.isWet(tester)) - y = tester.getGroundOrDry().getY(); // Force wells to not be submerged. - + SimpleBlock tester = new SimpleBlock(data, x, y + 1, z); + if (BlockUtils.isWet(tester)) { + y = tester.getGroundOrDry().getY(); // Force wells to not be submerged. + } + BlockFace roomDir = ((DirectionalCubeRoom) room).getDirection(); - + try { - SimpleBlock core = new SimpleBlock(data, x,y+1,z); - TerraSchematic schem = TerraSchematic.load(villageWellSchems[rand.nextInt(villageWellSchems.length)], core.getDown()); - schem.parser = new PlainsVillageWellSchematicParser(); - schem.apply(); - - int depth = GenUtils.randInt(rand, 5, 20); - - for(int i = 0; i < depth; i++) { - boolean breakOut = false; - if(i > 0) - for(BlockFace face:BlockUtils.flatBlockFaces3x3) { - // no solid ground beneath. Do not place water. - if(!core.getRelative(face).getDown(depth+1).isSolid()) { - breakOut = true; - break; - } - } - if(breakOut) break; - if(i == 0) - core.setType(Material.AIR); - else - core.getRelative(0,-i,0).setType(Material.WATER); - - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - if(i == 0) - core.getRelative(face).setType(Material.AIR); - else - core.getRelative(0,-i,0).getRelative(face).setType(Material.WATER); - } - } - - for(int nx = -3; nx <= 3; nx++) { - for(int nz = -3; nz <= 3; nz++) { - Wall target = new Wall(core.getRelative(nx,-1,nz)); - if(target.getType() == Material.COBBLESTONE - ||target.getType() == Material.MOSSY_COBBLESTONE) { - target.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - } - } - } - - Wall w = new Wall(core.getRelative(roomDir,3), roomDir); - - int pathLength = room.getWidthX()/2; - if(BlockUtils.getAxisFromBlockFace(roomDir) == Axis.Z) - pathLength = room.getWidthZ()/2; - - for(int i = 0; i < pathLength-1; i++) { - w.getGround().setType(Material.DIRT_PATH); - w.getLeft().getGround().setType(Material.DIRT_PATH); - w.getRight().getGround().setType(Material.DIRT_PATH); - - if(GenUtils.chance(rand, 1, 10)) { - BlockFace lampFace = BlockUtils.getTurnBlockFace(rand, roomDir); - SimpleBlock target = w.getRelative(lampFace,2).getGround().getUp().get(); - if(target.getDown().getType() != Material.DIRT_PATH - && PlainsVillagePathPopulator.canPlaceLamp(target)) { - PlainsVillagePathPopulator.placeLamp(rand, target); - } - } - - w = w.getRelative(roomDir); - } - - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } + SimpleBlock core = new SimpleBlock(data, x, y + 1, z); + TerraSchematic schem = TerraSchematic.load( + villageWellSchems[rand.nextInt(villageWellSchems.length)], + core.getDown() + ); + schem.parser = new PlainsVillageWellSchematicParser(); + schem.apply(); + + int depth = GenUtils.randInt(rand, 5, 20); + + for (int i = 0; i < depth; i++) { + boolean breakOut = false; + if (i > 0) { + for (BlockFace face : BlockUtils.flatBlockFaces3x3) { + // no solid ground beneath. Do not place water. + if (!core.getRelative(face).getDown(depth + 1).isSolid()) { + breakOut = true; + break; + } + } + } + if (breakOut) { + break; + } + if (i == 0) { + core.setType(Material.AIR); + } + else { + core.getRelative(0, -i, 0).setType(Material.WATER); + } + + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + if (i == 0) { + core.getRelative(face).setType(Material.AIR); + } + else { + core.getRelative(0, -i, 0).getRelative(face).setType(Material.WATER); + } + } + } + + for (int nx = -3; nx <= 3; nx++) { + for (int nz = -3; nz <= 3; nz++) { + Wall target = new Wall(core.getRelative(nx, -1, nz)); + if (target.getType() == Material.COBBLESTONE || target.getType() == Material.MOSSY_COBBLESTONE) { + target.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + } + } + + Wall w = new Wall(core.getRelative(roomDir, 3), roomDir); + + int pathLength = room.getWidthX() / 2; + if (BlockUtils.getAxisFromBlockFace(roomDir) == Axis.Z) { + pathLength = room.getWidthZ() / 2; + } + + for (int i = 0; i < pathLength - 1; i++) { + w.getGround().setType(Material.DIRT_PATH); + w.getLeft().getGround().setType(Material.DIRT_PATH); + w.getRight().getGround().setType(Material.DIRT_PATH); + + if (GenUtils.chance(rand, 1, 10)) { + BlockFace lampFace = BlockUtils.getTurnBlockFace(rand, roomDir); + SimpleBlock target = w.getRelative(lampFace, 2).getGround().getUp().get(); + if (target.getDown().getType() != Material.DIRT_PATH && PlainsVillagePathPopulator.canPlaceLamp( + target)) + { + PlainsVillagePathPopulator.placeLamp(rand, target); + } + } + + w = w.getRelative(roomDir); + } + + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } } @@ -137,33 +153,32 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room public boolean canPopulate(@NotNull CubeRoom room) { return room.getWidthX() <= 10; } - - private class PlainsVillageWellSchematicParser extends SchematicParser{ + + private class PlainsVillageWellSchematicParser extends SchematicParser { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } else if(data.getMaterial() == Material.IRON_BARS){ - if(Version.isAtLeast(16)) { - data = Bukkit.createBlockData(Material.CHAIN); - } + } + else if (data.getMaterial() == Material.IRON_BARS) { + if (Version.isAtLeast(16)) { + data = Bukkit.createBlockData(Material.CHAIN); + } super.applyData(block, data); - } else if(data.getMaterial().toString().startsWith("OAK_")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "oak_", - plainsVillagePopulator.wood - ) - ); + } + else if (data.getMaterial().toString().startsWith("OAK_")) { + data = Bukkit.createBlockData(data.getAsString().replaceAll("oak_", plainsVillagePopulator.wood)); super.applyData(block, data); - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeChimneyPiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeChimneyPiece.java index 75dd9c4b..fc12e5fb 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeChimneyPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeChimneyPiece.java @@ -19,173 +19,199 @@ public class PlainsVillageForgeChimneyPiece extends PlainsVillageForgeStandardPiece { - public PlainsVillageForgeChimneyPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); - } - - // Use postBuildDecoration, as the walls are built after build() + public PlainsVillageForgeChimneyPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); + } + + // Use postBuildDecoration, as the walls are built after build() @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); - if(this.getWalledFaces().isEmpty()) { - spawnStraightChimney(random, new Wall(core)); - } - - if(this.getWalledFaces().size() == 1){ - if(core.getRelative(this.getWalledFaces().get(0),3).getType() == Material.CHISELED_STONE_BRICKS) { - spawnStraightChimney(random, new Wall(core)); - return; - } - } - ArrayList walledFaces = this.getWalledFaces(); - Collections.shuffle(walledFaces); - for(BlockFace face:walledFaces) { - - // Don't spawn walled chimney against entrance - if(core.getRelative(face,3).getType() == Material.CHISELED_STONE_BRICKS) - continue; - - Wall target = new Wall(core,face.getOppositeFace()); - spawnWallChimney(random, target.getRear(2)); - return; - } + SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); + if (this.getWalledFaces().isEmpty()) { + spawnStraightChimney(random, new Wall(core)); + } + + if (this.getWalledFaces().size() == 1) { + if (core.getRelative(this.getWalledFaces().get(0), 3).getType() == Material.CHISELED_STONE_BRICKS) { + spawnStraightChimney(random, new Wall(core)); + return; + } + } + ArrayList walledFaces = this.getWalledFaces(); + Collections.shuffle(walledFaces); + for (BlockFace face : walledFaces) { + + // Don't spawn walled chimney against entrance + if (core.getRelative(face, 3).getType() == Material.CHISELED_STONE_BRICKS) { + continue; + } + + Wall target = new Wall(core, face.getOppositeFace()); + spawnWallChimney(random, target.getRear(2)); + return; + } } - + /** * 3x3 chimney spawned right in the middle of the room. + * * @param core must contain the direction the chimney is to face. */ private void spawnWallChimney(@NotNull Random random, Wall core) { - core = core.getUp(); - - // Refers to the height of the segment of the - // chimney where there's a repeating pattern - int chimneyCoreHeight = random.nextInt(3)+5; - - for(BlockFace face:BlockUtils.xzDiagonalPlaneBlockFaces) { - Wall target = core.getRelative(face); - target.Pillar(chimneyCoreHeight+1, true, random, Material.COBBLESTONE_WALL, Material.COBBLESTONE); - target.CorrectMultipleFacing(chimneyCoreHeight+1); - } - - for(BlockFace face:BlockUtils.directBlockFaces) { - - - core.getRelative(face).setType(Material.COBBLESTONE); - - for(int i = 0; i < chimneyCoreHeight; i++) { - if(i % 2 == 0) - new StairBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(core.getRelative(0,2+i,0).getRelative(face)); - else - core.getRelative(0,2+i,0).getRelative(face).setType(Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - } - - if(face == core.getDirection()) { // Front - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(core.getFront(2).getLeft()) - .apply(core.getFront(2).getRight()); - core.getFront().getLeft().setType(Material.COBBLESTONE); - core.getFront().getRight().setType(Material.COBBLESTONE); - - }else if(face != core.getDirection().getOppositeFace()) // Sides - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(core.getRelative(face,2)); - - else { // Walled face - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(core.getRelative(face,2)) - .setHalf(Half.TOP) - .apply(core.getUp(2).getRelative(face,2)); - - - // Modify the exterior. - core.getRelative(face,2).getUp(3).Pillar(2, random, Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - - core.getRelative(face,2).getLeft().getDown() - .Pillar(6, random, Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - - core.getRelative(face,2).getRight().getDown() - .Pillar(6, random, Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(BlockUtils.getLeft(face)) - .apply(core.getRelative(face, 2).getUp(4).getLeft()) - .setFacing(BlockUtils.getRight(face)) - .apply(core.getRelative(face, 2).getUp(4).getRight()); - - core.getRelative(face, 2).getUp(5).setType(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB); - - // This will be the base - core.getRelative(face,2).getDown(2).getLeft().downUntilSolid(random,Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - core.getRelative(face,2).getDown().downUntilSolid(random, Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - core.getRelative(face,2).getDown(2).getRight().downUntilSolid(random,Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - - // Solidify the wall behind - core.getRelative(face).Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - core.getRelative(face).getLeft().Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - core.getRelative(face).getRight().Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - } - - // Iron bars placed last. - core.getUp().getRelative(face).setType(Material.IRON_BARS); - core.getUp().getRelative(face).CorrectMultipleFacing(1); - } - - new DirectionalBuilder(Material.BLAST_FURNACE) - .setFacing(core.getDirection()) - .apply(core.getFront()); - - core.Pillar(chimneyCoreHeight+2, random, Material.AIR); - core.getDown().setType(Material.CAMPFIRE); - core.getDown(2).setType(Material.HAY_BLOCK); - core.setType(Material.LAVA); + core = core.getUp(); + + // Refers to the height of the segment of the + // chimney where there's a repeating pattern + int chimneyCoreHeight = random.nextInt(3) + 5; + + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + Wall target = core.getRelative(face); + target.Pillar(chimneyCoreHeight + 1, true, random, Material.COBBLESTONE_WALL, Material.COBBLESTONE); + target.CorrectMultipleFacing(chimneyCoreHeight + 1); + } + + for (BlockFace face : BlockUtils.directBlockFaces) { + + + core.getRelative(face).setType(Material.COBBLESTONE); + + for (int i = 0; i < chimneyCoreHeight; i++) { + if (i % 2 == 0) { + new StairBuilder( + Material.COBBLESTONE_STAIRS, + Material.MOSSY_COBBLESTONE_STAIRS + ).setFacing(face.getOppositeFace()).apply(core.getRelative(0, 2 + i, 0).getRelative(face)); + } + else { + core.getRelative(0, 2 + i, 0) + .getRelative(face) + .setType(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + } + + if (face == core.getDirection()) { // Front + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(face.getOppositeFace()) + .apply(core.getFront(2).getLeft()) + .apply(core.getFront(2).getRight()); + core.getFront().getLeft().setType(Material.COBBLESTONE); + core.getFront().getRight().setType(Material.COBBLESTONE); + + } + else if (face != core.getDirection().getOppositeFace()) // Sides + { + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(face.getOppositeFace()) + .apply(core.getRelative(face, 2)); + } + + else { // Walled face + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(face.getOppositeFace()) + .apply(core.getRelative(face, 2)) + .setHalf(Half.TOP) + .apply(core.getUp(2).getRelative(face, 2)); + + + // Modify the exterior. + core.getRelative(face, 2).getUp(3).Pillar(2, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + core.getRelative(face, 2) + .getLeft() + .getDown() + .Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + core.getRelative(face, 2) + .getRight() + .getDown() + .Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(BlockUtils.getLeft(face)) + .apply(core.getRelative(face, 2).getUp(4).getLeft()) + .setFacing(BlockUtils.getRight(face)) + .apply(core.getRelative(face, 2).getUp(4).getRight()); + + core.getRelative(face, 2).getUp(5).setType(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB); + + // This will be the base + core.getRelative(face, 2) + .getDown(2) + .getLeft() + .downUntilSolid(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + core.getRelative(face, 2) + .getDown() + .downUntilSolid(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + core.getRelative(face, 2) + .getDown(2) + .getRight() + .downUntilSolid(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + // Solidify the wall behind + core.getRelative(face).Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + core.getRelative(face).getLeft().Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + core.getRelative(face).getRight().Pillar(6, random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + + // Iron bars placed last. + core.getUp().getRelative(face).setType(Material.IRON_BARS); + core.getUp().getRelative(face).CorrectMultipleFacing(1); + } + + new DirectionalBuilder(Material.BLAST_FURNACE).setFacing(core.getDirection()).apply(core.getFront()); + + core.Pillar(chimneyCoreHeight + 2, random, Material.AIR); + core.getDown().setType(Material.CAMPFIRE); + core.getDown(2).setType(Material.HAY_BLOCK); + core.setType(Material.LAVA); } - + /** * 3x3 chimney spawned right in the middle of the room. */ private void spawnStraightChimney(@NotNull Random random, Wall core) { - core = core.getUp(); - - // Refers to the height of the segment of the - // chimney where there's a repeating pattern - int chimneyCoreHeight = random.nextInt(3)+6; - for(BlockFace face:BlockUtils.directBlockFaces) { - - core.getRelative(face).setType(Material.COBBLESTONE); - core.getUp().getRelative(face).setType(Material.IRON_BARS); - - for(int i = 0; i < chimneyCoreHeight; i++) { - if(i % 2 == 0) - new StairBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .apply(core.getRelative(0,2+i,0).getRelative(face)); - else - core.getRelative(0,2+i,0).getRelative(face).setType(Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - } - } - - for(BlockFace face:BlockUtils.xzDiagonalPlaneBlockFaces) { - Wall target = core.getRelative(face); - target.Pillar(chimneyCoreHeight+1, true, random, Material.COBBLESTONE_WALL, Material.COBBLESTONE); - target.CorrectMultipleFacing(chimneyCoreHeight+1); - } - - BlockFace blastFurnaceDir = BlockUtils.getDirectBlockFace(random); - new DirectionalBuilder(Material.BLAST_FURNACE) - .setFacing(blastFurnaceDir) - .apply(core.getRelative(blastFurnaceDir)); - - // Empty out space in the chimney - core.Pillar(chimneyCoreHeight+2, random, Material.AIR); - core.getDown().setType(Material.CAMPFIRE); - core.getDown(2).setType(Material.HAY_BLOCK); - core.setType(Material.LAVA); + core = core.getUp(); + + // Refers to the height of the segment of the + // chimney where there's a repeating pattern + int chimneyCoreHeight = random.nextInt(3) + 6; + for (BlockFace face : BlockUtils.directBlockFaces) { + + core.getRelative(face).setType(Material.COBBLESTONE); + core.getUp().getRelative(face).setType(Material.IRON_BARS); + + for (int i = 0; i < chimneyCoreHeight; i++) { + if (i % 2 == 0) { + new StairBuilder( + Material.COBBLESTONE_STAIRS, + Material.MOSSY_COBBLESTONE_STAIRS + ).setFacing(face.getOppositeFace()).apply(core.getRelative(0, 2 + i, 0).getRelative(face)); + } + else { + core.getRelative(0, 2 + i, 0) + .getRelative(face) + .setType(Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + } + } + + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + Wall target = core.getRelative(face); + target.Pillar(chimneyCoreHeight + 1, true, random, Material.COBBLESTONE_WALL, Material.COBBLESTONE); + target.CorrectMultipleFacing(chimneyCoreHeight + 1); + } + + BlockFace blastFurnaceDir = BlockUtils.getDirectBlockFace(random); + new DirectionalBuilder(Material.BLAST_FURNACE).setFacing(blastFurnaceDir) + .apply(core.getRelative(blastFurnaceDir)); + + // Empty out space in the chimney + core.Pillar(chimneyCoreHeight + 2, random, Material.AIR); + core.getDown().setType(Material.CAMPFIRE); + core.getDown(2).setType(Material.HAY_BLOCK); + core.setType(Material.LAVA); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeEntrancePiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeEntrancePiece.java index 34c2695b..5a8fc948 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeEntrancePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeEntrancePiece.java @@ -20,7 +20,13 @@ public class PlainsVillageForgeEntrancePiece extends PlainsVillageForgePiece { - public PlainsVillageForgeEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public PlainsVillageForgeEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); } @@ -36,94 +42,109 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w = w.getLeft(); } - Wall core = new Wall(new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()), this.getRotation()); + Wall core = new Wall(new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ), this.getRotation()); core = core.getRear(2); - + // Stairway down - if(core.getFront().isSolid()) { - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .setStairwayDirection(BlockFace.UP) - .build(core.getFront(3)); - core.getFront().Pillar(2, rand, Material.AIR); - core.getFront(2).Pillar(3, rand, Material.AIR); - }else - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .build(core.getFront().getDown()); - + if (core.getFront().isSolid()) { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .setStairwayDirection( + BlockFace.UP) + .build(core.getFront(3)); + core.getFront().Pillar(2, rand, Material.AIR); + core.getFront(2).Pillar(3, rand, Material.AIR); + } + else { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .build(core.getFront() + .getDown()); + } + } - + @Override public void postBuildDecoration(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { - if(getWallType() == PlainsVillageForgeWallType.SOLID) { // Door entrance - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey().getDown(); - for (int i = 0; i < entry.getValue(); i++) { - w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - w.RPillar(5, rand, Material.COBBLESTONE, Material.ANDESITE, Material.STONE); - w = w.getLeft(); - } - Wall core = new Wall(new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()), this.getRotation()); - core = core.getRear(2); - core.getDown().setType(Material.CHISELED_STONE_BRICKS); - BlockUtils.placeDoor(data, plainsVillagePopulator.woodDoor, core.getX(), core.getY(), core.getZ(), core.getDirection().getOppositeFace()); - - // Door decor - core.getUp(2).getFront().setType(Material.STONE_BRICK_SLAB); - - core.getUp(2).setType(Material.CHISELED_STONE_BRICKS); - core.getLeft().Pillar(2, rand, Material.CHISELED_STONE_BRICKS); - core.getRight().Pillar(2, rand, Material.CHISELED_STONE_BRICKS); - - core.getLeft().getFront().setType(Material.STONE_BRICK_WALL); - core.getRight().getFront().setType(Material.STONE_BRICK_WALL); - - core.getLeft().getFront().getDown().setType(Material.STONE_BRICKS); - core.getRight().getFront().getDown().setType(Material.STONE_BRICKS); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(core.getRight().getFront().getUp()) - .setFacing(BlockUtils.getRight(core.getDirection())) - .apply(core.getLeft().getFront().getUp()) - .setHalf(Half.TOP) - .apply(core.getRight().getUp(2)) - .setFacing(BlockUtils.getLeft(core.getDirection())) - .apply(core.getLeft().getUp(2)); - } - else // Just a hole in a fence - { - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey(); - for (int i = 0; i < entry.getValue(); i++) { - w.getDown(2).downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - - if(i == 2) { - // Opening - w.getDown().setType(Material.CHISELED_STONE_BRICKS); - } - else if(i == 1 || i == 3) - { - w.getDown().Pillar(2, rand, plainsVillagePopulator.woodLog); - w.getUp().setType(Material.STONE_SLAB,Material.COBBLESTONE_SLAB,Material.ANDESITE_SLAB); - } - else - { - w.get().lsetType(plainsVillagePopulator.woodFence); - w.CorrectMultipleFacing(1); - new OrientableBuilder(plainsVillagePopulator.woodLog) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) - .apply(w.getDown()); - } - - w = w.getLeft(); - } - } - + if (getWallType() == PlainsVillageForgeWallType.SOLID) { // Door entrance + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + Wall w = entry.getKey().getDown(); + for (int i = 0; i < entry.getValue(); i++) { + w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + w.RPillar(5, rand, Material.COBBLESTONE, Material.ANDESITE, Material.STONE); + w = w.getLeft(); + } + Wall core = new Wall(new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ), this.getRotation()); + core = core.getRear(2); + core.getDown().setType(Material.CHISELED_STONE_BRICKS); + BlockUtils.placeDoor( + data, + plainsVillagePopulator.woodDoor, + core.getX(), + core.getY(), + core.getZ(), + core.getDirection().getOppositeFace() + ); + + // Door decor + core.getUp(2).getFront().setType(Material.STONE_BRICK_SLAB); + + core.getUp(2).setType(Material.CHISELED_STONE_BRICKS); + core.getLeft().Pillar(2, rand, Material.CHISELED_STONE_BRICKS); + core.getRight().Pillar(2, rand, Material.CHISELED_STONE_BRICKS); + + core.getLeft().getFront().setType(Material.STONE_BRICK_WALL); + core.getRight().getFront().setType(Material.STONE_BRICK_WALL); + + core.getLeft().getFront().getDown().setType(Material.STONE_BRICKS); + core.getRight().getFront().getDown().setType(Material.STONE_BRICKS); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(core.getRight().getFront().getUp()) + .setFacing(BlockUtils.getRight(core.getDirection())) + .apply(core.getLeft().getFront().getUp()) + .setHalf(Half.TOP) + .apply(core.getRight().getUp(2)) + .setFacing(BlockUtils.getLeft(core.getDirection())) + .apply(core.getLeft().getUp(2)); + } + else // Just a hole in a fence + { + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + w.getDown(2).downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + if (i == 2) { + // Opening + w.getDown().setType(Material.CHISELED_STONE_BRICKS); + } + else if (i == 1 || i == 3) { + w.getDown().Pillar(2, rand, plainsVillagePopulator.woodLog); + w.getUp().setType(Material.STONE_SLAB, Material.COBBLESTONE_SLAB, Material.ANDESITE_SLAB); + } + else { + w.get().lsetType(plainsVillagePopulator.woodFence); + w.CorrectMultipleFacing(1); + new OrientableBuilder(plainsVillagePopulator.woodLog).setAxis(BlockUtils.getAxisFromBlockFace( + BlockUtils.getLeft(w.getDirection()))).apply(w.getDown()); + } + + w = w.getLeft(); + } + } + } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeJigsawBuilder.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeJigsawBuilder.java index 952ef178..9fd044ba 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeJigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeJigsawBuilder.java @@ -19,111 +19,160 @@ public class PlainsVillageForgeJigsawBuilder extends JigsawBuilder { - private final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageForgeJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, int widthX, int widthZ, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + private final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageForgeJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int widthZ, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { super(widthX, widthZ, data, x, y, z); this.plainsVillagePopulator = plainsVillagePopulator; - this.pieceRegistry = new JigsawStructurePiece[]{ - new PlainsVillageForgeWeaponSmithPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageForgeMasonPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageForgeWallPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.END, BlockUtils.directBlockFaces), - new PlainsVillageForgeEntrancePiece(plainsVillagePopulator, 5, 3, 5, JigsawType.ENTRANCE, BlockUtils.directBlockFaces) + this.pieceRegistry = new JigsawStructurePiece[] { + new PlainsVillageForgeWeaponSmithPiece( + plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageForgeMasonPiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageForgeWallPiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.END, + BlockUtils.directBlockFaces + ), + new PlainsVillageForgeEntrancePiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.ENTRANCE, + BlockUtils.directBlockFaces + ) }; this.chanceToAddNewPiece = 50; } - + @Override public @NotNull JigsawStructurePiece getFirstPiece(@NotNull Random random) { - return new PlainsVillageForgeChimneyPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces); - // return getPiece(pieceRegistry, JigsawType.STANDARD, random).getInstance(random, 0); + return new PlainsVillageForgeChimneyPiece( + plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ); + // return getPiece(pieceRegistry, JigsawType.STANDARD, random).getInstance(random, 0); } @Override public void build(@NotNull Random random) { super.build(random); ArrayList rectanglePieces = PlainsVillageForgeRoofHandler.identifyRectangle(pieces); - + ArrayList builtWalls = new ArrayList<>(); - + // Decorate walls and entrance based on the rectangle identified. - for(JigsawStructurePiece piece:pieces.values()) { - PlainsVillageForgeWallType wallType = PlainsVillageForgeWallType.FENCE; - if(rectanglePieces.contains(piece.getRoom().getSimpleLocation())) { - wallType = PlainsVillageForgeWallType.SOLID; - } - ((PlainsVillageForgePiece) piece).setWallType(wallType); - for(BlockFace face:BlockUtils.directBlockFaces) { - JigsawStructurePiece wall = getAdjacentWall(piece.getRoom().getSimpleLocation(), face); - if(wall != null && !builtWalls.contains(wall)) { - builtWalls.add(wall); - ((PlainsVillageForgePiece) wall).setWallType(wallType); - } - } + for (JigsawStructurePiece piece : pieces.values()) { + PlainsVillageForgeWallType wallType = PlainsVillageForgeWallType.FENCE; + if (rectanglePieces.contains(piece.getRoom().getSimpleLocation())) { + wallType = PlainsVillageForgeWallType.SOLID; + } + ((PlainsVillageForgePiece) piece).setWallType(wallType); + for (BlockFace face : BlockUtils.directBlockFaces) { + JigsawStructurePiece wall = getAdjacentWall(piece.getRoom().getSimpleLocation(), face); + if (wall != null && !builtWalls.contains(wall)) { + builtWalls.add(wall); + ((PlainsVillageForgePiece) wall).setWallType(wallType); + } + } } - + // Make sure awkward corners are fixed for (JigsawStructurePiece piece : this.pieces.values()) { - SimpleBlock core = new SimpleBlock( - this.core.getPopData(), + SimpleBlock core = new SimpleBlock(this.core.getPopData(), piece.getRoom().getX(), piece.getRoom().getY(), - piece.getRoom().getZ()); + piece.getRoom().getZ() + ); Wall target; PlainsVillageForgeWallType type = PlainsVillageForgeWallType.FENCE; - if(rectanglePieces.contains(piece.getRoom().getSimpleLocation())) - type = PlainsVillageForgeWallType.SOLID; - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // nw + if (rectanglePieces.contains(piece.getRoom().getSimpleLocation())) { + type = PlainsVillageForgeWallType.SOLID; + } + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // nw target = new Wall(core.getRelative(-3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST, type); } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // ne + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // ne target = new Wall(core.getRelative(3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST, type); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // sw + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // sw target = new Wall(core.getRelative(-3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST, type); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // se + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // se target = new Wall(core.getRelative(3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST, type); } } - + PlainsVillageForgeRoofHandler.placeRoof(this.plainsVillagePopulator, core, rectanglePieces); - + // Decorate rooms and walls for (JigsawStructurePiece piece : this.overlapperPieces) { piece.postBuildDecoration(random, this.core.getPopData()); } - + for (JigsawStructurePiece piece : this.pieces.values()) { piece.postBuildDecoration(random, this.core.getPopData()); } - + } - - public void decorateAwkwardCorner(@NotNull Wall target, @NotNull Random random, BlockFace one, BlockFace two, PlainsVillageForgeWallType wallType) { - if(wallType == PlainsVillageForgeWallType.SOLID) { - // Corner logs + + public void decorateAwkwardCorner(@NotNull Wall target, + @NotNull Random random, + BlockFace one, + BlockFace two, + PlainsVillageForgeWallType wallType) + { + if (wallType == PlainsVillageForgeWallType.SOLID) { + // Corner logs target.Pillar(4, random, plainsVillagePopulator.woodLog); - + target.getDown().downUntilSolid(random, plainsVillagePopulator.woodLog); target.getUp(); } - else - { - // Fence stubs + else { + // Fence stubs target.Pillar(2, random, plainsVillagePopulator.woodLog); - target.getUp(2).setType(Material.STONE_SLAB,Material.COBBLESTONE_SLAB,Material.ANDESITE_SLAB); - target.getDown().downUntilSolid(random,plainsVillagePopulator.woodLog); + target.getUp(2).setType(Material.STONE_SLAB, Material.COBBLESTONE_SLAB, Material.ANDESITE_SLAB); + target.getDown().downUntilSolid(random, plainsVillagePopulator.woodLog); } - + } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeMasonPiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeMasonPiece.java index 2920f5c4..f48436ae 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeMasonPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeMasonPiece.java @@ -17,140 +17,146 @@ public class PlainsVillageForgeMasonPiece extends PlainsVillageForgeStandardPiece { - public PlainsVillageForgeMasonPiece(PlainsVillagePopulator plainsVillagePopulator,int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(plainsVillagePopulator,widthX, height, widthZ, type, validDirs); - } - - // Use postBuildDecoration. + public PlainsVillageForgeMasonPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); + } + + // Use postBuildDecoration. @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); - if(this.getWalledFaces().isEmpty()) { - spawnCenteredPileOfRocks(random, new Wall(core)); - } - - if(this.getWalledFaces().size() == 1){ - if(core.getRelative(this.getWalledFaces().get(0),3).getType() == Material.CHISELED_STONE_BRICKS) { - spawnCenteredPileOfRocks(random, new Wall(core)); - return; - } - } - ArrayList walledFaces = this.getWalledFaces(); - Collections.shuffle(walledFaces); - for(BlockFace face:walledFaces) { - - // Don't spawn stone pile against entrance - if(core.getRelative(face,3).getType() == Material.CHISELED_STONE_BRICKS) - continue; - - Wall target = new Wall(core,face); - spawnedWalledPileOfRocks(random, target); - return; - } + SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); + if (this.getWalledFaces().isEmpty()) { + spawnCenteredPileOfRocks(random, new Wall(core)); + } + + if (this.getWalledFaces().size() == 1) { + if (core.getRelative(this.getWalledFaces().get(0), 3).getType() == Material.CHISELED_STONE_BRICKS) { + spawnCenteredPileOfRocks(random, new Wall(core)); + return; + } + } + ArrayList walledFaces = this.getWalledFaces(); + Collections.shuffle(walledFaces); + for (BlockFace face : walledFaces) { + + // Don't spawn stone pile against entrance + if (core.getRelative(face, 3).getType() == Material.CHISELED_STONE_BRICKS) { + continue; + } + + Wall target = new Wall(core, face); + spawnedWalledPileOfRocks(random, target); + return; + } } - + /** * Force 3x3 size */ private void spawnCenteredPileOfRocks(@NotNull Random random, Wall core) { - core = core.getUp(); - Material[] ores = new Material[] { - Material.IRON_ORE, - Material.COAL_ORE, - Material.GOLD_ORE, - Material.LAPIS_ORE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE - }; - core.Pillar(random.nextInt(3)+1, random, ores); - - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - core.getRelative(face).Pillar(random.nextInt(3), random, ores); - } - - // Place stone cutter - Wall target = core.getRelative(BlockUtils.getXZPlaneBlockFace(random)); - while(target.isSolid()) { - target = target.getUp(); - } - new DirectionalBuilder(Material.STONECUTTER) - .setFacing(BlockUtils.getDirectBlockFace(new Random())) - .apply(target); - - // Place one or two lamps next to the cutter - for(int i = 0; i < random.nextInt(2)+1; i++) { - target = target.getAtY(core.getY()+1).getRelative(BlockUtils.getDirectBlockFace(random)); - while(target.isSolid()) { - target = target.getUp(); - } - if(target.getDown().getType() != Material.LANTERN) - target.setType(Material.LANTERN); - } + core = core.getUp(); + Material[] ores = new Material[] { + Material.IRON_ORE, + Material.COAL_ORE, + Material.GOLD_ORE, + Material.LAPIS_ORE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE + }; + core.Pillar(random.nextInt(3) + 1, random, ores); + + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + core.getRelative(face).Pillar(random.nextInt(3), random, ores); + } + + // Place stone cutter + Wall target = core.getRelative(BlockUtils.getXZPlaneBlockFace(random)); + while (target.isSolid()) { + target = target.getUp(); + } + new DirectionalBuilder(Material.STONECUTTER).setFacing(BlockUtils.getDirectBlockFace(new Random())) + .apply(target); + + // Place one or two lamps next to the cutter + for (int i = 0; i < random.nextInt(2) + 1; i++) { + target = target.getAtY(core.getY() + 1).getRelative(BlockUtils.getDirectBlockFace(random)); + while (target.isSolid()) { + target = target.getUp(); + } + if (target.getDown().getType() != Material.LANTERN) { + target.setType(Material.LANTERN); + } + } } - + /** * No such limitation */ private void spawnedWalledPileOfRocks(@NotNull Random random, Wall core) { - core = core.getUp(); - Material[] ores = new Material[] { - Material.IRON_ORE, - Material.COAL_ORE, - Material.GOLD_ORE, - Material.LAPIS_ORE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE, - Material.ANDESITE, - Material.DIORITE, - Material.GRANITE, - Material.STONE - }; - - // Place stone cutter - new DirectionalBuilder(Material.STONECUTTER) - .setFacing(BlockUtils.getDirectBlockFace(new Random())) - .apply(core); - // core.setType(Material.STONECUTTER); - - // Move against the wall - core = core.getRelative(core.getDirection(),2); - - // Highest ores are against the wall - core.Pillar(random.nextInt(3)+1, random, ores); - core.getLeft().Pillar(random.nextInt(3)+1, random, ores); - core.getRight().Pillar(random.nextInt(3)+1, random, ores); - - core.getLeft(2).Pillar(random.nextInt(3), random, ores); - core.getRight(2).Pillar(random.nextInt(3), random, ores); - - core.getRear().Pillar(random.nextInt(3), random, ores); - core.getRear().getLeft().Pillar(random.nextInt(3), random, ores); - core.getRear().getRight().Pillar(random.nextInt(3), random, ores); - - - // Place one or two lamps next to the cutter - for(int i = 0; i < random.nextInt(2)+1; i++) { - Wall target = core.getRelative(core.getDirection().getOppositeFace(), 2).getRelative(BlockUtils.getDirectBlockFace(random)); - while(target.isSolid()) { - target = target.getUp(); - } - target.setType(Material.LANTERN); - } + core = core.getUp(); + Material[] ores = new Material[] { + Material.IRON_ORE, + Material.COAL_ORE, + Material.GOLD_ORE, + Material.LAPIS_ORE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE, + Material.ANDESITE, + Material.DIORITE, + Material.GRANITE, + Material.STONE + }; + + // Place stone cutter + new DirectionalBuilder(Material.STONECUTTER).setFacing(BlockUtils.getDirectBlockFace(new Random())).apply(core); + // core.setType(Material.STONECUTTER); + + // Move against the wall + core = core.getRelative(core.getDirection(), 2); + + // Highest ores are against the wall + core.Pillar(random.nextInt(3) + 1, random, ores); + core.getLeft().Pillar(random.nextInt(3) + 1, random, ores); + core.getRight().Pillar(random.nextInt(3) + 1, random, ores); + + core.getLeft(2).Pillar(random.nextInt(3), random, ores); + core.getRight(2).Pillar(random.nextInt(3), random, ores); + + core.getRear().Pillar(random.nextInt(3), random, ores); + core.getRear().getLeft().Pillar(random.nextInt(3), random, ores); + core.getRear().getRight().Pillar(random.nextInt(3), random, ores); + + + // Place one or two lamps next to the cutter + for (int i = 0; i < random.nextInt(2) + 1; i++) { + Wall target = core.getRelative(core.getDirection().getOppositeFace(), 2) + .getRelative(BlockUtils.getDirectBlockFace(random)); + while (target.isSolid()) { + target = target.getUp(); + } + target.setType(Material.LANTERN); + } } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgePiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgePiece.java index 07245c1d..9b5729b8 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgePiece.java @@ -9,26 +9,39 @@ public abstract class PlainsVillageForgePiece extends JigsawStructurePiece { - protected final PlainsVillagePopulator plainsVillagePopulator; - private @Nullable PlainsVillageForgeWallType wallType = null; - - public PlainsVillageForgePiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(widthX, height, widthZ, type, validDirs); - this.plainsVillagePopulator = plainsVillagePopulator; - } - - public PlainsVillageForgePiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, boolean unique, BlockFace... validDirs) { - super(widthX, height, widthZ, type, unique, validDirs); - this.plainsVillagePopulator = plainsVillagePopulator; - } - - public @Nullable PlainsVillageForgeWallType getWallType() { - return wallType; - } - - public void setWallType(@Nullable PlainsVillageForgeWallType wallType) { - this.wallType = wallType; - } - + protected final PlainsVillagePopulator plainsVillagePopulator; + private @Nullable PlainsVillageForgeWallType wallType = null; + + public PlainsVillageForgePiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(widthX, height, widthZ, type, validDirs); + this.plainsVillagePopulator = plainsVillagePopulator; + } + + public PlainsVillageForgePiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + BlockFace... validDirs) + { + super(widthX, height, widthZ, type, unique, validDirs); + this.plainsVillagePopulator = plainsVillagePopulator; + } + + public @Nullable PlainsVillageForgeWallType getWallType() { + return wallType; + } + + public void setWallType(@Nullable PlainsVillageForgeWallType wallType) { + this.wallType = wallType; + } + } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeRoofHandler.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeRoofHandler.java index b578a060..2126e831 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeRoofHandler.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeRoofHandler.java @@ -22,155 +22,195 @@ public class PlainsVillageForgeRoofHandler { - - public static void placeRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, @NotNull SimpleBlock core, @NotNull ArrayList rectangleLocations) { - SimpleLocation lowerBound = null; - SimpleLocation upperBound = null; - - Material roofCornerMaterial = GenUtils.randChoice(Material.STONE_BRICKS, Material.COBBLESTONE); - Material roofSlabCornerMaterial = Material.STONE_BRICK_SLAB; - if(roofCornerMaterial == Material.COBBLESTONE) - roofSlabCornerMaterial = Material.COBBLESTONE_SLAB; - - for(SimpleLocation sLoc:rectangleLocations) { - if(lowerBound == null) lowerBound = sLoc; - if(upperBound == null) upperBound = sLoc; - - if(lowerBound.getX() >= sLoc.getX() && lowerBound.getZ() >= sLoc.getZ()) - lowerBound = sLoc; - - if(upperBound.getX() <= sLoc.getX() && upperBound.getZ() <= sLoc.getZ()) - upperBound = sLoc; - } - - lowerBound = lowerBound.getRelative(-4, 0, -4); - upperBound = upperBound.getRelative(4, 0, 4); - Axis roofAxis = Axis.X; - if(upperBound.getZ() - lowerBound.getZ() > upperBound.getX() - lowerBound.getX()) - roofAxis = Axis.Z; - - for(int x = lowerBound.getX(); x <= upperBound.getX(); x++) { - for(int z = lowerBound.getZ(); z <= upperBound.getZ(); z++) { - // core.getPopData().setType(x, core.getY()+4, z, Material.RED_WOOL); - int height; - double percent; - if(roofAxis == Axis.X) { - // 0 to 1.0 - percent = ((double)x-(double)lowerBound.getX())/((double)upperBound.getX()-(double)lowerBound.getX()); - // -12(x-0.5)^2+3 - }else { - percent = ((double)z-(double)lowerBound.getZ())/((double)upperBound.getZ()-(double)lowerBound.getZ()); - // -12(x-0.5)^2+3 - } - height = (int) ((-12*Math.pow(percent-0.5,2)+3)); - SimpleBlock target = new SimpleBlock(core.getPopData(),x,core.getY()+4+((int)(((double)height)/2)),z); - if(height % 2 == 1) { // Use solid blocks for odd heights - if(x == lowerBound.getX() || x == upperBound.getX() || z == lowerBound.getZ() || z == upperBound.getZ()) { - target.setType(roofCornerMaterial); - - Wall adj = new Wall(target, BlockUtils.getBlockFaceFromAxis(roofAxis)); - new SlabBuilder(roofSlabCornerMaterial) - .setType(Type.TOP) - .lapply(adj.getFront()) - .lapply(adj.getRear()); - }else { - target.setType(plainsVillagePopulator.woodPlank); - } - - // Log center - if(height == 3) { - new OrientableBuilder(plainsVillagePopulator.woodLog) - .setAxis(BlockUtils.getPerpendicularHorizontalPlaneAxis(roofAxis)) - .apply(target); - - if((roofAxis == Axis.X && (z == lowerBound.getZ()+1||z == upperBound.getZ()-1)) - ||(roofAxis == Axis.Z && (x == lowerBound.getX()+1||x == upperBound.getX()-1))) { - - // Fill the holes between the walls and the roof - if(BlockUtils.isStoneLike(target.getDown(2).getType()) || target.getDown(2).getType() == plainsVillagePopulator.woodDoor) - new Wall(target.getDown()).downUntilSolid(new Random(), Material.STONE, Material.COBBLESTONE, Material.ANDESITE); - } - } - - } else { // Use slabs for even heights - if(x == lowerBound.getX() || x == upperBound.getX() || z == lowerBound.getZ() || z == upperBound.getZ()) { - new SlabBuilder(roofSlabCornerMaterial) - .apply(target); - }else { - new SlabBuilder(plainsVillagePopulator.woodSlab) - .apply(target); - } - } + private static final int pieceWidth = 5; + + public static void placeRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, + @NotNull SimpleBlock core, + @NotNull ArrayList rectangleLocations) + { + SimpleLocation lowerBound = null; + SimpleLocation upperBound = null; + + Material roofCornerMaterial = GenUtils.randChoice(Material.STONE_BRICKS, Material.COBBLESTONE); + Material roofSlabCornerMaterial = Material.STONE_BRICK_SLAB; + if (roofCornerMaterial == Material.COBBLESTONE) { + roofSlabCornerMaterial = Material.COBBLESTONE_SLAB; + } + + for (SimpleLocation sLoc : rectangleLocations) { + if (lowerBound == null) { + lowerBound = sLoc; + } + if (upperBound == null) { + upperBound = sLoc; + } + + if (lowerBound.getX() >= sLoc.getX() && lowerBound.getZ() >= sLoc.getZ()) { + lowerBound = sLoc; + } + + if (upperBound.getX() <= sLoc.getX() && upperBound.getZ() <= sLoc.getZ()) { + upperBound = sLoc; + } + } + + lowerBound = lowerBound.getRelative(-4, 0, -4); + upperBound = upperBound.getRelative(4, 0, 4); + Axis roofAxis = Axis.X; + if (upperBound.getZ() - lowerBound.getZ() > upperBound.getX() - lowerBound.getX()) { + roofAxis = Axis.Z; + } + + for (int x = lowerBound.getX(); x <= upperBound.getX(); x++) { + for (int z = lowerBound.getZ(); z <= upperBound.getZ(); z++) { + // core.getPopData().setType(x, core.getY()+4, z, Material.RED_WOOL); + int height; + double percent; + if (roofAxis == Axis.X) { + // 0 to 1.0 + percent = ((double) x - (double) lowerBound.getX()) / ((double) upperBound.getX() + - (double) lowerBound.getX()); + // -12(x-0.5)^2+3 + } + else { + percent = ((double) z - (double) lowerBound.getZ()) / ((double) upperBound.getZ() + - (double) lowerBound.getZ()); + // -12(x-0.5)^2+3 + } + height = (int) ((-12 * Math.pow(percent - 0.5, 2) + 3)); + SimpleBlock target = new SimpleBlock(core.getPopData(), + x, + core.getY() + 4 + ((int) (((double) height) / 2)), + z); + if (height % 2 == 1) { // Use solid blocks for odd heights + if (x == lowerBound.getX() + || x == upperBound.getX() + || z == lowerBound.getZ() + || z == upperBound.getZ()) + { + target.setType(roofCornerMaterial); + + Wall adj = new Wall(target, BlockUtils.getBlockFaceFromAxis(roofAxis)); + new SlabBuilder(roofSlabCornerMaterial).setType(Type.TOP) + .lapply(adj.getFront()) + .lapply(adj.getRear()); + } + else { + target.setType(plainsVillagePopulator.woodPlank); + } + + // Log center + if (height == 3) { + new OrientableBuilder(plainsVillagePopulator.woodLog).setAxis(BlockUtils.getPerpendicularHorizontalPlaneAxis( + roofAxis)).apply(target); + + if ((roofAxis == Axis.X && (z == lowerBound.getZ() + 1 || z == upperBound.getZ() - 1)) || ( + roofAxis == Axis.Z + && (x == lowerBound.getX() + 1 || x == upperBound.getX() - 1))) + { + + // Fill the holes between the walls and the roof + if (BlockUtils.isStoneLike(target.getDown(2).getType()) + || target.getDown(2).getType() == plainsVillagePopulator.woodDoor) + { + new Wall(target.getDown()).downUntilSolid(new Random(), + Material.STONE, + Material.COBBLESTONE, + Material.ANDESITE + ); + } + } + } + + } + else { // Use slabs for even heights + if (x == lowerBound.getX() + || x == upperBound.getX() + || z == lowerBound.getZ() + || z == upperBound.getZ()) + { + new SlabBuilder(roofSlabCornerMaterial).apply(target); + } + else { + new SlabBuilder(plainsVillagePopulator.woodSlab).apply(target); + } + } + + } + } + } + + /** + * @return a list of structure piece simplelocations that are contained within a rectangle. + * This rectangle may not be the largest in the provided hashmap. + */ + public static @NotNull ArrayList identifyRectangle(@NotNull HashMap pieces) { + ArrayList rectangleList = new ArrayList<>(); + SimpleLocation cornerLoc = null; + for (SimpleLocation loc : pieces.keySet()) { + cornerLoc = loc; + break; + } + + // Find a corner of the pieces + BlockFace sideToMove = BlockUtils.getDirectBlockFace(new Random()); + JigsawStructurePiece target = getAdjacentPiece(pieces, cornerLoc, sideToMove); + while (target != null) { + cornerLoc = target.getRoom().getSimpleLocation(); + target = getAdjacentPiece(pieces, cornerLoc, sideToMove); + } + target = pieces.get(cornerLoc); + + // Begin moving towards the opposite side. Add all relevant entries to the list. + while (target != null) { + cornerLoc = target.getRoom().getSimpleLocation(); + rectangleList.add(target.getRoom().getSimpleLocation()); + target = getAdjacentPiece(pieces, cornerLoc, sideToMove.getOppositeFace()); + } + + // For all entries in the list, find the maximum expansion towards one side. + sideToMove = BlockUtils.getTurnBlockFace(new Random(), sideToMove); + int shortestLength = 99; + for (SimpleLocation pLoc : rectangleList) { + JigsawStructurePiece piece = pieces.get(pLoc); + int expansionLength = 0; + piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); + while (piece != null) { + expansionLength++; + piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); } - } - } - - /** - * - * @return a list of structure piece simplelocations that are contained within a rectangle. - * This rectangle may not be the largest in the provided hashmap. - */ - public static @NotNull ArrayList identifyRectangle(@NotNull HashMap pieces){ - ArrayList rectangleList = new ArrayList<>(); - SimpleLocation cornerLoc = null; - for(SimpleLocation loc:pieces.keySet()) { - cornerLoc = loc; - break; - } - - // Find a corner of the pieces - BlockFace sideToMove = BlockUtils.getDirectBlockFace(new Random()); - JigsawStructurePiece target = getAdjacentPiece(pieces, cornerLoc, sideToMove); - while(target != null) { - cornerLoc = target.getRoom().getSimpleLocation(); - target = getAdjacentPiece(pieces, cornerLoc, sideToMove); - } - target = pieces.get(cornerLoc); - - // Begin moving towards the opposite side. Add all relevant entries to the list. - while(target != null) { - cornerLoc = target.getRoom().getSimpleLocation(); - rectangleList.add(target.getRoom().getSimpleLocation()); - target = getAdjacentPiece(pieces, cornerLoc, sideToMove.getOppositeFace()); - } - - // For all entries in the list, find the maximum expansion towards one side. - sideToMove = BlockUtils.getTurnBlockFace(new Random(), sideToMove); - int shortestLength = 99; - for(SimpleLocation pLoc:rectangleList) { - JigsawStructurePiece piece = pieces.get(pLoc); - int expansionLength = 0; - piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); - while(piece != null) { - expansionLength++; - piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); - } - if(expansionLength < shortestLength) shortestLength = expansionLength; - if(expansionLength == 0) break; // Shortest side is 0. Break out. - } - - // Add all associated pieces to the list. - Collection toAdd = new ArrayList<>(); - for(SimpleLocation pLoc:rectangleList) { - JigsawStructurePiece piece = pieces.get(pLoc); - piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); - for(int i = 0; i < shortestLength; i++) { - toAdd.add(piece.getRoom().getSimpleLocation()); - piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); - } - } - - rectangleList.addAll(toAdd); - return rectangleList; - } - - private static final int pieceWidth = 5; - private static JigsawStructurePiece getAdjacentPiece(@NotNull HashMap pieces, @NotNull SimpleLocation loc, @NotNull BlockFace face) { - SimpleLocation other = new SimpleLocation( - loc.getX() + face.getModX() * pieceWidth, + if (expansionLength < shortestLength) { + shortestLength = expansionLength; + } + if (expansionLength == 0) { + break; // Shortest side is 0. Break out. + } + } + + // Add all associated pieces to the list. + Collection toAdd = new ArrayList<>(); + for (SimpleLocation pLoc : rectangleList) { + JigsawStructurePiece piece = pieces.get(pLoc); + piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); + for (int i = 0; i < shortestLength; i++) { + toAdd.add(piece.getRoom().getSimpleLocation()); + piece = getAdjacentPiece(pieces, piece.getRoom().getSimpleLocation(), sideToMove); + } + } + + rectangleList.addAll(toAdd); + return rectangleList; + } + + private static JigsawStructurePiece getAdjacentPiece(@NotNull HashMap pieces, + @NotNull SimpleLocation loc, + @NotNull BlockFace face) + { + SimpleLocation other = new SimpleLocation(loc.getX() + face.getModX() * pieceWidth, loc.getY() + face.getModY() * pieceWidth, - loc.getZ() + face.getModZ() * pieceWidth); + loc.getZ() + face.getModZ() * pieceWidth + ); return pieces.get(other); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeStandardPiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeStandardPiece.java index b49c82e4..c0c366ff 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeStandardPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeStandardPiece.java @@ -14,11 +14,24 @@ public class PlainsVillageForgeStandardPiece extends PlainsVillageForgePiece { - public PlainsVillageForgeStandardPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, boolean unique, BlockFace[] validDirs) { + public PlainsVillageForgeStandardPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + BlockFace[] validDirs) + { super(plainsVillagePopulator, widthX, height, widthZ, type, unique, validDirs); } - - public PlainsVillageForgeStandardPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + + public PlainsVillageForgeStandardPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); } @@ -28,31 +41,30 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { int[] upperCorner = this.getRoom().getUpperCorner(0); // Place flooring. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setType(x, this.getRoom().getY(), z, - GenUtils.randChoice( - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - )); - new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)) - .downUntilSolid(rand, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - ); + data.setType(x, this.getRoom().getY(), z, GenUtils.randChoice( + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + )); + new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)).downUntilSolid( + rand, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } + } } - } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWallPiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWallPiece.java index 1ee05ad0..7e6b0492 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWallPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWallPiece.java @@ -19,90 +19,114 @@ public class PlainsVillageForgeWallPiece extends PlainsVillageForgePiece { - public PlainsVillageForgeWallPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public PlainsVillageForgeWallPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); } @Override public void build(PopulatorDataAbstract data, Random rand) { - // All handled in postBuildDecoration, as the type to build is only identified then. - } - + // All handled in postBuildDecoration, as the type to build is only identified then. + } + @Override public void postBuildDecoration(@NotNull Random rand, @NotNull PopulatorDataAbstract data) { - if(getWallType() == PlainsVillageForgeWallType.SOLID) { // Wall - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey().getDown(); - for (int i = 0; i < entry.getValue(); i++) { - w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - w.RPillar(5, rand, Material.COBBLESTONE, Material.ANDESITE, Material.STONE); - - // Handle window hole placement - if(i == 2) { // Center - w.getUp(2).setType(Material.AIR); - new SlabBuilder(Material.COBBLESTONE_SLAB,Material.ANDESITE_SLAB,Material.STONE_SLAB,Material.STONE_BRICK_SLAB) - .setType(Type.TOP) - .apply(w.getUp(3).getFront()); - - new StairBuilder(Material.COBBLESTONE_STAIRS,Material.ANDESITE_STAIRS,Material.STONE_STAIRS,Material.STONE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getUp().getFront()); - - w.getFront().downUntilSolid(rand, Material.COBBLESTONE,Material.MOSSY_COBBLESTONE); - } - else if(i == 1 || i == 3) { // Beside the opening - w.getUp(3).getFront().setType(Material.COBBLESTONE_SLAB,Material.ANDESITE_SLAB,Material.STONE_SLAB,Material.STONE_BRICK_SLAB); - w.getUp(2).getFront().setType(Material.COBBLESTONE_WALL,Material.STONE_BRICK_WALL,Material.ANDESITE_WALL); - - // Stair decor - if(i == 1) - new StairBuilder(Material.COBBLESTONE_STAIRS,Material.ANDESITE_STAIRS,Material.STONE_STAIRS,Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getUp(2)) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .setHalf(Half.TOP) - .apply(w.getUp().getFront()); - else - new StairBuilder(Material.COBBLESTONE_STAIRS,Material.ANDESITE_STAIRS,Material.STONE_STAIRS,Material.STONE_BRICK_STAIRS) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getUp(2)) - .setFacing(BlockUtils.getRight(w.getDirection())) - .setHalf(Half.TOP) - .apply(w.getUp().getFront()); - - } - - w = w.getLeft(); - } - } - else // Fences - { - SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); - Wall w = entry.getKey(); - for (int i = 0; i < entry.getValue(); i++) { - w.getDown(2).downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - - if(i == 2) { - w.getDown().Pillar(2, rand, plainsVillagePopulator.woodLog); - w.getUp().setType(Material.STONE_SLAB,Material.COBBLESTONE_SLAB,Material.ANDESITE_SLAB); - } - else - { - w.get().lsetType(plainsVillagePopulator.woodFence); - w.CorrectMultipleFacing(1); - new OrientableBuilder(plainsVillagePopulator.woodLog) - .setAxis(BlockUtils.getAxisFromBlockFace(BlockUtils.getLeft(w.getDirection()))) - .apply(w.getDown()); - } - - w = w.getLeft(); - } - } - + if (getWallType() == PlainsVillageForgeWallType.SOLID) { // Wall + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + Wall w = entry.getKey().getDown(); + for (int i = 0; i < entry.getValue(); i++) { + w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + w.RPillar(5, rand, Material.COBBLESTONE, Material.ANDESITE, Material.STONE); + + // Handle window hole placement + if (i == 2) { // Center + w.getUp(2).setType(Material.AIR); + new SlabBuilder(Material.COBBLESTONE_SLAB, + Material.ANDESITE_SLAB, + Material.STONE_SLAB, + Material.STONE_BRICK_SLAB).setType(Type.TOP).apply(w.getUp(3).getFront()); + + new StairBuilder(Material.COBBLESTONE_STAIRS, + Material.ANDESITE_STAIRS, + Material.STONE_STAIRS, + Material.STONE_BRICK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getUp().getFront()); + + w.getFront().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + } + else if (i == 1 || i == 3) { // Beside the opening + w.getUp(3) + .getFront() + .setType(Material.COBBLESTONE_SLAB, + Material.ANDESITE_SLAB, + Material.STONE_SLAB, + Material.STONE_BRICK_SLAB); + w.getUp(2) + .getFront() + .setType(Material.COBBLESTONE_WALL, Material.STONE_BRICK_WALL, Material.ANDESITE_WALL); + + // Stair decor + if (i == 1) { + new StairBuilder( + Material.COBBLESTONE_STAIRS, + Material.ANDESITE_STAIRS, + Material.STONE_STAIRS, + Material.STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getRight(w.getDirection())) + .apply(w.getUp(2)) + .setFacing(BlockUtils.getLeft(w.getDirection())) + .setHalf(Half.TOP) + .apply(w.getUp().getFront()); + } + else { + new StairBuilder( + Material.COBBLESTONE_STAIRS, + Material.ANDESITE_STAIRS, + Material.STONE_STAIRS, + Material.STONE_BRICK_STAIRS + ).setFacing(BlockUtils.getLeft(w.getDirection())) + .apply(w.getUp(2)) + .setFacing(BlockUtils.getRight(w.getDirection())) + .setHalf(Half.TOP) + .apply(w.getUp().getFront()); + } + + } + + w = w.getLeft(); + } + } + else // Fences + { + SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + w.getDown(2).downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); + + if (i == 2) { + w.getDown().Pillar(2, rand, plainsVillagePopulator.woodLog); + w.getUp().setType(Material.STONE_SLAB, Material.COBBLESTONE_SLAB, Material.ANDESITE_SLAB); + } + else { + w.get().lsetType(plainsVillagePopulator.woodFence); + w.CorrectMultipleFacing(1); + new OrientableBuilder(plainsVillagePopulator.woodLog).setAxis(BlockUtils.getAxisFromBlockFace( + BlockUtils.getLeft(w.getDirection()))).apply(w.getDown()); + } + + w = w.getLeft(); + } + } + } - + public enum PlainsVillageForgeWallType { - SOLID, FENCE + SOLID, FENCE } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWeaponSmithPiece.java b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWeaponSmithPiece.java index 0aaf58ae..1ac0f0a3 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWeaponSmithPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/forge/PlainsVillageForgeWeaponSmithPiece.java @@ -20,69 +20,77 @@ public class PlainsVillageForgeWeaponSmithPiece extends PlainsVillageForgeStandardPiece { - public PlainsVillageForgeWeaponSmithPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); - } - - // Use postBuildDecoration. + public PlainsVillageForgeWeaponSmithPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); + } + + // Use postBuildDecoration. @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { - // SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); - if(this.getWalledFaces().isEmpty()) { - // Leave the room empty if you can't spawn anything. - return; - } - - ArrayList walledFaces = this.getWalledFaces(); - Collections.shuffle(walledFaces); - boolean placedJobBlock = false; - for(BlockFace face:walledFaces) { - Entry entry = this.getRoom().getWall(data, face, 0); - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - - // Ensure that you don't place anything against the entrance - if(w.getRear().getDown().getType() != Material.CHISELED_STONE_BRICKS) - { - int choice = random.nextInt(4); - switch(choice) { - case 0: - if(!placedJobBlock){ - placedJobBlock = true; - w.setType(Material.SMITHING_TABLE, Material.FLETCHING_TABLE); - } - break; - case 1: // Workbench & lantern - if(GenUtils.chance(random, 3, 4)) - break; - w.setType(Material.CRAFTING_TABLE); - w.getUp().setType(Material.LANTERN); - if(w.getUp().getRear().isSolid() && !placedJobBlock) { - placedJobBlock = true; - new DirectionalBuilder(Material.GRINDSTONE) - .setFacing(w.getDirection()) - .apply(w.getUp()); - } - break; - case 2: // Anvil - if(GenUtils.chance(random, 3, 4)) - break; - new DirectionalBuilder(Material.ANVIL, Material.CHIPPED_ANVIL, Material.DAMAGED_ANVIL) - .setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w); - break; - case 3: - if(GenUtils.chance(random, 1,4)) - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.VILLAGE_ARMORER) - .apply(w); - break; - } - } - - w = w.getLeft(); - } - } + // SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY(), this.getRoom().getZ()); + if (this.getWalledFaces().isEmpty()) { + // Leave the room empty if you can't spawn anything. + return; + } + + ArrayList walledFaces = this.getWalledFaces(); + Collections.shuffle(walledFaces); + boolean placedJobBlock = false; + for (BlockFace face : walledFaces) { + Entry entry = this.getRoom().getWall(data, face, 0); + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + + // Ensure that you don't place anything against the entrance + if (w.getRear().getDown().getType() != Material.CHISELED_STONE_BRICKS) { + int choice = random.nextInt(4); + switch (choice) { + case 0: + if (!placedJobBlock) { + placedJobBlock = true; + w.setType(Material.SMITHING_TABLE, Material.FLETCHING_TABLE); + } + break; + case 1: // Workbench & lantern + if (GenUtils.chance(random, 3, 4)) { + break; + } + w.setType(Material.CRAFTING_TABLE); + w.getUp().setType(Material.LANTERN); + if (w.getUp().getRear().isSolid() && !placedJobBlock) { + placedJobBlock = true; + new DirectionalBuilder(Material.GRINDSTONE).setFacing(w.getDirection()) + .apply(w.getUp()); + } + break; + case 2: // Anvil + if (GenUtils.chance(random, 3, 4)) { + break; + } + new DirectionalBuilder( + Material.ANVIL, + Material.CHIPPED_ANVIL, + Material.DAMAGED_ANVIL + ).setFacing(BlockUtils.getLeft(w.getDirection())).apply(w); + break; + case 3: + if (GenUtils.chance(random, 1, 4)) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.VILLAGE_ARMORER) + .apply(w); + } + break; + } + } + + w = w.getLeft(); + } + } } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageBedroomPiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageBedroomPiece.java index ad6989b2..8a0d7729 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageBedroomPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageBedroomPiece.java @@ -11,7 +11,6 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; import org.terraform.small_items.DecorationsBuilder; import org.terraform.structure.room.jigsaw.JigsawType; import org.terraform.structure.village.plains.PlainsVillagePopulator; @@ -26,7 +25,14 @@ public class PlainsVillageBedroomPiece extends PlainsVillageStandardPiece { - public PlainsVillageBedroomPiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant variant, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public PlainsVillageBedroomPiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant variant, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, variant, widthX, height, widthZ, type, validDirs); } @@ -43,18 +49,19 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb if (this.getWalledFaces().isEmpty()) { // Place a dining table or smt, idk - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()); + SimpleBlock core = new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ); core.setType(Material.SMOOTH_STONE); for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { - new SlabBuilder(Material.SMOOTH_STONE_SLAB) - .setType(Slab.Type.TOP) - .apply(core.getRelative(face)); + new SlabBuilder(Material.SMOOTH_STONE_SLAB).setType(Slab.Type.TOP).apply(core.getRelative(face)); } for (BlockFace face : BlockUtils.directBlockFaces) { - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(face) - .apply(core.getRelative(face, 2)); + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(face).apply(core.getRelative(face, 2)); } BlockUtils.pickPottedPlant().build(core.getUp()); @@ -70,10 +77,12 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb // First pass, place beds for (int i = 0; i < entry.getValue(); i++) { if (!w.getFront().isSolid() - && placedBeds < 2 - && w.getRear().getType() != plainsVillagePopulator.woodDoor) { - if ((GenUtils.chance(random, 2, 5) && placedBeds == 0) - || (GenUtils.chance(random, 1, 10) && placedBeds == 1)) { + && placedBeds < 2 + && w.getRear().getType() != plainsVillagePopulator.woodDoor) + { + if ((GenUtils.chance(random, 2, 5) && placedBeds == 0) || (GenUtils.chance(random, 1, 10) + && placedBeds == 1)) + { BlockUtils.placeBed(w.get(), BlockUtils.pickBed(), w.getDirection()); placedBeds++; // Spawn a villager on the bed. @@ -90,39 +99,40 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb // Don't place stuff in front of doors if (w.getRear().getType() != plainsVillagePopulator.woodDoor) { if (!Tag.BEDS.isTagged(w.getType())) { // don't replace beds - if (Tag.BEDS.isTagged(w.getRight().getType()) - || Tag.BEDS.isTagged(w.getLeft().getType())) { + if (Tag.BEDS.isTagged(w.getRight().getType()) || Tag.BEDS.isTagged(w.getLeft().getType())) { // If next to bed, if (random.nextBoolean()) { // Place Night stand - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(w); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.POLISHED_ANDESITE_STAIRS + ).setFacing(w.getDirection().getOppositeFace()).setHalf(Half.TOP).apply(w); BlockUtils.pickPottedPlant().build(w.getUp()); - } else { + } + else { // Place Crafting Table DecorationsBuilder.CRAFTING_TABLE.build(w); } - } else { // Not next to a bed + } + else { // Not next to a bed if (GenUtils.chance(random, 1, 10)) { // Chest - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.VILLAGE_PLAINS_HOUSE) - .apply(w); - } else if (GenUtils.chance(random, 1, 5)) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.VILLAGE_PLAINS_HOUSE) + .apply(w); + } + else if (GenUtils.chance(random, 1, 5)) { // Study table, if there's enough space if (!w.getFront().isSolid()) { - new SlabBuilder(Material.SMOOTH_STONE_SLAB, Material.POLISHED_ANDESITE_SLAB) - .setType(Slab.Type.TOP) - .apply(w); - new StairBuilder(Material.POLISHED_ANDESITE_STAIRS) - .setFacing(w.getDirection()) - .apply(w.getFront()); + new SlabBuilder( + Material.SMOOTH_STONE_SLAB, + Material.POLISHED_ANDESITE_SLAB + ).setType(Slab.Type.TOP).apply(w); + new StairBuilder(Material.POLISHED_ANDESITE_STAIRS).setFacing(w.getDirection()) + .apply(w.getFront()); } } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageEntrancePiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageEntrancePiece.java index 4be2a73e..e75339ee 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageEntrancePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageEntrancePiece.java @@ -23,7 +23,15 @@ public class PlainsVillageEntrancePiece extends JigsawStructurePiece { final PlainsVillageHouseVariant var; final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant var, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + + public PlainsVillageEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant var, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.var = var; this.plainsVillagePopulator = plainsVillagePopulator; @@ -39,34 +47,43 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.Pillar(2, rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - if (this.var == PlainsVillageHouseVariant.CLAY) + if (this.var == PlainsVillageHouseVariant.CLAY) { w.getUp(2).Pillar(2, rand, Material.WHITE_TERRACOTTA); - else + } + else { w.getUp(2).Pillar(2, rand, plainsVillagePopulator.woodPlank); + } w = w.getLeft(); } // The door w = w.getRight(3).getUp(); - BlockUtils.placeDoor(data, plainsVillagePopulator.woodDoor, - w.getX(), w.getY(), w.getZ(), w.getDirection().getOppositeFace()); - - - if(w.getFront().isSolid()) { - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .setStairwayDirection(BlockFace.UP) - .build(w.getFront(4)); - w.getFront().Pillar(2, new Random(), Material.AIR); - w.getFront(2).Pillar(2, new Random(), Material.AIR); - w.getFront(3).Pillar(3, new Random(), Material.AIR); - }else - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .build(w.getFront().getDown()); + BlockUtils.placeDoor(data, + plainsVillagePopulator.woodDoor, + w.getX(), + w.getY(), + w.getZ(), + w.getDirection().getOppositeFace() + ); + + + if (w.getFront().isSolid()) { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .setStairwayDirection( + BlockFace.UP) + .build(w.getFront(4)); + w.getFront().Pillar(2, new Random(), Material.AIR); + w.getFront(2).Pillar(2, new Random(), Material.AIR); + w.getFront(3).Pillar(3, new Random(), Material.AIR); + } + else { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .build(w.getFront() + .getDown()); + } // Decorations depending on variant if (this.var == PlainsVillageHouseVariant.COBBLESTONE) { @@ -80,10 +97,12 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getRight().getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); Orientable log = (Orientable) Bukkit.createBlockData(plainsVillagePopulator.woodLog); - if (w.getDirection().getModZ() != 0) + if (w.getDirection().getModZ() != 0) { log.setAxis(Axis.X); - else + } + else { log.setAxis(Axis.Z); + } w.getUp(2).setBlockData(log); w.getRight().getUp(2).setBlockData(log); @@ -94,21 +113,20 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getRight().getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - new SlabBuilder(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB) - .setType(Slab.Type.TOP) - .apply(w.getUp(2)); + new SlabBuilder(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB).setType(Slab.Type.TOP) + .apply(w.getUp(2)); - new SlabBuilder(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB) - .setType(Slab.Type.BOTTOM) - .apply(w.getUp(2).getLeft()) - .apply(w.getUp(2).getRight()); + new SlabBuilder(Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB).setType(Slab.Type.BOTTOM) + .apply(w.getUp(2).getLeft()) + .apply(w.getUp(2).getRight()); w.getLeft().Pillar(2, rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); w.getRight().Pillar(2, rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); w.getLeft().CorrectMultipleFacing(2); w.getRight().CorrectMultipleFacing(2); - } else if (this.var == PlainsVillageHouseVariant.CLAY) { + } + else if (this.var == PlainsVillageHouseVariant.CLAY) { w.getLeft().getUp().setType(plainsVillagePopulator.woodLog); w.getRight().getUp().setType(plainsVillagePopulator.woodLog); w = w.getFront(); @@ -116,10 +134,12 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getRight().getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); Orientable log = (Orientable) Bukkit.createBlockData(plainsVillagePopulator.woodLog); - if (w.getDirection().getModZ() != 0) + if (w.getDirection().getModZ() != 0) { log.setAxis(Axis.Z); - else + } + else { log.setAxis(Axis.X); + } w.getLeft().setType(plainsVillagePopulator.woodLog); w.getLeft().getUp().setType(Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL); @@ -142,12 +162,15 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getLeft().CorrectMultipleFacing(1); w.getRight().setType(Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL); w.getRight().CorrectMultipleFacing(1); - } else if (this.var == PlainsVillageHouseVariant.WOODEN) { + } + else if (this.var == PlainsVillageHouseVariant.WOODEN) { Orientable log = (Orientable) Bukkit.createBlockData(plainsVillagePopulator.woodLog); - if (w.getDirection().getModZ() != 0) + if (w.getDirection().getModZ() != 0) { log.setAxis(Axis.Z); - else + } + else { log.setAxis(Axis.X); + } // w.getUp(2).setBlockData(log); diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseJigsawBuilder.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseJigsawBuilder.java index d37927e7..9bab0055 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseJigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseJigsawBuilder.java @@ -17,72 +17,131 @@ public class PlainsVillageHouseJigsawBuilder extends JigsawBuilder { final PlainsVillageHouseVariant var; final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageHouseJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, int widthX, int widthZ, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + + public PlainsVillageHouseJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int widthZ, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { super(widthX, widthZ, data, x, y, z); this.plainsVillagePopulator = plainsVillagePopulator; this.var = PlainsVillageHouseVariant.roll(new Random()); - this.pieceRegistry = new JigsawStructurePiece[]{ - new PlainsVillageBedroomPiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageKitchenPiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageLibraryPiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageWallPiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.END, BlockUtils.directBlockFaces), - new PlainsVillageEntrancePiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.ENTRANCE, BlockUtils.directBlockFaces) + this.pieceRegistry = new JigsawStructurePiece[] { + new PlainsVillageBedroomPiece( + plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageKitchenPiece(plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageLibraryPiece(plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageWallPiece(plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.END, + BlockUtils.directBlockFaces + ), + new PlainsVillageEntrancePiece(plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.ENTRANCE, + BlockUtils.directBlockFaces + ) }; this.chanceToAddNewPiece = 30; } @Override public @NotNull JigsawStructurePiece getFirstPiece(@NotNull Random random) { - return new PlainsVillageBedroomPiece(plainsVillagePopulator, var, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces); + return new PlainsVillageBedroomPiece( + plainsVillagePopulator, + var, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ); } - + @Override public void build(@NotNull Random random) { super.build(random); // Make sure awkward corners are fixed for (JigsawStructurePiece piece : this.pieces.values()) { - SimpleBlock core = new SimpleBlock( - this.core.getPopData(), + SimpleBlock core = new SimpleBlock(this.core.getPopData(), piece.getRoom().getX(), piece.getRoom().getY(), - piece.getRoom().getZ()); + piece.getRoom().getZ() + ); Wall target; Material[] fenceType = {plainsVillagePopulator.woodFence}; Material cornerType = plainsVillagePopulator.woodLog; - if (this.var == PlainsVillageHouseVariant.COBBLESTONE) - fenceType = new Material[]{Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL}; + if (this.var == PlainsVillageHouseVariant.COBBLESTONE) { + fenceType = new Material[] {Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL}; + } else if (this.var == PlainsVillageHouseVariant.CLAY) { - fenceType = new Material[]{Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL}; + fenceType = new Material[] {Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL}; cornerType = plainsVillagePopulator.woodStrippedLog; } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // nw + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // nw target = new Wall(core.getRelative(-3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST, cornerType, fenceType); } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // ne + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // ne target = new Wall(core.getRelative(3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST, cornerType, fenceType); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // sw + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // sw target = new Wall(core.getRelative(-3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST, cornerType, fenceType); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // se + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // se target = new Wall(core.getRelative(3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST, cornerType, fenceType); } } // Place the roof - if (!PlainsVillageRoofHandler.isRectangle(this)) + if (!PlainsVillageRoofHandler.isRectangle(this)) { PlainsVillageRoofHandler.placeStandardRoof(plainsVillagePopulator, this); - else + } + else { PlainsVillageRoofHandler.placeTentRoof(plainsVillagePopulator, random, this); + } // Decorate rooms and walls for (JigsawStructurePiece piece : this.pieces.values()) { @@ -91,7 +150,13 @@ else if (this.var == PlainsVillageHouseVariant.CLAY) { } - public void decorateAwkwardCorner(@NotNull Wall target, @NotNull Random random, @NotNull BlockFace one, @NotNull BlockFace two, Material cornerType, Material[] fenceType) { + public void decorateAwkwardCorner(@NotNull Wall target, + @NotNull Random random, + @NotNull BlockFace one, + @NotNull BlockFace two, + Material cornerType, + Material[] fenceType) + { target.Pillar(4, random, cornerType); target.getDown().downUntilSolid(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); target = target.getUp(); diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseVariant.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseVariant.java index 984b7c3a..4120322b 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseVariant.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageHouseVariant.java @@ -5,9 +5,7 @@ import java.util.Random; public enum PlainsVillageHouseVariant { - WOODEN, - CLAY, - COBBLESTONE; + WOODEN, CLAY, COBBLESTONE; public static PlainsVillageHouseVariant roll(@NotNull Random rand) { int index = rand.nextInt(PlainsVillageHouseVariant.values().length); diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageKitchenPiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageKitchenPiece.java index 9f0f22e5..f749d395 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageKitchenPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageKitchenPiece.java @@ -26,7 +26,14 @@ public class PlainsVillageKitchenPiece extends PlainsVillageStandardPiece { - public PlainsVillageKitchenPiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant variant, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public PlainsVillageKitchenPiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant variant, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, variant, widthX, height, widthZ, type, validDirs); } @@ -41,7 +48,12 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb // Pick a random walled face to be the primary wall, where all the stuff goes. BlockFace primaryWall = this.getWalledFaces().get(random.nextInt(this.getWalledFaces().size())); - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()); + SimpleBlock core = new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ); int numUtilities = 5; if (core.getRelative(primaryWall, 3).getType() == plainsVillagePopulator.woodDoor) { numUtilities--; @@ -73,14 +85,12 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb break; case FURNACE: // Furnace and smoker handled the same way case SMOKER: - new DirectionalBuilder(mat) - .setFacing(w.getDirection()).apply(w); + new DirectionalBuilder(mat).setFacing(w.getDirection()).apply(w); w.getUp().setType(plainsVillagePopulator.woodPressurePlate); - new StairBuilder(Material.BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Bisected.Half.TOP) - .apply(w.getUp(2)); + new StairBuilder(Material.BRICK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .setHalf(Bisected.Half.TOP) + .apply(w.getUp(2)); Wall chimneyWall = w.getUp(3); boolean hitCeiling = false; @@ -88,9 +98,12 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb while (chimneyHeight < 4) { if (chimneyWall.isSolid()) { hitCeiling = true; - } else if (hitCeiling) { + } + else if (hitCeiling) { chimneyHeight++; - if (GenUtils.chance(random, chimneyHeight, 3)) break; + if (GenUtils.chance(random, chimneyHeight, 3)) { + break; + } } chimneyWall.setType(Material.BRICKS); @@ -111,33 +124,37 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb // Other walls can be decorated with random and loot // Populate for walled areas for (BlockFace face : this.getWalledFaces()) { - if (face == primaryWall) continue; + if (face == primaryWall) { + continue; + } entry = this.getRoom().getWall(data, face, 0); w = entry.getKey(); for (int i = 0; i < entry.getValue(); i++) { - if (w.getRear().getType() != plainsVillagePopulator.woodDoor - && !w.isSolid()) { + if (w.getRear().getType() != plainsVillagePopulator.woodDoor && !w.isSolid()) { int decor = random.nextInt(5); switch (decor) { case 0: // Counter - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.POLISHED_ANDESITE_STAIRS, plainsVillagePopulator.woodStairs) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(w); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + plainsVillagePopulator.woodStairs + ).setFacing(w.getDirection().getOppositeFace()).setHalf(Half.TOP).apply(w); break; case 1: // Solid counter or other random solid blocks - w.setType( - Material.SMOOTH_STONE, + w.setType(Material.SMOOTH_STONE, Material.POLISHED_ANDESITE, Material.PUMPKIN, Material.DRIED_KELP_BLOCK, - Material.MELON); + Material.MELON + ); break; case 2: // Random loot - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.VILLAGE_BUTCHER, TerraLootTable.VILLAGE_PLAINS_HOUSE); + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable( + TerraLootTable.VILLAGE_BUTCHER, + TerraLootTable.VILLAGE_PLAINS_HOUSE + ); default: // Do nothing break; } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageLibraryPiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageLibraryPiece.java index 37a19464..5d5bbeb0 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageLibraryPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageLibraryPiece.java @@ -23,7 +23,14 @@ public class PlainsVillageLibraryPiece extends PlainsVillageStandardPiece { - public PlainsVillageLibraryPiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant variant, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + public PlainsVillageLibraryPiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant variant, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(plainsVillagePopulator, variant, widthX, height, widthZ, type, validDirs); } @@ -32,10 +39,13 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb super.postBuildDecoration(random, data); // In the center, place a single lectern - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()); - new DirectionalBuilder(Material.LECTERN) - .setFacing(BlockUtils.getDirectBlockFace(random)) - .apply(core); + SimpleBlock core = new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ); + new DirectionalBuilder(Material.LECTERN).setFacing(BlockUtils.getDirectBlockFace(random)).apply(core); // Populate for walled areas for (BlockFace face : this.getWalledFaces()) { @@ -49,28 +59,29 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb Ladder ladder = (Ladder) Bukkit.createBlockData(Material.LADDER); ladder.setFacing(w.getDirection()); for (int h = 0; h < 25; h++) { - if (w.getFront().getRelative(0, h, 0).isSolid()) + if (w.getFront().getRelative(0, h, 0).isSolid()) { break; + } w.getFront().getRelative(0, h, 0).setBlockData(ladder); } } - } else if (i == 1 || i == 3) { - new StairBuilder(plainsVillagePopulator.woodStairs) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w); - new StairBuilder(Material.STONE_BRICK_STAIRS, Material.MOSSY_STONE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .setHalf(Half.TOP) - .apply(w.getUp(2)); + } + else if (i == 1 || i == 3) { + new StairBuilder(plainsVillagePopulator.woodStairs).setFacing(w.getDirection().getOppositeFace()) + .apply(w); + new StairBuilder( + Material.STONE_BRICK_STAIRS, + Material.MOSSY_STONE_BRICK_STAIRS + ).setFacing(w.getDirection().getOppositeFace()).setHalf(Half.TOP).apply(w.getUp(2)); w.getUp(3).LPillar(25, random, Material.BOOKSHELF); - } else { - if (w.getRear().getType() != plainsVillagePopulator.woodDoor) - new SlabBuilder(plainsVillagePopulator.woodSlab) - .apply(w); + } + else { + if (w.getRear().getType() != plainsVillagePopulator.woodDoor) { + new SlabBuilder(plainsVillagePopulator.woodSlab).apply(w); + } - new SlabBuilder(Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB) - .setType(Slab.Type.TOP) - .apply(w.getUp(2)); + new SlabBuilder(Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB).setType(Slab.Type.TOP) + .apply(w.getUp(2)); w.getUp(3).LPillar(25, random, Material.BOOKSHELF); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageRoofHandler.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageRoofHandler.java index 85c0187c..1db9cad2 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageRoofHandler.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageRoofHandler.java @@ -29,18 +29,24 @@ public static boolean isRectangle(@NotNull PlainsVillageHouseJigsawBuilder build for (JigsawStructurePiece piece : builder.getPieces().values()) { if (lowestCoords == null) { y = piece.getRoom().getY(); - lowestCoords = new int[]{piece.getRoom().getX(), piece.getRoom().getZ()}; + lowestCoords = new int[] {piece.getRoom().getX(), piece.getRoom().getZ()}; } - if (highestCoords == null) highestCoords = new int[]{piece.getRoom().getX(), piece.getRoom().getZ()}; - if (piece.getRoom().getX() < lowestCoords[0]) + if (highestCoords == null) { + highestCoords = new int[] {piece.getRoom().getX(), piece.getRoom().getZ()}; + } + if (piece.getRoom().getX() < lowestCoords[0]) { lowestCoords[0] = piece.getRoom().getX(); - if (piece.getRoom().getZ() < lowestCoords[1]) + } + if (piece.getRoom().getZ() < lowestCoords[1]) { lowestCoords[1] = piece.getRoom().getZ(); + } - if (piece.getRoom().getX() > highestCoords[0]) + if (piece.getRoom().getX() > highestCoords[0]) { highestCoords[0] = piece.getRoom().getX(); - if (piece.getRoom().getZ() > highestCoords[1]) + } + if (piece.getRoom().getZ() > highestCoords[1]) { highestCoords[1] = piece.getRoom().getZ(); + } } // Check and see if every piece is accounted for when looping through the coords. @@ -49,8 +55,10 @@ public static boolean isRectangle(@NotNull PlainsVillageHouseJigsawBuilder build for (int z = lowestCoords[1]; z <= highestCoords[1]; z += builder.getPieceWidth()) { if (!builder.getPieces().containsKey(new SimpleLocation(x, y, z))) { return false; - } else + } + else { count++; + } } } @@ -59,7 +67,10 @@ public static boolean isRectangle(@NotNull PlainsVillageHouseJigsawBuilder build } - public static void placeTentRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, @NotNull Random rand, @NotNull PlainsVillageHouseJigsawBuilder builder) { + public static void placeTentRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, + @NotNull Random rand, + @NotNull PlainsVillageHouseJigsawBuilder builder) + { Axis superiorAxis; PopulatorDataAbstract data = builder.getCore().getPopData(); int[] lowestCoords = null; @@ -69,28 +80,37 @@ public static void placeTentRoof(@NotNull PlainsVillagePopulator plainsVillagePo for (JigsawStructurePiece piece : builder.getPieces().values()) { if (lowestCoords == null) { y = piece.getRoom().getY(); - lowestCoords = new int[]{piece.getRoom().getX(), piece.getRoom().getZ()}; + lowestCoords = new int[] {piece.getRoom().getX(), piece.getRoom().getZ()}; } - if (highestCoords == null) - highestCoords = new int[]{piece.getRoom().getX(), piece.getRoom().getZ()}; - if (piece.getRoom().getX() < lowestCoords[0]) + if (highestCoords == null) { + highestCoords = new int[] {piece.getRoom().getX(), piece.getRoom().getZ()}; + } + if (piece.getRoom().getX() < lowestCoords[0]) { lowestCoords[0] = piece.getRoom().getX(); - if (piece.getRoom().getZ() < lowestCoords[1]) + } + if (piece.getRoom().getZ() < lowestCoords[1]) { lowestCoords[1] = piece.getRoom().getZ(); + } - if (piece.getRoom().getX() > highestCoords[0]) + if (piece.getRoom().getX() > highestCoords[0]) { highestCoords[0] = piece.getRoom().getX(); - if (piece.getRoom().getZ() > highestCoords[1]) + } + if (piece.getRoom().getZ() > highestCoords[1]) { highestCoords[1] = piece.getRoom().getZ(); + } } // Longer axis is the superior one - if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) + if (highestCoords[0] - lowestCoords[0] > highestCoords[1] - lowestCoords[1]) { superiorAxis = Axis.X; - else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) + } + else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1]) { superiorAxis = Axis.Z; + } else // Square house - superiorAxis = new Axis[]{Axis.X, Axis.Z}[rand.nextInt(1)]; + { + superiorAxis = new Axis[] {Axis.X, Axis.Z}[rand.nextInt(1)]; + } lowestCoords[0] -= 3; @@ -105,7 +125,8 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] length = highestCoords[0] - lowestCoords[0] + 5; breadth = (highestCoords[1] - lowestCoords[1]) + 3; w = new Wall(new SimpleBlock(data, highestCoords[0] + 2, y + 4, lowestCoords[1] - 1), BlockFace.WEST); - } else { + } + else { length = highestCoords[1] - lowestCoords[1] + 5; breadth = (highestCoords[0] - lowestCoords[0]) + 3; w = new Wall(new SimpleBlock(data, lowestCoords[0] - 1, y + 4, lowestCoords[1] - 2), BlockFace.SOUTH); @@ -127,21 +148,21 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] if (right != 0 && right != breadth - 1) { // Sandwiched by trapdoors if (i == 0) { - new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor) - .setHalf(Half.TOP) - .setOpen(true) - .setFacing(target.getDirection().getOppositeFace()) - .apply(target.getDown()); - } else if (i == length - 1) { - new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor) - .setHalf(Half.TOP) - .setOpen(true) - .setFacing(target.getDirection()) - .apply(target.getDown()); - } else { - new OrientableBuilder(plainsVillagePopulator.woodLog) - .setAxis(superiorAxis) - .apply(target.getDown().get()); + new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor).setHalf(Half.TOP) + .setOpen(true) + .setFacing(target.getDirection() + .getOppositeFace()) + .apply(target.getDown()); + } + else if (i == length - 1) { + new TrapdoorBuilder(plainsVillagePopulator.woodTrapdoor).setHalf(Half.TOP) + .setOpen(true) + .setFacing(target.getDirection()) + .apply(target.getDown()); + } + else { + new OrientableBuilder(plainsVillagePopulator.woodLog).setAxis(superiorAxis) + .apply(target.getDown().get()); } } @@ -149,44 +170,39 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] Material[] slabType = {Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB}; if (right == 0 || right == breadth - 1 || i == 0 || i == length - 1) { - stairType = new Material[]{Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS}; + stairType = new Material[] {Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS}; } if (breadth % 2 == 1) { // For odd breadth. if (right > breadth / 2) { // Slope down - new StairBuilder(stairType) - .setFacing(BlockUtils.getLeft(target.getDirection())) - .apply(target); + new StairBuilder(stairType).setFacing(BlockUtils.getLeft(target.getDirection())).apply(target); target = target.getRight().getDown(); - } else if (right < breadth / 2) { + } + else if (right < breadth / 2) { // Slope up - new StairBuilder(stairType) - .setFacing(BlockUtils.getRight(target.getDirection())) - .apply(target); + new StairBuilder(stairType).setFacing(BlockUtils.getRight(target.getDirection())).apply(target); target = target.getRight().getUp(); - } else { + } + else { // Top (Only exists when the breadth is odd. target.setType(slabType); target = target.getRight().getDown(); } - } else { // For even breadth + } + else { // For even breadth if (right == breadth / 2 - 1) { - new StairBuilder(stairType) - .setFacing(BlockUtils.getRight(target.getDirection())) - .apply(target); + new StairBuilder(stairType).setFacing(BlockUtils.getRight(target.getDirection())).apply(target); target = target.getRight(); - } else if (right >= breadth / 2) { + } + else if (right >= breadth / 2) { // Slope down - new StairBuilder(stairType) - .setFacing(BlockUtils.getLeft(target.getDirection())) - .apply(target); + new StairBuilder(stairType).setFacing(BlockUtils.getLeft(target.getDirection())).apply(target); target = target.getRight().getDown(); - } else if (right < breadth / 2) { + } + else if (right < breadth / 2) { // Slope up - new StairBuilder(stairType) - .setFacing(BlockUtils.getRight(target.getDirection())) - .apply(target); + new StairBuilder(stairType).setFacing(BlockUtils.getRight(target.getDirection())).apply(target); target = target.getRight().getUp(); } } @@ -199,7 +215,9 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] private static @Nullable Material getLowestMaterial(@NotNull Wall w) { Wall other = w.findFloor(10); - if (other != null) return other.getType(); + if (other != null) { + return other.getType(); + } return null; } @@ -208,15 +226,21 @@ else if (highestCoords[0] - lowestCoords[0] < highestCoords[1] - lowestCoords[1] * changes the sides to stairs. Doesn't look very sophisticated, so it will be * used for the weirdly shaped houses that aren't rectangles. */ - public static void placeStandardRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, @NotNull PlainsVillageHouseJigsawBuilder builder) { + public static void placeStandardRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, + @NotNull PlainsVillageHouseJigsawBuilder builder) + { PopulatorDataAbstract data = builder.getCore().getPopData(); Material[] solidMat = {plainsVillagePopulator.woodPlank}; Material[] stairMat = {plainsVillagePopulator.woodStairs}; if (builder.getVariant() == PlainsVillageHouseVariant.CLAY) { - solidMat = new Material[]{Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE}; - stairMat = new Material[]{Material.COBBLESTONE_STAIRS, Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS}; + solidMat = new Material[] {Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE}; + stairMat = new Material[] { + Material.COBBLESTONE_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_COBBLESTONE_STAIRS + }; } // Pass One, handle the general shape of the roof @@ -225,10 +249,15 @@ public static void placeStandardRoof(@NotNull PlainsVillagePopulator plainsVilla for (int depth = -2; depth <= 0; depth++) { int[] lowerCorner = piece.getRoom().getLowerCorner(depth); int[] upperCorner = piece.getRoom().getUpperCorner(depth); - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) - data.setType(x, piece.getRoom().getY() + piece.getRoom().getHeight() + 3 + depth, z, - GenUtils.randChoice(solidMat)); + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + data.setType(x, + piece.getRoom().getY() + piece.getRoom().getHeight() + 3 + depth, + z, + GenUtils.randChoice(solidMat) + ); + } + } } } @@ -238,12 +267,17 @@ public static void placeStandardRoof(@NotNull PlainsVillagePopulator plainsVilla for (int depth = -2; depth <= 0; depth++) { int[] lowerCorner = piece.getRoom().getLowerCorner(depth); int[] upperCorner = piece.getRoom().getUpperCorner(depth); - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - SimpleBlock target = new SimpleBlock(data, x, piece.getRoom().getY() + piece.getRoom().getHeight() + 3 + depth, z); + SimpleBlock target = new SimpleBlock(data, + x, + piece.getRoom().getY() + piece.getRoom().getHeight() + 3 + depth, + z + ); if (target.getType() != Material.COBBLESTONE - && target.getType() != plainsVillagePopulator.woodPlank - && target.getType() != Material.MOSSY_COBBLESTONE) { + && target.getType() != plainsVillagePopulator.woodPlank + && target.getType() != Material.MOSSY_COBBLESTONE) + { // BlockUtils.correctSurroundingStairData(target); continue; } @@ -251,15 +285,14 @@ public static void placeStandardRoof(@NotNull PlainsVillagePopulator plainsVilla for (BlockFace face : BlockUtils.directBlockFaces) { if (!target.getRelative(face).isSolid()) { - new StairBuilder(stairMat) - .setFacing(face.getOppositeFace()) - .apply(target); + new StairBuilder(stairMat).setFacing(face.getOppositeFace()).apply(target); BlockUtils.correctSurroundingStairData(target); break; // exposedFaces.add(face); } } } + } } } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageStandardPiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageStandardPiece.java index 4aea0791..cadaa8fb 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageStandardPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageStandardPiece.java @@ -20,7 +20,15 @@ public class PlainsVillageStandardPiece extends JigsawStructurePiece { final PlainsVillageHouseVariant variant; final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageStandardPiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant variant, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + + public PlainsVillageStandardPiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant variant, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.variant = variant; this.plainsVillagePopulator = plainsVillagePopulator; @@ -32,25 +40,25 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { int[] upperCorner = this.getRoom().getUpperCorner(0); // Place flooring. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setType(x, this.getRoom().getY(), z, - GenUtils.randChoice( - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.MOSSY_STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - )); - new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)) - .downUntilSolid(rand, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.MOSSY_STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - ); + data.setType(x, this.getRoom().getY(), z, GenUtils.randChoice( + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + )); + new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)).downUntilSolid( + rand, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } + } } @Override @@ -58,10 +66,11 @@ public void postBuildDecoration(Random random, @NotNull PopulatorDataAbstract da int[] lowerCorner = this.getRoom().getLowerCorner(0); int[] upperCorner = this.getRoom().getUpperCorner(0); // Raise ceiling. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { data.setType(x, this.getRoom().getY() + 4, z, Material.AIR); } + } // Fix weird walling for standard roofs. for (BlockFace face : this.getWalledFaces()) { @@ -99,7 +108,8 @@ private void genLanterns(@NotNull PopulatorDataAbstract data, int x, int z) { Lantern lantern = (Lantern) Bukkit.createBlockData(Material.LANTERN); lantern.setHanging(true); w.setBlockData(lantern); - } else { + } + else { w.setType(Material.CHAIN); w = w.getDown(); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageWallPiece.java b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageWallPiece.java index f2825189..81b56956 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageWallPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/house/PlainsVillageWallPiece.java @@ -22,7 +22,15 @@ public class PlainsVillageWallPiece extends JigsawStructurePiece { final PlainsVillageHouseVariant var; final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageWallPiece(PlainsVillagePopulator plainsVillagePopulator, PlainsVillageHouseVariant var, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + + public PlainsVillageWallPiece(PlainsVillagePopulator plainsVillagePopulator, + PlainsVillageHouseVariant var, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.var = var; this.plainsVillagePopulator = plainsVillagePopulator; @@ -38,10 +46,12 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.Pillar(2, rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - if (this.var == PlainsVillageHouseVariant.CLAY) + if (this.var == PlainsVillageHouseVariant.CLAY) { w.getUp(2).Pillar(2, rand, Material.WHITE_TERRACOTTA); - else + } + else { w.getUp(2).Pillar(2, rand, plainsVillagePopulator.woodPlank); + } w = w.getLeft(); } @@ -60,25 +70,21 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { // Variant Cobblestone if (var == PlainsVillageHouseVariant.COBBLESTONE) { - slabType = new Material[]{Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB}; - fenceType = new Material[]{Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL}; - baseType = new Material[]{plainsVillagePopulator.woodLog}; - stairType = new Material[]{plainsVillagePopulator.woodStairs}; - } else if (var == PlainsVillageHouseVariant.CLAY) { + slabType = new Material[] {Material.COBBLESTONE_SLAB, Material.MOSSY_COBBLESTONE_SLAB}; + fenceType = new Material[] {Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL}; + baseType = new Material[] {plainsVillagePopulator.woodLog}; + stairType = new Material[] {plainsVillagePopulator.woodStairs}; + } + else if (var == PlainsVillageHouseVariant.CLAY) { slabType = BlockUtils.stoneBrickSlabs; - fenceType = new Material[]{Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL}; - baseType = new Material[]{plainsVillagePopulator.woodStrippedLog}; - stairType = new Material[]{plainsVillagePopulator.woodStairs}; + fenceType = new Material[] {Material.STONE_BRICK_WALL, Material.MOSSY_STONE_BRICK_WALL}; + baseType = new Material[] {plainsVillagePopulator.woodStrippedLog}; + stairType = new Material[] {plainsVillagePopulator.woodStairs}; } - new SlabBuilder(slabType) - .setType(Slab.Type.TOP) - .apply(w.getUp(2)); + new SlabBuilder(slabType).setType(Slab.Type.TOP).apply(w.getUp(2)); - new SlabBuilder(slabType) - .setType(Slab.Type.BOTTOM) - .apply(w.getUp(2).getLeft()) - .apply(w.getUp(2).getRight()); + new SlabBuilder(slabType).setType(Slab.Type.BOTTOM).apply(w.getUp(2).getLeft()).apply(w.getUp(2).getRight()); w.getUp().getLeft().setType(fenceType); w.getUp().getLeft().CorrectMultipleFacing(1); @@ -95,9 +101,9 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { trapdoor.setOpen(true); w.getFront().setBlockData(trapdoor); BlockUtils.pickFlower().build(w.getUp()); - } else { // Stairs - new StairBuilder(stairType).setFacing(w.getDirection().getOppositeFace()) - .apply(w); + } + else { // Stairs + new StairBuilder(stairType).setFacing(w.getDirection().getOppositeFace()).apply(w); } w.getLeft().getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleClericAltarPiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleClericAltarPiece.java index 7d0ea7f1..8c4aeb42 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleClericAltarPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleClericAltarPiece.java @@ -19,77 +19,86 @@ public class PlainsVillageTempleClericAltarPiece extends PlainsVillageTempleStandardPiece { - PlainsVillageTempleJigsawBuilder builder; - public PlainsVillageTempleClericAltarPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, boolean unique, PlainsVillageTempleJigsawBuilder builder, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, unique, validDirs); - this.builder = builder; - } - - private static final Material[] stairTypes = { - Material.POLISHED_GRANITE_STAIRS, - Material.POLISHED_ANDESITE_STAIRS, - Material.POLISHED_DIORITE_STAIRS, - Material.STONE_BRICK_STAIRS - }; - - @Override - public @NotNull JigsawStructurePiece getInstance(@NotNull Random rand, int depth) { - PlainsVillageTempleClericAltarPiece p = (PlainsVillageTempleClericAltarPiece) super.getInstance(rand, depth); - p.builder = this.builder; - return p; - } - - @Override + private static final Material[] stairTypes = { + Material.POLISHED_GRANITE_STAIRS, + Material.POLISHED_ANDESITE_STAIRS, + Material.POLISHED_DIORITE_STAIRS, + Material.STONE_BRICK_STAIRS + }; + PlainsVillageTempleJigsawBuilder builder; + + public PlainsVillageTempleClericAltarPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + PlainsVillageTempleJigsawBuilder builder, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, unique, validDirs); + this.builder = builder; + } + + @Override + public @NotNull JigsawStructurePiece getInstance(@NotNull Random rand, int depth) { + PlainsVillageTempleClericAltarPiece p = (PlainsVillageTempleClericAltarPiece) super.getInstance(rand, depth); + p.builder = this.builder; + return p; + } + + @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { super.postBuildDecoration(random, data); - + Material stairType = stairTypes[random.nextInt(stairTypes.length)]; - - SimpleBlock core = new SimpleBlock(data,this.getRoom().getX(),this.getRoom().getY()+1,this.getRoom().getZ()); - + + SimpleBlock core = new SimpleBlock(data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ()); + BlockFace dir = this.builder.getEntranceDirection(); - - if(dir == null) - dir = BlockUtils.getDirectBlockFace(random); - + + if (dir == null) { + dir = BlockUtils.getDirectBlockFace(random); + } + core.setType(Material.CHISELED_STONE_BRICKS); core.getUp().setType(Material.BREWING_STAND); - - for(Entry entry:this.getRoom().getFourWalls(data, 0).entrySet()) { - Wall w = entry.getKey().getDown(); - for(int i = 0; i < entry.getValue(); i++) { - w.getUp().setType(Material.AIR); - - new StairBuilder(stairType) - .setFacing(w.getDirection().getOppositeFace()) - .setWaterlogged(true) - .apply(w); - - if(!Tag.STAIRS.isTagged(w.getFront().getType())) { - w.getFront().getUp().setType(Material.AIR); - w.getFront().setType(Material.WATER); - w.getFront().getDown().setType(Material.CHISELED_STONE_BRICKS); - - // Sometimes the pond will have corals. - if(random.nextBoolean()) - w.getFront().setType(CoralGenerator.CORAL_FANS); - } - - w = w.getLeft(); - } + + for (Entry entry : this.getRoom().getFourWalls(data, 0).entrySet()) { + Wall w = entry.getKey().getDown(); + for (int i = 0; i < entry.getValue(); i++) { + w.getUp().setType(Material.AIR); + + new StairBuilder(stairType).setFacing(w.getDirection().getOppositeFace()).setWaterlogged(true).apply(w); + + if (!Tag.STAIRS.isTagged(w.getFront().getType())) { + w.getFront().getUp().setType(Material.AIR); + w.getFront().setType(Material.WATER); + w.getFront().getDown().setType(Material.CHISELED_STONE_BRICKS); + + // Sometimes the pond will have corals. + if (random.nextBoolean()) { + w.getFront().setType(CoralGenerator.CORAL_FANS); + } + } + + w = w.getLeft(); + } } - - new StairBuilder(Material.COBBLESTONE_STAIRS,Material.STONE_BRICK_STAIRS) - .setFacing(dir.getOppositeFace()) - .apply(core.getRelative(dir)); - + + new StairBuilder(Material.COBBLESTONE_STAIRS, Material.STONE_BRICK_STAIRS).setFacing(dir.getOppositeFace()) + .apply(core.getRelative(dir)); + core.getDown().setType(Material.STONE_BRICKS); core.getRelative(dir).getDown().setType(Material.STONE_BRICKS); - core.getRelative(dir,2).getDown().setType(Material.STONE_BRICKS); - - for(int[] corner :this.getRoom().getAllCorners()) { - data.setType(corner[0], getRoom().getY(), corner[1], Material.CHISELED_STONE_BRICKS); - data.setType(corner[0], getRoom().getY()+1, corner[1], Material.LANTERN); + core.getRelative(dir, 2).getDown().setType(Material.STONE_BRICKS); + + for (int[] corner : this.getRoom().getAllCorners()) { + data.setType(corner[0], getRoom().getY(), corner[1], Material.CHISELED_STONE_BRICKS); + data.setType(corner[0], getRoom().getY() + 1, corner[1], Material.LANTERN); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleEntrancePiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleEntrancePiece.java index c348b672..521ccdce 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleEntrancePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleEntrancePiece.java @@ -19,15 +19,27 @@ public class PlainsVillageTempleEntrancePiece extends JigsawStructurePiece { - final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageTempleEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageTempleEntrancePiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.plainsVillagePopulator = plainsVillagePopulator; } @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { - Material[] stoneBricks = {Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + Material[] stoneBricks = { + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + }; SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); @@ -41,43 +53,54 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { } // Carve Doorway - Wall core = new Wall(new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()), this.getRotation()); + Wall core = new Wall(new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ), this.getRotation()); core = core.getRear(2); - BlockUtils.placeDoor(data, plainsVillagePopulator.woodDoor, core.getX(), core.getY(), core.getZ(), core.getDirection()); + BlockUtils.placeDoor( + data, + plainsVillagePopulator.woodDoor, + core.getX(), + core.getY(), + core.getZ(), + core.getDirection() + ); // Stairway down - if(core.getFront().isSolid()) { - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .setStairwayDirection(BlockFace.UP) - .build(core.getFront(3)); - core.getFront().Pillar(2, rand, Material.AIR); - core.getFront(2).Pillar(3, rand, Material.AIR); - }else - new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS) - .setAngled(true) - .setStopAtWater(true) - .build(core.getFront().getDown()); + if (core.getFront().isSolid()) { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .setStairwayDirection( + BlockFace.UP) + .build(core.getFront(3)); + core.getFront().Pillar(2, rand, Material.AIR); + core.getFront(2).Pillar(3, rand, Material.AIR); + } + else { + new StairwayBuilder(Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS).setAngled(true) + .setStopAtWater(true) + .build(core.getFront() + .getDown()); + } // Decorate Doorway with some details - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setHalf(Half.TOP) - .setFacing(core.getDirection().getOppositeFace()) - .apply(core.getFront().getUp(2)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setHalf(Half.TOP) + .setFacing(core.getDirection().getOppositeFace()) + .apply(core.getFront().getUp(2)); core.getFront().getUp(3).setType(Material.CHISELED_STONE_BRICKS); Wall doorAdj = core.getFront().getRight(); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(doorAdj.getDirection().getOppositeFace()) - .apply(doorAdj.getUp()); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(doorAdj.getDirection().getOppositeFace()) + .apply(doorAdj.getUp()); doorAdj.downUntilSolid(rand, stoneBricks); doorAdj = core.getFront().getLeft(); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(doorAdj.getDirection().getOppositeFace()) - .apply(doorAdj.getUp()); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(doorAdj.getDirection().getOppositeFace()) + .apply(doorAdj.getUp()); doorAdj.downUntilSolid(rand, stoneBricks); diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java index 716947a1..bc616a43 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java @@ -19,149 +19,220 @@ public class PlainsVillageTempleJigsawBuilder extends JigsawBuilder { - final PlainsVillagePopulator plainsVillagePopulator; - public PlainsVillageTempleJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, int widthX, int widthZ, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + final PlainsVillagePopulator plainsVillagePopulator; + + public PlainsVillageTempleJigsawBuilder(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int widthZ, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { super(widthX, widthZ, data, x, y, z); this.plainsVillagePopulator = plainsVillagePopulator; - this.pieceRegistry = new JigsawStructurePiece[]{ - new PlainsVillageTempleLoungePiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), - new PlainsVillageTempleRelicPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, true, BlockUtils.directBlockFaces), - new PlainsVillageTempleLootPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, BlockUtils.directBlockFaces), + this.pieceRegistry = new JigsawStructurePiece[] { + new PlainsVillageTempleLoungePiece( + plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), + new PlainsVillageTempleRelicPiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + true, + BlockUtils.directBlockFaces + ), + new PlainsVillageTempleLootPiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + BlockUtils.directBlockFaces + ), new PlainsVillageTempleWallPiece(5, 3, 5, JigsawType.END, BlockUtils.directBlockFaces), - new PlainsVillageTempleEntrancePiece(plainsVillagePopulator, 5, 3, 5, JigsawType.ENTRANCE, BlockUtils.directBlockFaces) + new PlainsVillageTempleEntrancePiece(plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.ENTRANCE, + BlockUtils.directBlockFaces + ) }; this.chanceToAddNewPiece = 50; } - + + /** + * Refers to walls that are parallel and directly connected are in the form: + * __ + */ + protected static boolean hasAdjacentWall(@NotNull JigsawStructurePiece piece, + @NotNull BlockFace face, + @NotNull ArrayList overlapperPieces) + { + for (JigsawStructurePiece other : overlapperPieces) { + if (other.getRoom().getSimpleLocation().equals(piece.getRoom().getSimpleLocation().getRelative(face, 5))) { + if (other.getRotation() == piece.getRotation()) { + return true; + } + } + } + return false; + } + + /** + * Refers to walls that are directly connected and perpendicular on the same location. + * I.e. the wall must turn inwards instead of outwards (NORTH and WEST facing walls connected) + */ + protected static boolean hasAdjacentInwardWall(@NotNull JigsawStructurePiece piece, + @NotNull BlockFace face, + @NotNull ArrayList overlapperPieces) + { + + for (JigsawStructurePiece other : overlapperPieces) { + if (other.getRoom().getSimpleLocation().equals(piece.getRoom().getSimpleLocation())) { + if (other.getRotation() == face.getOppositeFace()) { + return true; + } + } + } + return false; + } + @Override public @NotNull JigsawStructurePiece getFirstPiece(@NotNull Random random) { - return new PlainsVillageTempleClericAltarPiece(plainsVillagePopulator, 5, 3, 5, JigsawType.STANDARD, true, this, BlockUtils.directBlockFaces); - // return getPiece(pieceRegistry, JigsawType.STANDARD, random).getInstance(random, 0); + return new PlainsVillageTempleClericAltarPiece( + plainsVillagePopulator, + 5, + 3, + 5, + JigsawType.STANDARD, + true, + this, + BlockUtils.directBlockFaces + ); + // return getPiece(pieceRegistry, JigsawType.STANDARD, random).getInstance(random, 0); } @Override public void build(@NotNull Random random) { - if ( !TConfigOption.areStructuresEnabled()) return; + if (!TConfigOption.areStructuresEnabled()) { + return; + } super.build(random); // Make sure awkward corners are fixed for (JigsawStructurePiece piece : this.pieces.values()) { - SimpleBlock core = new SimpleBlock( - this.core.getPopData(), + SimpleBlock core = new SimpleBlock(this.core.getPopData(), piece.getRoom().getX(), piece.getRoom().getY(), - piece.getRoom().getZ()); + piece.getRoom().getZ() + ); Wall target; - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // nw + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // nw target = new Wall(core.getRelative(-3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.WEST); } - if (piece.getWalledFaces().contains(BlockFace.NORTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // ne + if (piece.getWalledFaces().contains(BlockFace.NORTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // ne target = new Wall(core.getRelative(3, 0, -3)); decorateAwkwardCorner(target, random, BlockFace.NORTH, BlockFace.EAST); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.WEST)) { // sw + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.WEST)) + { // sw target = new Wall(core.getRelative(-3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.WEST); } - if (piece.getWalledFaces().contains(BlockFace.SOUTH) - && piece.getWalledFaces().contains(BlockFace.EAST)) { // se + if (piece.getWalledFaces().contains(BlockFace.SOUTH) && piece.getWalledFaces() + .contains(BlockFace.EAST)) + { // se target = new Wall(core.getRelative(3, 0, 3)); decorateAwkwardCorner(target, random, BlockFace.SOUTH, BlockFace.EAST); } } - + // Declare one of the pieces a tower int randIndex = random.nextInt(this.pieces.size()); int i = 0; - for(JigsawStructurePiece p:this.pieces.values()) { - if(i == randIndex) { - ((PlainsVillageTempleStandardPiece) p).setTower(true); - // break; - } + for (JigsawStructurePiece p : this.pieces.values()) { + if (i == randIndex) { + ((PlainsVillageTempleStandardPiece) p).setTower(true); + // break; + } } - + // Place roofing - for(JigsawStructurePiece piece:overlapperPieces) { - PlainsVillageTempleRoofHandler.handleTempleRoof(plainsVillagePopulator, this.core.getPopData(), piece, overlapperPieces); + for (JigsawStructurePiece piece : overlapperPieces) { + PlainsVillageTempleRoofHandler.handleTempleRoof( + plainsVillagePopulator, + this.core.getPopData(), + piece, + overlapperPieces + ); } - + // Try to place large windows between pairs of walls - for(JigsawStructurePiece wallPiece:overlapperPieces) { - for(BlockFace face:BlockUtils.getAdjacentFaces(wallPiece.getRotation())) { - if(hasAdjacentWall(wallPiece, face, overlapperPieces)) { - PlainsVillageTempleWallPiece - .setLargeWindow(this.core.getPopData(),wallPiece.getRotation(), wallPiece.getRoom(), face); - } - } + for (JigsawStructurePiece wallPiece : overlapperPieces) { + for (BlockFace face : BlockUtils.getAdjacentFaces(wallPiece.getRotation())) { + if (hasAdjacentWall(wallPiece, face, overlapperPieces)) { + PlainsVillageTempleWallPiece.setLargeWindow( + this.core.getPopData(), + wallPiece.getRotation(), + wallPiece.getRoom(), + face + ); + } + } } - + PlainsVillageTempleRoofHandler.placeCeilingTerracotta(this.core.getPopData(), this.pieces.values()); - + // Decorate rooms and walls for (JigsawStructurePiece piece : this.pieces.values()) { piece.postBuildDecoration(random, this.core.getPopData()); } } - - /** - * Refers to walls that are parallel and directly connected are in the form: - * __ - */ - protected static boolean hasAdjacentWall(@NotNull JigsawStructurePiece piece, @NotNull BlockFace face, @NotNull ArrayList overlapperPieces) { - for(JigsawStructurePiece other:overlapperPieces) { - if(other.getRoom().getSimpleLocation() - .equals(piece.getRoom().getSimpleLocation().getRelative(face,5))) { - if(other.getRotation() == piece.getRotation()) - return true; - } - } - return false; - } - - /** - * Refers to walls that are directly connected and perpendicular on the same location. - * I.e. the wall must turn inwards instead of outwards (NORTH and WEST facing walls connected) - */ - protected static boolean hasAdjacentInwardWall(@NotNull JigsawStructurePiece piece, @NotNull BlockFace face, @NotNull ArrayList overlapperPieces) { - - for(JigsawStructurePiece other:overlapperPieces) { - if(other.getRoom().getSimpleLocation() - .equals(piece.getRoom().getSimpleLocation())) { - if(other.getRotation() == face.getOppositeFace()) - return true; - } - } - return false; - } - public void decorateAwkwardCorner(@NotNull Wall target, @NotNull Random random, @NotNull BlockFace one, @NotNull BlockFace two) { + public void decorateAwkwardCorner(@NotNull Wall target, + @NotNull Random random, + @NotNull BlockFace one, + @NotNull BlockFace two) + { Material[] cobblestone = {Material.COBBLESTONE, Material.MOSSY_COBBLESTONE}; - Material[] stoneBricks = {Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + Material[] stoneBricks = { + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + }; // Corner and corner spires target.Pillar(5, random, BlockUtils.stoneBricks); - + target.getDown().downUntilSolid(random, cobblestone); target = target.getUp(); // Areas next to the corner. Decorative. target.getRelative(one).Pillar(3, random, stoneBricks); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(one.getOppositeFace()) - .apply(target.getRelative(one).getUp(3)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(one.getOppositeFace()) + .apply(target.getRelative(one).getUp(3)); target.getRelative(two).Pillar(3, random, stoneBricks); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(two.getOppositeFace()) - .apply(target.getRelative(two).getUp(3)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(two.getOppositeFace()) + .apply(target.getRelative(two).getUp(3)); // Solid platform underneath in case of uneven ground. target = target.getDown(); diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLootPiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLootPiece.java index 8c47f9d7..19e25eda 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLootPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLootPiece.java @@ -16,28 +16,33 @@ public class PlainsVillageTempleLootPiece extends PlainsVillageTempleStandardPiece { - public PlainsVillageTempleLootPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); - } - - - @Override + public PlainsVillageTempleLootPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); + } + + + @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { - super.postBuildDecoration(random,data); - for(BlockFace face:this.getWalledFaces()) { - SimpleEntry entry = this.getRoom().getWall(data, face, 0); - Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) { - if(GenUtils.chance(random,1,5) && w.getRear().getType() != plainsVillagePopulator.woodDoor) { - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.VILLAGE_TEMPLE) - .apply(w); - } - w = w.getLeft(); - } - } - - } + super.postBuildDecoration(random, data); + for (BlockFace face : this.getWalledFaces()) { + SimpleEntry entry = this.getRoom().getWall(data, face, 0); + Wall w = entry.getKey(); + for (int i = 0; i < entry.getValue(); i++) { + if (GenUtils.chance(random, 1, 5) && w.getRear().getType() != plainsVillagePopulator.woodDoor) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.VILLAGE_TEMPLE) + .apply(w); + } + w = w.getLeft(); + } + } + + } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java index a4c031a9..e52d139e 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java @@ -15,38 +15,48 @@ public class PlainsVillageTempleLoungePiece extends PlainsVillageTempleStandardPiece { - public PlainsVillageTempleLoungePiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); - } - - private static final Material[] stairTypes = { - Material.POLISHED_GRANITE_STAIRS, - Material.POLISHED_ANDESITE_STAIRS, - Material.POLISHED_DIORITE_STAIRS - }; - - @Override + private static final Material[] stairTypes = { + Material.POLISHED_GRANITE_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.POLISHED_DIORITE_STAIRS + }; + + public PlainsVillageTempleLoungePiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, validDirs); + } + + @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { super.postBuildDecoration(random, data); Material stairType = stairTypes[random.nextInt(stairTypes.length)]; - SimpleBlock core = new SimpleBlock(data, this.getRoom().getX(), this.getRoom().getY() + 1, this.getRoom().getZ()); + SimpleBlock core = new SimpleBlock( + data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ() + ); - for(BlockFace face : BlockUtils.getRandomBlockfaceAxis(random)) { + for (BlockFace face : BlockUtils.getRandomBlockfaceAxis(random)) { - new StairBuilder(stairType) - .setFacing(face) - .apply(core.getRelative(face).getRelative(BlockUtils.getAdjacentFaces(face)[0])) - .apply(core.getRelative(face).getRelative(BlockUtils.getAdjacentFaces(face)[1])); + new StairBuilder(stairType).setFacing(face) + .apply(core.getRelative(face).getRelative(BlockUtils.getAdjacentFaces(face)[0])) + .apply(core.getRelative(face).getRelative(BlockUtils.getAdjacentFaces(face)[1])); } - if(TConfigOption.areDecorationsEnabled()) { + if (TConfigOption.areDecorationsEnabled()) { core.setType(plainsVillagePopulator.woodLog, Material.CRAFTING_TABLE, plainsVillagePopulator.woodPlank); - if(!TConfigOption.arePlantsEnabled() || random.nextBoolean()) + if (!TConfigOption.arePlantsEnabled() || random.nextBoolean()) { core.getUp().setType(Material.LANTERN); - else + } + else { BlockUtils.pickPottedPlant().build(core.getUp()); + } } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRelicPiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRelicPiece.java index 18df6bb5..1302552b 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRelicPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRelicPiece.java @@ -14,25 +14,17 @@ public class PlainsVillageTempleRelicPiece extends PlainsVillageTempleStandardPiece { - public PlainsVillageTempleRelicPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, boolean unique, BlockFace[] validDirs) { - super(plainsVillagePopulator, widthX, height, widthZ, type, unique, validDirs); - } - - private static final Material[] stairTypes = { - Material.POLISHED_GRANITE_STAIRS, - Material.POLISHED_ANDESITE_STAIRS, - Material.POLISHED_DIORITE_STAIRS - }; - - private static final Material[] slabTypes = { - Material.POLISHED_GRANITE_SLAB, - Material.POLISHED_ANDESITE_SLAB, - Material.POLISHED_DIORITE_SLAB, - Material.SMOOTH_STONE_SLAB - }; - - private static final Material[] relics = { - Material.EMERALD_BLOCK, + private static final Material[] stairTypes = { + Material.POLISHED_GRANITE_STAIRS, Material.POLISHED_ANDESITE_STAIRS, Material.POLISHED_DIORITE_STAIRS + }; + private static final Material[] slabTypes = { + Material.POLISHED_GRANITE_SLAB, + Material.POLISHED_ANDESITE_SLAB, + Material.POLISHED_DIORITE_SLAB, + Material.SMOOTH_STONE_SLAB + }; + private static final Material[] relics = { + Material.EMERALD_BLOCK, Material.WHITE_GLAZED_TERRACOTTA, Material.BLACK_GLAZED_TERRACOTTA, Material.BLUE_GLAZED_TERRACOTTA, @@ -50,23 +42,35 @@ public PlainsVillageTempleRelicPiece(PlainsVillagePopulator plainsVillagePopulat Material.RED_GLAZED_TERRACOTTA, Material.YELLOW_GLAZED_TERRACOTTA, Material.GOLD_BLOCK - }; - - @Override + }; + + public PlainsVillageTempleRelicPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + BlockFace[] validDirs) + { + super(plainsVillagePopulator, widthX, height, widthZ, type, unique, validDirs); + } + + @Override public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAbstract data) { super.postBuildDecoration(random, data); - + Material stairType = stairTypes[random.nextInt(stairTypes.length)]; Material slab = slabTypes[random.nextInt(slabTypes.length)]; - - SimpleBlock core = new SimpleBlock(data,this.getRoom().getX(),this.getRoom().getY()+1,this.getRoom().getZ()); - for(BlockFace face:BlockUtils.directBlockFaces) { - new StairBuilder(stairType) - .setFacing(face.getOppositeFace()) - .apply(core.getRelative(face)); + + SimpleBlock core = new SimpleBlock(data, + this.getRoom().getX(), + this.getRoom().getY() + 1, + this.getRoom().getZ()); + for (BlockFace face : BlockUtils.directBlockFaces) { + new StairBuilder(stairType).setFacing(face.getOppositeFace()).apply(core.getRelative(face)); } - for(BlockFace face:BlockUtils.xzDiagonalPlaneBlockFaces) { - core.getRelative(face).setType(slab); + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + core.getRelative(face).setType(slab); } core.getUp().setType(relics[random.nextInt(relics.length)]); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRoofHandler.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRoofHandler.java index 5530b769..562086b8 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRoofHandler.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleRoofHandler.java @@ -21,122 +21,142 @@ import java.util.Random; public class PlainsVillageTempleRoofHandler { - // private static final Material[] stoneBricks = {Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; - - public static void handleTempleRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, @NotNull PopulatorDataAbstract data, @NotNull JigsawStructurePiece piece, @NotNull ArrayList wallPieces) { - Wall base = new Wall(new SimpleBlock(data, - piece.getRoom().getX(), - piece.getRoom().getY()+5, - piece.getRoom().getZ()),piece.getRotation()); - for(BlockFace face:BlockUtils.getAdjacentFaces(piece.getRotation())) { - int multiplier; - - if(PlainsVillageTempleJigsawBuilder.hasAdjacentWall(piece, face, wallPieces)) { - multiplier = 0;// Wall leads to another wall, so all segments are equal - }else if(PlainsVillageTempleJigsawBuilder.hasAdjacentInwardWall(piece, face, wallPieces)){ - multiplier = 1; // Wall leads to inwards turn, so segments are increasing - }else { - multiplier = -1; // Wall leads to a corner, so segments are decreasing (slant up) - - } - - for(int height = 0; height < 3; height++) { - for(int horDepth = 0; horDepth < 3+height*multiplier; horDepth++) { - Wall w = base.getRelative(face, horDepth); - new StairBuilder(Material.COBBLESTONE_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w.getRear(height+2).getRelative(0,height*2,0)) - .correct(); - - // Add tiny spikes at the sides of corners - if(multiplier == -1 && horDepth == 2+height*multiplier) { - Wall pillar = w.getRelative(face).getRear(height+2).getRelative(0,height*2,0); - pillar.Pillar(3,new Random(),Material.COBBLESTONE_WALL,Material.COBBLESTONE_WALL,Material.COBBLESTONE_WALL,Material.MOSSY_COBBLESTONE_WALL); - pillar.setType(Material.CHISELED_STONE_BRICKS); - - // Add lantern decorations to the interior corners - // if(height != 0) { - pillar = w.getRear(height+3).getRelative(0,(height+1)*2,0); - pillar.getDown(2).setType(plainsVillagePopulator.woodLog); - Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); - l.setHanging(true); - pillar.getDown(3).setBlockData(l); - // } - }else if(multiplier == 1 && horDepth == 2+height*multiplier) { - Wall pillar = w.getRelative(face,1).getRear(height+3).getRelative(0,(height+1)*2,0); - // Add lantern decorations to the interior corners - pillar.getDown().get().lsetType(plainsVillagePopulator.woodLog); - pillar.getDown(2).setType(plainsVillagePopulator.woodLog); - Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); - l.setHanging(true); - pillar.getDown(3).setBlockData(l); - } - - // Don't place stairs where the roof ends. - if(height != 2) - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(w.getDirection()) - .setHalf(Half.TOP) - .lapply(w.getRear(height+3).getRelative(0,height*2,0)) - .correct(); - else - new OrientableBuilder(plainsVillagePopulator.woodLog) - .setAxis(BlockUtils.getAxisFromBlockFace(face)) - .lapply(w.getRear(height+3).getRelative(0,height*2,0)); - - - - w.getRelative(0,height*2+1,0).getRear(height+3).setType(Material.POLISHED_ANDESITE); - } - } - - // Do more corner related cleaning and decorations + // private static final Material[] stoneBricks = {Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + + public static void handleTempleRoof(@NotNull PlainsVillagePopulator plainsVillagePopulator, + @NotNull PopulatorDataAbstract data, + @NotNull JigsawStructurePiece piece, + @NotNull ArrayList wallPieces) + { + Wall base = new Wall(new SimpleBlock(data, + piece.getRoom().getX(), + piece.getRoom().getY() + 5, + piece.getRoom().getZ() + ), piece.getRotation()); + for (BlockFace face : BlockUtils.getAdjacentFaces(piece.getRotation())) { + int multiplier; + + if (PlainsVillageTempleJigsawBuilder.hasAdjacentWall(piece, face, wallPieces)) { + multiplier = 0;// Wall leads to another wall, so all segments are equal + } + else if (PlainsVillageTempleJigsawBuilder.hasAdjacentInwardWall(piece, face, wallPieces)) { + multiplier = 1; // Wall leads to inwards turn, so segments are increasing + } + else { + multiplier = -1; // Wall leads to a corner, so segments are decreasing (slant up) + + } + + for (int height = 0; height < 3; height++) { + for (int horDepth = 0; horDepth < 3 + height * multiplier; horDepth++) { + Wall w = base.getRelative(face, horDepth); + new StairBuilder(Material.COBBLESTONE_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w.getRear(height + 2) + .getRelative(0, height * 2, 0)) + .correct(); + + // Add tiny spikes at the sides of corners + if (multiplier == -1 && horDepth == 2 + height * multiplier) { + Wall pillar = w.getRelative(face).getRear(height + 2).getRelative(0, height * 2, 0); + pillar.Pillar(3, + new Random(), + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL); + pillar.setType(Material.CHISELED_STONE_BRICKS); + + // Add lantern decorations to the interior corners + // if(height != 0) { + pillar = w.getRear(height + 3).getRelative(0, (height + 1) * 2, 0); + pillar.getDown(2).setType(plainsVillagePopulator.woodLog); + Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); + l.setHanging(true); + pillar.getDown(3).setBlockData(l); + // } + } + else if (multiplier == 1 && horDepth == 2 + height * multiplier) { + Wall pillar = w.getRelative(face, 1).getRear(height + 3).getRelative(0, (height + 1) * 2, 0); + // Add lantern decorations to the interior corners + pillar.getDown().get().lsetType(plainsVillagePopulator.woodLog); + pillar.getDown(2).setType(plainsVillagePopulator.woodLog); + Lantern l = (Lantern) Bukkit.createBlockData(Material.LANTERN); + l.setHanging(true); + pillar.getDown(3).setBlockData(l); + } + + // Don't place stairs where the roof ends. + if (height != 2) { + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(w.getDirection()) + .setHalf(Half.TOP) + .lapply(w.getRear(height + 3) + .getRelative(0, height * 2, 0)) + .correct(); + } + else { + new OrientableBuilder(plainsVillagePopulator.woodLog).setAxis(BlockUtils.getAxisFromBlockFace( + face)).lapply(w.getRear(height + 3).getRelative(0, height * 2, 0)); + } + + + w.getRelative(0, height * 2 + 1, 0).getRear(height + 3).setType(Material.POLISHED_ANDESITE); + } + } + + // Do more corner related cleaning and decorations } - } - - public static void placeCeilingTerracotta(@NotNull PopulatorDataAbstract data, @NotNull Collection structurePieces) { - Material glazedTerracotta = BlockUtils.GLAZED_TERRACOTTA[new Random().nextInt(BlockUtils.GLAZED_TERRACOTTA.length)]; - for(JigsawStructurePiece piece:structurePieces) { - int[] lowerCorner = piece.getRoom().getLowerCorner(); - int[] upperCorner = piece.getRoom().getUpperCorner(); - - for(int x = lowerCorner[0]; x <= upperCorner[0]; x++) - for(int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - SimpleBlock b = new SimpleBlock(data, x, piece.getRoom().getY()+1,z); - int i; - for(i = 0; i < 9; i++) { - if(!b.isSolid()) { - b = b.getUp(); - }else { - break; - } - } - - if(i == 9 && !b.isSolid()) { - placeGlazedTerracotta(b, glazedTerracotta); - b.getUp().setType(Material.POLISHED_ANDESITE); - } - } - } - } - + } + + public static void placeCeilingTerracotta(@NotNull PopulatorDataAbstract data, + @NotNull Collection structurePieces) + { + Material glazedTerracotta = BlockUtils.GLAZED_TERRACOTTA[new Random().nextInt(BlockUtils.GLAZED_TERRACOTTA.length)]; + for (JigsawStructurePiece piece : structurePieces) { + int[] lowerCorner = piece.getRoom().getLowerCorner(); + int[] upperCorner = piece.getRoom().getUpperCorner(); + + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { + for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { + SimpleBlock b = new SimpleBlock(data, x, piece.getRoom().getY() + 1, z); + int i; + for (i = 0; i < 9; i++) { + if (!b.isSolid()) { + b = b.getUp(); + } + else { + break; + } + } + + if (i == 9 && !b.isSolid()) { + placeGlazedTerracotta(b, glazedTerracotta); + b.getUp().setType(Material.POLISHED_ANDESITE); + } + } + } + } + } + private static void placeGlazedTerracotta(@NotNull SimpleBlock target, @NotNull Material glazedTerracotta) { BlockFace dir; - if(target.getX() % 2 == 0) { - if(target.getZ() % 2 == 0) - dir = BlockFace.SOUTH; - else - dir = BlockFace.WEST; - }else { - if(target.getZ() % 2 == 0) - dir = BlockFace.EAST; - else - dir = BlockFace.NORTH; - } - new DirectionalBuilder(glazedTerracotta) - .setFacing(dir) - .apply(target); + if (target.getX() % 2 == 0) { + if (target.getZ() % 2 == 0) { + dir = BlockFace.SOUTH; + } + else { + dir = BlockFace.WEST; + } + } + else { + if (target.getZ() % 2 == 0) { + dir = BlockFace.EAST; + } + else { + dir = BlockFace.NORTH; + } + } + new DirectionalBuilder(glazedTerracotta).setFacing(dir).apply(target); } - + } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStairway.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStairway.java index 7e90c95c..af482ca0 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStairway.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStairway.java @@ -18,7 +18,7 @@ public PlainsVillageTempleStairway(int widthX, int height, int widthZ, JigsawTyp @Override public void build(@NotNull PopulatorDataAbstract data, Random rand) { - this.getRoom().fillRoom(data, new Material[]{Material.YELLOW_STAINED_GLASS}); + this.getRoom().fillRoom(data, new Material[] {Material.YELLOW_STAINED_GLASS}); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStandardPiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStandardPiece.java index 501c3678..75c5545e 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStandardPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleStandardPiece.java @@ -16,15 +16,28 @@ public class PlainsVillageTempleStandardPiece extends JigsawStructurePiece { - private boolean isTower = false; - final PlainsVillagePopulator plainsVillagePopulator; + final PlainsVillagePopulator plainsVillagePopulator; + private boolean isTower = false; - public PlainsVillageTempleStandardPiece(PlainsVillagePopulator plainsVillagePopulator, int widthX, int height, int widthZ, JigsawType type, boolean unique, BlockFace[] validDirs) { + public PlainsVillageTempleStandardPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + boolean unique, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, unique, validDirs); this.plainsVillagePopulator = plainsVillagePopulator; } - - public PlainsVillageTempleStandardPiece(PlainsVillagePopulator plainsVillagePopulator,int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { + + public PlainsVillageTempleStandardPiece(PlainsVillagePopulator plainsVillagePopulator, + int widthX, + int height, + int widthZ, + JigsawType type, + BlockFace[] validDirs) + { super(widthX, height, widthZ, type, validDirs); this.plainsVillagePopulator = plainsVillagePopulator; } @@ -35,29 +48,29 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { int[] upperCorner = this.getRoom().getUpperCorner(0); // Place flooring. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - data.setType(x, this.getRoom().getY(), z, - GenUtils.randChoice( - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - )); - new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)) - .downUntilSolid(rand, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.STONE_BRICKS, - Material.CRACKED_STONE_BRICKS - ); + data.setType(x, this.getRoom().getY(), z, GenUtils.randChoice( + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + )); + new Wall(new SimpleBlock(data, x, this.getRoom().getY() - 1, z)).downUntilSolid( + rand, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } + } } @Override @@ -65,41 +78,46 @@ public void postBuildDecoration(Random random, @NotNull PopulatorDataAbstract da int[] lowerCorner = this.getRoom().getLowerCorner(0); int[] upperCorner = this.getRoom().getUpperCorner(0); -// int[] choices = {-2, -1, 0, 1, 2}; -// int[] steps = new int[3]; -// for (int i = 0; i < 3; i++) steps[i] = choices[random.nextInt(choices.length)]; -// Material other = BRIGHT_CARPETS.get(random.nextInt(BRIGHT_CARPETS.size())); + // int[] choices = {-2, -1, 0, 1, 2}; + // int[] steps = new int[3]; + // for (int i = 0; i < 3; i++) steps[i] = choices[random.nextInt(choices.length)]; + // Material other = BRIGHT_CARPETS.get(random.nextInt(BRIGHT_CARPETS.size())); // Place carpets. - for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) + for (int x = lowerCorner[0]; x <= upperCorner[0]; x++) { for (int z = lowerCorner[1]; z <= upperCorner[1]; z++) { - if(x % 2 == 0 && z % 2 == 0) - data.setType(x, getRoom().getY(), z, Material.TORCH); - - if(!data.getType(x, getRoom().getY()+1, z).isSolid()) { - boolean canPlace = true; - - // VILLAGERS CAN'T WALK THROUGH CARPETS FOR SOME FUCK REASON - // Don't place carpet if there's a door next to it. - for(BlockFace face:BlockUtils.directBlockFaces) { - if(data.getType(x+face.getModX(),getRoom().getY()+1,z+face.getModZ()) == plainsVillagePopulator.woodDoor) { - canPlace = false; - data.setType(x, getRoom().getY(), z, Material.WHITE_WOOL); - } - } - if(canPlace) - data.setType(x, getRoom().getY()+1, z, Material.WHITE_CARPET); - } + if (x % 2 == 0 && z % 2 == 0) { + data.setType(x, getRoom().getY(), z, Material.TORCH); + } + + if (!data.getType(x, getRoom().getY() + 1, z).isSolid()) { + boolean canPlace = true; + + // VILLAGERS CAN'T WALK THROUGH CARPETS FOR SOME FUCK REASON + // Don't place carpet if there's a door next to it. + for (BlockFace face : BlockUtils.directBlockFaces) { + if (data.getType(x + face.getModX(), getRoom().getY() + 1, z + face.getModZ()) + == plainsVillagePopulator.woodDoor) + { + canPlace = false; + data.setType(x, getRoom().getY(), z, Material.WHITE_WOOL); + } + } + if (canPlace) { + data.setType(x, getRoom().getY() + 1, z, Material.WHITE_CARPET); + } + } } - + } + // Commented out because it's ugly af // Random pattern on floor } - public boolean isTower() { - return isTower; - } + public boolean isTower() { + return isTower; + } - public void setTower(boolean isTower) { - this.isTower = isTower; - } + public void setTower(boolean isTower) { + this.isTower = isTower; + } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleTowerSpawner.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleTowerSpawner.java index 7684e077..dfcde53d 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleTowerSpawner.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleTowerSpawner.java @@ -4,11 +4,11 @@ public class PlainsVillageTempleTowerSpawner { - final SimpleBlock core; - public PlainsVillageTempleTowerSpawner(SimpleBlock core) { - this.core = core; - } - - - + final SimpleBlock core; + + public PlainsVillageTempleTowerSpawner(SimpleBlock core) { + this.core = core; + } + + } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleWallPiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleWallPiece.java index 69525763..035e1867 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleWallPiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleWallPiece.java @@ -33,22 +33,87 @@ public class PlainsVillageTempleWallPiece extends JigsawStructurePiece { add(Material.YELLOW_STAINED_GLASS_PANE); }}; - + public PlainsVillageTempleWallPiece(int widthX, int height, int widthZ, JigsawType type, BlockFace[] validDirs) { super(widthX, height, widthZ, type, validDirs); } + public static void setLargeWindow(@NotNull PopulatorDataAbstract data, + @NotNull BlockFace rotation, + @NotNull CubeRoom room, + @NotNull BlockFace face) + { + Material pane; + Wall w = new Wall(new SimpleBlock(data, room.getX(), room.getY() + 2, room.getZ()), rotation); + w = w.getRelative(rotation.getOppositeFace(), 2).getRelative(face, 2); + + // Remove roof ledge for windows + w.getRear().getUp(3).Pillar(3, new Random(), Material.AIR); + w.getRear(2).getUp(3).Pillar(4, new Random(), Material.AIR); + + // Interior stair decor + new StairBuilder(Material.POLISHED_DIORITE_STAIRS).setHalf(Half.TOP) + .setFacing(w.getDirection()) + .apply(w.getRear().getUp(5)) + .apply(w.getRear(2).getUp(6)); + + // Place the window + if (BRIGHT_STAINED_GLASS_PANES.contains(w.getRelative(face).getType())) { + pane = w.getRelative(face).getType(); + } + else { + pane = BRIGHT_STAINED_GLASS_PANES.get(new Random().nextInt(BRIGHT_STAINED_GLASS_PANES.size())); + } + + w.Pillar(5, new Random(), pane); + w.getDown() + .getRelative(face.getOppositeFace()) + .Pillar(6, + new Random(), + Material.POLISHED_DIORITE + );// Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS); + w.CorrectMultipleFacing(5); + + // Decorate the sides + w = w.getRelative(face.getOppositeFace()).getFront().getUp(); + new SlabBuilder(Material.STONE_BRICK_SLAB).setType(Slab.Type.TOP).apply(w); + w = w.getUp(); + w.Pillar(2, new Random(), Material.COBBLESTONE_WALL); + w.CorrectMultipleFacing(2); + w = w.getUp(2); + + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(face) + .apply(w) + .apply(w.getRear().getUp()) + .apply(w.getRear(2).getUp(2)) + .apply(w.getUp().getRelative(face)) + .apply(w.getRear().getUp().getRelative(face)) + .apply(w.getRear().getUp(2).getRelative(face)) + .apply(w.getRear(2).getUp(3).getRelative(face)); + + w.getUp().getRelative(face).getRear().setType(Material.CHISELED_STONE_BRICKS); + w.getUp().getRear(2).setType(Material.CHISELED_STONE_BRICKS); + w.getUp(2).getRelative(face).getRear(2).setType(Material.CHISELED_STONE_BRICKS); + w.getUp(3).getRelative(face).getRear(3).setType(Material.CHISELED_STONE_BRICKS); + + + } @Override public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { - Material[] stoneBricks = {Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + Material[] stoneBricks = { + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + }; SimpleEntry entry = this.getRoom().getWall(data, getRotation().getOppositeFace(), 0); Wall w = entry.getKey().getDown(); Wall core = null; for (int i = 0; i < entry.getValue(); i++) { w.getDown().downUntilSolid(rand, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.Pillar(5, rand, stoneBricks); - + if (i == 2) { core = w; setTempleWindows(w); @@ -57,93 +122,35 @@ public void build(@NotNull PopulatorDataAbstract data, @NotNull Random rand) { } - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(core.getDirection().getOppositeFace()) - .apply(core.getFront()); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(core.getDirection().getOppositeFace()) + .apply(core.getFront()); core.getFront().getDown().downUntilSolid(rand, stoneBricks); Wall doorAdj = core.getFront().getRight(); if (!doorAdj.getUp(2).isSolid()) { - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(doorAdj.getDirection().getOppositeFace()) - .apply(doorAdj.getUp(2)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(doorAdj.getDirection().getOppositeFace()) + .apply(doorAdj.getUp(2)); doorAdj.getUp().downUntilSolid(rand, stoneBricks); - } else { + } + else { doorAdj.getUp(2).setType(Material.CHISELED_STONE_BRICKS); doorAdj.getUp(3).setType(Material.STONE_BRICK_WALL); } doorAdj = core.getFront().getLeft(); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(doorAdj.getDirection().getOppositeFace()) - .apply(doorAdj.getUp(2)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(doorAdj.getDirection().getOppositeFace()) + .apply(doorAdj.getUp(2)); doorAdj.getUp().downUntilSolid(rand, stoneBricks); } - public static void setLargeWindow(@NotNull PopulatorDataAbstract data, @NotNull BlockFace rotation, @NotNull CubeRoom room, @NotNull BlockFace face) { - Material pane; - Wall w = new Wall(new SimpleBlock(data, - room.getX(), - room.getY()+2, - room.getZ()),rotation); - w = w.getRelative(rotation.getOppositeFace(),2).getRelative(face,2); - - // Remove roof ledge for windows - w.getRear().getUp(3).Pillar(3,new Random(),Material.AIR); - w.getRear(2).getUp(3).Pillar(4,new Random(),Material.AIR); - - // Interior stair decor - new StairBuilder(Material.POLISHED_DIORITE_STAIRS) - .setHalf(Half.TOP) - .setFacing(w.getDirection()) - .apply(w.getRear().getUp(5)) - .apply(w.getRear(2).getUp(6)); - - // Place the window - if(BRIGHT_STAINED_GLASS_PANES.contains(w.getRelative(face).getType())) { - pane = w.getRelative(face).getType(); - }else - pane = BRIGHT_STAINED_GLASS_PANES.get(new Random().nextInt(BRIGHT_STAINED_GLASS_PANES.size())); - - w.Pillar(5, new Random(), pane); - w.getDown().getRelative(face.getOppositeFace()).Pillar(6, new Random(), Material.POLISHED_DIORITE);// Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS); - w.CorrectMultipleFacing(5); - - // Decorate the sides - w = w.getRelative(face.getOppositeFace()).getFront().getUp(); - new SlabBuilder(Material.STONE_BRICK_SLAB).setType(Slab.Type.TOP).apply(w); - w = w.getUp(); - w.Pillar(2, new Random(), Material.COBBLESTONE_WALL); - w.CorrectMultipleFacing(2); - w = w.getUp(2); - - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(face) - .apply(w) - .apply(w.getRear().getUp()) - .apply(w.getRear(2).getUp(2)) - .apply(w.getUp().getRelative(face)) - .apply(w.getRear().getUp().getRelative(face)) - .apply(w.getRear().getUp(2).getRelative(face)) - .apply(w.getRear(2).getUp(3).getRelative(face)); - - w.getUp().getRelative(face).getRear().setType(Material.CHISELED_STONE_BRICKS); - w.getUp().getRear(2).setType(Material.CHISELED_STONE_BRICKS); - w.getUp(2).getRelative(face).getRear(2).setType(Material.CHISELED_STONE_BRICKS); - w.getUp(3).getRelative(face).getRear(3).setType(Material.CHISELED_STONE_BRICKS); - - - } - private void setTempleWindows(Wall w) { - Material pane = BRIGHT_STAINED_GLASS_PANES.get(new Random().nextInt(BRIGHT_STAINED_GLASS_PANES.size())); + Material pane = BRIGHT_STAINED_GLASS_PANES.get(new Random().nextInt(BRIGHT_STAINED_GLASS_PANES.size())); w = w.getUp(); - new StairBuilder(Material.STONE_BRICK_STAIRS) - .setFacing(w.getDirection().getOppositeFace()) - .apply(w) - .setHalf(Half.TOP) - .apply(w.getUp(3)); + new StairBuilder(Material.STONE_BRICK_STAIRS).setFacing(w.getDirection().getOppositeFace()) + .apply(w) + .setHalf(Half.TOP) + .apply(w.getUp(3)); w.getUp().downUntilSolid(new Random(), Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); w.getUp().Pillar(2, new Random(), pane); diff --git a/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java index 2d1e503d..6315b23b 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java @@ -24,37 +24,48 @@ public class VillageHousePopulator extends SingleMegaChunkStructurePopulator { } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { - return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_VILLAGEHOUSE_SPAWNRATIO - .getDouble() * 10000), - 10000); + return GenUtils.chance( + tw.getHashedRand(chunkX, chunkZ, 12422), + (int) (TConfigOption.STRUCTURES_VILLAGEHOUSE_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @NotNull BiomeBank biome) { - if (!isEnabled()) return false; + if (!isEnabled()) { + return false; + } MegaChunk mc = new MegaChunk(chunkX, chunkZ); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); if (coords[0] >> 4 == chunkX && coords[1] >> 4 == chunkZ) { - - if(!biome.isDry()) - return false; - + + if (!biome.isDry()) { + return false; + } + // If it is below sea level, DON'T SPAWN IT. if (HeightMap.getBlockHeight(tw, coords[0], coords[1]) > TerraformGenerator.seaLevel) { - if (biome == (BiomeBank.DESERT) - || biome == (BiomeBank.BADLANDS) - || biome == (BiomeBank.ICE_SPIKES)) { - return TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean() && rollSpawnRatio(tw,chunkX,chunkZ); - } else if (biome == (BiomeBank.SNOWY_TAIGA) - || biome == (BiomeBank.SNOWY_WASTELAND) - || biome == (BiomeBank.JUNGLE)) { - - return TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw,chunkX,chunkZ); - }else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { - - return TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw,chunkX,chunkZ); + if (biome == (BiomeBank.DESERT) || biome == (BiomeBank.BADLANDS) || biome == (BiomeBank.ICE_SPIKES)) { + return TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean() && rollSpawnRatio(tw, + chunkX, + chunkZ); + } + else if (biome == (BiomeBank.SNOWY_TAIGA) + || biome == (BiomeBank.SNOWY_WASTELAND) + || biome == (BiomeBank.JUNGLE)) + { + + return TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw, + chunkX, + chunkZ); + } + else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { + + return TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw, + chunkX, + chunkZ); } } } @@ -63,7 +74,9 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); @@ -71,25 +84,29 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // if (GenUtils.getHighestGround(data, coords[0], coords[1]) > TerraformGenerator.seaLevel) { - if (biome == (BiomeBank.DESERT) - || biome == (BiomeBank.BADLANDS) - || biome == (BiomeBank.ICE_SPIKES)) { - if (!TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean()) + if (biome == (BiomeBank.DESERT) || biome == (BiomeBank.BADLANDS) || biome == (BiomeBank.ICE_SPIKES)) { + if (!TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean()) { return; + } new AnimalFarmPopulator().populate(tw, data); - } else if (biome == (BiomeBank.SNOWY_TAIGA) - || biome == (BiomeBank.SNOWY_WASTELAND) - || biome == (BiomeBank.JUNGLE)) { + } + else if (biome == (BiomeBank.SNOWY_TAIGA) + || biome == (BiomeBank.SNOWY_WASTELAND) + || biome == (BiomeBank.JUNGLE)) + { - if (!TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean()) + if (!TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean()) { return; + } new FarmhousePopulator().populate(tw, data); - } else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { + } + else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { - if (!TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean()) + if (!TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean()) { return; + } new MountainhousePopulator().populate(tw, data); } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPathPopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPathPopulator.java index aa322325..78eacfa5 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPathPopulator.java @@ -24,18 +24,26 @@ public AnimalFarmPathPopulator(RoomLayoutGenerator gen, Random rand) { public void populate(@NotNull PathPopulatorData ppd) { Wall w = new Wall(ppd.base, ppd.dir); for (CubeRoom room : gen.getRooms()) { - if (room.isPointInside(new int[]{w.get().getX(), w.get().getZ()})) + if (room.isPointInside(new int[] {w.get().getX(), w.get().getZ()})) { return; + } } if (GenUtils.chance(rand, 1, 50)) { - w.getLeft().getGround().getUp() - .setType(Material.CAMPFIRE); + w.getLeft().getGround().getUp().setType(Material.CAMPFIRE); + } + if (GenUtils.chance(rand, 2, 10)) { + w.getGround() + .setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); + } + if (GenUtils.chance(rand, 2, 10)) { + w.getLeft() + .getGround() + .setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); + } + if (GenUtils.chance(rand, 2, 10)) { + w.getRight() + .getGround() + .setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); } - if (GenUtils.chance(rand, 2, 10)) - w.getGround().setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); - if (GenUtils.chance(rand, 2, 10)) - w.getLeft().getGround().setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); - if (GenUtils.chance(rand, 2, 10)) - w.getRight().getGround().setType(GenUtils.randChoice(Material.COBBLESTONE, Material.COARSE_DIRT, Material.MOSSY_COBBLESTONE)); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPopulator.java index 4245a6a7..afffd70e 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmPopulator.java @@ -33,11 +33,7 @@ public class AnimalFarmPopulator extends VillageHousePopulator { private static final EntityType[] farmAnimals = { - EntityType.PIG, - EntityType.SHEEP, - EntityType.COW, - EntityType.HORSE, - EntityType.CHICKEN + EntityType.PIG, EntityType.SHEEP, EntityType.COW, EntityType.HORSE, EntityType.CHICKEN }; @@ -47,8 +43,7 @@ public class AnimalFarmPopulator extends VillageHousePopulator { } @Override - public void populate(@NotNull TerraformWorld tw, - @NotNull PopulatorDataAbstract data) { + public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); int x = coords[0];// data.getChunkX()*16 + random.nextInt(16); @@ -62,12 +57,19 @@ public void spawnAnimalFarm(@NotNull TerraformWorld tw, @NotNull PopulatorDataAb Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); BiomeBank biome = tw.getBiomeBank(x, z); BlockFace dir = BlockUtils.getDirectBlockFace(random); - TerraSchematic animalFarm = TerraSchematic.load("animalfarm", new SimpleBlock(data,x,y,z)); + TerraSchematic animalFarm = TerraSchematic.load("animalfarm", new SimpleBlock(data, x, y, z)); animalFarm.parser = new AnimalFarmSchematicParser(biome, random, data); animalFarm.setFace(dir); animalFarm.apply(); - TerraformGeneratorPlugin.logger.info("Spawning animal farm at " + x + "," + y + "," + z + " with rotation of " + animalFarm.getFace()); + TerraformGeneratorPlugin.logger.info("Spawning animal farm at " + + x + + "," + + y + + "," + + z + + " with rotation of " + + animalFarm.getFace()); data.addEntity(x, y + 1, z, EntityType.VILLAGER); // Two villagers data.addEntity(x, y + 1, z, EntityType.VILLAGER); @@ -77,27 +79,54 @@ public void spawnAnimalFarm(@NotNull TerraformWorld tw, @NotNull PopulatorDataAb if (dir == BlockFace.EAST || dir == BlockFace.WEST) { for (int nx = -5; nx <= 5; nx++) { for (int nz = -10; nz <= 10; nz++) { - if (data.getType(x + nx, y - 1, z + nz).isSolid()) - BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); + if (data.getType(x + nx, y - 1, z + nz).isSolid()) { + BlockUtils.setDownUntilSolid(x + nx, + y - 2, + z + nz, + data, + WoodUtils.getWoodForBiome(biome, WoodType.LOG) + ); + } } } - } else { + } + else { for (int nx = -10; nx <= 10; nx++) { for (int nz = -5; nz <= 5; nz++) { - if (data.getType(x + nx, y - 1, z + nz).isSolid()) - BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); + if (data.getType(x + nx, y - 1, z + nz).isSolid()) { + BlockUtils.setDownUntilSolid(x + nx, + y - 2, + z + nz, + data, + WoodUtils.getWoodForBiome(biome, WoodType.LOG) + ); + } } } } createSurroundingFences(tw, biome, random, data, x, y, z); - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + x + "," + y + "," + z + "!"); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + + x + + "," + + y + + "," + + z + + "!"); TerraformGeneratorPlugin.logger.stackTrace(e); } } - private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeBank biome, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + private void createSurroundingFences(@NotNull TerraformWorld tw, + @NotNull BiomeBank biome, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { RoomLayoutGenerator gen = new RoomLayoutGenerator(random, RoomLayout.RANDOM_BRUTEFORCE, 50, x, y, z, 75); gen.setPathPopulator(new AnimalFarmPathPopulator(gen, tw.getHashedRand(x, y, z, 1234))); gen.setRoomMaxX(17); @@ -119,31 +148,41 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB for (int nx = -50; nx <= 50; nx++) { for (int nz = -50; nz <= 50; nz++) { int height = GenUtils.getHighestGround(data, x + nx, z + nz); - if (!BlockUtils.isDirtLike(data.getType(x + nx, height, z + nz)) || - data.getType(x + nx, height + 1, z + nz) != Material.AIR) + if (!BlockUtils.isDirtLike(data.getType(x + nx, height, z + nz)) + || data.getType(x + nx, height + 1, z + nz) != Material.AIR) + { continue; + } double noise = fieldNoise.GetNoise(nx + x, nz + z); double dist = Math.pow(nx, 2) + Math.pow(nz, 2); double multiplier = Math.pow((1 / (dist - 2500)) + 1, 255); - if (multiplier < 0 || dist > 2500 + (radiusNoise.GetNoise(nx, nz) * 500.0)) multiplier = 0; + if (multiplier < 0 || dist > 2500 + (radiusNoise.GetNoise(nx, nz) * 500.0)) { + multiplier = 0; + } noise = Math.abs(noise * multiplier); if (GenUtils.chance(random, (2500 - dist) > 0 ? (int) (2500 - dist) : 0, 2500)) { - if(0.1 < noise && noise < 0.2) { // Grass hedges - data.setType(nx + x, height, nz + z, GenUtils.randChoice( - random, + if (0.1 < noise && noise < 0.2) { // Grass hedges + data.setType(nx + x, height, nz + z, GenUtils.randChoice(random, Material.CHISELED_STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, - Material.STONE_BRICKS)); - } else if ( noise <= 0.1 ) { - if(GenUtils.chance(random, (int) (100 * Math.pow(multiplier, 3)), 100)) { - data.setType(nx + x, height, nz + z, GenUtils.randChoice( - random, - Material.COBBLESTONE_SLAB, - Material.MOSSY_COBBLESTONE_SLAB)); + Material.STONE_BRICKS + )); + } + else if (noise <= 0.1) { + if (GenUtils.chance(random, (int) (100 * Math.pow(multiplier, 3)), 100)) { + data.setType( + nx + x, + height, + nz + z, + GenUtils.randChoice(random, + Material.COBBLESTONE_SLAB, + Material.MOSSY_COBBLESTONE_SLAB + ) + ); } } } @@ -154,10 +193,14 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB int pens = 0; for (CubeRoom room : gen.getRooms()) { // Don't touch the center room - if (room.getWidthX() == 20 && room.getWidthZ() == 20) continue; + if (room.getWidthX() == 20 && room.getWidthZ() == 20) { + continue; + } // Don't generate pens inside water - if (GenUtils.getHighestGround(data, room.getX(), room.getZ()) < TerraformGenerator.seaLevel) continue; + if (GenUtils.getHighestGround(data, room.getX(), room.getZ()) < TerraformGenerator.seaLevel) { + continue; + } // Create fences for (int t = 0; t <= 360; t += 5) { @@ -170,9 +213,24 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB // General lighting if (GenUtils.chance(random, 1, 30)) { data.setType(ePX, highest + 1, ePZ, Material.CHISELED_STONE_BRICKS); - data.setType(ePX, highest + 2, ePZ, GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); - data.setType(ePX, highest + 3, ePZ, GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); - data.setType(ePX, highest + 4, ePZ, GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); + data.setType( + ePX, + highest + 2, + ePZ, + GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL) + ); + data.setType( + ePX, + highest + 3, + ePZ, + GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL) + ); + data.setType( + ePX, + highest + 4, + ePZ, + GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL) + ); data.setType(ePX, highest + 5, ePZ, Material.CAMPFIRE); } BlockUtils.correctSurroundingMultifacingData(new SimpleBlock(data, ePX, highest + 1, ePZ)); @@ -189,20 +247,19 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB if (GenUtils.chance(random, 1, 50)) { SimpleBlock rear = w.getRear().get(); int highest = GenUtils.getHighestGround(data, rear.getX(), rear.getZ()); - data.setType(rear.getX(), highest + 1, rear.getZ(), GenUtils.randChoice( - Material.CAULDRON, - Material.SMOKER, - Material.LOOM - )); + data.setType( + rear.getX(), + highest + 1, + rear.getZ(), + GenUtils.randChoice(Material.CAULDRON, Material.SMOKER, Material.LOOM) + ); } } } int animalCount = GenUtils.randInt(3, 7); EntityType animal = farmAnimals[random.nextInt(farmAnimals.length)]; - if(Version.isAtLeast(20) - && pens == 0 - && biome.getClimate() == BiomeClimate.HOT_BARREN) { + if (Version.isAtLeast(20) && pens == 0 && biome.getClimate() == BiomeClimate.HOT_BARREN) { animal = OneTwentyBlockHandler.CAMEL; animalCount = 2; } @@ -217,11 +274,16 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB for (int nx = room.getLowerCorner()[0] + 2; nx <= room.getUpperCorner()[0] - 2; nx++) { for (int nz = room.getLowerCorner()[1] + 2; nz <= room.getUpperCorner()[1] - 2; nz++) { int highest = GenUtils.getHighestGround(data, nx, nz); - if (data.getType(nx, highest, nz) == Material.CHISELED_STONE_BRICKS) + if (data.getType(nx, highest, nz) == Material.CHISELED_STONE_BRICKS) { highest--; + } - if (Math.pow((nx - room.getX()) / (room.getWidthX() / 2f), 2) - + Math.pow((nz - room.getZ()) / (room.getWidthZ() / 2f), 2) <= 1) { + if (Math.pow((nx - room.getX()) / (room.getWidthX() / 2f), 2) + Math.pow( + (nz - room.getZ()) + / (room.getWidthZ() / 2f), + 2 + ) <= 1) + { data.setType(nx, highest, nz, GenUtils.randChoice(random, Material.GRASS_BLOCK, @@ -231,13 +293,19 @@ private void createSurroundingFences(@NotNull TerraformWorld tw, @NotNull BiomeB Material.GRASS_BLOCK, Material.DIRT_PATH, Material.GRASS_BLOCK, - Material.COARSE_DIRT)); + Material.COARSE_DIRT + )); } if (GenUtils.chance(random, 1, 60)) { - BlockUtils.replaceUpperSphere(nx + 7 * nz + 17 * 17, 1.1f, 2f, 1.1f, + BlockUtils.replaceUpperSphere(nx + 7 * nz + 17 * 17, + 1.1f, + 2f, + 1.1f, new SimpleBlock(data, nx, highest + 1, nz), - false, Material.HAY_BLOCK); + false, + Material.HAY_BLOCK + ); } } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmSchematicParser.java b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmSchematicParser.java index 595bcb52..ad8623a9 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/animalfarm/AnimalFarmSchematicParser.java @@ -22,8 +22,7 @@ public class AnimalFarmSchematicParser extends SchematicParser { private final Random rand; private final PopulatorDataAbstract pop; - public AnimalFarmSchematicParser(BiomeBank biome, Random rand, - PopulatorDataAbstract pop) { + public AnimalFarmSchematicParser(BiomeBank biome, Random rand, PopulatorDataAbstract pop) { this.biome = biome; this.rand = rand; this.pop = pop; @@ -32,54 +31,56 @@ public AnimalFarmSchematicParser(BiomeBank biome, Random rand, @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial() == Material.COBBLESTONE) { - if (GenUtils.chance(rand, 1, 5)) data = Bukkit - .createBlockData(Material.STONE); + if (GenUtils.chance(rand, 1, 5)) { + data = Bukkit.createBlockData(Material.STONE); + } } if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); return; - } else if (data.getMaterial().toString().contains("STONE_BRICK")) { - if (GenUtils.chance(rand, 1, 5)) - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "stone_brick", - "mossy_stone_brick" - ) - ); + } + else if (data.getMaterial().toString().contains("STONE_BRICK")) { + if (GenUtils.chance(rand, 1, 5)) { + data = Bukkit.createBlockData(data.getAsString().replaceAll("stone_brick", "mossy_stone_brick")); + } super.applyData(block, data); return; - } else if (data.getMaterial().toString().contains("OAK")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - data.getMaterial().toString().toLowerCase(Locale.ENGLISH), - WoodUtils.getWoodForBiome(biome, - WoodType.parse(data.getMaterial())).toString().toLowerCase(Locale.ENGLISH) - ).toString().toLowerCase(Locale.ENGLISH)); + } + else if (data.getMaterial().toString().contains("OAK")) { + data = Bukkit.createBlockData(data.getAsString() + .replaceAll(data.getMaterial().toString().toLowerCase(Locale.ENGLISH), + WoodUtils.getWoodForBiome(biome, + WoodType.parse(data.getMaterial()) + ).toString().toLowerCase(Locale.ENGLISH) + ) + .toString() + .toLowerCase(Locale.ENGLISH)); super.applyData(block, data); return; - } else if (data.getMaterial() == Material.CHEST) { + } + else if (data.getMaterial() == Material.CHEST) { if (GenUtils.chance(rand, 1, 5)) { block.setType(Material.AIR); return; // A fifth of chests is not placed. } super.applyData(block, data); int i = rand.nextInt(3); - switch(i) { - case 0 -> pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.VILLAGE_BUTCHER); - case 1 -> pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.VILLAGE_TANNERY); - default -> pop.lootTableChest(block.getX(), block.getY(), block.getZ(), - TerraLootTable.VILLAGE_SHEPHERD); + switch (i) { + case 0 -> pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_BUTCHER); + case 1 -> pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_TANNERY); + default -> + pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_SHEPHERD); } - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java index 40182328..363aac8d 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java @@ -33,7 +33,9 @@ public class FarmhousePopulator extends VillageHousePopulator { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if ( !TConfigOption.areStructuresEnabled()) return; + if (!TConfigOption.areStructuresEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); @@ -43,18 +45,33 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract spawnFarmHouse(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, height + 1, z); } - public void spawnFarmHouse(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if ( !TConfigOption.areStructuresEnabled()) return; + public void spawnFarmHouse(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + if (!TConfigOption.areStructuresEnabled()) { + return; + } try { BiomeBank biome = tw.getBiomeBank(x, z); y += GenUtils.randInt(random, 1, 3); - TerraSchematic farmHouse = TerraSchematic.load("farmhouse", new SimpleBlock(data,x,y,z)); + TerraSchematic farmHouse = TerraSchematic.load("farmhouse", new SimpleBlock(data, x, y, z)); farmHouse.parser = new FarmhouseSchematicParser(biome, random, data); farmHouse.setFace(BlockUtils.getDirectBlockFace(random)); farmHouse.apply(); - TerraformGeneratorPlugin.logger.info("Spawning farmhouse at " + x + "," + y + "," + z + " with rotation of " + farmHouse.getFace()); + TerraformGeneratorPlugin.logger.info("Spawning farmhouse at " + + x + + "," + + y + + "," + + z + + " with rotation of " + + farmHouse.getFace()); data.addEntity(x, y + 1, z, EntityType.VILLAGER); // Two villagers data.addEntity(x, y + 1, z, EntityType.VILLAGER); @@ -63,46 +80,88 @@ public void spawnFarmHouse(@NotNull TerraformWorld tw, @NotNull Random random, @ // Spawn a base on the house to sit on for (int nx = -17 / 2 - 1; nx <= 17 / 2 + 1; nx++) { for (int nz = -17 / 2 - 1; nz <= 17 / 2 + 1; nz++) { - if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") || - data.getType(x + nx, y - 1, z + nz).toString().contains("STONE_BRICKS")) - BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE); - else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) + if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") || data.getType(x + nx, + y - 1, + z + nz + ).toString().contains("STONE_BRICKS")) + { + BlockUtils.setDownUntilSolid( + x + nx, + y - 2, + z + nz, + data, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ); + } + else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) { BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, data.getType(x + nx, y - 1, z + nz)); + } } } // Spawn a stairway from the house. Wall w = new Wall(new SimpleBlock(data, x, y - 1, z), farmHouse.getFace()).getRight(); - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { w = w.getFront(); + } // while(w.getType() != Material.DIRT){ - while (!w.isSolid() || - w.getType().toString().contains("PLANKS")) { - Stairs stairs = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(random, Material.COBBLESTONE_STAIRS, Material.COBBLESTONE_STAIRS, - Material.COBBLESTONE_STAIRS, Material.MOSSY_COBBLESTONE_STAIRS)); + while (!w.isSolid() || w.getType().toString().contains("PLANKS")) { + Stairs stairs = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(random, + Material.COBBLESTONE_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.COBBLESTONE_STAIRS, + Material.MOSSY_COBBLESTONE_STAIRS + )); stairs.setFacing(w.getDirection().getOppositeFace()); w.getRight().setBlockData(stairs); w.setBlockData(stairs); w.getLeft().setBlockData(stairs); w.getLeft().getLeft().getUp().downUntilSolid(random, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); - w.getLeft().getLeft().getUp(2).setType(GenUtils.randChoice(random, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, - Material.MOSSY_COBBLESTONE_WALL)); + w.getLeft().getLeft().getUp(2).setType(GenUtils.randChoice(random, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + )); w.getRight().getRight().getUp().downUntilSolid(random, WoodUtils.getWoodForBiome(biome, WoodType.LOG)); - w.getRight().getRight().getUp(2).setType(GenUtils.randChoice(random, Material.COBBLESTONE_WALL, Material.COBBLESTONE_WALL, - Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); + w.getRight().getRight().getUp(2).setType(GenUtils.randChoice(random, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL + )); w = w.getFront().getDown(); } createFields(tw, biome, random, data, x, y, z); - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + x + "," + y + "," + z + "!"); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place farmhouse at " + + x + + "," + + y + + "," + + z + + "!"); TerraformGeneratorPlugin.logger.stackTrace(e); } } - private void placeLamp(TerraformWorld tw, BiomeBank biome, @NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areDecorationsEnabled()) return; + private void placeLamp(TerraformWorld tw, + BiomeBank biome, + @NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + if (!TConfigOption.areDecorationsEnabled()) { + return; + } SimpleBlock b = new SimpleBlock(data, x, y, z); b.setType(GenUtils.randChoice(rand, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS)); @@ -112,15 +171,30 @@ private void placeLamp(TerraformWorld tw, BiomeBank biome, @NotNull Random rand, b.getUp(4).setType(Material.CAMPFIRE); b.getUp(5).setType(GenUtils.randChoice(rand, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS)); for (BlockFace face : BlockUtils.directBlockFaces) { - Slab tSlab = (Slab) Bukkit.createBlockData(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); + Slab tSlab = (Slab) Bukkit.createBlockData(GenUtils.randChoice( + rand, + Material.STONE_BRICK_SLAB, + Material.MOSSY_STONE_BRICK_SLAB + )); tSlab.setType(Type.TOP); b.getRelative(face).getUp(3).setBlockData(tSlab); - b.getRelative(face).getUp(4).setType(GenUtils.randChoice(rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); - b.getRelative(face).getUp(5).setType(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); + b.getRelative(face) + .getUp(4) + .setType(GenUtils.randChoice(rand, Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL)); + b.getRelative(face) + .getUp(5) + .setType(GenUtils.randChoice(rand, Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB)); } } - private void createFields(@NotNull TerraformWorld tw, @NotNull BiomeBank biome, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + private void createFields(@NotNull TerraformWorld tw, + @NotNull BiomeBank biome, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { FastNoise fieldNoise = new FastNoise(tw.getHashedRand(x, y, z, 23).nextInt(225)); fieldNoise.SetNoiseType(NoiseType.Simplex); fieldNoise.SetFrequency(0.05f); @@ -140,49 +214,64 @@ private void createFields(@NotNull TerraformWorld tw, @NotNull BiomeBank biome, for (int nx = -50; nx <= 50; nx++) { for (int nz = -50; nz <= 50; nz++) { int height = GenUtils.getTrueHighestBlock(data, x + nx, z + nz); - if (!BlockUtils.isDirtLike(data.getType(x + nx, height, z + nz)) || - data.getType(x + nx, height + 1, z + nz) != Material.AIR) + if (!BlockUtils.isDirtLike(data.getType(x + nx, height, z + nz)) + || data.getType(x + nx, height + 1, z + nz) != Material.AIR) + { continue; + } double noise = fieldNoise.GetNoise(nx + x, nz + z); double dist = Math.pow(nx, 2) + Math.pow(nz, 2); double multiplier = Math.pow((1 / (dist - 2500)) + 1, 255); - if (multiplier < 0 || dist > 2500 + (radiusNoise.GetNoise(nx, nz) * 500.0)) multiplier = 0; + if (multiplier < 0 || dist > 2500 + (radiusNoise.GetNoise(nx, nz) * 500.0)) { + multiplier = 0; + } noise = noise * multiplier; - if (dist < 2500) + if (dist < 2500) { if (GenUtils.chance(random, 1, 300)) { data.setType(x + nx, height + 1, z + nz, Material.COMPOSTER); continue; } + } if (noise < -0.2) { // Crop one if (GenUtils.chance(random, 1, 15)) { data.setType(nx + x, height, nz + z, Material.WATER); for (BlockFace face : BlockUtils.directBlockFaces) { - BlockUtils.setDownUntilSolid(nx + x + face.getModX(), height, nz + z + face.getModZ(), + BlockUtils.setDownUntilSolid(nx + x + face.getModX(), + height, + nz + z + face.getModZ(), data, - Material.FARMLAND); + Material.FARMLAND + ); } - } else { + } + else { Farmland fl = (Farmland) Bukkit.createBlockData(Material.FARMLAND); fl.setMoisture(fl.getMaximumMoisture()); data.setBlockData(nx + x, height, nz + z, fl); Ageable crop = (Ageable) Bukkit.createBlockData(cropOne); crop.setAge(GenUtils.randInt(random, 0, crop.getMaximumAge())); - if (!data.getType(nx + x, height + 1, nz + z).isSolid()) + if (!data.getType(nx + x, height + 1, nz + z).isSolid()) { data.setBlockData(nx + x, height + 1, nz + z, crop); + } } - } else if (noise > 0.2) { // Crop two + } + else if (noise > 0.2) { // Crop two if (GenUtils.chance(random, 1, 15)) { data.setType(nx + x, height, nz + z, Material.WATER); for (BlockFace face : BlockUtils.directBlockFaces) { - BlockUtils.setDownUntilSolid(nx + x + face.getModX(), height, nz + z + face.getModZ(), + BlockUtils.setDownUntilSolid(nx + x + face.getModX(), + height, + nz + z + face.getModZ(), data, - Material.FARMLAND); + Material.FARMLAND + ); } - } else { + } + else { Farmland fl = (Farmland) Bukkit.createBlockData(Material.FARMLAND); fl.setMoisture(fl.getMaximumMoisture()); data.setBlockData(nx + x, height, nz + z, fl); @@ -190,15 +279,28 @@ private void createFields(@NotNull TerraformWorld tw, @NotNull BiomeBank biome, crop.setAge(GenUtils.randInt(random, 0, crop.getMaximumAge())); data.setBlockData(nx + x, height + 1, nz + z, crop); } - } else if (Math.abs(noise) < 0.2 && Math.abs(noise) > 0.1) { // Grass hedges - BlockUtils.setPersistentLeaves(data, nx + x, height + 1, nz + z, WoodUtils.getWoodForBiome(biome, WoodType.LEAVES)); + } + else if (Math.abs(noise) < 0.2 && Math.abs(noise) > 0.1) { // Grass hedges + BlockUtils.setPersistentLeaves( + data, + nx + x, + height + 1, + nz + z, + WoodUtils.getWoodForBiome(biome, WoodType.LEAVES) + ); if (GenUtils.chance(random, 1, 100)) { placeLamp(tw, biome, random, data, nx + x, height + 1, z + nz); } - } else { + } + else { if (GenUtils.chance(random, (int) (100 * Math.pow(multiplier, 3)), 100)) { - data.setType(nx + x, height, nz + z, GenUtils.randChoice(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE)); + data.setType( + nx + x, + height, + nz + z, + GenUtils.randChoice(random, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) + ); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhouseSchematicParser.java b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhouseSchematicParser.java index 5eed7d32..87591c40 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhouseSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhouseSchematicParser.java @@ -22,8 +22,7 @@ public class FarmhouseSchematicParser extends SchematicParser { private final Random rand; private final PopulatorDataAbstract pop; - public FarmhouseSchematicParser(BiomeBank biome, Random rand, - PopulatorDataAbstract pop) { + public FarmhouseSchematicParser(BiomeBank biome, Random rand, PopulatorDataAbstract pop) { this.biome = biome; this.rand = rand; this.pop = pop; @@ -32,30 +31,36 @@ public FarmhouseSchematicParser(BiomeBank biome, Random rand, @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.COBBLESTONE, Material.COBBLESTONE, Material.MOSSY_COBBLESTONE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.COBBLESTONE, + Material.MOSSY_COBBLESTONE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } else if (data.getMaterial().toString().contains("OAK")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - data.getMaterial().toString().toLowerCase(Locale.ENGLISH), - WoodUtils.getWoodForBiome(biome, - WoodType.parse(data.getMaterial())).toString().toLowerCase(Locale.ENGLISH) - ).toString().toLowerCase(Locale.ENGLISH)); + } + else if (data.getMaterial().toString().contains("OAK")) { + data = Bukkit.createBlockData(data.getAsString() + .replaceAll(data.getMaterial().toString().toLowerCase(Locale.ENGLISH), + WoodUtils.getWoodForBiome(biome, + WoodType.parse(data.getMaterial()) + ).toString().toLowerCase(Locale.ENGLISH) + ) + .toString() + .toLowerCase(Locale.ENGLISH)); super.applyData(block, data); - } else if (data.getMaterial() == Material.CHEST) { + } + else if (data.getMaterial() == Material.CHEST) { if (GenUtils.chance(rand, 1, 5)) { block.setType(Material.AIR); return; // A fifth of chests are not placed. } super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_PLAINS_HOUSE); - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhousePopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhousePopulator.java index 98f684d8..1d166be8 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhousePopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhousePopulator.java @@ -17,6 +17,7 @@ import org.terraform.utils.SphereBuilder; import org.terraform.utils.SphereBuilder.SphereType; import org.terraform.utils.StairwayBuilder; + import java.util.Random; public class MountainhousePopulator extends VillageHousePopulator { @@ -27,52 +28,61 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int x = coords[0];// data.getChunkX()*16 + random.nextInt(16); int z = coords[1];// data.getChunkZ()*16 + random.nextInt(16); int height = GenUtils.getHighestGround(data, x, z); - + // Forcefully sink the house downwards to try and make it more tolerant to wackiness Random random = this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()); int sinkDown = GenUtils.randInt(random, 7, 10); - spawnMountainhouse(tw, random, - data, x, height - sinkDown, z); + spawnMountainhouse(tw, random, data, x, height - sinkDown, z); } - public void spawnMountainhouse(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public void spawnMountainhouse(@NotNull TerraformWorld tw, + @NotNull Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { try { - - BlockFace face = BlockUtils.getDirectBlockFace(random); - Wall core = new Wall(data,x,y,z,face); + + BlockFace face = BlockUtils.getDirectBlockFace(random); + Wall core = new Wall(data, x, y, z, face); BiomeBank biome = tw.getBiomeBank(x, z); - - new SphereBuilder(random, core.getUp(12), Material.AIR) - .setRX(17) - .setRZ(17) - .setRY(18) - .setMinRadius(0.7) - .setHardReplace(true) - .build(); - - // Place platform to prevent mountain weirdness - new SphereBuilder(random, core.getDown(2).getRight(7).getFront(3), - Material.DIRT) - .setRX(12) - .setRZ(12) - .setRY(7) - .setPadding(4) - .setSphereFrequency(0.11f) - .setMinRadius(0.8) - .setHardReplace(false) - .setUpperType(Material.GRASS_BLOCK) - .setSphereType(SphereType.LOWER_SEMISPHERE) - .build(); - - // Place schematic + + new SphereBuilder(random, core.getUp(12), Material.AIR).setRX(17) + .setRZ(17) + .setRY(18) + .setMinRadius(0.7) + .setHardReplace(true) + .build(); + + // Place platform to prevent mountain weirdness + new SphereBuilder(random, core.getDown(2).getRight(7).getFront(3), Material.DIRT).setRX(12) + .setRZ(12) + .setRY(7) + .setPadding(4) + .setSphereFrequency(0.11f) + .setMinRadius(0.8) + .setHardReplace(false) + .setUpperType(Material.GRASS_BLOCK) + .setSphereType(SphereType.LOWER_SEMISPHERE) + .build(); + + // Place schematic y += GenUtils.randInt(random, 1, 3); core = core.getAtY(y); - TerraSchematic mountainHouse = TerraSchematic.load("mountainhouse", core); + TerraSchematic mountainHouse = TerraSchematic.load("mountainhouse", core); mountainHouse.parser = new MountainhouseSchematicParser(biome, random, data); mountainHouse.setFace(face); mountainHouse.apply(); - TerraformGeneratorPlugin.logger.info("Spawning mountainhouse at " + x + "," + y + "," + z + " with rotation of " + mountainHouse.getFace()); + TerraformGeneratorPlugin.logger.info("Spawning mountainhouse at " + + x + + "," + + y + + "," + + z + + " with rotation of " + + mountainHouse.getFace()); data.addEntity(x, y + 1, z, EntityType.VILLAGER); // Two villagers data.addEntity(x, y + 1, z, EntityType.VILLAGER); @@ -81,39 +91,75 @@ public void spawnMountainhouse(@NotNull TerraformWorld tw, @NotNull Random rando // Spawn a base on the house to sit on for (int nx = -17 / 2 - 1; nx <= 17 / 2 + 1; nx++) { for (int nz = -17 / 2 - 1; nz <= 17 / 2 + 1; nz++) { - if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") || - BlockUtils.isStoneLike(data.getType(x + nx, y - 1, z + nz)) || - data.getType(x + nx, y - 1, z + nz).toString().contains("STONE_BRICKS")) - BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, Material.COBBLESTONE, Material.ANDESITE, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.COBBLESTONE, Material.ANDESITE); - else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) + if (data.getType(x + nx, y - 1, z + nz).toString().contains("PLANKS") + || BlockUtils.isStoneLike(data.getType(x + nx, y - 1, z + nz)) + || data.getType(x + nx, y - 1, z + nz).toString().contains("STONE_BRICKS")) + { + BlockUtils.setDownUntilSolid( + x + nx, + y - 2, + z + nz, + data, + Material.COBBLESTONE, + Material.ANDESITE, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS, + Material.COBBLESTONE, + Material.ANDESITE + ); + } + else if (data.getType(x + nx, y - 1, z + nz).toString().contains("LOG")) { BlockUtils.setDownUntilSolid(x + nx, y - 2, z + nz, data, data.getType(x + nx, y - 1, z + nz)); + } } } // Spawn a stairway from the house. - new StairwayBuilder(Material.COBBLESTONE, Material.STONE_BRICKS) - .setAngled(false) - .setMaxExtensionForward(10) - .setStairwayDirection(BlockFace.DOWN) - .build(core.getFront(4).getRight(4).getUp(4)) - .build(core.getFront(4).getRight(7).getUp(4)); - - new StairwayBuilder(Material.STONE_STAIRS, Material.COBBLESTONE_STAIRS, Material.ANDESITE_STAIRS) - .setAngled(false) - .setMaxExtensionForward(10) - .setStairwayDirection(BlockFace.DOWN) - .build(core.getFront(4).getRight(5).getUp(4)) - .build(core.getFront(4).getRight(6).getUp(4)); - - new StairwayBuilder(Material.SPRUCE_STAIRS) - .setAngled(false) - .setDownTypes(Material.SPRUCE_PLANKS) - .setMaxExtensionForward(10) - .setStairwayDirection(BlockFace.DOWN) - .build(new Wall(core.getRear(2).getRight(9).getDown(), BlockUtils.getRight(core.getDirection()))); - - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Something went wrong trying to place mountain house at " + x + "," + y + "," + z + "!"); + new StairwayBuilder(Material.COBBLESTONE, Material.STONE_BRICKS).setAngled(false) + .setMaxExtensionForward(10) + .setStairwayDirection(BlockFace.DOWN) + .build(core.getFront(4) + .getRight(4) + .getUp(4)) + .build(core.getFront(4) + .getRight(7) + .getUp(4)); + + new StairwayBuilder(Material.STONE_STAIRS, Material.COBBLESTONE_STAIRS, Material.ANDESITE_STAIRS).setAngled( + false) + .setMaxExtensionForward( + 10) + .setStairwayDirection( + BlockFace.DOWN) + .build(core.getFront( + 4) + .getRight( + 5) + .getUp(4)) + .build(core.getFront( + 4) + .getRight( + 6) + .getUp(4)); + + new StairwayBuilder(Material.SPRUCE_STAIRS).setAngled(false) + .setDownTypes(Material.SPRUCE_PLANKS) + .setMaxExtensionForward(10) + .setStairwayDirection(BlockFace.DOWN) + .build(new Wall( + core.getRear(2).getRight(9).getDown(), + BlockUtils.getRight(core.getDirection()) + )); + + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Something went wrong trying to place mountain house at " + + x + + "," + + y + + "," + + z + + "!"); TerraformGeneratorPlugin.logger.stackTrace(e); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhouseSchematicParser.java b/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhouseSchematicParser.java index 7fe9d7b7..8e20b36e 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhouseSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/mountainhouse/MountainhouseSchematicParser.java @@ -20,8 +20,7 @@ public class MountainhouseSchematicParser extends SchematicParser { private final Random rand; private final PopulatorDataAbstract pop; - public MountainhouseSchematicParser(BiomeBank biome, Random rand, - PopulatorDataAbstract pop) { + public MountainhouseSchematicParser(BiomeBank biome, Random rand, PopulatorDataAbstract pop) { // this.biome = biome; this.rand = rand; this.pop = pop; @@ -30,45 +29,48 @@ public MountainhouseSchematicParser(BiomeBank biome, Random rand, @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { if (data.getMaterial().toString().contains("COBBLESTONE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "cobblestone", - GenUtils.randChoice(rand, Material.COBBLESTONE, Material.ANDESITE, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.COBBLESTONE, Material.ANDESITE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("cobblestone", + GenUtils.randChoice(rand, + Material.COBBLESTONE, + Material.ANDESITE, + Material.STONE_BRICKS, + Material.CRACKED_STONE_BRICKS, + Material.COBBLESTONE, + Material.ANDESITE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } + } if (data.getMaterial() == Material.BRICKS) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "bricks", - GenUtils.randChoice(rand, Material.BRICKS, Material.GRANITE, Material.POLISHED_GRANITE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("bricks", + GenUtils.randChoice(rand, Material.BRICKS, Material.GRANITE, Material.POLISHED_GRANITE) + .toString() + .toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); } else if (data.getMaterial().toString().contains("WHITE_CONCRETE")) { - data = Bukkit.createBlockData( - data.getAsString().replaceAll( - "white_concrete", - GenUtils.randChoice(rand, Material.WHITE_CONCRETE, Material.WHITE_CONCRETE, Material.WHITE_WOOL, Material.DIORITE, Material.DIORITE) - .toString().toLowerCase(Locale.ENGLISH) - ) - ); + data = Bukkit.createBlockData(data.getAsString().replaceAll("white_concrete", + GenUtils.randChoice(rand, + Material.WHITE_CONCRETE, + Material.WHITE_CONCRETE, + Material.WHITE_WOOL, + Material.DIORITE, + Material.DIORITE + ).toString().toLowerCase(Locale.ENGLISH) + )); super.applyData(block, data); - } + } // Don't do wood replacements. This schematic uses different wood types. -// else if (data.getMaterial().toString().contains("SPRUCE")) { -// data = Bukkit.createBlockData( -// data.getAsString().replaceAll( -// data.getMaterial().toString().toLowerCase(Locale.ENGLISH), -// WoodUtils.getWoodForBiome(biome, -// WoodType.parse(data.getMaterial())).toString().toLowerCase(Locale.ENGLISH) -// ).toString().toLowerCase(Locale.ENGLISH)); -// super.applyData(block, data); -// } + // else if (data.getMaterial().toString().contains("SPRUCE")) { + // data = Bukkit.createBlockData( + // data.getAsString().replaceAll( + // data.getMaterial().toString().toLowerCase(Locale.ENGLISH), + // WoodUtils.getWoodForBiome(biome, + // WoodType.parse(data.getMaterial())).toString().toLowerCase(Locale.ENGLISH) + // ).toString().toLowerCase(Locale.ENGLISH)); + // super.applyData(block, data); + // } else if (data.getMaterial() == Material.CHEST) { if (GenUtils.chance(rand, 1, 5)) { block.setType(Material.AIR); @@ -76,7 +78,8 @@ else if (data.getMaterial() == Material.CHEST) { } super.applyData(block, data); pop.lootTableChest(block.getX(), block.getY(), block.getZ(), TerraLootTable.VILLAGE_TAIGA_HOUSE); - } else { + } + else { super.applyData(block, data); } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java index 0cce805f..94db6eab 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.Random; -public class WarmOceanAltarRoom extends WarmOceanBaseRoom{ +public class WarmOceanAltarRoom extends WarmOceanBaseRoom { public WarmOceanAltarRoom(Random rand, boolean forceSpawn, boolean unique) { super(rand, forceSpawn, unique); } @@ -23,32 +23,27 @@ public WarmOceanAltarRoom(Random rand, boolean forceSpawn, boolean unique) { public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { super.populate(data, room); - for(Map.Entry entry:room.getFourWalls(data,3).entrySet()) - { + for (Map.Entry entry : room.getFourWalls(data, 3).entrySet()) { Wall w = entry.getKey().getGround(); - for(int i = 0; i < entry.getValue(); i++) - { - if(i % 2 == 0 && rand.nextBoolean()) - { - int h = 2+rand.nextInt(3); + for (int i = 0; i < entry.getValue(); i++) { + if (i % 2 == 0 && rand.nextBoolean()) { + int h = 2 + rand.nextInt(3); w.getUp().Pillar(h, Material.CUT_SANDSTONE); - w.getUp(h+1).setType(Material.POLISHED_DIORITE, - Material.POLISHED_ANDESITE, - Material.POLISHED_GRANITE); + w.getUp(h + 1) + .setType(Material.POLISHED_DIORITE, Material.POLISHED_ANDESITE, Material.POLISHED_GRANITE); } - else if(i % 2 == 1 && rand.nextBoolean()) - { - int h = 2+rand.nextInt(3); + else if (i % 2 == 1 && rand.nextBoolean()) { + int h = 2 + rand.nextInt(3); w.getUp().setType(Material.CUT_SANDSTONE_SLAB, Material.SMOOTH_SANDSTONE); } - if(i > 0 && i < entry.getValue()-1 - && GenUtils.chance(rand, 1, 9)) - new ChestBuilder(Material.CHEST) - .setFacing(w.getDirection()) - .setLootTable(TerraLootTable.UNDERWATER_RUIN_SMALL) - .setWaterlogged(w.getUp().getY() <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(w.getFront().getRight().getUp()); + if (i > 0 && i < entry.getValue() - 1 && GenUtils.chance(rand, 1, 9)) { + new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) + .setLootTable(TerraLootTable.UNDERWATER_RUIN_SMALL) + .setWaterlogged(w.getUp().getY() + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(w.getFront().getRight().getUp()); + } w = w.getLeft().getGround(); } } @@ -56,6 +51,6 @@ else if(i % 2 == 1 && rand.nextBoolean()) @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getWidthX()<25; + return room.getWidthX() < 25; } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanBaseRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanBaseRoom.java index e5082844..579e523d 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanBaseRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanBaseRoom.java @@ -30,27 +30,34 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room ); // Spawn suspicious sand relative to room size // Sprinkle some magma blocks too - for(int i = 0; i < (room.getWidthX()*room.getWidthZ())/70; i++) - { + for (int i = 0; i < (room.getWidthX() * room.getWidthZ()) / 70; i++) { int[] coords = room.randomCoords(rand); coords[1] = GenUtils.getHighestGround(data, coords[0], coords[2]); - if(data.getType(coords[0],coords[1],coords[2]) == Material.SAND - || data.getType(coords[0],coords[1],coords[2]) == Material.GRAVEL) { - if(Version.isAtLeast(20) - && GenUtils.chance(rand, 3, 4)) { - if(data.getType(coords[0],coords[1],coords[2]) == Material.SAND) { + if (data.getType(coords[0], coords[1], coords[2]) == Material.SAND + || data.getType(coords[0], coords[1], coords[2]) == Material.GRAVEL) + { + if (Version.isAtLeast(20) && GenUtils.chance(rand, 3, 4)) { + if (data.getType(coords[0], coords[1], coords[2]) == Material.SAND) { data.setType(coords[0], coords[1], coords[2], OneTwentyBlockHandler.SUSPICIOUS_SAND); - data.lootTableChest(coords[0], coords[1], coords[2], TerraLootTable.OCEAN_RUIN_WARM_ARCHAEOLOGY); + data.lootTableChest(coords[0], + coords[1], + coords[2], + TerraLootTable.OCEAN_RUIN_WARM_ARCHAEOLOGY + ); } - else - { + else { data.setType(coords[0], coords[1], coords[2], OneTwentyBlockHandler.SUSPICIOUS_GRAVEL); - data.lootTableChest(coords[0], coords[1], coords[2], TerraLootTable.OCEAN_RUIN_COLD_ARCHAEOLOGY); + data.lootTableChest(coords[0], + coords[1], + coords[2], + TerraLootTable.OCEAN_RUIN_COLD_ARCHAEOLOGY + ); } } } - else - data.setType(coords[0],coords[1],coords[2],Material.MAGMA_BLOCK); + else { + data.setType(coords[0], coords[1], coords[2], Material.MAGMA_BLOCK); + } } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java index bafebe95..7da52a59 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java @@ -16,7 +16,7 @@ import java.util.Random; -public class WarmOceanDomeHutRoom extends WarmOceanBaseRoom{ +public class WarmOceanDomeHutRoom extends WarmOceanBaseRoom { public WarmOceanDomeHutRoom(Random rand, boolean forceSpawn, boolean unique) { super(rand, forceSpawn, unique); } @@ -26,72 +26,63 @@ public WarmOceanDomeHutRoom(Random rand, boolean forceSpawn, boolean unique) { public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { super.populate(data, room); - Material decorator = new Material[]{ - Material.POLISHED_DIORITE, - Material.POLISHED_GRANITE, - Material.POLISHED_ANDESITE + Material decorator = new Material[] { + Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE }[rand.nextInt(3)]; // This is just a cylinder with an ellipse on it SimpleBlock centre = room.getCenterSimpleBlock(data); - float radius = Math.min(room.getWidthX(),room.getWidthZ())/3.0f; + float radius = Math.min(room.getWidthX(), room.getWidthZ()) / 3.0f; int cylSize = GenUtils.randInt(rand, 3, 5); // Carves the actual dome, with sandstone flooring - new CylinderBuilder(rand, centre.getDown(), Material.SMOOTH_SANDSTONE, Material.SANDSTONE) - .setStartFromZero(true) - .setRadius(radius) - .setRY(cylSize+1) - .setNoiseMagnitude(0) - .setHardReplace(true) - .build(); - new CylinderBuilder(rand, centre, Material.WATER) - .setStartFromZero(true) - .setRadius(radius-1) - .setRY(cylSize) - .setNoiseMagnitude(0) - .setHardReplace(true) - .build(); - new SphereBuilder(rand, centre.getUp(cylSize-1), Material.SMOOTH_SANDSTONE, Material.SANDSTONE) - .setRadius(radius) - .setSphereType(SphereBuilder.SphereType.UPPER_SEMISPHERE) - .setSmooth(true) - .build(); - new SphereBuilder(rand, centre.getUp(cylSize-1), Material.WATER) - .setRadius(radius-1) - .setSphereType(SphereBuilder.SphereType.UPPER_SEMISPHERE) - .setSmooth(true) - .setHardReplace(true) - .build(); + new CylinderBuilder( + rand, + centre.getDown(), + Material.SMOOTH_SANDSTONE, + Material.SANDSTONE + ).setStartFromZero(true).setRadius(radius).setRY(cylSize + 1).setNoiseMagnitude(0).setHardReplace(true).build(); + new CylinderBuilder(rand, centre, Material.WATER).setStartFromZero(true) + .setRadius(radius - 1) + .setRY(cylSize) + .setNoiseMagnitude(0) + .setHardReplace(true) + .build(); + new SphereBuilder(rand, centre.getUp(cylSize - 1), Material.SMOOTH_SANDSTONE, Material.SANDSTONE).setRadius( + radius).setSphereType(SphereBuilder.SphereType.UPPER_SEMISPHERE).setSmooth(true).build(); + new SphereBuilder(rand, centre.getUp(cylSize - 1), Material.WATER).setRadius(radius - 1) + .setSphereType(SphereBuilder.SphereType.UPPER_SEMISPHERE) + .setSmooth(true) + .setHardReplace(true) + .build(); // Place chest BlockFace entrance = BlockUtils.getDirectBlockFace(rand); - new ChestBuilder(Material.CHEST) - .setFacing(entrance) - .setLootTable(TerraLootTable.UNDERWATER_RUIN_SMALL) - .apply(centre.getRelative(entrance.getOppositeFace(), ((int)radius)-2)); + new ChestBuilder(Material.CHEST).setFacing(entrance) + .setLootTable(TerraLootTable.UNDERWATER_RUIN_SMALL) + .apply(centre.getRelative(entrance.getOppositeFace(), ((int) radius) - 2)); // Carve door centre.getRelative(entrance, (int) radius).physicsSetType(Material.WATER, true); centre.getUp().getRelative(entrance, (int) radius).physicsSetType(Material.WATER, true); // Holes - for(int i = 0; i < GenUtils.randInt(rand,2,4); i++) - { - BlockUtils.replaceWaterSphere(i*room.getX()*room.getZ(), - GenUtils.randInt(2, 4), - centre.getRelative(GenUtils.getSign(rand)*rand.nextInt((int)radius), - 3+rand.nextInt((int)radius), - GenUtils.getSign(rand)*rand.nextInt((int)radius))); + for (int i = 0; i < GenUtils.randInt(rand, 2, 4); i++) { + BlockUtils.replaceWaterSphere(i * room.getX() * room.getZ(), GenUtils.randInt(2, 4), centre.getRelative( + GenUtils.getSign(rand) * rand.nextInt((int) radius), + 3 + rand.nextInt((int) radius), + GenUtils.getSign(rand) * rand.nextInt((int) radius) + )); } // Decorate stuff - centre.getUp((int) (cylSize+radius-1)).setType(decorator); - for(BlockFace face:BlockUtils.directBlockFaces) - { - if(face == entrance) continue; + centre.getUp((int) (cylSize + radius - 1)).setType(decorator); + for (BlockFace face : BlockUtils.directBlockFaces) { + if (face == entrance) { + continue; + } - centre.getUp(cylSize/2).getRelative(face, (int) radius).setType(decorator); + centre.getUp(cylSize / 2).getRelative(face, (int) radius).setType(decorator); } // Drowned @@ -100,6 +91,6 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getWidthX()<25; + return room.getWidthX() < 25; } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java index 69abae2d..c833d6a8 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java @@ -30,111 +30,123 @@ public WarmOceanLargeArcRoom(Random rand, boolean forceSpawn, boolean unique) { @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - super.populate(data,room); + super.populate(data, room); BlockFace facing = BlockUtils.getDirectBlockFace(rand); // Place a chest somewhere - Wall chestTarget = new Wall(room.getCenterSimpleBlock(data), facing) - .getLeft(GenUtils.getSign(rand)*rand.nextInt(2)) - .getFront(GenUtils.getSign(rand)*rand.nextInt(6)) - .getGround().getUp(); - new ChestBuilder(Material.CHEST) - .setFacing(BlockUtils.getDirectBlockFace(rand)) - .setLootTable(TerraLootTable.UNDERWATER_RUIN_BIG) - .setWaterlogged(chestTarget.getY() <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(chestTarget); + Wall chestTarget = new Wall(room.getCenterSimpleBlock(data), facing).getLeft(GenUtils.getSign(rand) + * rand.nextInt(2)) + .getFront(GenUtils.getSign(rand) + * rand.nextInt(6)) + .getGround() + .getUp(); + new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getDirectBlockFace(rand)) + .setLootTable(TerraLootTable.UNDERWATER_RUIN_BIG) + .setWaterlogged(chestTarget.getY() + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(chestTarget); // Create a 3x3 pattern to use in the arc's walls - Material[] centrePattern = new Material[]{ + Material[] centrePattern = new Material[] { GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), - }; - Material[] sidePattern = new Material[]{ + }; + Material[] sidePattern = new Material[] { GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), GenUtils.randChoice(Material.POLISHED_DIORITE, Material.POLISHED_GRANITE, Material.POLISHED_ANDESITE), - }; + }; // Create another 3x3 slab pattern to overlay BlockData[] centreSlabs = new BlockData[3]; BlockData[] sideSlabs = new BlockData[3]; - for(int i = 0; i < 3; i++) - { + for (int i = 0; i < 3; i++) { centreSlabs[i] = Bukkit.createBlockData(Material.CUT_SANDSTONE_SLAB); - if(rand.nextBoolean()) ((Slab) centreSlabs[i]).setType(Slab.Type.TOP); - if(GenUtils.chance(rand,1,4)) centreSlabs[i] = Bukkit.createBlockData(Material.CHISELED_SANDSTONE); + if (rand.nextBoolean()) { + ((Slab) centreSlabs[i]).setType(Slab.Type.TOP); + } + if (GenUtils.chance(rand, 1, 4)) { + centreSlabs[i] = Bukkit.createBlockData(Material.CHISELED_SANDSTONE); + } sideSlabs[i] = Bukkit.createBlockData(Material.CUT_SANDSTONE_SLAB); - if(rand.nextBoolean()) ((Slab) sideSlabs[i]).setType(Slab.Type.TOP); + if (rand.nextBoolean()) { + ((Slab) sideSlabs[i]).setType(Slab.Type.TOP); + } } // For both the left and right buttresses - for(BlockFace pillarDir:BlockUtils.getAdjacentFaces(facing)) { - SimpleBlock pillarCore = room.getCenterSimpleBlock(data).getRelative(pillarDir,5); + for (BlockFace pillarDir : BlockUtils.getAdjacentFaces(facing)) { + SimpleBlock pillarCore = room.getCenterSimpleBlock(data).getRelative(pillarDir, 5); // Core pillar pillarCore.LPillar(8, Material.CUT_SANDSTONE); // Make the under-stairs to smoothly connect the buttress to the top - for(BlockFace face:BlockUtils.getAdjacentFaces(pillarDir)) - { - new StairBuilder(Material.SANDSTONE_STAIRS) - .setHalf(Bisected.Half.TOP) - .setFacing(pillarDir) - .setWaterlogged(pillarCore.getY()+6 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(pillarCore.getUp(6) - .getRelative(face,2) - .getRelative(pillarDir.getOppositeFace(), 3)) - .setWaterlogged(pillarCore.getY()+7 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(pillarCore.getUp(7) - .getRelative(face,2) - .getRelative(pillarDir.getOppositeFace(), 4)); + for (BlockFace face : BlockUtils.getAdjacentFaces(pillarDir)) { + new StairBuilder(Material.SANDSTONE_STAIRS).setHalf(Bisected.Half.TOP) + .setFacing(pillarDir) + .setWaterlogged(pillarCore.getY() + 6 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(pillarCore.getUp(6) + .getRelative(face, 2) + .getRelative( + pillarDir.getOppositeFace(), + 3 + )) + .setWaterlogged(pillarCore.getY() + 7 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(pillarCore.getUp(7) + .getRelative(face, 2) + .getRelative( + pillarDir.getOppositeFace(), + 4 + )); pillarCore.getUp(7) - .getRelative(face,2) - .getRelative(pillarDir.getOppositeFace(), 3) - .setType(Material.SMOOTH_SANDSTONE); + .getRelative(face, 2) + .getRelative(pillarDir.getOppositeFace(), 3) + .setType(Material.SMOOTH_SANDSTONE); } // Make the corners - for(BlockFace face:BlockUtils.xzDiagonalPlaneBlockFaces) - { - pillarCore.getRelative(face,3).setType(Material.CUT_SANDSTONE_SLAB); - pillarCore.getRelative(face,2).Pillar(8, Material.CUT_SANDSTONE); - pillarCore.getUp(4).getRelative(face,2).setType(Material.CHISELED_SANDSTONE); + for (BlockFace face : BlockUtils.xzDiagonalPlaneBlockFaces) { + pillarCore.getRelative(face, 3).setType(Material.CUT_SANDSTONE_SLAB); + pillarCore.getRelative(face, 2).Pillar(8, Material.CUT_SANDSTONE); + pillarCore.getUp(4).getRelative(face, 2).setType(Material.CHISELED_SANDSTONE); } // Create the base and central bit of the pillar - for(int ny: new int[]{0,4}) - for(int nx = -2; nx <= 2; nx++) - for(int nz = -2; nz <= 2; nz++) { + for (int ny : new int[] {0, 4}) { + for (int nx = -2; nx <= 2; nx++) { + for (int nz = -2; nz <= 2; nz++) { pillarCore.getRelative(nx, ny, nz).setType(Material.CHISELED_SANDSTONE); - if(ny == 0) + if (ny == 0) { pillarCore.getDown().downLPillar(new Random(), 10 + rand.nextInt(5), Material.SANDSTONE); + } } + } + } // Walls - for(BlockFace face:BlockUtils.directBlockFaces) - { - for(BlockFace dir:BlockUtils.getAdjacentFaces(face)) { - pillarCore.getRelative(face, 3).getRelative(dir) - .setType(Material.CUT_SANDSTONE_SLAB); - - new StairBuilder(Material.SANDSTONE_STAIRS) - .setFacing(dir) - .setWaterlogged(pillarCore.getY() <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(pillarCore.getRelative(face, 3).getRelative(dir, 2)); + for (BlockFace face : BlockUtils.directBlockFaces) { + for (BlockFace dir : BlockUtils.getAdjacentFaces(face)) { + pillarCore.getRelative(face, 3).getRelative(dir).setType(Material.CUT_SANDSTONE_SLAB); + + new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(dir) + .setWaterlogged(pillarCore.getY() + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(pillarCore.getRelative(face, 3) + .getRelative(dir, 2)); } - new StairBuilder(Material.SANDSTONE_STAIRS) - .setFacing(face.getOppositeFace()) - .setWaterlogged(pillarCore.getY() <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(pillarCore.getRelative(face,3)); + new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(face.getOppositeFace()) + .setWaterlogged(pillarCore.getY() + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(pillarCore.getRelative(face, 3)); // Place the patterns - for(int up : new int[]{1, 5}) - { - Wall patternCore = new Wall(pillarCore.getUp(up).getRelative(face,1),face); - for(int i = 0; i < 3; i++) - { + for (int up : new int[] {1, 5}) { + Wall patternCore = new Wall(pillarCore.getUp(up).getRelative(face, 1), face); + for (int i = 0; i < 3; i++) { patternCore.getUp(i).setType(centrePattern[i]); patternCore.getUp(i).getLeft().setType(sidePattern[i]); patternCore.getUp(i).getRight().setType(sidePattern[i]); @@ -148,27 +160,33 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Place the upper bridge connecting the two buttresses - Wall core = new Wall(new SimpleBlock(data, room.getX(),room.getY()+8, room.getZ()), facing); - for(int lr = -9; lr <=9; lr++) - for(int fb = -4; fb <= 4; fb++) { - if(Math.abs(lr) < 9 && Math.abs(fb) < 4) { + Wall core = new Wall(new SimpleBlock(data, room.getX(), room.getY() + 8, room.getZ()), facing); + for (int lr = -9; lr <= 9; lr++) { + for (int fb = -4; fb <= 4; fb++) { + if (Math.abs(lr) < 9 && Math.abs(fb) < 4) { core.getLeft(lr).getFront(fb).setType(Material.CUT_SANDSTONE); - if(Math.abs(lr) < 7 && Math.abs(fb) < 2) + if (Math.abs(lr) < 7 && Math.abs(fb) < 2) { core.getLeft(lr).getFront(fb).getUp(4).setType(Material.CUT_SANDSTONE_SLAB); - else if(Math.abs(lr) == 7 || Math.abs(fb) == 2) + } + else if (Math.abs(lr) == 7 || Math.abs(fb) == 2) { core.getLeft(lr).getFront(fb).getUp(4).setType(Material.CUT_SANDSTONE); - else - new SlabBuilder(Material.CUT_SANDSTONE_SLAB) - .setType(Slab.Type.TOP) - .setWaterlogged(core.getY()+4 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(core.getLeft(lr).getFront(fb).getUp(4)); - }else - new SlabBuilder(Material.CUT_SANDSTONE_SLAB) - .setType(Slab.Type.TOP) - .setWaterlogged(core.getY() <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(core.getLeft(lr).getFront(fb)); + } + else { + new SlabBuilder(Material.CUT_SANDSTONE_SLAB).setType(Slab.Type.TOP) + .setWaterlogged(core.getY() + 4 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(core.getLeft(lr).getFront(fb).getUp(4)); + } + } + else { + new SlabBuilder(Material.CUT_SANDSTONE_SLAB).setType(Slab.Type.TOP) + .setWaterlogged(core.getY() + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(core.getLeft(lr).getFront(fb)); + } } + } // Place the pattern on the top of the bridge CubeRoom topCoreRoom = new CubeRoom( @@ -180,51 +198,55 @@ else if(Math.abs(lr) == 7 || Math.abs(fb) == 2) room.getZ() ); - for(Map.Entry entry:topCoreRoom.getFourWalls(data,0).entrySet()) - { + for (Map.Entry entry : topCoreRoom.getFourWalls(data, 0).entrySet()) { Wall w = entry.getKey(); - for(int i = 0; i < entry.getValue(); i++) - { - if(i != 0 && i != entry.getValue()-1) - if(i == 2 || i == 7 || i == 12) - for(int j = 0; j < 3; j++) + for (int i = 0; i < entry.getValue(); i++) { + if (i != 0 && i != entry.getValue() - 1) { + if (i == 2 || i == 7 || i == 12) { + for (int j = 0; j < 3; j++) { w.getFront().getUp(j).setType(centrePattern[j]); - else - for(int j = 0; j < 3; j++) + } + } + else { + for (int j = 0; j < 3; j++) { w.getFront().getUp(j).setType(sidePattern[j]); + } + } + } // Decorations in the top of the bridge - if(i == 0) - { + if (i == 0) { w.Pillar(3, Material.CHISELED_SANDSTONE); new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft()) - .setHalf(Bisected.Half.TOP) - .setWaterlogged(w.getY()+2 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(w.getLeft().getUp(2)); + .apply(w.getLeft()) + .setHalf(Bisected.Half.TOP) + .setWaterlogged(w.getY() + 2 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(w.getLeft().getUp(2)); } - else if(i == entry.getValue()-1) - { + else if (i == entry.getValue() - 1) { w.Pillar(3, Material.CHISELED_SANDSTONE); new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRight()) - .setHalf(Bisected.Half.TOP) - .setWaterlogged(w.getY() + 2 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(w.getRight().getUp(2)); + .apply(w.getRight()) + .setHalf(Bisected.Half.TOP) + .setWaterlogged(w.getY() + 2 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(w.getRight().getUp(2)); } - else if(i == 4 || i == 10) - { + else if (i == 4 || i == 10) { w.Pillar(3, Material.CHISELED_SANDSTONE); new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(BlockUtils.getLeft(w.getDirection())) - .apply(w.getRight()) - .setHalf(Bisected.Half.TOP) - .setWaterlogged(w.getY() + 2 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(w.getRight().getUp(2)); + .apply(w.getRight()) + .setHalf(Bisected.Half.TOP) + .setWaterlogged(w.getY() + 2 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(w.getRight().getUp(2)); new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) - .apply(w.getLeft()) - .setHalf(Bisected.Half.TOP) - .setWaterlogged(w.getY() + 2 <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) - .apply(w.getLeft().getUp(2)); + .apply(w.getLeft()) + .setHalf(Bisected.Half.TOP) + .setWaterlogged(w.getY() + 2 + <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + .apply(w.getLeft().getUp(2)); } w = w.getLeft(); } @@ -232,18 +254,18 @@ else if(i == 4 || i == 10) // Procedurally create holes Wall centre = new Wall(room.getCenterSimpleBlock(data), facing); - for(int i = 0; i < 1+rand.nextInt(3); i++) - { - BlockUtils.replaceWaterSphere(i*room.getX()*room.getZ(), + for (int i = 0; i < 1 + rand.nextInt(3); i++) { + BlockUtils.replaceWaterSphere( + i * room.getX() * room.getZ(), GenUtils.randInt(3, 4), centre.getUp(6) - .getLeft(GenUtils.getSign(rand)*rand.nextInt(7)) - .getFront(GenUtils.getSign(rand)*rand.nextInt(3))); + .getLeft(GenUtils.getSign(rand) * rand.nextInt(7)) + .getFront(GenUtils.getSign(rand) * rand.nextInt(3)) + ); } // Drowned - for(int i = 0; i < 1+rand.nextInt(3); i++) - { + for (int i = 0; i < 1 + rand.nextInt(3); i++) { centre.getUp().addEntity(EntityType.DROWNED); } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java index aa0c922b..ac33ef1c 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java @@ -20,35 +20,40 @@ public class WarmOceanRuinsPopulator extends SingleMegaChunkStructurePopulator { public @NotNull Random getHashedRandom(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return tw.getHashedRand(352341322, chunkX, chunkZ); } - + private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 65732), - (int) (TConfigOption.STRUCTURES_WARMOCEANRUINS_SPAWNRATIO - .getDouble() * 10000), - 10000); + (int) (TConfigOption.STRUCTURES_WARMOCEANRUINS_SPAWNRATIO.getDouble() * 10000), + 10000 + ); } @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { - if (!isEnabled()) return false; - - if(biome == (BiomeBank.DEEP_WARM_OCEAN) - || biome == (BiomeBank.WARM_OCEAN) - || biome == (BiomeBank.DEEP_LUKEWARM_OCEAN) - || biome == (BiomeBank.CORAL_REEF_OCEAN) - || biome == (BiomeBank.COLD_OCEAN) - || biome == (BiomeBank.DEEP_COLD_OCEAN) - || biome == (BiomeBank.FROZEN_OCEAN) - || biome == (BiomeBank.DEEP_FROZEN_OCEAN)) { - - return rollSpawnRatio(tw,chunkX,chunkZ); + if (!isEnabled()) { + return false; + } + + if (biome == (BiomeBank.DEEP_WARM_OCEAN) + || biome == (BiomeBank.WARM_OCEAN) + || biome == (BiomeBank.DEEP_LUKEWARM_OCEAN) + || biome == (BiomeBank.CORAL_REEF_OCEAN) + || biome == (BiomeBank.COLD_OCEAN) + || biome == (BiomeBank.DEEP_COLD_OCEAN) + || biome == (BiomeBank.FROZEN_OCEAN) + || biome == (BiomeBank.DEEP_FROZEN_OCEAN)) + { + + return rollSpawnRatio(tw, chunkX, chunkZ); } return false; } @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!isEnabled()) return; + if (!isEnabled()) { + return; + } MegaChunk mc = new MegaChunk(data.getChunkX(), data.getChunkZ()); int[] coords = mc.getCenterBiomeSectionBlockCoords(); // getCoordsFromMegaChunk(tw, mc); @@ -57,17 +62,30 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // Height set to 50 as plains village will settle its own height. int y = GenUtils.getHighestGround(data, x, z); - spawnWarmOceanRuins(tw,this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), - data,x,y,z); + spawnWarmOceanRuins(tw, this.getHashedRandom(tw, data.getChunkX(), data.getChunkZ()), data, x, y, z); } - public void spawnWarmOceanRuins(@NotNull TerraformWorld tw, Random random, @NotNull PopulatorDataAbstract data, int x, int y, int z){ + public void spawnWarmOceanRuins(@NotNull TerraformWorld tw, + Random random, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { int numRooms = 10; int range = 80; // Level One Random hashedRand = tw.getHashedRand(x, y, z); - RoomLayoutGenerator gen = new RoomLayoutGenerator(hashedRand, RoomLayout.RANDOM_BRUTEFORCE, numRooms, x, y, z, range); + RoomLayoutGenerator gen = new RoomLayoutGenerator( + hashedRand, + RoomLayout.RANDOM_BRUTEFORCE, + numRooms, + x, + y, + z, + range + ); // gen.setPathPopulator(new WarmOceansPathPopulator()); gen.setRoomMaxX(15); gen.setRoomMaxZ(15); @@ -75,7 +93,7 @@ public void spawnWarmOceanRuins(@NotNull TerraformWorld tw, Random random, @NotN gen.setRoomMinZ(10); gen.setRoomMaxHeight(15); gen.setCarveRooms(true); - gen.setCarveRoomsMultiplier(0,0,0); // No carving + gen.setCarveRoomsMultiplier(0, 0, 0); // No carving gen.forceAddRoom(25, 25, 25); // At least one room that is the center room. @@ -84,7 +102,14 @@ public void spawnWarmOceanRuins(@NotNull TerraformWorld tw, Random random, @NotN gen.registerRoomPopulator(new WarmOceanWellRoom(random, false, false)); gen.registerRoomPopulator(new WarmOceanLargeArcRoom(random, false, false)); gen.calculateRoomPlacement(); - gen.fillRoomsOnly(data, tw, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.CRACKED_STONE_BRICKS); + gen.fillRoomsOnly( + data, + tw, + Material.STONE_BRICKS, + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + ); } @@ -97,14 +122,15 @@ public int getChunkBufferDistance() { // spawn everywhere. @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.DEEP_WARM_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.WARM_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_LUKEWARM_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.CORAL_REEF_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.COLD_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_COLD_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.FROZEN_OCEAN) - || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_FROZEN_OCEAN)) + return TConfigOption.areStructuresEnabled() + && (BiomeBank.isBiomeEnabled(BiomeBank.DEEP_WARM_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.WARM_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_LUKEWARM_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.CORAL_REEF_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.COLD_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_COLD_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.FROZEN_OCEAN) + || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_FROZEN_OCEAN)) && TConfigOption.STRUCTURES_WARMOCEANRUINS_ENABLED.getBoolean(); } } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanWellRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanWellRoom.java index 6f98df9e..3473e070 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanWellRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanWellRoom.java @@ -7,7 +7,7 @@ import java.util.Random; -public class WarmOceanWellRoom extends WarmOceanBaseRoom{ +public class WarmOceanWellRoom extends WarmOceanBaseRoom { public WarmOceanWellRoom(Random rand, boolean forceSpawn, boolean unique) { super(rand, forceSpawn, unique); } @@ -16,12 +16,18 @@ public WarmOceanWellRoom(Random rand, boolean forceSpawn, boolean unique) { @Override public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { super.populate(data, room); - new DesertWellPopulator().spawnDesertWell(data.getTerraformWorld(), rand, - data, room.getX(), room.getY()-1, room.getZ(), false); + new DesertWellPopulator().spawnDesertWell(data.getTerraformWorld(), + rand, + data, + room.getX(), + room.getY() - 1, + room.getZ(), + false + ); } @Override public boolean canPopulate(@NotNull CubeRoom room) { - return room.getWidthX()<25; + return room.getWidthX() < 25; } } diff --git a/common/src/main/java/org/terraform/tree/FractalLeaves.java b/common/src/main/java/org/terraform/tree/FractalLeaves.java index 92fb791f..7c998e56 100644 --- a/common/src/main/java/org/terraform/tree/FractalLeaves.java +++ b/common/src/main/java/org/terraform/tree/FractalLeaves.java @@ -22,24 +22,26 @@ import java.util.HashSet; import java.util.Random; -public class FractalLeaves implements Cloneable{ +public class FractalLeaves implements Cloneable { - int oriY; - int maxHeight; - TerraformWorld tw; + @NotNull + final Random rand = new Random(); + /** + * Used for caching leaves that are already processed. + * Meant to be cleared when a new tree begins using the class. + */ + private final HashSet occupiedLeaves = new HashSet<>(); public float radiusX = 4; public float radiusY = 2; public int numYSegments = 5; public float radiusZ = 4; public int offsetY = 0; - public Material[] material = new Material[] {Material.OAK_LEAVES}; + int oriY; // public FractalTreeBuilder builder; - + int maxHeight; + TerraformWorld tw; boolean semiSphereLeaves = false; - @NotNull - final - Random rand = new Random(); float leafNoiseMultiplier = 0.7f; float leafNoiseFrequency = 0.09f; double hollowLeaves = 0.0; @@ -52,51 +54,43 @@ public class FractalLeaves implements Cloneable{ int unitLeafSize = 0; float unitLeafChance = 0; - /** - * Used for caching leaves that are already processed. - * Meant to be cleared when a new tree begins using the class. - */ - private final HashSet occupiedLeaves = new HashSet<>(); - public void purgeOccupiedLeavesCache(){ occupiedLeaves.clear(); } + public void purgeOccupiedLeavesCache() { + occupiedLeaves.clear(); + } public void placeLeaves(@NotNull SimpleBlock centre) { placeLeaves(centre.getPopData().getTerraformWorld(), -999, 999, centre); } + /** * This is a sphere algorithm + * * @param centre the centre of the sphere. */ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull SimpleBlock centre) { - // Setup noise to be used in randomising the sphere + // Setup noise to be used in randomising the sphere this.tw = tw; this.oriY = oriY; this.maxHeight = maxHeight; - FastNoise noiseGen = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.FRACTALTREES_LEAVES_NOISE, - world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetFractalOctaves(5); - n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); - - return n; - }); + FastNoise noiseGen = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.FRACTALTREES_LEAVES_NOISE, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetFractalOctaves(5); + n.SetNoiseType(FastNoise.NoiseType.SimplexFractal); + + return n; + }); noiseGen.SetFrequency(leafNoiseFrequency); - + // Don't place anything if radius is nothing - if (radiusX <= 0 && - radiusY <= 0 && - radiusZ <= 0) { + if (radiusX <= 0 && radiusY <= 0 && radiusZ <= 0) { return; } // Radius 0.5 is 1 block - if (radiusX <= 0.5 && - radiusY <= 0.5 && - radiusZ <= 0.5) { + if (radiusX <= 0.5 && radiusY <= 0.5 && radiusZ <= 0.5) { centre.setType(material); return; } @@ -104,13 +98,15 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim // Initialise noise to be used in randomising the sphere float noiseMultiplier = leafNoiseMultiplier; int minRadiusY = -Math.round(radiusY); - if(semiSphereLeaves) minRadiusY = 0; + if (semiSphereLeaves) { + minRadiusY = 0; + } ArrayList changed = new ArrayList<>(); for (int y = minRadiusY; y <= radiusY; y++) { for (int x = -Math.round(radiusX); x <= radiusX; x++) { for (int z = -Math.round(radiusZ); z <= radiusZ; z++) { - Material material = this.material[rand.nextInt(this.material.length)]; + Material material = this.material[rand.nextInt(this.material.length)]; SimpleBlock relativeBlock = centre.getRelative(x, y + offsetY, z); if (relativeBlock.getY() - oriY > maxHeight) { @@ -119,7 +115,9 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim if (relativeBlock.getY() - oriY == maxHeight) { if (rand.nextBoolean()) // Fade off if too high + { return; + } } float effectiveY = y; @@ -127,45 +125,68 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim if (coneLeaves) { effectiveY += radiusY / 2; // Shift center area downwards // Compress negative y - if (effectiveY < 0) effectiveY = effectiveY * 2.0f; + if (effectiveY < 0) { + effectiveY = effectiveY * 2.0f; + } // Extend positive y and multiply it by a power to make it sharp if (effectiveY > 0) { effectiveY = effectiveY * (2.0f / 3.0f); effectiveY = (float) Math.pow(effectiveY, 1.3); - if (effectiveY > radiusY) effectiveY = radiusY; + if (effectiveY > radiusY) { + effectiveY = radiusY; + } } relativeBlock = relativeBlock.getRelative(0, (int) (radiusY / 2), 0); } // Continue as early as possible. - if(occupiedLeaves.contains(relativeBlock)) + if (occupiedLeaves.contains(relativeBlock)) { continue; + } - double equationResult = Math.pow(x, 2) / Math.pow(radiusX, 2) - + Math.pow(effectiveY, 2) / Math.pow(radiusY, 2) - + Math.pow(z, 2) / Math.pow(radiusZ, 2); - - if (equationResult <= 1 + noiseMultiplier * noiseGen.GetNoise(relativeBlock.getX(), relativeBlock.getY(), relativeBlock.getZ())) { - if (equationResult < hollowLeaves) + double equationResult = Math.pow(x, 2) / Math.pow(radiusX, 2) + Math.pow(effectiveY, 2) / Math.pow( + radiusY, + 2 + ) + Math.pow(z, 2) / Math.pow(radiusZ, 2); + + if (equationResult <= 1 + noiseMultiplier * noiseGen.GetNoise( + relativeBlock.getX(), + relativeBlock.getY(), + relativeBlock.getZ() + )) + { + if (equationResult < hollowLeaves) { continue; + } // cache this block so that getType and setType aren't called for already processed blocks occupiedLeaves.add(relativeBlock); - if(mangrovePropagules && Version.isAtLeast(19) && !BlockUtils.isWet(relativeBlock.getDown())) { - if (GenUtils.chance(1, 50)) { - relativeBlock.getDown().rsetBlockData(BlockUtils.replacableByTrees, OneOneNineBlockHandler.getHangingMangrovePropagule()); - } + if (mangrovePropagules && Version.isAtLeast(19) && !BlockUtils.isWet(relativeBlock.getDown())) { + if (GenUtils.chance(1, 50)) { + relativeBlock.getDown() + .rsetBlockData( + BlockUtils.replacableByTrees, + OneOneNineBlockHandler.getHangingMangrovePropagule() + ); + } } // For fixing up corals later if (Tag.CORALS.isTagged(material)) { - if (!changed.contains(relativeBlock)) + if (!changed.contains(relativeBlock)) { changed.add(relativeBlock); + } } // Decorate with fans if (coralDecoration) { - CoralGenerator.generateSingleCoral(relativeBlock.getPopData(), relativeBlock.getX(), relativeBlock.getY(), relativeBlock.getZ(), this.material[0].toString()); + CoralGenerator.generateSingleCoral( + relativeBlock.getPopData(), + relativeBlock.getX(), + relativeBlock.getY(), + relativeBlock.getZ(), + this.material[0].toString() + ); } // Leaves do not replace solid blocks. @@ -173,14 +194,15 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim unitSet(relativeBlock, material); // Handle placing random cubes in the leaves - if(this.unitLeafSize > 0 && this.unitLeafChance > 0) - { - if(GenUtils.chance(this.rand, (int) (this.unitLeafChance*100),100)) - { - for(int scaleX = -unitLeafSize; scaleX < unitLeafSize; scaleX++) - for(int scaleZ = -unitLeafSize; scaleZ < unitLeafSize; scaleZ++) - for(int scaleY = -unitLeafSize; scaleY < unitLeafSize; scaleY++) + if (this.unitLeafSize > 0 && this.unitLeafChance > 0) { + if (GenUtils.chance(this.rand, (int) (this.unitLeafChance * 100), 100)) { + for (int scaleX = -unitLeafSize; scaleX < unitLeafSize; scaleX++) { + for (int scaleZ = -unitLeafSize; scaleZ < unitLeafSize; scaleZ++) { + for (int scaleY = -unitLeafSize; scaleY < unitLeafSize; scaleY++) { unitSet(relativeBlock.getRelative(scaleX, scaleY, scaleZ), material); + } + } + } } } } @@ -193,7 +215,11 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim } if (weepingLeavesChance > 0 && Math.random() < weepingLeavesChance) { - weepingLeaves(relativeBlock, Math.round(weepingLeavesChance * weepingLeavesLength), weepingLeavesLength); + weepingLeaves( + relativeBlock, + Math.round(weepingLeavesChance * weepingLeavesLength), + weepingLeavesLength + ); } } } @@ -206,18 +232,19 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim if (!CoralGenerator.isSaturatedCoral(sb)) { // No floating coral fans for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALL_CORALS.isTagged(sb.getRelative(face).getType())) + if (Tag.WALL_CORALS.isTagged(sb.getRelative(face).getType())) { sb.getRelative(face).setType(Material.WATER); + } } // No levitating sea pickles & fans - if (sb.getUp().getType() == Material.SEA_PICKLE || - Tag.CORAL_PLANTS.isTagged(sb.getUp().getType())) { + if (sb.getUp().getType() == Material.SEA_PICKLE || Tag.CORAL_PLANTS.isTagged(sb.getUp().getType())) { sb.getUp().setType(Material.WATER); } sb.setType(Material.WATER); - } else { + } + else { sb.setType(material); } } @@ -228,13 +255,14 @@ private void unitSet(@NotNull SimpleBlock relativeBlock, @NotNull Material mater Leaves leaf = (Leaves) Bukkit.createBlockData(material); leaf.setDistance(1); relativeBlock.rsetBlockData(BlockUtils.replacableByTrees, leaf); - } else { - relativeBlock.rsetType(BlockUtils.replacableByTrees,material); + } + else { + relativeBlock.rsetType(BlockUtils.replacableByTrees, material); } } private void weepingLeaves(@NotNull SimpleBlock base, int minDist, int maxDist) { - Material material = this.material[rand.nextInt(this.material.length)]; + Material material = this.material[rand.nextInt(this.material.length)]; BlockData type = Bukkit.createBlockData(material); if (Tag.LEAVES.isTagged(material)) { Leaves leaf = (Leaves) type; @@ -242,10 +270,12 @@ private void weepingLeaves(@NotNull SimpleBlock base, int minDist, int maxDist) } for (int i = 1; i <= GenUtils.randInt(minDist, maxDist); i++) { - if (BlockUtils.isAir(base.getRelative(0, -i, 0).getType())) + if (BlockUtils.isAir(base.getRelative(0, -i, 0).getType())) { base.getRelative(0, -i, 0).rsetBlockData(BlockUtils.replacableByTrees, type); - else + } + else { break; + } } } @@ -266,7 +296,7 @@ private void weepingLeaves(@NotNull SimpleBlock base, int minDist, int maxDist) public @NotNull FractalLeaves setRadiusY(float radiusY) { this.radiusY = radiusY; - this.numYSegments = (int) Math.ceil(radiusY*2+1); + this.numYSegments = (int) Math.ceil(radiusY * 2 + 1); return this; } @@ -318,9 +348,11 @@ private void weepingLeaves(@NotNull SimpleBlock base, int minDist, int maxDist) this.mangrovePropagules = mangrovePropagules; return this; } + /** * Creates dangling leaves without vines. Useful for * creating types of weeping trees. + * * @param chance chance of creating dangling leaves per block (0 - 1) * @param maxLength maximum length of dangling leaves */ @@ -335,11 +367,13 @@ private void weepingLeaves(@NotNull SimpleBlock base, int minDist, int maxDist) this.unitLeafChance = unitLeafChance; return this; } + public @NotNull FractalLeaves setUnitLeafSize(int unitSize) { this.unitLeafSize = unitSize; return this; } + public @NotNull FractalLeaves setSemiSphereLeaves(boolean semiSphereLeaves) { this.semiSphereLeaves = semiSphereLeaves; @@ -372,7 +406,7 @@ public void setTw(TerraformWorld tw) { @Override - public FractalLeaves clone() throws CloneNotSupportedException{ + public FractalLeaves clone() throws CloneNotSupportedException { return (FractalLeaves) super.clone(); } } diff --git a/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java b/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java index ffd48170..7b911e7e 100644 --- a/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java +++ b/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java @@ -21,8 +21,8 @@ import org.terraform.utils.CoralGenerator; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; -import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.FastNoise.NoiseType; +import org.terraform.utils.noise.NoiseCacheHandler; import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry; import org.terraform.utils.version.BeeHiveSpawner; import org.terraform.utils.version.OneOneNineBlockHandler; @@ -33,6 +33,8 @@ import java.util.Random; public class FractalTreeBuilder { + protected TerraformWorld tw; + protected boolean coralDecoration = false; int height = 0; SimpleBlock top; float baseThickness = 3; @@ -40,7 +42,6 @@ public class FractalTreeBuilder { float thicknessDecrement = 0.5f; float minThickness = 0f; int maxDepth = 4; - // maxHeight is used for corals to force sea-level cutoff. int maxHeight = 999; float lengthDecrement = 1; @@ -69,522 +70,545 @@ public class FractalTreeBuilder { int fractalsDone = 0; double maxPitch = 9999; double minPitch = -9999; - protected TerraformWorld tw; float branchNoiseMultiplier = 0.7f; float branchNoiseFrequency = 0.09f; int oriX; int oriY; int oriZ; private SimpleBlock beeHive; - protected boolean coralDecoration = false; private double initialAngle; - private int initialHeight; + private int initialHeight; private boolean heightGradientChecked = false; public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { switch (type) { case FOREST: - this - .setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) - .setBaseHeight(9) - .setBaseThickness(3.0f) - .setThicknessDecrement(0.3f) - .setLengthDecrement(1.3f) - .setMinBend(0.7 * Math.PI / 6) - .setMaxBend(0.85 * Math.PI / 6) - .setMaxDepth(4) - .setHeightVariation(2) - .setLeafBranchFrequency(0.05f) - .setFractalLeaves(new FractalLeaves().setRadius(3) - .setLeafNoiseFrequency(1.0f).setLeafNoiseMultiplier(1.0f)); + this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) + .setBaseHeight(9) + .setBaseThickness(3.0f) + .setThicknessDecrement(0.3f) + .setLengthDecrement(1.3f) + .setMinBend(0.7 * Math.PI / 6) + .setMaxBend(0.85 * Math.PI / 6) + .setMaxDepth(4) + .setHeightVariation(2) + .setLeafBranchFrequency(0.05f) + .setFractalLeaves(new FractalLeaves().setRadius(3) + .setLeafNoiseFrequency(1.0f) + .setLeafNoiseMultiplier(1.0f)); break; case NORMAL_SMALL: this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) - .setBaseHeight(5) - .setBaseThickness(1) - .setThicknessDecrement(1f) - .setMaxDepth(1) - .setFractalLeaves(new FractalLeaves().setRadius(3) - .setLeafNoiseFrequency(1.0f).setLeafNoiseMultiplier(1.0f)) - .setHeightVariation(1); + .setBaseHeight(5) + .setBaseThickness(1) + .setThicknessDecrement(1f) + .setMaxDepth(1) + .setFractalLeaves(new FractalLeaves().setRadius(3) + .setLeafNoiseFrequency(1.0f) + .setLeafNoiseMultiplier(1.0f)) + .setHeightVariation(1); break; case AZALEA_TOP: this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) - .setBaseHeight(3) - .setBaseThickness(1) - .setThicknessDecrement(0.3f) - .setLengthDecrement(0.3f) - .setMaxDepth(2) - .setFractalLeaves(new FractalLeaves() - .setMaterial(Material.AZALEA_LEAVES, Material.FLOWERING_AZALEA_LEAVES) - .setRadiusX(3) - .setRadiusZ(3) - .setRadiusY(1.5f) - .setLeafNoiseFrequency(1.0f).setLeafNoiseMultiplier(1.0f) - .setWeepingLeaves(0.3f,3)) - .setVines(3) - .setMinBend(0.9 * Math.PI / 6) - .setMaxBend(1.1 * Math.PI / 6) - .setHeightVariation(0); + .setBaseHeight(3) + .setBaseThickness(1) + .setThicknessDecrement(0.3f) + .setLengthDecrement(0.3f) + .setMaxDepth(2) + .setFractalLeaves(new FractalLeaves().setMaterial( + Material.AZALEA_LEAVES, + Material.FLOWERING_AZALEA_LEAVES + ) + .setRadiusX(3) + .setRadiusZ(3) + .setRadiusY(1.5f) + .setLeafNoiseFrequency(1.0f) + .setLeafNoiseMultiplier(1.0f) + .setWeepingLeaves(0.3f, 3)) + .setVines(3) + .setMinBend(0.9 * Math.PI / 6) + .setMaxBend(1.1 * Math.PI / 6) + .setHeightVariation(0); break; case BIRCH_BIG: this.setBaseHeight(6) - .setBaseThickness(1) - .setThicknessDecrement(0f) - .setMaxDepth(4) - .setHeightVariation(2) - .setMinBend(0.9 * Math.PI / 6) - .setMaxBend(1.1 * Math.PI / 6) - .setLengthDecrement(0.5f) - .setTrunkType(Material.BIRCH_WOOD) - .setFractalLeaves(new FractalLeaves().setMaterial(Material.BIRCH_LEAVES).setRadius(3, 2.3f, 3)); + .setBaseThickness(1) + .setThicknessDecrement(0f) + .setMaxDepth(4) + .setHeightVariation(2) + .setMinBend(0.9 * Math.PI / 6) + .setMaxBend(1.1 * Math.PI / 6) + .setLengthDecrement(0.5f) + .setTrunkType(Material.BIRCH_WOOD) + .setFractalLeaves(new FractalLeaves().setMaterial(Material.BIRCH_LEAVES).setRadius(3, 2.3f, 3)); break; case BIRCH_SMALL: this.setBaseHeight(3) - .setBaseThickness(1) - .setThicknessDecrement(0f) - .setMaxDepth(3) - .setHeightVariation(1) - .setMinBend(0.9 * Math.PI / 6) - .setMaxBend(1.1 * Math.PI / 6) - .setLengthDecrement(0.5f) - .setTrunkType(Material.BIRCH_WOOD) - .setFractalLeaves(new FractalLeaves().setMaterial(Material.BIRCH_LEAVES).setRadius(3, 2.3f, 3)); + .setBaseThickness(1) + .setThicknessDecrement(0f) + .setMaxDepth(3) + .setHeightVariation(1) + .setMinBend(0.9 * Math.PI / 6) + .setMaxBend(1.1 * Math.PI / 6) + .setLengthDecrement(0.5f) + .setTrunkType(Material.BIRCH_WOOD) + .setFractalLeaves(new FractalLeaves().setMaterial(Material.BIRCH_LEAVES).setRadius(3, 2.3f, 3)); break; case CHERRY_SMALL: this.setBaseHeight(4) - .setBaseThickness(2.5f) - .setThicknessDecrement(0.5f) - .setMaxDepth(3) - .setDepthPitchMultiplier(0.8f) - .setInitialTilt(Math.PI / 8) - .setHeightVariation(1) - .setMinBend(0.9 * Math.PI / 6) - .setMaxBend(1.1 * Math.PI / 6) - .setLengthDecrement(-0.5f) - .setMinThickness(1.0f) - .setTrunkType(OneTwentyBlockHandler.CHERRY_LOG) - .setFractalLeaves(new FractalLeaves() - .setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) - .setRadius(3, 2f, 3)); + .setBaseThickness(2.5f) + .setThicknessDecrement(0.5f) + .setMaxDepth(3) + .setDepthPitchMultiplier(0.8f) + .setInitialTilt(Math.PI / 8) + .setHeightVariation(1) + .setMinBend(0.9 * Math.PI / 6) + .setMaxBend(1.1 * Math.PI / 6) + .setLengthDecrement(-0.5f) + .setMinThickness(1.0f) + .setTrunkType(OneTwentyBlockHandler.CHERRY_LOG) + .setFractalLeaves(new FractalLeaves().setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) + .setRadius(3, 2f, 3)); break; case CHERRY_THICK: this.setBaseHeight(5) - .setBaseThickness(3f) - .setThicknessDecrement(0.4f) - .setMaxDepth(4) - .setDepthPitchMultiplier(-0.6f) - .setInitialTilt(1.3 * Math.PI / 6) - .setMinInitialTilt(Math.PI / 6) - .setHeightVariation(0) - .setMinBend(0.9 * Math.PI / 6) - .setMaxBend(1.1 * Math.PI / 6) - .setLengthDecrement(0.3f) - .setMinThickness(1.0f) - .setTrunkType(OneTwentyBlockHandler.CHERRY_WOOD) - .setFractalLeaves(new FractalLeaves() - .setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) - .setRadius(3, 2f, 3) - .setLeafNoiseFrequency(0.15f)); + .setBaseThickness(3f) + .setThicknessDecrement(0.4f) + .setMaxDepth(4) + .setDepthPitchMultiplier(-0.6f) + .setInitialTilt(1.3 * Math.PI / 6) + .setMinInitialTilt(Math.PI / 6) + .setHeightVariation(0) + .setMinBend(0.9 * Math.PI / 6) + .setMaxBend(1.1 * Math.PI / 6) + .setLengthDecrement(0.3f) + .setMinThickness(1.0f) + .setTrunkType(OneTwentyBlockHandler.CHERRY_WOOD) + .setFractalLeaves(new FractalLeaves().setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) + .setRadius(3, 2f, 3) + .setLeafNoiseFrequency(0.15f)); break; case ANDESITE_PETRIFIED_SMALL: this.setBaseHeight(6) - .setBaseThickness(3) - .setThicknessDecrement(0.5f) - .setMaxDepth(3) - .setTrunkType(Material.ANDESITE) - .setMinBend(1.1 * Math.PI / 6) - .setMaxBend(1.3 * Math.PI / 6) - .setLengthDecrement(1) - .setHeightVariation(2) - .setVines(3) - .setFractalLeaves( - new FractalLeaves() - .setRadius(4, 2f, 4) - .setMaterial(Material.ANDESITE, Material.POLISHED_ANDESITE, Material.ANDESITE) - .setWeepingLeaves(0.3f,3) - ); + .setBaseThickness(3) + .setThicknessDecrement(0.5f) + .setMaxDepth(3) + .setTrunkType(Material.ANDESITE) + .setMinBend(1.1 * Math.PI / 6) + .setMaxBend(1.3 * Math.PI / 6) + .setLengthDecrement(1) + .setHeightVariation(2) + .setVines(3) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2f, 4) + .setMaterial(Material.ANDESITE, + Material.POLISHED_ANDESITE, + Material.ANDESITE + ) + .setWeepingLeaves(0.3f, 3)); break; case GRANITE_PETRIFIED_SMALL: this.setBaseHeight(6) - .setBaseThickness(3) - .setThicknessDecrement(0.5f) - .setMaxDepth(3) - .setTrunkType(Material.GRANITE) - .setMinBend(1.1 * Math.PI / 6) - .setMaxBend(1.3 * Math.PI / 6) - .setLengthDecrement(1) - .setHeightVariation(2) - .setVines(3) - .setFractalLeaves( - new FractalLeaves() - .setRadius(4, 2f, 4) - .setMaterial(Material.GRANITE, Material.POLISHED_GRANITE, Material.GRANITE) - .setWeepingLeaves(0.3f,3) - ); + .setBaseThickness(3) + .setThicknessDecrement(0.5f) + .setMaxDepth(3) + .setTrunkType(Material.GRANITE) + .setMinBend(1.1 * Math.PI / 6) + .setMaxBend(1.3 * Math.PI / 6) + .setLengthDecrement(1) + .setHeightVariation(2) + .setVines(3) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2f, 4) + .setMaterial(Material.GRANITE, + Material.POLISHED_GRANITE, + Material.GRANITE + ) + .setWeepingLeaves(0.3f, 3)); break; case DIORITE_PETRIFIED_SMALL: this.setBaseHeight(6) - .setBaseThickness(3) - .setThicknessDecrement(0.5f) - .setMaxDepth(3) - .setTrunkType(Material.DIORITE) - .setMinBend(1.1 * Math.PI / 6) - .setMaxBend(1.3 * Math.PI / 6) - .setLengthDecrement(1) - .setHeightVariation(2) - .setVines(3) - .setFractalLeaves( - new FractalLeaves() - .setRadius(4, 2f, 4) - .setMaterial(Material.DIORITE, Material.POLISHED_DIORITE, Material.DIORITE) - .setWeepingLeaves(0.3f,3) - ); + .setBaseThickness(3) + .setThicknessDecrement(0.5f) + .setMaxDepth(3) + .setTrunkType(Material.DIORITE) + .setMinBend(1.1 * Math.PI / 6) + .setMaxBend(1.3 * Math.PI / 6) + .setLengthDecrement(1) + .setHeightVariation(2) + .setVines(3) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2f, 4) + .setMaterial(Material.DIORITE, + Material.POLISHED_DIORITE, + Material.DIORITE + ) + .setWeepingLeaves(0.3f, 3)); break; case SAVANNA_SMALL: this.setBaseHeight(7) - .setBaseThickness(1) - .setThicknessDecrement(0) - .setMaxDepth(2) - .setTrunkType(Material.ACACIA_LOG) - .setMinBend(0.5 * Math.PI / 2) - .setMaxBend(0.8 * Math.PI / 2) - .setLengthDecrement(1) - .setHeightVariation(1) - .setFractalLeaves(new FractalLeaves().setRadius(4, 2f, 4).setMaterial(Material.ACACIA_LEAVES)); + .setBaseThickness(1) + .setThicknessDecrement(0) + .setMaxDepth(2) + .setTrunkType(Material.ACACIA_LOG) + .setMinBend(0.5 * Math.PI / 2) + .setMaxBend(0.8 * Math.PI / 2) + .setLengthDecrement(1) + .setHeightVariation(1) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2f, 4).setMaterial(Material.ACACIA_LEAVES)); break; case JUNGLE_BIG: this.setBaseHeight(15) - .setBaseThickness(5) - .setThicknessDecrement(1f) - .setMaxDepth(3) - .setHeightVariation(6) - .setMaxBend(Math.PI / 6) - .setLengthDecrement(2) - .setVines(7) - .setTrunkType(Material.JUNGLE_WOOD) - .setCocoaBeans(3) - .setFractalLeaves(new FractalLeaves().setRadius(4, 1, 4) - .setMaterial(Material.JUNGLE_LEAVES).setOffsetY(1) - .setWeepingLeaves(0.4f,7)); + .setBaseThickness(5) + .setThicknessDecrement(1f) + .setMaxDepth(3) + .setHeightVariation(6) + .setMaxBend(Math.PI / 6) + .setLengthDecrement(2) + .setVines(7) + .setTrunkType(Material.JUNGLE_WOOD) + .setCocoaBeans(3) + .setFractalLeaves(new FractalLeaves().setRadius(4, 1, 4) + .setMaterial(Material.JUNGLE_LEAVES) + .setOffsetY(1) + .setWeepingLeaves(0.4f, 7)); break; case JUNGLE_SMALL: this.setBaseHeight(5) - .setHeightVariation(1) - .setLengthDecrement(1.5f) - .setMaxDepth(2) - .setBaseThickness(3) - .setThicknessDecrement(1.5f) - .setMaxBend(Math.PI / 3) - .setVines(3) - .setTrunkType(Material.JUNGLE_WOOD) - .setCocoaBeans(1) - .setFractalLeaves(new FractalLeaves() - .setRadius(4, 2, 4) - .setMaterial(Material.JUNGLE_LEAVES) - .setWeepingLeaves(0.3f,3)); + .setHeightVariation(1) + .setLengthDecrement(1.5f) + .setMaxDepth(2) + .setBaseThickness(3) + .setThicknessDecrement(1.5f) + .setMaxBend(Math.PI / 3) + .setVines(3) + .setTrunkType(Material.JUNGLE_WOOD) + .setCocoaBeans(1) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2, 4) + .setMaterial(Material.JUNGLE_LEAVES) + .setWeepingLeaves(0.3f, 3)); break; case JUNGLE_EXTRA_SMALL: this.setBaseHeight(3) - .setMaxDepth(1) - .setBaseThickness(1.5f) - .setThicknessDecrement(0f) - .setVines(3) - .setTrunkType(Material.JUNGLE_WOOD) - .setCocoaBeans(1) - .setFractalLeaves(new FractalLeaves() - .setRadius(3, 2, 3) - .setMaterial(Material.JUNGLE_LEAVES).setWeepingLeaves(0.3f,3)); + .setMaxDepth(1) + .setBaseThickness(1.5f) + .setThicknessDecrement(0f) + .setVines(3) + .setTrunkType(Material.JUNGLE_WOOD) + .setCocoaBeans(1) + .setFractalLeaves(new FractalLeaves().setRadius(3, 2, 3) + .setMaterial(Material.JUNGLE_LEAVES) + .setWeepingLeaves(0.3f, 3)); break; case SAVANNA_BIG: this.setBaseHeight(10) - .setBaseThickness(15) - .setThicknessDecrement(4f) - .setMaxDepth(4) - .setTrunkType(Material.ACACIA_LOG) - .setLengthDecrement(0.4f) - .setHeightVariation(2) - .setFractalLeaves(new FractalLeaves().setRadius(4, 2.5f, 4) - .setMaterial(Material.ACACIA_LEAVES).setLeafNoiseFrequency(0.7f).setLeafNoiseMultiplier(0.8f)); + .setBaseThickness(15) + .setThicknessDecrement(4f) + .setMaxDepth(4) + .setTrunkType(Material.ACACIA_LOG) + .setLengthDecrement(0.4f) + .setHeightVariation(2) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2.5f, 4) + .setMaterial(Material.ACACIA_LEAVES) + .setLeafNoiseFrequency(0.7f) + .setLeafNoiseMultiplier(0.8f)); break; case WASTELAND_BIG: this.setBaseHeight(6) - .setBaseThickness(4) - .setThicknessDecrement(1f) - .setMaxDepth(4) - .setTrunkType(Material.SPRUCE_WOOD) - .setLengthDecrement(0.5f) - .setHeightVariation(1) - .setFractalLeaves(new FractalLeaves().setRadius(0).setMaterial(Material.AIR)); + .setBaseThickness(4) + .setThicknessDecrement(1f) + .setMaxDepth(4) + .setTrunkType(Material.SPRUCE_WOOD) + .setLengthDecrement(0.5f) + .setHeightVariation(1) + .setFractalLeaves(new FractalLeaves().setRadius(0).setMaterial(Material.AIR)); break; case TAIGA_BIG: - this.setBaseHeight(10).setBaseThickness(3.5f) - .setThicknessDecrement(0.5f) - .setMaxDepth(5) - .setTrunkType(Material.SPRUCE_WOOD) - .setLengthDecrement(2) - .setHeightVariation(2) - .setAlwaysOneStraight(4) - .setAlwaysOneStraightExtendedBranches(true) - .setMinBend(Math.PI / 2) - .setMaxBend(Math.PI / 2) - .setFractalLeaves(new FractalLeaves().setRadius(3, 5, 3).setMaterial(Material.SPRUCE_LEAVES) - .setConeLeaves(true).setLeafNoiseFrequency(0.3f).setLeafNoiseMultiplier(0.7f)); + this.setBaseHeight(10) + .setBaseThickness(3.5f) + .setThicknessDecrement(0.5f) + .setMaxDepth(5) + .setTrunkType(Material.SPRUCE_WOOD) + .setLengthDecrement(2) + .setHeightVariation(2) + .setAlwaysOneStraight(4) + .setAlwaysOneStraightExtendedBranches(true) + .setMinBend(Math.PI / 2) + .setMaxBend(Math.PI / 2) + .setFractalLeaves(new FractalLeaves().setRadius(3, 5, 3) + .setMaterial(Material.SPRUCE_LEAVES) + .setConeLeaves(true) + .setLeafNoiseFrequency(0.3f) + .setLeafNoiseMultiplier(0.7f)); break; case TAIGA_SMALL: - this.setBaseHeight(5).setBaseThickness(1f) - .setThicknessDecrement(0.3f) - .setMaxDepth(4) - .setTrunkType(Material.SPRUCE_WOOD) - .setFractalLeaves(new FractalLeaves().setLeafNoiseFrequency(0.65f).setLeafNoiseMultiplier(0.8f) - .setRadius(2).setMaterial(Material.SPRUCE_LEAVES).setConeLeaves(true)) - .setLengthDecrement(1) - .setAlwaysOneStraight(4) - .setAlwaysOneStraightExtendedBranches(true) - .setMinBend(Math.PI / 2) - .setMaxBend(Math.PI / 2) - .setHeightVariation(2); + this.setBaseHeight(5) + .setBaseThickness(1f) + .setThicknessDecrement(0.3f) + .setMaxDepth(4) + .setTrunkType(Material.SPRUCE_WOOD) + .setFractalLeaves(new FractalLeaves().setLeafNoiseFrequency(0.65f) + .setLeafNoiseMultiplier(0.8f) + .setRadius(2) + .setMaterial(Material.SPRUCE_LEAVES) + .setConeLeaves(true)) + .setLengthDecrement(1) + .setAlwaysOneStraight(4) + .setAlwaysOneStraightExtendedBranches(true) + .setMinBend(Math.PI / 2) + .setMaxBend(Math.PI / 2) + .setHeightVariation(2); break; case SCARLET_BIG: - this.setBaseHeight(10).setBaseThickness(6f) - .setThicknessDecrement(0.7f) - .setLengthDecrement(0.5f) - .setLengthDecrementMultiplier(1.5f) - .setMinThickness(0.5f) - .setMaxDepth(7) - .setTrunkType(Material.BIRCH_WOOD) - .setHeightVariation(2) - .setAlwaysOneStraightBranchLength(14) - .setAlwaysOneStraight(6) - .setAlwaysOneStraightExtendedBranches(false) - .setAlwaysOneStraightBranchYawLowerMultiplier(0.7d) - .setAlwaysOneStraightBranchYawUpperMultiplier(1.3d) - .setAlwaysOneStraightBranchSpawningDepth(3) - .setMinBend(Math.PI / 3) - .setMaxBend(Math.PI / 2) - .setFractalLeaves(new FractalLeaves().setRadius(5, 2, 5).setMaterial(Material.OAK_LEAVES) - .setConeLeaves(true).setLeafNoiseFrequency(0.5f).setLeafNoiseMultiplier(0.8f)); + this.setBaseHeight(10) + .setBaseThickness(6f) + .setThicknessDecrement(0.7f) + .setLengthDecrement(0.5f) + .setLengthDecrementMultiplier(1.5f) + .setMinThickness(0.5f) + .setMaxDepth(7) + .setTrunkType(Material.BIRCH_WOOD) + .setHeightVariation(2) + .setAlwaysOneStraightBranchLength(14) + .setAlwaysOneStraight(6) + .setAlwaysOneStraightExtendedBranches(false) + .setAlwaysOneStraightBranchYawLowerMultiplier(0.7d) + .setAlwaysOneStraightBranchYawUpperMultiplier(1.3d) + .setAlwaysOneStraightBranchSpawningDepth(3) + .setMinBend(Math.PI / 3) + .setMaxBend(Math.PI / 2) + .setFractalLeaves(new FractalLeaves().setRadius(5, 2, 5) + .setMaterial(Material.OAK_LEAVES) + .setConeLeaves(true) + .setLeafNoiseFrequency(0.5f) + .setLeafNoiseMultiplier(0.8f)); break; case SCARLET_SMALL: - this.setBaseHeight(2).setBaseThickness(1f) - .setThicknessDecrement(0.3f) - .setMaxDepth(1) - .setTrunkType(Material.BIRCH_LOG) - .setFractalLeaves(new FractalLeaves().setLeafNoiseFrequency(0.65f).setLeafNoiseMultiplier(0.8f) - .setRadius(2).setMaterial(Material.OAK_LEAVES).setConeLeaves(true)) - .setLengthDecrement(1) - .setHeightVariation(1); + this.setBaseHeight(2) + .setBaseThickness(1f) + .setThicknessDecrement(0.3f) + .setMaxDepth(1) + .setTrunkType(Material.BIRCH_LOG) + .setFractalLeaves(new FractalLeaves().setLeafNoiseFrequency(0.65f) + .setLeafNoiseMultiplier(0.8f) + .setRadius(2) + .setMaterial(Material.OAK_LEAVES) + .setConeLeaves(true)) + .setLengthDecrement(1) + .setHeightVariation(1); break; case SWAMP_TOP: this.setBaseHeight(8) - .setBaseThickness(3) - .setThicknessDecrement(0.5f) - .setMaxDepth(4) - .setLengthDecrement(0f) - .setHeightVariation(2) - .setTrunkType(OneOneNineBlockHandler.MANGROVE_WOOD) - .setVines(7) - .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f,7).setMaterial(OneOneNineBlockHandler.MANGROVE_LEAVES).setRadius(5, 2, 5).setMangrovePropagules(true)); + .setBaseThickness(3) + .setThicknessDecrement(0.5f) + .setMaxDepth(4) + .setLengthDecrement(0f) + .setHeightVariation(2) + .setTrunkType(OneOneNineBlockHandler.MANGROVE_WOOD) + .setVines(7) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f, 7) + .setMaterial(OneOneNineBlockHandler.MANGROVE_LEAVES) + .setRadius(5, 2, 5) + .setMangrovePropagules(true)); break; case COCONUT_TOP: this.setBaseHeight(8) - .setInitialTilt(Math.PI / 6) - .setBaseThickness(1) - .setThicknessDecrement(0f) - .setMaxDepth(1) - .setLengthDecrement(2) - .setHeightVariation(1) - .setVines(3) - .setTrunkType(Material.JUNGLE_WOOD) - .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f,3).setRadius(3, 1.2f, 3)); + .setInitialTilt(Math.PI / 6) + .setBaseThickness(1) + .setThicknessDecrement(0f) + .setMaxDepth(1) + .setLengthDecrement(2) + .setHeightVariation(1) + .setVines(3) + .setTrunkType(Material.JUNGLE_WOOD) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 3).setRadius(3, 1.2f, 3)); break; case GIANT_PUMPKIN: this.setBaseHeight(6) - .setBaseThickness(1) - .setThicknessDecrement(1f) - .setMaxDepth(0) - .setLengthDecrement(-0.5f) - .setHeightVariation(0) - .setTrunkType(Material.OAK_LOG) - .setFractalLeaves(new FractalLeaves().setRadius(4).setMaterial(Material.PUMPKIN)); + .setBaseThickness(1) + .setThicknessDecrement(1f) + .setMaxDepth(0) + .setLengthDecrement(-0.5f) + .setHeightVariation(0) + .setTrunkType(Material.OAK_LOG) + .setFractalLeaves(new FractalLeaves().setRadius(4).setMaterial(Material.PUMPKIN)); case DARK_OAK_SMALL: this.setBaseHeight(3) - .setBaseThickness(3) - .setThicknessDecrement(0.5f) - .setMaxDepth(3) - .setTrunkType(Material.DARK_OAK_WOOD) - .setLengthDecrement(0) - .setHeightVariation(0) - .setFractalThreshold(4) - .setMaxBend(1.4 * Math.PI / 6) - .setMinBend(1 * Math.PI / 6) - .setMaxPitch(Math.PI/1.5) - .setMinPitch(0) - .setFractalLeaves(new FractalLeaves().setRadius(5, 1, 5).setMaterial(Material.DARK_OAK_LEAVES)); + .setBaseThickness(3) + .setThicknessDecrement(0.5f) + .setMaxDepth(3) + .setTrunkType(Material.DARK_OAK_WOOD) + .setLengthDecrement(0) + .setHeightVariation(0) + .setFractalThreshold(4) + .setMaxBend(1.4 * Math.PI / 6) + .setMinBend(1 * Math.PI / 6) + .setMaxPitch(Math.PI / 1.5) + .setMinPitch(0) + .setFractalLeaves(new FractalLeaves().setRadius(5, 1, 5).setMaterial(Material.DARK_OAK_LEAVES)); break; case DARK_OAK_BIG_TOP: this.setBaseHeight(6) - .setBaseThickness(8) - .setThicknessDecrement(2.5f) - .setMaxDepth(3) - .setTrunkType(Material.DARK_OAK_WOOD) - .setLengthDecrement(0) - .setHeightVariation(1) - .setFractalThreshold(4) - .setMaxBend(1.4 * Math.PI / 6) - .setMinBend(1 * Math.PI / 6) - .setMaxPitch(Math.PI/1.5) - .setMinPitch(0) - .setFractalLeaves(new FractalLeaves().setRadius(6, 2, 6).setMaterial(Material.DARK_OAK_LEAVES).setOffsetY(1)); + .setBaseThickness(8) + .setThicknessDecrement(2.5f) + .setMaxDepth(3) + .setTrunkType(Material.DARK_OAK_WOOD) + .setLengthDecrement(0) + .setHeightVariation(1) + .setFractalThreshold(4) + .setMaxBend(1.4 * Math.PI / 6) + .setMinBend(1 * Math.PI / 6) + .setMaxPitch(Math.PI / 1.5) + .setMinPitch(0) + .setFractalLeaves(new FractalLeaves().setRadius(6, 2, 6) + .setMaterial(Material.DARK_OAK_LEAVES) + .setOffsetY(1)); break; case FROZEN_TREE_BIG: this.setBaseHeight(4) - .setBaseThickness(4) - .setThicknessDecrement(2f) - .setMaxDepth(4) - .setVines(4) - .setTrunkType(Material.SPRUCE_WOOD) - .setLengthDecrement(0) - .setHeightVariation(1) - .setFractalThreshold(4) - .setMaxBend(1.6 * Math.PI / 6) - .setMinBend(1.2 * Math.PI / 6) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setFractalLeaves(new FractalLeaves().setRadius(4, 2, 4).setMaterial(Material.ICE)); + .setBaseThickness(4) + .setThicknessDecrement(2f) + .setMaxDepth(4) + .setVines(4) + .setTrunkType(Material.SPRUCE_WOOD) + .setLengthDecrement(0) + .setHeightVariation(1) + .setFractalThreshold(4) + .setMaxBend(1.6 * Math.PI / 6) + .setMinBend(1.2 * Math.PI / 6) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setFractalLeaves(new FractalLeaves().setRadius(4, 2, 4).setMaterial(Material.ICE)); break; case FROZEN_TREE_SMALL: this.setBaseHeight(1) - .setBaseThickness(2) - .setThicknessDecrement(0.2f) - .setMaxDepth(4) - .setVines(4) - .setTrunkType(Material.SPRUCE_WOOD) - .setLengthDecrement(0) - .setHeightVariation(0) - .setFractalThreshold(4) - .setMaxBend(1.6 * Math.PI / 6) - .setMinBend(1.2 * Math.PI / 6) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setFractalLeaves(new FractalLeaves().setRadius(4, 1, 4).setMaterial(Material.ICE)); + .setBaseThickness(2) + .setThicknessDecrement(0.2f) + .setMaxDepth(4) + .setVines(4) + .setTrunkType(Material.SPRUCE_WOOD) + .setLengthDecrement(0) + .setHeightVariation(0) + .setFractalThreshold(4) + .setMaxBend(1.6 * Math.PI / 6) + .setMinBend(1.2 * Math.PI / 6) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setFractalLeaves(new FractalLeaves().setRadius(4, 1, 4).setMaterial(Material.ICE)); break; case FIRE_CORAL: this.setBaseHeight(2) - .setInitialTilt(Math.PI / 2) - .setBaseThickness(1) - .setThicknessDecrement(0) - .setMaxDepth(3) - .setFractalLeaves(new FractalLeaves().setRadius(1, 4, 1).setMaterial(Material.FIRE_CORAL_BLOCK)) - .setTrunkType(Material.FIRE_CORAL_BLOCK) - .setLengthDecrement(-2f) - .setHeightVariation(0) - .setMaxBend(Math.PI / 2) - .setMinBend(Math.PI / 2.5) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setCoralDecoration(true); + .setInitialTilt(Math.PI / 2) + .setBaseThickness(1) + .setThicknessDecrement(0) + .setMaxDepth(3) + .setFractalLeaves(new FractalLeaves().setRadius(1, 4, 1).setMaterial(Material.FIRE_CORAL_BLOCK)) + .setTrunkType(Material.FIRE_CORAL_BLOCK) + .setLengthDecrement(-2f) + .setHeightVariation(0) + .setMaxBend(Math.PI / 2) + .setMinBend(Math.PI / 2.5) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setCoralDecoration(true); break; case HORN_CORAL: this.setBaseHeight(2) - .setBaseThickness(2) - .setThicknessDecrement(0) - .setMaxDepth(3) - .setFractalLeaves(new FractalLeaves().setRadius(3, 1, 3).setMaterial(Material.HORN_CORAL_BLOCK)) - .setTrunkType(Material.HORN_CORAL_BLOCK) - .setLengthDecrement(-1) - .setHeightVariation(0) - .setMaxBend(Math.PI / 3) - .setMinBend(Math.PI / 4) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setCoralDecoration(true) - .setNoMainStem(true); + .setBaseThickness(2) + .setThicknessDecrement(0) + .setMaxDepth(3) + .setFractalLeaves(new FractalLeaves().setRadius(3, 1, 3).setMaterial(Material.HORN_CORAL_BLOCK)) + .setTrunkType(Material.HORN_CORAL_BLOCK) + .setLengthDecrement(-1) + .setHeightVariation(0) + .setMaxBend(Math.PI / 3) + .setMinBend(Math.PI / 4) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setCoralDecoration(true) + .setNoMainStem(true); break; case BRAIN_CORAL: this.setBaseHeight(1) - .setBaseThickness(1) - .setThicknessDecrement(0f) - .setMaxDepth(3) - .setFractalLeaves(new FractalLeaves() - .setRadius(1, 2, 1) - .setHollowLeaves(0.9) - .setMaterial(Material.BRAIN_CORAL_BLOCK)) - .setTrunkType(Material.BRAIN_CORAL_BLOCK) - .setLengthDecrement(0) - .setHeightVariation(0) - .setFractalThreshold(3) - .setMaxBend(Math.PI / 3) - .setMinBend(Math.PI / 4) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setCoralDecoration(true); + .setBaseThickness(1) + .setThicknessDecrement(0f) + .setMaxDepth(3) + .setFractalLeaves(new FractalLeaves().setRadius(1, 2, 1) + .setHollowLeaves(0.9) + .setMaterial(Material.BRAIN_CORAL_BLOCK)) + .setTrunkType(Material.BRAIN_CORAL_BLOCK) + .setLengthDecrement(0) + .setHeightVariation(0) + .setFractalThreshold(3) + .setMaxBend(Math.PI / 3) + .setMinBend(Math.PI / 4) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setCoralDecoration(true); break; case TUBE_CORAL: this.setBaseHeight(3) - .setAlwaysOneStraight(3) - .setBaseThickness(3) - .setThicknessDecrement(0f) - .setMaxDepth(3) - .setFractalLeaves(new FractalLeaves() - .setRadius(1, 1, 1) - .setHollowLeaves(0.9) - .setMaterial(Material.TUBE_CORAL_BLOCK)) - .setTrunkType(Material.TUBE_CORAL_BLOCK) - .setLengthDecrement(0) - .setHeightVariation(1) - .setMaxBend(Math.PI / 3) - .setMinBend(Math.PI / 4) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setCoralDecoration(true); + .setAlwaysOneStraight(3) + .setBaseThickness(3) + .setThicknessDecrement(0f) + .setMaxDepth(3) + .setFractalLeaves(new FractalLeaves().setRadius(1, 1, 1) + .setHollowLeaves(0.9) + .setMaterial(Material.TUBE_CORAL_BLOCK)) + .setTrunkType(Material.TUBE_CORAL_BLOCK) + .setLengthDecrement(0) + .setHeightVariation(1) + .setMaxBend(Math.PI / 3) + .setMinBend(Math.PI / 4) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setCoralDecoration(true); break; case BUBBLE_CORAL: this.setBaseHeight(3) - .setBaseThickness(1) - .setThicknessDecrement(0f) - .setMaxDepth(3) - .setFractalLeaves(new FractalLeaves() - .setRadius(3, 3, 3) - .setHollowLeaves(0.9) - .setMaterial(Material.BUBBLE_CORAL_BLOCK)) - .setTrunkType(Material.BUBBLE_CORAL_BLOCK) - .setLengthDecrement(-1) - .setHeightVariation(1) - .setMaxBend(Math.PI / 2) - .setMinBend(Math.PI / 3) - .setMaxPitch(Math.PI) - .setMinPitch(0) - .setCoralDecoration(true) - .setNoMainStem(true); + .setBaseThickness(1) + .setThicknessDecrement(0f) + .setMaxDepth(3) + .setFractalLeaves(new FractalLeaves().setRadius(3, 3, 3) + .setHollowLeaves(0.9) + .setMaterial(Material.BUBBLE_CORAL_BLOCK)) + .setTrunkType(Material.BUBBLE_CORAL_BLOCK) + .setLengthDecrement(-1) + .setHeightVariation(1) + .setMaxBend(Math.PI / 2) + .setMinBend(Math.PI / 3) + .setMaxPitch(Math.PI) + .setMinPitch(0) + .setCoralDecoration(true) + .setNoMainStem(true); break; } } - + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean checkGradient(PopulatorDataAbstract data, int x, int z) { - heightGradientChecked = true; - return (HeightMap.getTrueHeightGradient(data, x, z, 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); + heightGradientChecked = true; + return (HeightMap.getTrueHeightGradient(data, x, z, 3) <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); } - + public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock block) { - return build(tw, block.getPopData(), block.getX(), block.getY(), block.getZ()); + return build(tw, block.getPopData(), block.getX(), block.getY(), block.getZ()); } - + public boolean build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) return false; + if (!TConfigOption.areTreesEnabled()) { + return false; + } fractalLeaves.purgeOccupiedLeavesCache(); - // Terrain too steep, don't attempt tree generation, - // lest it gets stuck in a wall. - if(!heightGradientChecked) { - if(!checkGradient(data,x,z)) return false; - } - - if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) { + // Terrain too steep, don't attempt tree generation, + // lest it gets stuck in a wall. + if (!heightGradientChecked) { + if (!checkGradient(data, x, z)) { + return false; + } + } + + if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) { this.trunkType = Material.getMaterial(StringUtils.replace(this.trunkType.toString(), "WOOD", "LOG")); } this.oriX = x; @@ -596,75 +620,80 @@ public boolean build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract this.fractalLeaves.setMaxHeight(maxHeight); // this.noiseGen = new FastNoise((int) tw.getSeed()); - FastNoise noiseGen = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.FRACTALTREES_BASE_NOISE, - world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(5); - return n; - }); - + FastNoise noiseGen = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.FRACTALTREES_BASE_NOISE, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(5); + return n; + }); + // Setup noise to be used in randomising the sphere noiseGen.SetFrequency(branchNoiseFrequency); - + this.rand = tw.getRand(16L * 16 * x + 16L * y + z); SimpleBlock base = new SimpleBlock(data, x, y, z); - if (this.top == null) top = base; + if (this.top == null) { + top = base; + } initialAngle = Math.PI / 2 + GenUtils.randDouble(rand, -initialTilt, initialTilt); - if(alwaysOneStraightBranchLength == 0) - alwaysOneStraightBranchLength = baseHeight; - + if (alwaysOneStraightBranchLength == 0) { + alwaysOneStraightBranchLength = baseHeight; + } + double initialPitch; - if(minInitialTilt != -1) { - initialPitch = new int[] {-1,1}[rand.nextInt(2)] - * GenUtils.randDouble(rand, minInitialTilt, initialTilt); - }else - initialPitch = GenUtils.randDouble(rand, -initialTilt, initialTilt); - - + if (minInitialTilt != -1) { + initialPitch = new int[] {-1, 1}[rand.nextInt(2)] * GenUtils.randDouble(rand, minInitialTilt, initialTilt); + } + else { + initialPitch = GenUtils.randDouble(rand, -initialTilt, initialTilt); + } + + if (alwaysOneStraight > 0) { // Starting Trunk - fractalBranch(rand, base, - initialAngle, - initialPitch, - 0, - baseThickness, - baseHeight); - } else { + fractalBranch(rand, base, initialAngle, initialPitch, 0, baseThickness, baseHeight); + } + else { initialHeight = baseHeight + GenUtils.randInt(-heightVariation, heightVariation); - fractalBranch(rand, base, - initialAngle, - initialPitch, - 0, baseThickness, - initialHeight); + fractalBranch(rand, base, initialAngle, initialPitch, 0, baseThickness, initialHeight); + } + + if (beeHive != null) { + for (int i = 0; i < 8; i++) { + if (!beeHive.isSolid()) { + BeeHiveSpawner.spawnFullBeeNest(beeHive); + // TerraformGeneratorPlugin.logger.debug("Bee nest spawned at " + two.getRelative(0,-i,0).getCoords()); + break; + } + else { + beeHive = beeHive.getDown(); + } + } } - - if(beeHive != null) - for (int i = 0; i < 8; i++) { - if (!beeHive.isSolid()) { - BeeHiveSpawner.spawnFullBeeNest(beeHive); - // TerraformGeneratorPlugin.logger.debug("Bee nest spawned at " + two.getRelative(0,-i,0).getCoords()); - break; - }else - beeHive = beeHive.getDown(); - } - + return true; - + } - private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, double pitch, double yaw, int depth, double thickness, double size) { + private void fractalBranch(@NotNull Random rand, + @NotNull SimpleBlock base, + double pitch, + double yaw, + int depth, + double thickness, + double size) + { + + if (thickness < minThickness) { + thickness = minThickness; + } - if(thickness < minThickness) - thickness = minThickness; - if (pitch > maxPitch) { // reset pitch pitch = maxPitch - rta(); - } else if (pitch < minPitch) { + } + else if (pitch < minPitch) { pitch = minPitch + rta(); } @@ -690,10 +719,14 @@ private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, doub int z = (int) (Math.round(size * Math.cos(pitch) * Math.cos(yaw))); SimpleBlock two = base.getRelative(x, y, z); - if (two.getY() > top.getY()) top = two; + if (two.getY() > top.getY()) { + top = two; + } // Set height - if (two.getY() - oriY > height) height = two.getY() - oriY; + if (two.getY() - oriY > height) { + height = two.getY() - oriY; + } if (restore) { two = base; @@ -703,12 +736,10 @@ private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, doub drawLine(base, two, (int) (size), thickness); - if (beeHive == null - && Version.isAtLeast(15.1) - && GenUtils.chance(rand, (int) (beeChance * 1000.0), 1000)) { + if (beeHive == null && Version.isAtLeast(15.1) && GenUtils.chance(rand, (int) (beeChance * 1000.0), 1000)) { for (int i = 0; i < 3; i++) { if (!two.getRelative(0, -i, 0).isSolid()) { - beeHive = two.getRelative(0,-i,0); + beeHive = two.getRelative(0, -i, 0); break; // TerraformGeneratorPlugin.logger.debug("Bee nest spawned at " + two.getRelative(0,-i,0).getCoords()); } @@ -718,16 +749,16 @@ private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, doub fractalsDone++; - if (fractalsDone % fractalThreshold != 0 - && thickness >= 1 - && size >= 1) { + if (fractalsDone % fractalThreshold != 0 && thickness >= 1 && size >= 1) { // Make 1 branch - fractalBranch(rand, two, pitch - randomAngle(depth), - yaw + GenUtils.randInt(rand, 1, 5) - * GenUtils.getSign(rand) * rta(), + fractalBranch(rand, + two, + pitch - randomAngle(depth), + yaw + GenUtils.randInt(rand, 1, 5) * GenUtils.getSign(rand) * rta(), depth, thickness, - size); + size + ); return; } @@ -735,7 +766,15 @@ private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, doub // For always straight trees, the branches don't have additional fractals. // Set depth to 99 and force leaf generation. if (alwaysOneStraight > 0 && pitch != initialAngle) { - fractalBranch(rand, two, pitch - randomAngle(depth), yaw - rta(), 99, thickness - thicknessDecrement, size - lengthDecrement); + fractalBranch( + rand, + two, + pitch - randomAngle(depth), + yaw - rta(), + 99, + thickness - thicknessDecrement, + size - lengthDecrement + ); return; } @@ -743,37 +782,157 @@ private void fractalBranch(@NotNull Random rand, @NotNull SimpleBlock base, doub alwaysOneStraightBranchLength -= (int) this.lengthDecrement; this.lengthDecrement *= this.lengthDecrementMultiplier; // Extend a central trunk and make more branches. - + // Only spawn branches if depth is sufficient. - if(depth >= alwaysOneStraightBranchSpawningDepth) { - fractalBranch(rand, two, pitch + randomAngle(depth), -ra(Math.PI / 4, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), ra(Math.PI / 4, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), 5 * ra(Math.PI / 4, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), -5 * ra(Math.PI / 4, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); + if (depth >= alwaysOneStraightBranchSpawningDepth) { + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + -ra(Math.PI / 4, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + ra(Math.PI / 4, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + 5 * ra(Math.PI / 4, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + -5 * ra(Math.PI / 4, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); // 4 more static angle fractals. if (alwaysOneStraightExtendedBranches) { - fractalBranch(rand, two, pitch + randomAngle(depth), ra(0, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), ra(Math.PI / 2, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), ra(Math.PI, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); - fractalBranch(rand, two, pitch + randomAngle(depth), -ra(Math.PI / 2, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), depth + 1, thickness - thicknessDecrement, alwaysOneStraightBranchLength); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + ra(0, alwaysOneStraightBranchYawLowerMultiplier, alwaysOneStraightBranchYawUpperMultiplier), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + ra(Math.PI / 2, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + ra(Math.PI, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + -ra(Math.PI / 2, + alwaysOneStraightBranchYawLowerMultiplier, + alwaysOneStraightBranchYawUpperMultiplier + ), + depth + 1, + thickness - thicknessDecrement, + alwaysOneStraightBranchLength + ); } } - + // this.logType = Material.SPRUCE_WOOD; fractalBranch(rand, two, pitch, yaw, depth + 1, thickness - thicknessDecrement, alwaysOneStraight); - } else { + } + else { // Make 4 branches - fractalBranch(rand, two, pitch - randomAngle(depth), yaw - rta(), depth + 1, thickness - thicknessDecrement, size - lengthDecrement); - fractalBranch(rand, two, pitch + randomAngle(depth), yaw + rta(), depth + 1, thickness - thicknessDecrement, size - lengthDecrement); - fractalBranch(rand, two, pitch + randomAngle(depth), yaw + 5 * rta(), depth + 1, thickness - thicknessDecrement, size - lengthDecrement); - fractalBranch(rand, two, pitch + randomAngle(depth), yaw - 5 * rta(), depth + 1, thickness - thicknessDecrement, size - lengthDecrement); + fractalBranch( + rand, + two, + pitch - randomAngle(depth), + yaw - rta(), + depth + 1, + thickness - thicknessDecrement, + size - lengthDecrement + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + yaw + rta(), + depth + 1, + thickness - thicknessDecrement, + size - lengthDecrement + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + yaw + 5 * rta(), + depth + 1, + thickness - thicknessDecrement, + size - lengthDecrement + ); + fractalBranch( + rand, + two, + pitch + randomAngle(depth), + yaw - 5 * rta(), + depth + 1, + thickness - thicknessDecrement, + size - lengthDecrement + ); } } private void drawLine(@NotNull SimpleBlock one, @NotNull SimpleBlock two, int segments, double thickness) { - if (one.equals(two)) return; + if (one.equals(two)) { + return; + } // Vector one to two; Vector v = two.toVector().subtract(one.toVector()); for (int i = 0; i <= segments; i++) { @@ -794,35 +953,29 @@ private void replaceSphere(float radius, @NotNull SimpleBlock base, @NotNull Mat private void replaceSphere(float rX, float rY, float rZ, @NotNull SimpleBlock block, @NotNull Material type) { // Don't place anything if radius is nothing - if (rX <= 0 && - rY <= 0 && - rZ <= 0) { + if (rX <= 0 && rY <= 0 && rZ <= 0) { return; } // Radius 0.5 is 1 block - if (rX <= 0.5 && - rY <= 0.5 && - rZ <= 0.5) { + if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { block.setType(type); - if(Tag.WALLS.isTagged(type)) - BlockUtils.correctMultifacingData(block); + if (Tag.WALLS.isTagged(type)) { + BlockUtils.correctMultifacingData(block); + } return; } float noiseMultiplier = branchNoiseMultiplier; - FastNoise noiseGen = NoiseCacheHandler.getNoise( - tw, - NoiseCacheEntry.FRACTALTREES_BASE_NOISE, - world -> { - FastNoise n = new FastNoise((int) world.getSeed()); - n.SetNoiseType(NoiseType.SimplexFractal); - n.SetFractalOctaves(5); - return n; - }); - + FastNoise noiseGen = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.FRACTALTREES_BASE_NOISE, world -> { + FastNoise n = new FastNoise((int) world.getSeed()); + n.SetNoiseType(NoiseType.SimplexFractal); + n.SetFractalOctaves(5); + return n; + }); + // Setup noise to be used in randomising the sphere noiseGen.SetFrequency(branchNoiseFrequency); @@ -837,25 +990,27 @@ private void replaceSphere(float rX, float rY, float rZ, @NotNull SimpleBlock bl } if (rel.getY() - this.oriY == this.maxHeight) { if (rand.nextBoolean()) // Fade off if too high + { return; + } } double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); if (equationResult <= 1 + noiseMultiplier * noiseGen.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { rel.rsetType(BlockUtils.replacableByTrees, type); - if(Tag.WALLS.isTagged(type)) - BlockUtils.correctMultifacingData(rel); + if (Tag.WALLS.isTagged(type)) { + BlockUtils.correctMultifacingData(rel); + } if (coralDecoration) { - if (!changed.contains(rel)) + if (!changed.contains(rel)) { changed.add(rel); + } } - - if (cocoaBeans > 0 - && Math.abs(x) >= rX - 2 - && Math.abs(z) >= rZ - 2) { + + if (cocoaBeans > 0 && Math.abs(x) >= rX - 2 && Math.abs(z) >= rZ - 2) { // Coca beans if (GenUtils.chance(cocoaBeans, 100)) { for (BlockFace face : BlockUtils.directBlockFaces) { @@ -863,17 +1018,16 @@ private void replaceSphere(float rX, float rY, float rZ, @NotNull SimpleBlock bl dir.setFacing(face.getOppositeFace()); ((Ageable) dir).setAge(GenUtils.randInt(rand, 0, ((Ageable) dir).getMaximumAge())); SimpleBlock beans = rel.getRelative(face); - if (beans.isSolid() || - beans.getType() == Material.WATER) continue; + if (beans.isSolid() || beans.getType() == Material.WATER) { + continue; + } beans.setBlockData(dir); } } } - if (vines > 0 - && Math.abs(x) >= rX - 2 - && Math.abs(z) >= rZ - 2) { + if (vines > 0 && Math.abs(x) >= rX - 2 && Math.abs(z) >= rZ - 2) { if (GenUtils.chance(2, 10)) { dangleLeavesDown(rel, vines / 2, vines); } @@ -882,26 +1036,28 @@ private void replaceSphere(float rX, float rY, float rZ, @NotNull SimpleBlock bl } } } - + // Ensures that corals don't die while (!changed.isEmpty()) { SimpleBlock sb = changed.remove(new Random().nextInt(changed.size())); if (!CoralGenerator.isSaturatedCoral(sb)) { // No floating coral fans for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALL_CORALS.isTagged(sb.getRelative(face).getType())) + if (Tag.WALL_CORALS.isTagged(sb.getRelative(face).getType())) { sb.getRelative(face).setType(Material.WATER); + } } // No levitating sea pickles & fans - if (sb.getUp().getType() == Material.SEA_PICKLE || - Tag.CORAL_PLANTS.isTagged(sb.getUp().getType())) { + if (sb.getUp().getType() == Material.SEA_PICKLE || Tag.CORAL_PLANTS.isTagged(sb.getUp().getType())) { sb.getUp().setType(Material.WATER); } sb.setType(Material.WATER); - } else + } + else { sb.setType(trunkType); + } } } @@ -915,35 +1071,38 @@ private void replaceSphere(float rX, float rY, float rZ, @NotNull SimpleBlock bl * That ungodly reason is that the branches run this * * @param block under which the vine spawns - * @param min minimum vine length - * @param max maximum vine length + * @param min minimum vine length + * @param max maximum vine length */ void dangleLeavesDown(@NotNull SimpleBlock block, int min, int max) { - Material material = fractalLeaves.material[rand.nextInt(fractalLeaves.material.length)]; + Material material = fractalLeaves.material[rand.nextInt(fractalLeaves.material.length)]; BlockData type = Bukkit.createBlockData(material); if (Tag.LEAVES.isTagged(material)) { Leaves leaf = (Leaves) type; leaf.setDistance(1); } for (int i = 1; i <= GenUtils.randInt(min, max); i++) { - if (!block.getRelative(0, -i, 0).isSolid()) - block.getRelative(0, -i, 0).rsetBlockData(BlockUtils.replacableByTrees,type); - else + if (!block.getRelative(0, -i, 0).isSolid()) { + block.getRelative(0, -i, 0).rsetBlockData(BlockUtils.replacableByTrees, type); + } + else { break; + } } // Log for good measure, as well as some surrounding leaves. - if (Tag.LEAVES.isTagged(material)) - block.rsetType(BlockUtils.replacableByTrees,this.trunkType); + if (Tag.LEAVES.isTagged(material)) { + block.rsetType(BlockUtils.replacableByTrees, this.trunkType); + } for (BlockFace face : BlockUtils.directBlockFaces) { - material = fractalLeaves.material[rand.nextInt(fractalLeaves.material.length)]; - type = Bukkit.createBlockData(material); - if(Tag.LEAVES.isTagged(material)) { - Leaves leaf = (Leaves) type; - leaf.setDistance(1); - } - - block.getRelative(face).rsetBlockData(BlockUtils.replacableByTrees,type); + material = fractalLeaves.material[rand.nextInt(fractalLeaves.material.length)]; + type = Bukkit.createBlockData(material); + if (Tag.LEAVES.isTagged(material)) { + Leaves leaf = (Leaves) type; + leaf.setDistance(1); + } + + block.getRelative(face).rsetBlockData(BlockUtils.replacableByTrees, type); } block.getUp().rsetBlockData(BlockUtils.replacableByTrees, type); } @@ -1080,7 +1239,7 @@ private int getCocoaBeans() { this.depthPitchMultiplier = depthPitchMultiplier; return this; } - + private @NotNull FractalTreeBuilder setLeafBranchFrequency(float freq) { this.branchNoiseFrequency = freq; return this; @@ -1092,8 +1251,8 @@ private int getCocoaBeans() { } public @NotNull FractalTreeBuilder skipGradientCheck() { - this.heightGradientChecked = true; - return this; + this.heightGradientChecked = true; + return this; } /** @@ -1112,11 +1271,12 @@ private int getHeight() { * Random angle defined by the min and max bend angles */ private double randomAngle(int depth) { - return (Math.pow(depthPitchMultiplier,depth))*GenUtils.randDouble(rand, minBend, maxBend); + return (Math.pow(depthPitchMultiplier, depth)) * GenUtils.randDouble(rand, minBend, maxBend); } /** * Random-thirty-ish-angle + * * @return An angle between 0.8*30 to 1.2*30 degrees in radians */ private double rta() { @@ -1125,6 +1285,7 @@ private double rta() { /** * Random-angle + * * @return An angle between lowerBound*base to upperBound*base degrees in radians */ private double ra(double base, double lowerBound, double upperBound) { @@ -1136,29 +1297,29 @@ private double ra(double base, double lowerBound, double upperBound) { this.fractalLeaves.coralDecoration = d; return this; } - + private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchLength(int alwaysOneStraightBranchLength) { - this.alwaysOneStraightBranchLength = alwaysOneStraightBranchLength; - return this; + this.alwaysOneStraightBranchLength = alwaysOneStraightBranchLength; + return this; + } + + private @NotNull FractalTreeBuilder setLengthDecrementMultiplier(float lengthDecrementMultiplier) { + this.lengthDecrementMultiplier = lengthDecrementMultiplier; + return this; + } + + private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchYawLowerMultiplier(double alwaysOneStraightBranchYawLowerMultiplier) { + this.alwaysOneStraightBranchYawLowerMultiplier = alwaysOneStraightBranchYawLowerMultiplier; + return this; } - private @NotNull FractalTreeBuilder setLengthDecrementMultiplier(float lengthDecrementMultiplier) { - this.lengthDecrementMultiplier = lengthDecrementMultiplier; - return this; - } - - private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchYawLowerMultiplier(double alwaysOneStraightBranchYawLowerMultiplier) { - this.alwaysOneStraightBranchYawLowerMultiplier = alwaysOneStraightBranchYawLowerMultiplier; - return this; - } - - private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchYawUpperMultiplier(double alwaysOneStraightBranchYawUpperMultiplier) { - this.alwaysOneStraightBranchYawUpperMultiplier = alwaysOneStraightBranchYawUpperMultiplier; - return this; - } - - private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchSpawningDepth(int alwaysOneStraightBranchSpawningDepth) { - this.alwaysOneStraightBranchSpawningDepth = alwaysOneStraightBranchSpawningDepth; - return this; - } + private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchYawUpperMultiplier(double alwaysOneStraightBranchYawUpperMultiplier) { + this.alwaysOneStraightBranchYawUpperMultiplier = alwaysOneStraightBranchYawUpperMultiplier; + return this; + } + + private @NotNull FractalTreeBuilder setAlwaysOneStraightBranchSpawningDepth(int alwaysOneStraightBranchSpawningDepth) { + this.alwaysOneStraightBranchSpawningDepth = alwaysOneStraightBranchSpawningDepth; + return this; + } } diff --git a/common/src/main/java/org/terraform/tree/FractalTypes.java b/common/src/main/java/org/terraform/tree/FractalTypes.java index 43478d8b..4930ebe3 100644 --- a/common/src/main/java/org/terraform/tree/FractalTypes.java +++ b/common/src/main/java/org/terraform/tree/FractalTypes.java @@ -14,253 +14,236 @@ public class FractalTypes { public enum Tree { - FOREST - ( + FOREST( // Medium Forest Tree - new NewFractalTreeBuilder() - .setLengthVariance(2) - .setOriginalTrunkLength(12) - .setInitialBranchRadius(1.6f) - .setMinBranchHorizontalComponent(0.7) - .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth*(1.0f-branchRatio/1.7f)) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> currentBranchLength/1.7f) - .setBranchSpawnChance(0.15) - .setCrownBranches(4) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 3) - .setRadius(4f) - .setRadiusY(2f)) - .setSpawnBees(true), + new NewFractalTreeBuilder().setLengthVariance(2) + .setOriginalTrunkLength(12) + .setInitialBranchRadius(1.6f) + .setMinBranchHorizontalComponent(0.7) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth + * (1.0f + - branchRatio + / 1.7f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + / 1.7f) + .setBranchSpawnChance(0.15) + .setCrownBranches(4) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 3) + .setRadius(4f) + .setRadiusY(2f)) + .setSpawnBees(true), // Large Forest Tree - new NewFractalTreeBuilder() - .setOriginalTrunkLength(18) - .setInitialBranchRadius(2f) - .setGetBranchWidth( - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/2f) - ) - .setBranchDecrement( - (currentBranchLength, totalTreeHeight) - -> currentBranchLength-7 - ) - .setBranchSpawnChance(0.2) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 2) - .setRadius(4f) - .setRadiusY(2.5f)) - .setSpawnBees(true), -// // Original Style Tree - new NewFractalTreeBuilder() - .setOriginalTrunkLength(18) - .setInitialBranchRadius(2f) - .setCrownBranches(5) - .setMaxDepth(2) - .setMinBranchHorizontalComponent(0.7) - .setGetBranchWidth( - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/1.5f) - ) - .setBranchDecrement( - (currentBranchLength, totalTreeHeight) - -> currentBranchLength/2f - ) - .setBranchSpawnChance(0.2) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 1) - .setRadius(4f) - .setRadiusY(2.5f) - ) - .setSpawnBees(true) - ) - , - NORMAL_SMALL( - new NewFractalTreeBuilder() - .setTreeRootThreshold(0) - .setOriginalTrunkLength(4) - .setLengthVariance(1) - .setMaxDepth(1) - .setCrownBranches(3) - .setInitialBranchRadius(0.8f) - .setNoisePriority(0.05f) - .setFirstEnd(1.0f) - .setMinBranchHorizontalComponent(1.2) - .setMaxBranchHorizontalComponent(2) - .setMaxInitialNormalDelta(0) - .setMinInitialNormalDelta(0) - .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth-(branchRatio*0.2f)) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> currentBranchLength-2) - .setMinBranchSpawnLength(0.8f) - .setBranchSpawnChance(0.1) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 1) - .setRadius(3f) - .setRadiusY(3f) - .setLeafNoiseFrequency(0.5f) - .setSemiSphereLeaves(true) - .setMaterial(Material.OAK_LEAVES)) + new NewFractalTreeBuilder().setOriginalTrunkLength(18) + .setInitialBranchRadius(2f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth + * (1.0f + - branchRatio + / 2f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + - 7) + .setBranchSpawnChance(0.2) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 2) + .setRadius(4f) + .setRadiusY(2.5f)) + .setSpawnBees(true), + // // Original Style Tree + new NewFractalTreeBuilder().setOriginalTrunkLength(18) + .setInitialBranchRadius(2f) + .setCrownBranches(5) + .setMaxDepth(2) + .setMinBranchHorizontalComponent(0.7) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth + * (1.0f + - branchRatio + / 1.5f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + / 2f) + .setBranchSpawnChance(0.2) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 1) + .setRadius(4f) + .setRadiusY(2.5f)) + .setSpawnBees(true) ), - AZALEA_TOP - ( - new NewFractalTreeBuilder() - .setTreeRootThreshold(0) - .setOriginalTrunkLength(6) - .setLengthVariance(1) - .setMaxDepth(1) - .setCrownBranches(3) - .setInitialBranchRadius(0.8f) - .setNoisePriority(0.05f) - .setFirstEnd(1.0f) - .setMinBranchHorizontalComponent(1.2) - .setMaxBranchHorizontalComponent(2) - .setMaxInitialNormalDelta(0) - .setMinInitialNormalDelta(0) - .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth-(branchRatio*0.2f)) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> currentBranchLength-2) - .setMinBranchSpawnLength(0.8f) - .setBranchSpawnChance(0.1) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.5f, 2) - .setRadius(4f) - .setRadiusY(1.5f) - .setLeafNoiseFrequency(0.2f) - .setMaterial(Material.AZALEA_LEAVES, Material.FLOWERING_AZALEA_LEAVES)) - ) - , - TAIGA_BIG( - new NewFractalTreeBuilder() - .setFirstEnd(1.0f) - .setTreeRootThreshold(2) - .setTreeRootMultiplier(1.3f) - .setBranchMaterial(Material.SPRUCE_LOG) - .setRootMaterial(Material.SPRUCE_WOOD) - .setOriginalTrunkLength(30) - .setLengthVariance(2) - .setInitialBranchRadius(1.8f) - // .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth/2) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { - if(currentBranchLength < 10) return 0f; - return 0.3f*Math.max(0,30 - totalTreeHeight); - }) - .setCrownBranches(0) - .setMaxDepth(3) - .setMaxInitialNormalDelta(0.1) - .setMinInitialNormalDelta(-0.1) - .setMinBranchHorizontalComponent(1.5) - .setMaxBranchHorizontalComponent(2.0) - .setBranchSpawnChance(1.0) - .setRandomBranchSpawnCooldown(4) - .setRandomBranchClusterCount(5) - .setRandomBranchSegmentCount(5) - .setMinBranchSpawnLength(0.3f) - .setLeafSpawnDepth(0) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.4f, 2) - .setConeLeaves(true) - .setRadius(1.5f) - .setRadiusY(2.3f) - .setLeafNoiseFrequency(0.3f) - .setMaterial(Material.SPRUCE_LEAVES) - ) + NORMAL_SMALL(new NewFractalTreeBuilder().setTreeRootThreshold(0) + .setOriginalTrunkLength(4) + .setLengthVariance(1) + .setMaxDepth(1) + .setCrownBranches(3) + .setInitialBranchRadius(0.8f) + .setNoisePriority(0.05f) + .setFirstEnd(1.0f) + .setMinBranchHorizontalComponent(1.2) + .setMaxBranchHorizontalComponent(2) + .setMaxInitialNormalDelta(0) + .setMinInitialNormalDelta(0) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> + initialBranchWidth + - (branchRatio * 0.2f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + - 2) + .setMinBranchSpawnLength(0.8f) + .setBranchSpawnChance(0.1) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 1) + .setRadius(3f) + .setRadiusY(3f) + .setLeafNoiseFrequency(0.5f) + .setSemiSphereLeaves(true) + .setMaterial(Material.OAK_LEAVES))), + AZALEA_TOP(new NewFractalTreeBuilder().setTreeRootThreshold(0) + .setOriginalTrunkLength(6) + .setLengthVariance(1) + .setMaxDepth(1) + .setCrownBranches(3) + .setInitialBranchRadius(0.8f) + .setNoisePriority(0.05f) + .setFirstEnd(1.0f) + .setMinBranchHorizontalComponent(1.2) + .setMaxBranchHorizontalComponent(2) + .setMaxInitialNormalDelta(0) + .setMinInitialNormalDelta(0) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth + - (branchRatio + * 0.2f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + - 2) + .setMinBranchSpawnLength(0.8f) + .setBranchSpawnChance(0.1) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.5f, 2) + .setRadius(4f) + .setRadiusY(1.5f) + .setLeafNoiseFrequency(0.2f) + .setMaterial( + Material.AZALEA_LEAVES, + Material.FLOWERING_AZALEA_LEAVES + ))), + TAIGA_BIG(new NewFractalTreeBuilder().setFirstEnd(1.0f) + .setTreeRootThreshold(2) + .setTreeRootMultiplier(1.3f) + .setBranchMaterial(Material.SPRUCE_LOG) + .setRootMaterial(Material.SPRUCE_WOOD) + .setOriginalTrunkLength(30) + .setLengthVariance(2) + .setInitialBranchRadius(1.8f) + // .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth/2) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { + if (currentBranchLength < 10) { + return 0f; + } + return 0.3f * Math.max(0, 30 - totalTreeHeight); + }) + .setCrownBranches(0) + .setMaxDepth(3) + .setMaxInitialNormalDelta(0.1) + .setMinInitialNormalDelta(-0.1) + .setMinBranchHorizontalComponent(1.5) + .setMaxBranchHorizontalComponent(2.0) + .setBranchSpawnChance(1.0) + .setRandomBranchSpawnCooldown(4) + .setRandomBranchClusterCount(5) + .setRandomBranchSegmentCount(5) + .setMinBranchSpawnLength(0.3f) + .setLeafSpawnDepth(0) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f, 2) + .setConeLeaves(true) + .setRadius(1.5f) + .setRadiusY(2.3f) + .setLeafNoiseFrequency(0.3f) + .setMaterial(Material.SPRUCE_LEAVES))), + TAIGA_SMALL( + new NewFractalTreeBuilder().setTreeRootThreshold(0) + .setBranchMaterial(Material.SPRUCE_LOG) + .setOriginalTrunkLength(16) + .setLengthVariance(1) + .setInitialBranchRadius(0.8f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { + if (currentBranchLength < 10) { + return 0f; + } + return Math.min(4, 0.5f * Math.max(0, 12 - totalTreeHeight)); + }) + .setCrownBranches(0) + .setMaxDepth(3) + .setMaxInitialNormalDelta(0.1) + .setMinInitialNormalDelta(-0.1) + .setMinBranchHorizontalComponent(1.5) + .setMaxBranchHorizontalComponent(2.0) + .setBranchSpawnChance(1.0) + .setRandomBranchSpawnCooldown(4) + .setRandomBranchClusterCount(4) + .setRandomBranchSegmentCount(4) + .setMinBranchSpawnLength(0.2f) + .setLeafSpawnDepth(0) + .setRootMaterial(Material.SPRUCE_WOOD) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f, 1) + .setConeLeaves(true) + .setRadius(1.3f) + .setRadiusY(2f) + .setMaterial(Material.SPRUCE_LEAVES)), + new NewFractalTreeBuilder().setTreeRootThreshold(0) + .setBranchMaterial(Material.SPRUCE_LOG) + .setOriginalTrunkLength(18) + .setLengthVariance(3) + .setInitialBranchRadius(0.8f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { + if (currentBranchLength < 10) { + return 0f; + } + return Math.min(4, 0.5f * Math.max(0, 12 - totalTreeHeight)); + }) + .setCrownBranches(0) + .setMaxDepth(3) + .setMaxInitialNormalDelta(0) + .setMinInitialNormalDelta(0) + .setMinBranchHorizontalComponent(1.5) + .setMaxBranchHorizontalComponent(2.0) + .setBranchSpawnChance(0.7) + .setRandomBranchSpawnCooldown(2) + .setRandomBranchClusterCount(4) + .setRandomBranchSegmentCount(4) + .setMinBranchSpawnLength(0.4f) + .setLeafSpawnDepth(0) + .setRootMaterial(Material.SPRUCE_WOOD) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f, 1) + .setConeLeaves(true) + .setRadius(1.3f) + .setRadiusY(3f) + .setMaterial(Material.SPRUCE_LEAVES)) ), - TAIGA_SMALL - ( - new NewFractalTreeBuilder() - .setTreeRootThreshold(0) - .setBranchMaterial(Material.SPRUCE_LOG) - .setOriginalTrunkLength(16) - .setLengthVariance(1) - .setInitialBranchRadius(0.8f) - .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { - if(currentBranchLength < 10) return 0f; - return Math.min(4,0.5f*Math.max(0,12 - totalTreeHeight)); - }) - .setCrownBranches(0) - .setMaxDepth(3) - .setMaxInitialNormalDelta(0.1) - .setMinInitialNormalDelta(-0.1) - .setMinBranchHorizontalComponent(1.5) - .setMaxBranchHorizontalComponent(2.0) - .setBranchSpawnChance(1.0) - .setRandomBranchSpawnCooldown(4) - .setRandomBranchClusterCount(4) - .setRandomBranchSegmentCount(4) - .setMinBranchSpawnLength(0.2f) - .setLeafSpawnDepth(0) - .setRootMaterial(Material.SPRUCE_WOOD) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.4f, 1) - .setConeLeaves(true) - .setRadius(1.3f) - .setRadiusY(2f) - .setMaterial(Material.SPRUCE_LEAVES) - ), - new NewFractalTreeBuilder() - .setTreeRootThreshold(0) - .setBranchMaterial(Material.SPRUCE_LOG) - .setOriginalTrunkLength(18) - .setLengthVariance(3) - .setInitialBranchRadius(0.8f) - .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth) - .setBranchDecrement((currentBranchLength, totalTreeHeight) -> { - if(currentBranchLength < 10) return 0f; - return Math.min(4,0.5f*Math.max(0,12 - totalTreeHeight)); - }) - .setCrownBranches(0) - .setMaxDepth(3) - .setMaxInitialNormalDelta(0) - .setMinInitialNormalDelta(0) - .setMinBranchHorizontalComponent(1.5) - .setMaxBranchHorizontalComponent(2.0) - .setBranchSpawnChance(0.7) - .setRandomBranchSpawnCooldown(2) - .setRandomBranchClusterCount(4) - .setRandomBranchSegmentCount(4) - .setMinBranchSpawnLength(0.4f) - .setLeafSpawnDepth(0) - .setRootMaterial(Material.SPRUCE_WOOD) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.4f, 1) - .setConeLeaves(true) - .setRadius(1.3f) - .setRadiusY(3f) - .setMaterial(Material.SPRUCE_LEAVES) - ) - ) - , SCARLET_BIG, SCARLET_SMALL, SAVANNA_SMALL, SAVANNA_BIG, WASTELAND_BIG, - SWAMP_TOP( - new NewFractalTreeBuilder() - .setOriginalTrunkLength(13) - .setLengthVariance(2) - .setMaxDepth(4) - .setInitialBranchRadius(2f) - .setGetBranchWidth( - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/2f) - ) - .setBranchDecrement( - (currentBranchLength, totalTreeHeight) - -> currentBranchLength/1.7f - ) - .setMinBranchHorizontalComponent(0.9f) - .setMaxBranchHorizontalComponent(1.3f) - .setBranchSpawnChance(0.2) - .setBranchMaterial(OneOneNineBlockHandler.MANGROVE_LOG) - .setRootMaterial(OneOneNineBlockHandler.MANGROVE_ROOTS) - .setTreeRootMultiplier(2f) - .setTreeRootThreshold(3) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.4f, 2) - .setRadius(4f) - .setRadiusY(1.5f) - .setMaterial(OneOneNineBlockHandler.MANGROVE_LEAVES) - .setMangrovePropagules(true)) - ), + SWAMP_TOP(new NewFractalTreeBuilder().setOriginalTrunkLength(13) + .setLengthVariance(2) + .setMaxDepth(4) + .setInitialBranchRadius(2f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth + * (1.0f + - branchRatio + / 2f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + / 1.7f) + .setMinBranchHorizontalComponent(0.9f) + .setMaxBranchHorizontalComponent(1.3f) + .setBranchSpawnChance(0.2) + .setBranchMaterial(OneOneNineBlockHandler.MANGROVE_LOG) + .setRootMaterial(OneOneNineBlockHandler.MANGROVE_ROOTS) + .setTreeRootMultiplier(2f) + .setTreeRootThreshold(3) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.4f, 2) + .setRadius(4f) + .setRadiusY(1.5f) + .setMaterial(OneOneNineBlockHandler.MANGROVE_LEAVES) + .setMangrovePropagules(true))), BIRCH_BIG, BIRCH_SMALL, CHERRY_SMALL, @@ -269,69 +252,55 @@ public enum Tree { JUNGLE_SMALL, JUNGLE_EXTRA_SMALL, COCONUT_TOP, - DARK_OAK_SMALL( - new NewFractalTreeBuilder() - .setOriginalTrunkLength(7) - .setLengthVariance(1) - .setInitialBranchRadius(2.7f) - .setCrownBranches(3) - .setMinBranchSpawnLength(0.2f) - .setMaxDepth(4) - .setBranchSpawnChance(0f) - .setMinBranchHorizontalComponent(0.5f) - .setMaxBranchHorizontalComponent(0.9f) - .setGetBranchWidth( - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/2f) - ) - .setBranchDecrement( - (currentBranchLength, totalTreeHeight) - -> currentBranchLength-1 - ) - .setBranchSpawnChance(0.05) - .setTreeRootMultiplier(1.3f) - .setTreeRootThreshold(3) - .setRootMaterial(Material.DARK_OAK_WOOD) - .setBranchMaterial(Material.DARK_OAK_LOG) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 1) - .setRadius(4.5f) - .setRadiusY(2.5f) - .setMaterial(Material.DARK_OAK_LEAVES) - ) - ), - DARK_OAK_BIG_TOP( - new NewFractalTreeBuilder() - .setOriginalTrunkLength(12) - .setLengthVariance(1) - .setInitialBranchRadius(2.7f) - .setCrownBranches(3) - .setMinBranchSpawnLength(0.2f) - .setMaxDepth(3) - .setBranchSpawnChance(0f) - .setMinBranchHorizontalComponent(-1.2) - .setMaxBranchHorizontalComponent(1.2f) - .setGetBranchWidth( - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/3f) - ) - .setBranchDecrement( - (currentBranchLength, totalTreeHeight) - -> currentBranchLength-0.5f - ) - .setRandomBranchClusterCount(3) - .setBranchSpawnChance(0.05) - .setTreeRootMultiplier(1.6f) - .setTreeRootThreshold(5) - .setRootMaterial(Material.DARK_OAK_WOOD) - .setBranchMaterial(Material.DARK_OAK_LOG) - .setFractalLeaves(new FractalLeaves() - .setWeepingLeaves(0.3f, 2) - .setRadius(4f) - .setRadiusY(2.5f) - .setMaterial(Material.DARK_OAK_LEAVES) - ) - ), + DARK_OAK_SMALL(new NewFractalTreeBuilder().setOriginalTrunkLength(7) + .setLengthVariance(1) + .setInitialBranchRadius(2.7f) + .setCrownBranches(3) + .setMinBranchSpawnLength(0.2f) + .setMaxDepth(4) + .setBranchSpawnChance(0f) + .setMinBranchHorizontalComponent(0.5f) + .setMaxBranchHorizontalComponent(0.9f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> + initialBranchWidth + * (1.0f - branchRatio / 2f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + - 1) + .setBranchSpawnChance(0.05) + .setTreeRootMultiplier(1.3f) + .setTreeRootThreshold(3) + .setRootMaterial(Material.DARK_OAK_WOOD) + .setBranchMaterial(Material.DARK_OAK_LOG) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 1) + .setRadius(4.5f) + .setRadiusY(2.5f) + .setMaterial(Material.DARK_OAK_LEAVES))), + DARK_OAK_BIG_TOP(new NewFractalTreeBuilder().setOriginalTrunkLength(12) + .setLengthVariance(1) + .setInitialBranchRadius(2.7f) + .setCrownBranches(3) + .setMinBranchSpawnLength(0.2f) + .setMaxDepth(3) + .setBranchSpawnChance(0f) + .setMinBranchHorizontalComponent(-1.2) + .setMaxBranchHorizontalComponent(1.2f) + .setGetBranchWidth((initialBranchWidth, branchRatio) -> + initialBranchWidth + * (1.0f - branchRatio / 3f)) + .setBranchDecrement((currentBranchLength, totalTreeHeight) -> + currentBranchLength + - 0.5f) + .setRandomBranchClusterCount(3) + .setBranchSpawnChance(0.05) + .setTreeRootMultiplier(1.6f) + .setTreeRootThreshold(5) + .setRootMaterial(Material.DARK_OAK_WOOD) + .setBranchMaterial(Material.DARK_OAK_LOG) + .setFractalLeaves(new FractalLeaves().setWeepingLeaves(0.3f, 2) + .setRadius(4f) + .setRadiusY(2.5f) + .setMaterial(Material.DARK_OAK_LEAVES))), FROZEN_TREE_BIG, FROZEN_TREE_SMALL, FIRE_CORAL, @@ -342,40 +311,50 @@ public enum Tree { GIANT_PUMPKIN, ANDESITE_PETRIFIED_SMALL, GRANITE_PETRIFIED_SMALL, - DIORITE_PETRIFIED_SMALL - ; + DIORITE_PETRIFIED_SMALL; private final NewFractalTreeBuilder[] builders; - Tree(){builders = new NewFractalTreeBuilder[]{};} - Tree(NewFractalTreeBuilder... builder){this.builders = builder;} + + Tree() { + builders = new NewFractalTreeBuilder[] {}; + } + + Tree(NewFractalTreeBuilder... builder) { + this.builders = builder; + } + public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base) { - return build(tw,base,null); + return build(tw, base, null); } // Use of treeMutator is currently not optimal as it makes a copy before every use // No idea how bad that is. - public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base, @Nullable Function treeMutator){ - if(builders.length > 0) { - NewFractalTreeBuilder b = Objects.requireNonNull( - GenUtils.choice( - tw.getHashedRand(base.getX(), base.getY(), base.getZ()), - builders) - ); - if(treeMutator != null) { + public boolean build(@NotNull TerraformWorld tw, + @NotNull SimpleBlock base, + @Nullable Function treeMutator) + { + if (builders.length > 0) { + NewFractalTreeBuilder b = Objects.requireNonNull(GenUtils.choice(tw.getHashedRand(base.getX(), + base.getY(), + base.getZ() + ), builders)); + if (treeMutator != null) { try { b = (NewFractalTreeBuilder) b.clone(); treeMutator.apply(b); - }catch(CloneNotSupportedException e){ + } + catch (CloneNotSupportedException e) { // good luck m8 TerraformGeneratorPlugin.logger.stackTrace(e); - return b.build(tw,base); + return b.build(tw, base); } } return b.build(tw, base); } - else + else { return new FractalTreeBuilder(this).build(tw, base); + } } } @@ -394,9 +373,6 @@ public enum Mushroom { } public enum MushroomCap { - ROUND, - FLAT, - FUNNEL, - POINTY + ROUND, FLAT, FUNNEL, POINTY } } diff --git a/common/src/main/java/org/terraform/tree/MushroomBuilder.java b/common/src/main/java/org/terraform/tree/MushroomBuilder.java index 5216300c..e726452c 100644 --- a/common/src/main/java/org/terraform/tree/MushroomBuilder.java +++ b/common/src/main/java/org/terraform/tree/MushroomBuilder.java @@ -22,20 +22,17 @@ // A handy tool for creating mushroom stems with right curvature: // https://www.geogebra.org/classic/hg7ckgwz public class MushroomBuilder { + final FractalTypes.Mushroom type; + final int heightVariation = 0; Random rand; FastNoise noiseGen; - @Nullable SimpleBlock stemTop; - - final FractalTypes.Mushroom type; FractalTypes.MushroomCap capShape = FractalTypes.MushroomCap.ROUND; Material stemType = Material.MUSHROOM_STEM; Material capType = Material.RED_MUSHROOM_BLOCK; Material spotType = Material.MUSHROOM_STEM; - int baseHeight = 18; - final int heightVariation = 0; float baseThickness = 3.8f; float segmentFactor = 2; @@ -58,108 +55,106 @@ public MushroomBuilder(FractalTypes.@NotNull Mushroom type) { switch (type) { case GIANT_BROWN_FUNNEL_MUSHROOM: this.setCapType(Material.BROWN_MUSHROOM_BLOCK) - .setCapRadius(13) - .setCapYOffset(-2) - .setCapShape(FractalTypes.MushroomCap.FUNNEL); + .setCapRadius(13) + .setCapYOffset(-2) + .setCapShape(FractalTypes.MushroomCap.FUNNEL); break; case GIANT_BROWN_MUSHROOM: this.setCapType(Material.BROWN_MUSHROOM_BLOCK); break; case GIANT_RED_MUSHROOM: - this.setBaseThickness(6f) - .setThicknessIncrement(1.5f) - .setCapRadius(15) - .setCapYOffset(-10); + this.setBaseThickness(6f).setThicknessIncrement(1.5f).setCapRadius(15).setCapYOffset(-10); break; case MEDIUM_BROWN_FUNNEL_MUSHROOM: this.setCapType(Material.BROWN_MUSHROOM_BLOCK) - .setCapRadius(5) - .setCapYOffset(-1) - .setBaseHeight(8) - .setBaseThickness(1.2f) - .setCapShape(FractalTypes.MushroomCap.FUNNEL); + .setCapRadius(5) + .setCapYOffset(-1) + .setBaseHeight(8) + .setBaseThickness(1.2f) + .setCapShape(FractalTypes.MushroomCap.FUNNEL); break; case MEDIUM_BROWN_MUSHROOM: this.setCapType(Material.BROWN_MUSHROOM_BLOCK) - .setCapRadius(5) - .setCapYOffset(-2) - .setBaseHeight(8) - .setBaseThickness(1.2f); + .setCapRadius(5) + .setCapYOffset(-2) + .setBaseHeight(8) + .setBaseThickness(1.2f); break; case MEDIUM_RED_MUSHROOM: this.setBaseThickness(1.3f) - .setBaseHeight(8) - .setThicknessIncrement(1.2f) - .setCapRadius(4.5f) - .setCapYOffset(-3); + .setBaseHeight(8) + .setThicknessIncrement(1.2f) + .setCapRadius(4.5f) + .setCapYOffset(-3); break; case SMALL_BROWN_MUSHROOM: this.setBaseThickness(0) - .setThicknessIncrement(0) - .setBaseHeight(5) - .setCapType(Material.BROWN_MUSHROOM_BLOCK) - .setMinTilt(0) - .setMaxTilt(Math.PI / 8) - .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) - .setFourAxisRotationOnly(true) - .setCapShape(FractalTypes.MushroomCap.FLAT) - .setCapRadius(3f) - .setCapYOffset(0); + .setThicknessIncrement(0) + .setBaseHeight(5) + .setCapType(Material.BROWN_MUSHROOM_BLOCK) + .setMinTilt(0) + .setMaxTilt(Math.PI / 8) + .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) + .setFourAxisRotationOnly(true) + .setCapShape(FractalTypes.MushroomCap.FLAT) + .setCapRadius(3f) + .setCapYOffset(0); break; case SMALL_RED_MUSHROOM: this.setBaseThickness(0) - .setThicknessIncrement(0.5f) - .setBaseHeight(4) - .setMaxTilt(Math.PI / 8) - .setMinTilt(0) - .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) - .setFourAxisRotationOnly(true) - .setCapRadius(2.3f) - .setCapYOffset(-1); + .setThicknessIncrement(0.5f) + .setBaseHeight(4) + .setMaxTilt(Math.PI / 8) + .setMinTilt(0) + .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) + .setFourAxisRotationOnly(true) + .setCapRadius(2.3f) + .setCapYOffset(-1); break; case SMALL_POINTY_RED_MUSHROOM: this.setBaseThickness(0) - .setThicknessIncrement(0) - .setBaseHeight(6) - .setMaxTilt(Math.PI / 18) - .setMinTilt(0) - .setFourAxisRotationOnly(true) - .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) - .setCapRadius(2.3f) - .setCapYOffset(-2) - .setCapShape(FractalTypes.MushroomCap.POINTY); + .setThicknessIncrement(0) + .setBaseHeight(6) + .setMaxTilt(Math.PI / 18) + .setMinTilt(0) + .setFourAxisRotationOnly(true) + .setStemCurve(0.8f, 0.2f, 0.8f, 0.4f) + .setCapRadius(2.3f) + .setCapYOffset(-2) + .setCapShape(FractalTypes.MushroomCap.POINTY); break; case TINY_RED_MUSHROOM: this.setBaseThickness(0) - .setThicknessIncrement(0) - .setBaseHeight(4) - .setMinTilt(0) - .setMaxTilt(0) - .setStemCurve(0.5f, 0.5f, 0.5f, 0.5f) - .setSegmentFactor(1) - .setCapRadius(1.2f) - .setCapYOffset(-2) - .setCapShape(FractalTypes.MushroomCap.POINTY); + .setThicknessIncrement(0) + .setBaseHeight(4) + .setMinTilt(0) + .setMaxTilt(0) + .setStemCurve(0.5f, 0.5f, 0.5f, 0.5f) + .setSegmentFactor(1) + .setCapRadius(1.2f) + .setCapYOffset(-2) + .setCapShape(FractalTypes.MushroomCap.POINTY); case TINY_BROWN_MUSHROOM: this.setBaseThickness(0) - .setThicknessIncrement(0) - .setBaseHeight(2) - .setMinTilt(0) - .setMaxTilt(0) - .setStemCurve(0.5f, 0.5f, 0.5f, 0.5f) - .setSegmentFactor(1) - .setCapRadius(1.5f) - .setCapYOffset(1) - .setCapShape(FractalTypes.MushroomCap.ROUND) - .setCapType(Material.BROWN_MUSHROOM_BLOCK); + .setThicknessIncrement(0) + .setBaseHeight(2) + .setMinTilt(0) + .setMaxTilt(0) + .setStemCurve(0.5f, 0.5f, 0.5f, 0.5f) + .setSegmentFactor(1) + .setCapRadius(1.5f) + .setCapYOffset(1) + .setCapShape(FractalTypes.MushroomCap.ROUND) + .setCapType(Material.BROWN_MUSHROOM_BLOCK); break; } } private void replaceSphere(float radius, @NotNull SimpleBlock base, @NotNull Material type) { if (radius < 0.5) { - if (!base.isSolid()) + if (!base.isSolid()) { base.setType(type); + } return; } @@ -172,10 +167,14 @@ private void replaceSphere(float radius, @NotNull SimpleBlock base, @NotNull Mat for (int z = -Math.round(radius); z <= Math.round(radius); z++) { SimpleBlock block = base.getRelative(x, y, z); - if (Math.pow(x, 2) / Math.pow(radius, 2) + - Math.pow(y, 2) / Math.pow(radius, 2) + - Math.pow(z, 2) / Math.pow(radius, 2) - <= 1 + 0.7 * noiseGen.GetNoise(block.getX(), block.getY(), block.getZ())) { + if (Math.pow(x, 2) / Math.pow(radius, 2) + + Math.pow(y, 2) / Math.pow(radius, 2) + + Math.pow(z, 2) / Math.pow(radius, 2) <= 1 + 0.7 * noiseGen.GetNoise( + block.getX(), + block.getY(), + block.getZ() + )) + { if (!block.isSolid()) { block.setType(type); } @@ -185,14 +184,23 @@ private void replaceSphere(float radius, @NotNull SimpleBlock base, @NotNull Mat } } - private void spawnSphericalCap(int seed, float r, float ry, @NotNull SimpleBlock base, boolean hardReplace, Material... type) { + private void spawnSphericalCap(int seed, + float r, + float ry, + @NotNull SimpleBlock base, + boolean hardReplace, + Material... type) + { Random rand = new Random(seed); // FastNoise noise = new FastNoise(seed); noiseGen.SetNoiseType(FastNoise.NoiseType.Simplex); noiseGen.SetFrequency(1.4f); float belowY = -0.25f * 2 * ry; - float lowThreshold = Math.min((float) (0.6 / 5 * Math.min(r, ry)), 0.6f); // When radius < 5 mushrooms less hollow + float lowThreshold = Math.min( + (float) (0.6 / 5 * Math.min(r, ry)), + 0.6f + ); // When radius < 5 mushrooms less hollow for (int x = Math.round(-r); x <= Math.round(r); x++) { for (int y = Math.round(belowY); y <= Math.round(ry); y++) { @@ -206,11 +214,12 @@ private void spawnSphericalCap(int seed, float r, float ry, @NotNull SimpleBlock SimpleBlock rel = base.getRelative(x, y, z); double equationResult = Math.pow(x, 2) / Math.pow(r, 2) - + Math.pow(y, 2) / Math.pow(ry, 2) - + Math.pow(z, 2) / Math.pow(r, 2); + + Math.pow(y, 2) / Math.pow(ry, 2) + + Math.pow(z, 2) / Math.pow(r, 2); if (equationResult <= 1 + 0.25 * Math.abs(noiseGen.GetNoise(x / r, y / ry, z / r)) - && equationResult >= lowThreshold) { + && equationResult >= lowThreshold) + { if (hardReplace || !rel.isSolid()) { rel.setType(GenUtils.randChoice(rand, type)); @@ -223,52 +232,77 @@ private void spawnSphericalCap(int seed, float r, float ry, @NotNull SimpleBlock } public void build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTallMushroomsEnabled()) return; - - if(TConfigOption.DEVSTUFF_VANILLA_MUSHROOMS.getBoolean()) { - String schemName; - if(this.type.toString().contains("RED")) - schemName = VanillaMushroomBuilder.RED_MUSHROOM_CAP; - else - schemName = VanillaMushroomBuilder.BROWN_MUSHROOM_CAP; - - VanillaMushroomBuilder.buildVanillaMushroom(tw, data, x, y, z, schemName); - return; + if (!TConfigOption.areTallMushroomsEnabled()) { + return; + } + + if (TConfigOption.DEVSTUFF_VANILLA_MUSHROOMS.getBoolean()) { + String schemName; + if (this.type.toString().contains("RED")) { + schemName = VanillaMushroomBuilder.RED_MUSHROOM_CAP; + } + else { + schemName = VanillaMushroomBuilder.BROWN_MUSHROOM_CAP; + } + + VanillaMushroomBuilder.buildVanillaMushroom(tw, data, x, y, z, schemName); + return; } - - this.noiseGen = new FastNoise((int) tw.getSeed()); + + this.noiseGen = new FastNoise((int) tw.getSeed()); this.rand = tw.getRand(16L * 16 * x + 16L * y + z); SimpleBlock base = new SimpleBlock(data, x, y, z); - if (this.stemTop == null) stemTop = base; + if (this.stemTop == null) { + stemTop = base; + } double initialAngle; - if (fourAxisRotationOnly) + if (fourAxisRotationOnly) { initialAngle = (Math.PI / 2.0) * Math.round(Math.random() * 4); - else initialAngle = 2 * Math.PI * Math.random(); + } + else { + initialAngle = 2 * Math.PI * Math.random(); + } int initialHeight = baseHeight + GenUtils.randInt(-heightVariation, heightVariation); - createStem(base, - GenUtils.randDouble(rand, minTilt, maxTilt), - initialAngle, - baseThickness, - initialHeight); + createStem(base, GenUtils.randDouble(rand, minTilt, maxTilt), initialAngle, baseThickness, initialHeight); switch (capShape) { case ROUND: spawnSphericalCap(tw.getHashedRand(x, y, z).nextInt(94929297), - capRadius, capRadius, stemTop.getRelative(0, capYOffset, 0), true, capType); + capRadius, + capRadius, + stemTop.getRelative(0, capYOffset, 0), + true, + capType + ); break; case FLAT: spawnSphericalCap(tw.getHashedRand(x, y, z).nextInt(94929297), - capRadius, 0.6f * capRadius, stemTop.getRelative(0, capYOffset, 0), true, capType); + capRadius, + 0.6f * capRadius, + stemTop.getRelative(0, capYOffset, 0), + true, + capType + ); break; case POINTY: spawnSphericalCap(tw.getHashedRand(x, y, z).nextInt(94929297), - capRadius, capRadius * 1.8f, stemTop.getRelative(0, capYOffset, 0), true, capType); + capRadius, + capRadius * 1.8f, + stemTop.getRelative(0, capYOffset, 0), + true, + capType + ); break; case FUNNEL: // Implement funnel algorithm spawnFunnelCap(tw.getHashedRand(x, y, z).nextInt(94929297), - capRadius, capRadius * 0.7f, capRadius * 0.1f, stemTop.getRelative(0, capYOffset, 0), capType); + capRadius, + capRadius * 0.7f, + capRadius * 0.1f, + stemTop.getRelative(0, capYOffset, 0), + capType + ); break; } } @@ -279,7 +313,10 @@ private void createStem(@NotNull SimpleBlock base, double tilt, double yaw, doub boolean oneBlockWide = thickness == 0; // The straight stem represented in 2d (x,y) - Vector2f stem2d = new Vector2f((float) (length * Math.cos(Math.PI / 2 - tilt)), (float) (length * Math.sin(Math.PI / 2 - tilt))); + Vector2f stem2d = new Vector2f( + (float) (length * Math.cos(Math.PI / 2 - tilt)), + (float) (length * Math.sin(Math.PI / 2 - tilt)) + ); // 2d control points Vector2f controlPoint1 = new Vector2f(curvatureControlPoint1.x * stem2d.x, curvatureControlPoint1.y * stem2d.y); @@ -301,8 +338,11 @@ private void createStem(@NotNull SimpleBlock base, double tilt, double yaw, doub lastSegment = base.getRelative(stem3d); if (!changedYs.contains(lastSegment.getY()) || !oneBlockWide) { - replaceSphere((float) (thickness / 2f + thicknessIncrement * thicknessIncrementCurve.calculate(1 - progress).y), - lastSegment, stemType); + replaceSphere((float) (thickness / 2f + thicknessIncrement * thicknessIncrementCurve.calculate(1 + - progress).y), + lastSegment, + stemType + ); changedYs.add(lastSegment.getY()); } @@ -311,7 +351,13 @@ private void createStem(@NotNull SimpleBlock base, double tilt, double yaw, doub stemTop = lastSegment; } - private void spawnFunnelCap(int seed, float r, float height, float thickness, @NotNull SimpleBlock base, Material... type) { + private void spawnFunnelCap(int seed, + float r, + float height, + float thickness, + @NotNull SimpleBlock base, + Material... type) + { Random rand = new Random(seed); // FastNoise noise = new FastNoise(seed); noiseGen.SetNoiseType(FastNoise.NoiseType.Simplex); @@ -321,8 +367,9 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N for (int y = 0; y <= Math.round(3 * thickness); y++) { for (int z = Math.round(-r); z <= Math.round(r); z++) { // Replace blocks in the middle - if (stemTop.getRelative(0, y, 0).getType() == stemType) + if (stemTop.getRelative(0, y, 0).getType() == stemType) { stemTop.getRelative(0, y, 0).setType(GenUtils.randChoice(rand, type)); + } double distToCenter = Math.sqrt(x * x + z * z) / r; @@ -333,9 +380,10 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N SimpleBlock rel = base.getRelative(x, (int) Math.round(realY), z); double equationResult = Math.pow(x / r, 2) - // For height max height: https://www.geogebra.org/classic/k5nefypu - + Math.pow(Math.abs(y) / (thickness / (1 - Math.pow(1 - (distToCenter + 0.1), 6))), 4) - + Math.pow(z / r, 2); + // For height max height: https://www.geogebra.org/classic/k5nefypu + + Math.pow(Math.abs(y) / (thickness / (1 - Math.pow(1 - (distToCenter + + 0.1), 6))), 4) + + Math.pow(z / r, 2); if (equationResult <= 1) { rel.setType(GenUtils.randChoice(rand, type)); @@ -355,18 +403,21 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N // Points from middle to a point on circle with radius of 0.9r List points = new BresenhamLine(new Vector2f(0, 0), - new Vector2f((float) (0.9 * r * Math.cos(angle)), (float) (0.9 * r * Math.sin(angle)))).getPoints(); + new Vector2f((float) (0.9 * r * Math.cos(angle)), (float) (0.9 * r * Math.sin(angle))) + ).getPoints(); - points: +points: for (Vector2f point : points) { SimpleBlock pointBase = base.getRelative(Math.round(point.x), 0, Math.round(point.y)); while (true) { if (pointBase.isSolid()) { - if (BlockUtils.isAir(pointBase.getDown().getType())) + if (BlockUtils.isAir(pointBase.getDown().getType())) { pointBase.getDown().setType(Material.MUSHROOM_STEM); + } continue points; - } else { + } + else { pointBase = pointBase.getUp(); } @@ -452,7 +503,11 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N /** * @see MushroomBuilder#setStemCurve(Vector2f, Vector2f) */ - private @NotNull MushroomBuilder setStemCurve(float controlP1x, float controlP1y, float controlP2x, float controlP2y) { + private @NotNull MushroomBuilder setStemCurve(float controlP1x, + float controlP1y, + float controlP2x, + float controlP2y) + { return setStemCurve(new Vector2f(controlP1x, controlP1y), new Vector2f(controlP2x, controlP2y)); } @@ -460,6 +515,7 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N * Thickness increment is added to the **radius** of the stem * based on Bezier thickness increment curve. On the ground * level the width of the stem will be (width + 2 * thicknessIncrement). + * * @param thicknessIncrement Thickness increment towards the ground. */ private @NotNull MushroomBuilder setThicknessIncrement(double thicknessIncrement) { @@ -485,7 +541,11 @@ private void spawnFunnelCap(int seed, float r, float height, float thickness, @N /** * @see MushroomBuilder#setThicknessIncrementCurve(Vector2f, Vector2f) */ - private @NotNull MushroomBuilder setThicknessIncrementCurve(float controlP1x, float controlP1y, float controlP2x, float controlP2y) { + private @NotNull MushroomBuilder setThicknessIncrementCurve(float controlP1x, + float controlP1y, + float controlP2x, + float controlP2y) + { return setThicknessIncrementCurve(new Vector2f(controlP1x, controlP1y), new Vector2f(controlP2x, controlP2y)); } diff --git a/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java b/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java index 44e211c5..05e873ac 100644 --- a/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java +++ b/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java @@ -24,6 +24,16 @@ */ public class NewFractalTreeBuilder implements Cloneable { + private static final int[][] rotationMatrixX = new int[][] { + new int[] {1, 0, 0}, new int[] {0, 0, -1}, new int[] {0, 1, 0} + }; + private static final int[][] rotationMatrixZ = new int[][] { + new int[] {0, -1, 0}, new int[] {1, 0, 0}, new int[] {0, 0, 1} + }; + final int maxHeight = 9999; + // Pitch rotates up or down, yaw rotates left/right + private final Vector initialNormal = new Vector(0, 1, 0);// .normalize(); + private final double displacementThetaDelta = 2 * Math.PI; // Supposedly final fields not meant for mutation during build private int maxDepth = 3; // Last branch is depth 1 private int originalTrunkLength = 20; // Starting length of the tree trunk @@ -36,9 +46,6 @@ public class NewFractalTreeBuilder implements Cloneable { private int randomBranchSegmentCount = 3; // Controls how randomised branches are placed. Attempts to rotate branches evenly to prevent weird looks. private float randomBranchSpawnCooldown = 0; // Controls the cooldown after every branch spawn before the next private int randomBranchClusterCount = 1; // Number of random branches to spawn per successful roll - - // Pitch rotates up or down, yaw rotates left/right - private final Vector initialNormal = new Vector(0,1,0);// .normalize(); private double maxInitialNormalDelta = 0.3; private double minInitialNormalDelta = -0.3; private double minBranchHorizontalComponent = 0.5; @@ -48,72 +55,78 @@ public class NewFractalTreeBuilder implements Cloneable { private float noisePriority = 0.1f; private int leafSpawnDepth = 1; private FractalLeaves fractalLeaves; - private final double displacementThetaDelta = 2*Math.PI; - /** * This function determines how branches will decrease in length * each recursion. */ - private BiFunction branchDecrement = (currentBranchLength, totalTreeHeight) - -> currentBranchLength * 0.7f; - + private BiFunction branchDecrement = (currentBranchLength, totalTreeHeight) -> + currentBranchLength + * 0.7f; /** * This function determines how branch width will decrease * each recursion. */ - private BiFunction getBranchWidth = - (initialBranchWidth, branchRatio) - -> initialBranchWidth*(1.0f-branchRatio/2.0f); - final int maxHeight = 9999; - + private BiFunction getBranchWidth = (initialBranchWidth, branchRatio) -> initialBranchWidth * ( + 1.0f + - branchRatio / 2.0f); private Material branchMaterial = Material.OAK_LOG; private Material rootMaterial = Material.OAK_WOOD; - private boolean spawnBees = false; - private boolean checkGradient = true; // [No more mutable fields. They caused concurrency problems]=================== + private boolean spawnBees = false; + private boolean checkGradient = true; public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base) { - if ( !TConfigOption.areTreesEnabled()) return false; + if (!TConfigOption.areTreesEnabled()) { + return false; + } // Clear and set mutable structures - if(!checkGradient(base.getPopData(),base.getX(),base.getZ())) return false; + if (!checkGradient(base.getPopData(), base.getX(), base.getZ())) { + return false; + } int oriY = base.getY(); Random random = tw.getHashedRand(base.getX(), base.getY(), base.getZ()); - double displacementTheta = GenUtils.randDouble(random, 0,displacementThetaDelta); + double displacementTheta = GenUtils.randDouble(random, 0, displacementThetaDelta); HashSet prospectiveHives = new HashSet<>(); double currentBranchTheta = GenUtils.randInt(random, 0, randomBranchSegmentCount); fractalLeaves.purgeOccupiedLeavesCache(); // Spawn the actual tree - branch(tw, random, base, initialNormal.clone() - .add( - new Vector( - GenUtils.randDouble(random, minInitialNormalDelta, maxInitialNormalDelta), - 0, - GenUtils.randDouble(random, minInitialNormalDelta, maxInitialNormalDelta) - )) - .normalize(), - prospectiveHives, + branch(tw, + random, + base, + initialNormal.clone() + .add(new Vector(GenUtils.randDouble(random, minInitialNormalDelta, maxInitialNormalDelta), + 0, + GenUtils.randDouble(random, minInitialNormalDelta, maxInitialNormalDelta) + )) + .normalize(), + prospectiveHives, currentBranchTheta, oriY, displacementTheta, - originalTrunkLength + (float)GenUtils.randDouble(random, -lengthVariance, lengthVariance),firstEnd, - 0, this.initialBranchRadius, - 0); + originalTrunkLength + (float) GenUtils.randDouble(random, -lengthVariance, lengthVariance), + firstEnd, + 0, + this.initialBranchRadius, + 0 + ); // Process prospectiveHives - if(spawnBees) - for(SimpleBlock b:prospectiveHives) - { + if (spawnBees) { + for (SimpleBlock b : prospectiveHives) { // TerraformGeneratorPlugin.logger.info("Testing " + b); - if(b.isSolid()) continue; // occupied block + if (b.isSolid()) { + continue; // occupied block + } // TerraformGeneratorPlugin.logger.info("Success: " + b); BeeHiveSpawner.spawnFullBeeNest(b); break; // just one. } + } // Undo mutated changes this.fractalLeaves.setSnowy(false); @@ -123,7 +136,7 @@ public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base) boolean checkGradient(PopulatorDataAbstract data, int x, int z) { return !checkGradient || (HeightMap.getTrueHeightGradient(data, x, z, 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); + <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); } public @NotNull NewFractalTreeBuilder setCheckGradient(boolean checkGradient) @@ -133,30 +146,39 @@ boolean checkGradient(PopulatorDataAbstract data, int x, int z) { } /** - * - * @param base the start of the branch's base. - * @param normal the direction of the branch represented via a unit vector - * @param prospectiveHives a collection of possible beehive locations + * @param base the start of the branch's base. + * @param normal the direction of the branch represented via a unit vector + * @param prospectiveHives a collection of possible beehive locations * @param currentBranchTheta a counter for getNextTheta to spawn cluster branches properly - * @param oriY original tree base Y - * @param displacementTheta I forgot what this is - * @param length length of the branch - * @param end is the percentage from 0.0 to 1.0 for where the branch is considered done - * @param depth of the current recursion. Starts from 0 and stops at maxDepth - * @param currentWidth width of the current recursion + * @param oriY original tree base Y + * @param displacementTheta I forgot what this is + * @param length length of the branch + * @param end is the percentage from 0.0 to 1.0 for where the branch is considered done + * @param depth of the current recursion. Starts from 0 and stops at maxDepth + * @param currentWidth width of the current recursion */ - void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base, @NotNull Vector normal, @NotNull HashSet prospectiveHives, double currentBranchTheta, int oriY, double displacementTheta, float length, float end, int depth, float currentWidth, float startingBranchIndex) + void branch(TerraformWorld tw, + @NotNull Random random, + @NotNull SimpleBlock base, + @NotNull Vector normal, + @NotNull HashSet prospectiveHives, + double currentBranchTheta, + int oriY, + double displacementTheta, + float length, + float end, + int depth, + float currentWidth, + float startingBranchIndex) { boolean spawnedNewBranch = false; SimpleBlock lastOperatedCentre = base; // Terminate on maxDepth. - if(length > 0 && depth < maxDepth) - { + if (length > 0 && depth < maxDepth) { float initialWidth = currentWidth; // Number of rotated cylindrical disks is length - FastNoise noiseGen = NoiseCacheHandler.getNoise( - tw, + FastNoise noiseGen = NoiseCacheHandler.getNoise(tw, NoiseCacheHandler.NoiseCacheEntry.FRACTALTREES_BASE_NOISE, world -> { FastNoise n = new FastNoise((int) world.getSeed()); @@ -164,7 +186,8 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base n.SetFractalOctaves(5); n.SetFrequency(0.05f); return n; - }); + } + ); // A vector representing the centre of the branch, including its length. Vector branchVect = normal.clone().multiply(length); @@ -176,54 +199,71 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base // I am the branchIndex, and steps is the maximum steps the branch will // take. Preferably, the radius of the branch will shrink as steps // increase. - for(float i = 0; i < length-startingBranchIndex; i+=0.5f) { - if((i / length) > end) break; + for (float i = 0; i < length - startingBranchIndex; i += 0.5f) { + if ((i / length) > end) { + break; + } + - float appliedWidth = currentWidth; float appliedNoisePriority = this.noisePriority; Vector appliedNormal = normal; // Base branches are thicker at the bottom for roots. Material temp = this.branchMaterial; - if(depth == 0 && i < treeRootThreshold) { - appliedWidth *= (float) (treeRootMultiplier + ((1.0-treeRootMultiplier)/treeRootThreshold)*i); - appliedNoisePriority = (float) (0.7 + ((this.noisePriority-0.4)/treeRootThreshold)*i); - appliedNormal = new Vector(0,1,0); + if (depth == 0 && i < treeRootThreshold) { + appliedWidth *= (float) (treeRootMultiplier + ((1.0 - treeRootMultiplier) / treeRootThreshold) * i); + appliedNoisePriority = (float) (0.7 + ((this.noisePriority - 0.4) / treeRootThreshold) * i); + appliedNormal = new Vector(0, 1, 0); this.branchMaterial = this.rootMaterial; } // this.setBranchMaterial(BlockUtils.WOOLS[(int) length]); - lastOperatedCentre = generateRotatedCircle( - random, oriY, + lastOperatedCentre = generateRotatedCircle(random, + oriY, lastOperatedCentre.getPopData(), - branchVect.clone().multiply(i/length).add(base.toVector()), - appliedNormal, prospectiveHives, appliedNoisePriority, appliedWidth, noiseGen, i); + branchVect.clone().multiply(i / length).add(base.toVector()), + appliedNormal, + prospectiveHives, + appliedNoisePriority, + appliedWidth, + noiseGen, + i + ); this.branchMaterial = temp; - currentWidth = getBranchWidth.apply(initialWidth, (i/length)); + currentWidth = getBranchWidth.apply(initialWidth, (i / length)); // TerraformGeneratorPlugin.logger.info("CWidth: " + currentWidth); // Tick cooldown down by the loop step randomBranchSpawnCooldownCurrent -= 0.5F; // Spawn more branches. These branches are random in nature. - if((i/length) > minBranchSpawnLength - && GenUtils.chance(random, (int) (100*branchSpawnChance), 100) - && randomBranchSpawnCooldownCurrent <= 0) + if ((i / length) > minBranchSpawnLength + && GenUtils.chance(random, (int) (100 * branchSpawnChance), 100) + && randomBranchSpawnCooldownCurrent <= 0) { randomBranchSpawnCooldownCurrent = randomBranchSpawnCooldown; spawnedNewBranch = true; // If the cluster count is more than 0, you must reshuffle displacement theta double effectiveDisplacementTheta = displacementTheta; - if(randomBranchClusterCount > 0) - displacementTheta = GenUtils.randDouble(random, 0,displacementThetaDelta); + if (randomBranchClusterCount > 0) { + displacementTheta = GenUtils.randDouble(random, 0, displacementThetaDelta); + } // Place the randomised branches. - for(int y = 0; y < randomBranchClusterCount; y++) { + for (int y = 0; y < randomBranchClusterCount; y++) { currentBranchTheta++; - branch(tw, random, lastOperatedCentre, - calculateNextProjection(random, normal, getNextTheta(currentBranchTheta, randomBranchSegmentCount, effectiveDisplacementTheta)), + branch(tw, + random, + lastOperatedCentre, + calculateNextProjection(random, + normal, + getNextTheta(currentBranchTheta, + randomBranchSegmentCount, + effectiveDisplacementTheta + ) + ), prospectiveHives, currentBranchTheta, oriY, @@ -231,19 +271,23 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base branchDecrement.apply(length, (float) (lastOperatedCentre.getY() - oriY)), 1.0f, depth + 1, - currentWidth, 0); + currentWidth, + 0 + ); } } } // This is the base branch. Check if you want to spawn crowning branches - if(depth == 0 && crownBranches > 0) { - double thetaDelta = (2*Math.PI)/crownBranches; - for(int i = 0; i < crownBranches; i++) { + if (depth == 0 && crownBranches > 0) { + double thetaDelta = (2 * Math.PI) / crownBranches; + for (int i = 0; i < crownBranches; i++) { // branchMaterial = BlockUtils.pickWool(); spawnedNewBranch = true; - branch(tw, random, lastOperatedCentre, - calculateNextProjection(random, normal, thetaDelta*i), + branch(tw, + random, + lastOperatedCentre, + calculateNextProjection(random, normal, thetaDelta * i), prospectiveHives, currentBranchTheta, oriY, @@ -251,14 +295,16 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base branchDecrement.apply(length, (float) (lastOperatedCentre.getY() - oriY)), 1.0f, depth + 1, - currentWidth, 0); + currentWidth, + 0 + ); } } } - if(length <= 0 || !spawnedNewBranch || depth >= leafSpawnDepth) { + if (length <= 0 || !spawnedNewBranch || depth >= leafSpawnDepth) { fractalLeaves.placeLeaves(tw, oriY, maxHeight, lastOperatedCentre); - // lastOperatedCentre.setType(Material.RED_WOOL); + // lastOperatedCentre.setType(Material.RED_WOOL); } } @@ -269,7 +315,7 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base */ double getNextTheta(double currentBranchTheta, int numSegments, double displacementTheta) { - double thetaDelta = (2*Math.PI)/((double)numSegments); + double thetaDelta = (2 * Math.PI) / ((double) numSegments); return (displacementTheta + currentBranchTheta * thetaDelta); } @@ -286,61 +332,55 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base * to the normal to slightly displace it. * * @param normal refers to the current normal - * @param theta refers to the yaw (represented by 0 to 2pi) + * @param theta refers to the yaw (represented by 0 to 2pi) * @return the new normal vector */ - @NotNull Vector calculateNextProjection(@NotNull Random random, @NotNull Vector normal, double theta) { + @NotNull + Vector calculateNextProjection(@NotNull Random random, @NotNull Vector normal, double theta) { // One perpendicular vector will be rotated about the normal to // generate a rotating projection. // Vector A = normal.clone(); // Rotate A to be perpendicular to the normal - A.setX(rotationMatrixX[0][0] * normal.getX() + rotationMatrixX[0][1] * normal.getY() + rotationMatrixX[0][2] * normal.getZ()); - A.setY(rotationMatrixX[1][0] * normal.getX() + rotationMatrixX[1][1] * normal.getY() + rotationMatrixX[1][2] * normal.getZ()); - A.setZ(rotationMatrixX[2][0] * normal.getX() + rotationMatrixX[2][1] * normal.getY() + rotationMatrixX[2][2] * normal.getZ()); + A.setX(rotationMatrixX[0][0] * normal.getX() + + rotationMatrixX[0][1] * normal.getY() + + rotationMatrixX[0][2] * normal.getZ()); + A.setY(rotationMatrixX[1][0] * normal.getX() + + rotationMatrixX[1][1] * normal.getY() + + rotationMatrixX[1][2] * normal.getZ()); + A.setZ(rotationMatrixX[2][0] * normal.getX() + + rotationMatrixX[2][1] * normal.getY() + + rotationMatrixX[2][2] * normal.getZ()); double x, y, z; double u, v, w; - x=A.getX();y=A.getY();z=A.getZ(); - u=normal.getX();v=normal.getY();w=normal.getZ(); + x = A.getX(); + y = A.getY(); + z = A.getZ(); + u = normal.getX(); + v = normal.getY(); + w = normal.getZ(); double AdotNormal = A.dot(normal); - double xPrime = u* AdotNormal *(1d - Math.cos(theta)) - + x*Math.cos(theta) - + (-w*y + v*z)*Math.sin(theta); - double yPrime = v* AdotNormal *(1d - Math.cos(theta)) - + y*Math.cos(theta) - + (w*x - u*z)*Math.sin(theta); - double zPrime = w* AdotNormal *(1d - Math.cos(theta)) - + z*Math.cos(theta) - + (-v*x + u*y)*Math.sin(theta); + double xPrime = u * AdotNormal * (1d - Math.cos(theta)) + x * Math.cos(theta) + (-w * y + v * z) * Math.sin( + theta); + double yPrime = v * AdotNormal * (1d - Math.cos(theta)) + + y * Math.cos(theta) + + (w * x - u * z) * Math.sin(theta); + double zPrime = w * AdotNormal * (1d - Math.cos(theta)) + z * Math.cos(theta) + (-v * x + u * y) * Math.sin( + theta); A = new Vector(xPrime, yPrime, zPrime); // Randomly rotate the normal by adding a minimum magnitude scalar to both A and B // with a random direction (+ or -) return normal.clone() - .add(A.multiply( - GenUtils.randDouble( - random, - minBranchHorizontalComponent, - maxBranchHorizontalComponent) - ) - ) - .normalize(); + .add(A.multiply(GenUtils.randDouble(random, + minBranchHorizontalComponent, + maxBranchHorizontalComponent + ))) + .normalize(); } - private static final int[][] rotationMatrixX = new int[][] { - new int[]{1, 0, 0}, - new int[]{0, 0, -1}, - new int[]{0, 1, 0} - }; - - private static final int[][] rotationMatrixZ = new int[][] { - new int[]{0, -1, 0}, - new int[]{1, 0, 0}, - new int[]{0, 0, 1} - }; - /** * Generate a noise-fuzzed circle rotated to the normal Vec3D. This will be * achieved by iterating values of theta and fuzzed values of radius calculated @@ -351,18 +391,27 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base * Theta's step to 2pi must be larger if the circle is larger. There may be * an equation for this, but for now I will stick with a small step. * - * @param normal to the circle. - * @param radius base radius of the circle. Actual radius may be larger or smaller + * @param normal to the circle. + * @param radius base radius of the circle. Actual radius may be larger or smaller * @param heightIndex Noise will be sampled based on theta relative to this height index. * The height index allows the branch to vary continuously across * its length. * @return the centre of the evaluated circle. */ - @NotNull SimpleBlock generateRotatedCircle(@NotNull Random random, int oriY, @NotNull PopulatorDataAbstract data, @NotNull Vector centre, @NotNull Vector normal, @NotNull HashSet prospectiveHives, float noisePriority, float radius, @NotNull FastNoise noiseGen, float heightIndex) + @NotNull + SimpleBlock generateRotatedCircle(@NotNull Random random, + int oriY, + @NotNull PopulatorDataAbstract data, + @NotNull Vector centre, + @NotNull Vector normal, + @NotNull HashSet prospectiveHives, + float noisePriority, + float radius, + @NotNull FastNoise noiseGen, + float heightIndex) { - if(radius <= 0.5f) - { - data.rsetType(centre, BlockUtils.replacableByTrees, branchMaterial); + if (radius <= 0.5f) { + data.rsetType(centre, BlockUtils.replacableByTrees, branchMaterial); return new SimpleBlock(data, centre); } @@ -374,167 +423,206 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base Vector A = normal.clone(); Vector B = normal.clone(); - A.setX(rotationMatrixX[0][0]*normal.getX()+rotationMatrixX[0][1]*normal.getY()+rotationMatrixX[0][2]*normal.getZ()); - A.setY(rotationMatrixX[1][0]*normal.getX()+rotationMatrixX[1][1]*normal.getY()+rotationMatrixX[1][2]*normal.getZ()); - A.setZ(rotationMatrixX[2][0]*normal.getX()+rotationMatrixX[2][1]*normal.getY()+rotationMatrixX[2][2]*normal.getZ()); - - B.setX(rotationMatrixZ[0][0]*normal.getX()+rotationMatrixZ[0][1]*normal.getY()+rotationMatrixZ[0][2]*normal.getZ()); - B.setY(rotationMatrixZ[1][0]*normal.getX()+rotationMatrixZ[1][1]*normal.getY()+rotationMatrixZ[1][2]*normal.getZ()); - B.setZ(rotationMatrixZ[2][0]*normal.getX()+rotationMatrixZ[2][1]*normal.getY()+rotationMatrixZ[2][2]*normal.getZ()); + A.setX(rotationMatrixX[0][0] * normal.getX() + + rotationMatrixX[0][1] * normal.getY() + + rotationMatrixX[0][2] * normal.getZ()); + A.setY(rotationMatrixX[1][0] * normal.getX() + + rotationMatrixX[1][1] * normal.getY() + + rotationMatrixX[1][2] * normal.getZ()); + A.setZ(rotationMatrixX[2][0] * normal.getX() + + rotationMatrixX[2][1] * normal.getY() + + rotationMatrixX[2][2] * normal.getZ()); + + B.setX(rotationMatrixZ[0][0] * normal.getX() + + rotationMatrixZ[0][1] * normal.getY() + + rotationMatrixZ[0][2] * normal.getZ()); + B.setY(rotationMatrixZ[1][0] * normal.getX() + + rotationMatrixZ[1][1] * normal.getY() + + rotationMatrixZ[1][2] * normal.getZ()); + B.setZ(rotationMatrixZ[2][0] * normal.getX() + + rotationMatrixZ[2][1] * normal.getY() + + rotationMatrixZ[2][2] * normal.getZ()); boolean didNotGenerate = true; // Now that you have an orthogonal basis, you can now // iterate in a 2D square based on multiples of A and B // Iterate from (-rA,-rB) to (rA, rB) - double maxPossibleRadius = (1+noisePriority*2)*radius; - for(double rA = -maxPossibleRadius; rA <= maxPossibleRadius; rA++) - for(double rB = -maxPossibleRadius; rB <= maxPossibleRadius; rB++) - { - double distFromCentre = Math.sqrt(Math.pow(rA,2)+Math.pow(rB,2)); + double maxPossibleRadius = (1 + noisePriority * 2) * radius; + for (double rA = -maxPossibleRadius; rA <= maxPossibleRadius; rA++) { + for (double rB = -maxPossibleRadius; rB <= maxPossibleRadius; rB++) { + double distFromCentre = Math.sqrt(Math.pow(rA, 2) + Math.pow(rB, 2)); // Theta will be used to calculate variations in radius // for fuzzing. - double theta = Math.atan2(rB,rA); + double theta = Math.atan2(rB, rA); // atan2 returns -pi to pi. Convert this to 0 to 2pi. - if(theta < 0) theta = 2*Math.PI - theta; + if (theta < 0) { + theta = 2 * Math.PI - theta; + } double newRadius; - if(noisePriority > 0) - newRadius = radius + (noisePriority*radius)*noiseGen.GetNoise( - Objects.hash(centre.getX(),centre.getZ()),(float) theta, heightIndex); - else + if (noisePriority > 0) { + newRadius = radius + (noisePriority * radius) * noiseGen.GetNoise(Objects.hash(centre.getX(), + centre.getZ() + ), (float) theta, heightIndex); + } + else { newRadius = radius; + } - if(distFromCentre <= newRadius) - { + if (distFromCentre <= newRadius) { // Re-convert coordinates from (A,B) to (x,y,z) // As a recap, (1,1,A), (B,1,1) - data.rsetType(centre.clone() - .add(A.clone().multiply(rA)) - .add(B.clone().multiply(rB)), + data.rsetType(centre.clone().add(A.clone().multiply(rA)).add(B.clone().multiply(rB)), BlockUtils.replacableByTrees, - branchMaterial); + branchMaterial + ); didNotGenerate = false; // Add possible beehives - if(spawnBees - && centre.getY() > oriY + originalTrunkLength/2f - && GenUtils.chance(random,1,200)) + if (spawnBees && centre.getY() > oriY + originalTrunkLength / 2f && GenUtils.chance(random, + 1, + 200 + )) + { prospectiveHives.add(new SimpleBlock(data, centre.clone() - .add(A.clone().multiply(rA)) - .add(B.clone().multiply(rB)) - .add(new Vector(0,-1,0)))); + .add(A.clone().multiply(rA)) + .add(B.clone().multiply(rB)) + .add(new Vector(0, -1, 0)) + )); + } } } + } - if(didNotGenerate) + if (didNotGenerate) { data.rsetType(centre, BlockUtils.replacableByTrees, branchMaterial); + } return new SimpleBlock(data, centre); } - @NotNull NewFractalTreeBuilder setMaxDepth(int maxDepth) { + @NotNull + NewFractalTreeBuilder setMaxDepth(int maxDepth) { this.maxDepth = maxDepth; return this; } - @NotNull NewFractalTreeBuilder setOriginalTrunkLength(int originalTrunkLength) { + @NotNull + NewFractalTreeBuilder setOriginalTrunkLength(int originalTrunkLength) { this.originalTrunkLength = originalTrunkLength; return this; } - @NotNull NewFractalTreeBuilder setFirstEnd(float firstEnd) { + @NotNull + NewFractalTreeBuilder setFirstEnd(float firstEnd) { this.firstEnd = firstEnd; return this; } - @NotNull NewFractalTreeBuilder setCrownBranches(int crownBranches) { + @NotNull + NewFractalTreeBuilder setCrownBranches(int crownBranches) { this.crownBranches = crownBranches; return this; } - @NotNull NewFractalTreeBuilder setInitialBranchRadius(float initialBranchRadius) { + @NotNull + NewFractalTreeBuilder setInitialBranchRadius(float initialBranchRadius) { this.initialBranchRadius = initialBranchRadius; return this; } - @NotNull NewFractalTreeBuilder setBranchSpawnChance(double branchSpawnChance) { + @NotNull + NewFractalTreeBuilder setBranchSpawnChance(double branchSpawnChance) { this.branchSpawnChance = branchSpawnChance; return this; } - @NotNull NewFractalTreeBuilder setMinBranchSpawnLength(float minBranchSpawnLength) { + @NotNull + NewFractalTreeBuilder setMinBranchSpawnLength(float minBranchSpawnLength) { this.minBranchSpawnLength = minBranchSpawnLength; return this; } - @NotNull NewFractalTreeBuilder setTreeRootThreshold(int treeRootThreshold) { + + @NotNull + NewFractalTreeBuilder setTreeRootThreshold(int treeRootThreshold) { this.treeRootThreshold = treeRootThreshold; return this; } - @NotNull NewFractalTreeBuilder setRandomBranchClusterCount(int randomBranchClusterCount) + + @NotNull + NewFractalTreeBuilder setRandomBranchClusterCount(int randomBranchClusterCount) { this.randomBranchClusterCount = randomBranchClusterCount; return this; } - @NotNull NewFractalTreeBuilder setRandomBranchSegmentCount(int randomBranchSegmentCount) { + + @NotNull + NewFractalTreeBuilder setRandomBranchSegmentCount(int randomBranchSegmentCount) { this.randomBranchSegmentCount = randomBranchSegmentCount; return this; } - @NotNull NewFractalTreeBuilder setMaxInitialNormalDelta(double maxInitialNormalDelta) { + @NotNull + NewFractalTreeBuilder setMaxInitialNormalDelta(double maxInitialNormalDelta) { this.maxInitialNormalDelta = maxInitialNormalDelta; return this; } - @NotNull NewFractalTreeBuilder setRandomBranchSpawnCooldown(float randomBranchSpawnCooldown) + @NotNull + NewFractalTreeBuilder setRandomBranchSpawnCooldown(float randomBranchSpawnCooldown) { this.randomBranchSpawnCooldown = randomBranchSpawnCooldown; return this; } - @NotNull NewFractalTreeBuilder setTreeRootMultiplier(float treeRootMultiplier) + @NotNull + NewFractalTreeBuilder setTreeRootMultiplier(float treeRootMultiplier) { this.treeRootMultiplier = treeRootMultiplier; return this; } - @NotNull NewFractalTreeBuilder setLeafSpawnDepth(int leafSpawnDepth) + + @NotNull + NewFractalTreeBuilder setLeafSpawnDepth(int leafSpawnDepth) { this.leafSpawnDepth = leafSpawnDepth; return this; } - @NotNull NewFractalTreeBuilder setMinBranchHorizontalComponent(double minBranchHorizontalComponent) { + @NotNull + NewFractalTreeBuilder setMinBranchHorizontalComponent(double minBranchHorizontalComponent) { this.minBranchHorizontalComponent = minBranchHorizontalComponent; return this; } - @NotNull NewFractalTreeBuilder setMaxBranchHorizontalComponent(double maxBranchHorizontalComponent) { + @NotNull + NewFractalTreeBuilder setMaxBranchHorizontalComponent(double maxBranchHorizontalComponent) { this.maxBranchHorizontalComponent = maxBranchHorizontalComponent; return this; } - @NotNull NewFractalTreeBuilder setFractalLeaves(FractalLeaves fractalLeaves) { - this.fractalLeaves = fractalLeaves; - return this; - } - - @NotNull NewFractalTreeBuilder setBranchDecrement(BiFunction branchDecrement) { + @NotNull + NewFractalTreeBuilder setBranchDecrement(BiFunction branchDecrement) { this.branchDecrement = branchDecrement; return this; } - @NotNull NewFractalTreeBuilder setGetBranchWidth(BiFunction getBranchWidth) { + @NotNull + NewFractalTreeBuilder setGetBranchWidth(BiFunction getBranchWidth) { this.getBranchWidth = getBranchWidth; return this; } - @NotNull NewFractalTreeBuilder setSpawnBees(boolean spawnBees) { + @NotNull + NewFractalTreeBuilder setSpawnBees(boolean spawnBees) { this.spawnBees = spawnBees; return this; } - @NotNull NewFractalTreeBuilder setLengthVariance(float lengthVariance) + @NotNull + NewFractalTreeBuilder setLengthVariance(float lengthVariance) { this.lengthVariance = lengthVariance; return this; @@ -544,18 +632,21 @@ void branch(TerraformWorld tw, @NotNull Random random, @NotNull SimpleBlock base this.branchMaterial = branchMaterial; return this; } + public @NotNull NewFractalTreeBuilder setRootMaterial(Material rootMaterial) { this.rootMaterial = rootMaterial; return this; } - @NotNull NewFractalTreeBuilder setNoisePriority(float noisePriority) + @NotNull + NewFractalTreeBuilder setNoisePriority(float noisePriority) { this.noisePriority = noisePriority; return this; } - @NotNull NewFractalTreeBuilder setMinInitialNormalDelta(double minInitialNormalDelta) { + @NotNull + NewFractalTreeBuilder setMinInitialNormalDelta(double minInitialNormalDelta) { this.minInitialNormalDelta = minInitialNormalDelta; return this; } @@ -564,8 +655,14 @@ public FractalLeaves getFractalLeaves() { return fractalLeaves; } + @NotNull + NewFractalTreeBuilder setFractalLeaves(FractalLeaves fractalLeaves) { + this.fractalLeaves = fractalLeaves; + return this; + } + @Override - protected @NotNull Object clone() throws CloneNotSupportedException{ + protected @NotNull Object clone() throws CloneNotSupportedException { NewFractalTreeBuilder cl = (NewFractalTreeBuilder) super.clone(); cl.setFractalLeaves(this.fractalLeaves.clone()); return cl; diff --git a/common/src/main/java/org/terraform/tree/SaplingOverrider.java b/common/src/main/java/org/terraform/tree/SaplingOverrider.java index d370b417..a56d4cdf 100644 --- a/common/src/main/java/org/terraform/tree/SaplingOverrider.java +++ b/common/src/main/java/org/terraform/tree/SaplingOverrider.java @@ -21,12 +21,16 @@ public class SaplingOverrider implements Listener { /** * Use priority highest to allow other plugins to modify event.getBlocks - */ - @EventHandler(priority= EventPriority.HIGHEST, ignoreCancelled = true) + */ + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTreeGrow(@NotNull StructureGrowEvent event) { - if (!TConfigOption.areTreesEnabled()) return; + if (!TConfigOption.areTreesEnabled()) { + return; + } - if (!(event.getWorld().getGenerator() instanceof TerraformGenerator)) return; + if (!(event.getWorld().getGenerator() instanceof TerraformGenerator)) { + return; + } TerraformWorld tw = TerraformWorld.get(event.getWorld()); PopulatorDataPostGen data = new PopulatorDataPostGen(event.getLocation().getChunk()); int x = event.getLocation().getBlockX(); @@ -36,11 +40,11 @@ public void onTreeGrow(@NotNull StructureGrowEvent event) { event.setCancelled(true); boolean isLarge = event.getBlocks().size() > 150; - List baseBlocks = event.getBlocks().stream() - .filter((b) -> Tag.LEAVES.isTagged(b.getType())) - .toList(); - if(baseBlocks.isEmpty()) - { // Leafless trees are not trees + List baseBlocks = event.getBlocks() + .stream() + .filter((b) -> Tag.LEAVES.isTagged(b.getType())) + .toList(); + if (baseBlocks.isEmpty()) { // Leafless trees are not trees event.setCancelled(false); return; } @@ -50,54 +54,56 @@ public void onTreeGrow(@NotNull StructureGrowEvent event) { // made event.getSpecies() give incorrect values. switch (baseBlock.getType()) { case ACACIA_LEAVES: - new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL) - .skipGradientCheck() - .build(tw, data, x, y, z); + new FractalTreeBuilder(FractalTypes.Tree.SAVANNA_SMALL).skipGradientCheck().build(tw, data, x, y, z); break; case OAK_LEAVES: - FractalTypes.Tree.NORMAL_SMALL - .build(tw, new SimpleBlock(data,x,y,z), (nt->nt.setCheckGradient(false))); + FractalTypes.Tree.NORMAL_SMALL.build( + tw, + new SimpleBlock(data, x, y, z), + (nt -> nt.setCheckGradient(false)) + ); break; case BIRCH_LEAVES: - new FractalTreeBuilder(FractalTypes.Tree.BIRCH_SMALL) - .skipGradientCheck() - .build(tw, data, x, y, z); + new FractalTreeBuilder(FractalTypes.Tree.BIRCH_SMALL).skipGradientCheck().build(tw, data, x, y, z); break; case JUNGLE_LEAVES: - if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() - && isLarge) - new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG) - .skipGradientCheck() - .build(tw, data, x, y, z); - else + if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() && isLarge) { + new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG).skipGradientCheck().build(tw, data, x, y, z); + } + else { TreeDB.spawnSmallJungleTree(true, tw, data, x, y, z); + } break; case DARK_OAK_LEAVES: - FractalTypes.Tree.DARK_OAK_SMALL - .build(tw, new SimpleBlock(data,x,y,z), (nt->nt.setCheckGradient(false))); + FractalTypes.Tree.DARK_OAK_SMALL.build( + tw, + new SimpleBlock(data, x, y, z), + (nt -> nt.setCheckGradient(false)) + ); break; case SPRUCE_LEAVES: - if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() - && isLarge) - { - FractalTypes.Tree.TAIGA_BIG - .build(tw, new SimpleBlock(data,x,y,z), (nt->nt.setCheckGradient(false))); + if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() && isLarge) { + FractalTypes.Tree.TAIGA_BIG.build(tw, + new SimpleBlock(data, x, y, z), + (nt -> nt.setCheckGradient(false)) + ); // Set the original podzol radius - event.getBlocks().stream() - .filter((b) -> b.getType() == Material.PODZOL) - .forEach((b)->data.setType(b.getX(),b.getY(),b.getZ(),b.getType())); + event.getBlocks() + .stream() + .filter((b) -> b.getType() == Material.PODZOL) + .forEach((b) -> data.setType(b.getX(), b.getY(), b.getZ(), b.getType())); + } + else { + FractalTypes.Tree.TAIGA_SMALL.build(tw, + new SimpleBlock(data, x, y, z), + (nt -> nt.setCheckGradient(false)) + ); } - else - FractalTypes.Tree.TAIGA_SMALL - .build(tw, new SimpleBlock(data,x,y,z), (nt->nt.setCheckGradient(false))); break; default: - if(baseBlock.getType() == OneTwentyBlockHandler.CHERRY_LEAVES) - { - new FractalTreeBuilder(FractalTypes.Tree.CHERRY_SMALL) - .skipGradientCheck() - .build(tw, data, x, y, z); + if (baseBlock.getType() == OneTwentyBlockHandler.CHERRY_LEAVES) { + new FractalTreeBuilder(FractalTypes.Tree.CHERRY_SMALL).skipGradientCheck().build(tw, data, x, y, z); return; } // Not handled by TG diff --git a/common/src/main/java/org/terraform/tree/TreeDB.java b/common/src/main/java/org/terraform/tree/TreeDB.java index f8ff5361..f6b72985 100644 --- a/common/src/main/java/org/terraform/tree/TreeDB.java +++ b/common/src/main/java/org/terraform/tree/TreeDB.java @@ -22,72 +22,108 @@ public class TreeDB { FractalTypes.Tree.HORN_CORAL, FractalTypes.Tree.BUBBLE_CORAL }; - + /** * Spawns an Azalea tree, complete with rooted dirt. */ - public static void spawnAzalea(@NotNull Random random, @NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) return; - - FractalTreeBuilder builder = new FractalTreeBuilder(FractalTypes.Tree.AZALEA_TOP); - builder.build(tw, data, x, y, z); - - SimpleBlock rooter = new SimpleBlock(data,x,y-1,z); - rooter.setType(Material.ROOTED_DIRT); - rooter = rooter.getDown(); - - while(!BlockUtils.isAir(rooter.getType())) { - rooter.setType(Material.ROOTED_DIRT); - for(BlockFace face:BlockUtils.xzPlaneBlockFaces) { - SimpleBlock rel = rooter.getRelative(face); - if(random.nextBoolean() && BlockUtils.isStoneLike(rel.getType())) { - rel.setType(Material.ROOTED_DIRT); - if(BlockUtils.isAir(rel.getDown().getType())) - rel.getDown().setType(Material.HANGING_ROOTS); - } - } - rooter = rooter.getDown(); - } - rooter.setType(Material.HANGING_ROOTS); + public static void spawnAzalea(@NotNull Random random, + @NotNull TerraformWorld tw, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + if (!TConfigOption.areTreesEnabled()) { + return; + } + + FractalTreeBuilder builder = new FractalTreeBuilder(FractalTypes.Tree.AZALEA_TOP); + builder.build(tw, data, x, y, z); + + SimpleBlock rooter = new SimpleBlock(data, x, y - 1, z); + rooter.setType(Material.ROOTED_DIRT); + rooter = rooter.getDown(); + + while (!BlockUtils.isAir(rooter.getType())) { + rooter.setType(Material.ROOTED_DIRT); + for (BlockFace face : BlockUtils.xzPlaneBlockFaces) { + SimpleBlock rel = rooter.getRelative(face); + if (random.nextBoolean() && BlockUtils.isStoneLike(rel.getType())) { + rel.setType(Material.ROOTED_DIRT); + if (BlockUtils.isAir(rel.getDown().getType())) { + rel.getDown().setType(Material.HANGING_ROOTS); + } + } + } + rooter = rooter.getDown(); + } + rooter.setType(Material.HANGING_ROOTS); } - public static void spawnCoconutTree(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) return; + public static void spawnCoconutTree(@NotNull TerraformWorld tw, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + if (!TConfigOption.areTreesEnabled()) { + return; + } SimpleBlock base = new SimpleBlock(data, x, y, z); FractalTreeBuilder builder = new FractalTreeBuilder(FractalTypes.Tree.COCONUT_TOP); - + // If gradient too steep, don't try spawning - if(!builder.checkGradient(data, x, z)) - return; - + if (!builder.checkGradient(data, x, z)) { + return; + } + // Spawn the base Material log = Material.JUNGLE_WOOD; - if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) log = Material.JUNGLE_LOG; + if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) { + log = Material.JUNGLE_LOG; + } for (BlockFace face : BlockUtils.directBlockFaces) { new Wall(base.getRelative(face), BlockFace.NORTH).downUntilSolid(new Random(), log); } builder.build(tw, data, x, y, z); } - public static void spawnSmallJungleTree(boolean skipGradientCheck, @NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) return; - - FractalTreeBuilder ftb; - if (GenUtils.chance(1, 8)) - ftb = new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_EXTRA_SMALL); - else - ftb = new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_SMALL); - - if(skipGradientCheck) ftb.skipGradientCheck(); - ftb.build(tw, data, x, y, z); + public static void spawnSmallJungleTree(boolean skipGradientCheck, + @NotNull TerraformWorld tw, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { + if (!TConfigOption.areTreesEnabled()) { + return; + } + + FractalTreeBuilder ftb; + if (GenUtils.chance(1, 8)) { + ftb = new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_EXTRA_SMALL); + } + else { + ftb = new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_SMALL); + } + + if (skipGradientCheck) { + ftb.skipGradientCheck(); + } + ftb.build(tw, data, x, y, z); } /** * Corals will always dig 2 blocks deeper first. * Grows a random giant coral (fire, tube, etc) */ - public static void spawnRandomGiantCoral(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { + public static void spawnRandomGiantCoral(@NotNull TerraformWorld tw, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z) + { FractalTypes.Tree type = FRACTAL_CORAL_TYPES[tw.getHashedRand(x, y, z).nextInt(5)]; FractalTreeBuilder ftb = new FractalTreeBuilder(type); ftb.setMaxHeight(TerraformGenerator.seaLevel - y - 1); // Max height is one below sea level @@ -100,17 +136,20 @@ public static void spawnRandomGiantCoral(@NotNull TerraformWorld tw, @NotNull Po *
    * Roots will extend at least a little above sea level */ - public static void spawnBreathingRoots(@NotNull TerraformWorld tw, @NotNull SimpleBlock centre, Material type){ - if (!TConfigOption.areTreesEnabled()) return; - - Random rand = tw.getHashedRand(centre.getX(),centre.getY(),centre.getZ(),178782); - for(int i = 0; i < 4+rand.nextInt(8); i++) - { - SimpleBlock core = centre.getRelative( - GenUtils.getSign(rand)*GenUtils.randInt(4,8),0, - GenUtils.getSign(rand)*GenUtils.randInt(4,8)).getGround().getUp(); - int min = core.getY() < TerraformGenerator.seaLevel ? - TerraformGenerator.seaLevel - core.getY() + 1 : 1; + public static void spawnBreathingRoots(@NotNull TerraformWorld tw, @NotNull SimpleBlock centre, Material type) { + if (!TConfigOption.areTreesEnabled()) { + return; + } + + Random rand = tw.getHashedRand(centre.getX(), centre.getY(), centre.getZ(), 178782); + for (int i = 0; i < 4 + rand.nextInt(8); i++) { + SimpleBlock core = centre.getRelative(GenUtils.getSign(rand) * GenUtils.randInt(4, 8), + 0, + GenUtils.getSign(rand) * GenUtils.randInt(4, 8) + ) + .getGround() + .getUp(); + int min = core.getY() < TerraformGenerator.seaLevel ? TerraformGenerator.seaLevel - core.getY() + 1 : 1; core.LPillar(min + rand.nextInt(4), type); } } diff --git a/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java b/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java index ee44f8c9..746776dc 100644 --- a/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java +++ b/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java @@ -1,40 +1,49 @@ package org.terraform.tree; -import java.io.FileNotFoundException; -import java.util.Random; - import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; import org.terraform.main.TerraformGeneratorPlugin; +import org.terraform.main.config.TConfigOption; import org.terraform.schematic.TerraSchematic; import org.terraform.utils.GenUtils; +import java.io.FileNotFoundException; +import java.util.Random; + public class VanillaMushroomBuilder { - // I hate supporting another plugin - - public static final String RED_MUSHROOM_CAP = "redmushroomcap"; - public static final String BROWN_MUSHROOM_CAP = "brownmushroomcap"; - - public static void buildVanillaMushroom(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z, String capSchematic) { - if ( !TConfigOption.areTallMushroomsEnabled()) return; - - Random rand = tw.getRand(16L * 16 * x + 16L * y + z); - - int height = GenUtils.randInt(rand, 5, 7); - - new Wall(new SimpleBlock(data,x,y,z)).Pillar(height, Material.MUSHROOM_STEM); - - try { - TerraSchematic capSchem = TerraSchematic.load(capSchematic, new SimpleBlock(data, x, y + height - 2, z)); - capSchem.apply(); - } catch (FileNotFoundException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - } + // I hate supporting another plugin + + public static final String RED_MUSHROOM_CAP = "redmushroomcap"; + public static final String BROWN_MUSHROOM_CAP = "brownmushroomcap"; + + public static void buildVanillaMushroom(@NotNull TerraformWorld tw, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + String capSchematic) + { + if (!TConfigOption.areTallMushroomsEnabled()) { + return; + } + + Random rand = tw.getRand(16L * 16 * x + 16L * y + z); + + int height = GenUtils.randInt(rand, 5, 7); + + new Wall(new SimpleBlock(data, x, y, z)).Pillar(height, Material.MUSHROOM_STEM); + + try { + TerraSchematic capSchem = TerraSchematic.load(capSchematic, new SimpleBlock(data, x, y + height - 2, z)); + capSchem.apply(); + } + catch (FileNotFoundException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + } } diff --git a/common/src/main/java/org/terraform/utils/ArmorStandUtils.java b/common/src/main/java/org/terraform/utils/ArmorStandUtils.java index e90c169d..f99b69a0 100644 --- a/common/src/main/java/org/terraform/utils/ArmorStandUtils.java +++ b/common/src/main/java/org/terraform/utils/ArmorStandUtils.java @@ -1,62 +1,82 @@ package org.terraform.utils; -import java.util.Random; - import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleBlock; +import java.util.Random; + public class ArmorStandUtils { - public static void placeArmorStand(@NotNull SimpleBlock target, @NotNull BlockFace facing, @NotNull Random rand) { - placeArmorStand(target, facing, ArmorStandQuality.rollQuality(rand)); - } - - public static void placeArmorStand(@NotNull SimpleBlock target, @NotNull BlockFace facing, @NotNull ArmorStandQuality quality) { - if(target.getPopData() instanceof PopulatorDataPostGen postGen) { - ArmorStand stand = (ArmorStand) postGen.getWorld().spawnEntity(new Location(postGen.getWorld(), - - target.getX() + 0.5f, target.getY(), target.getZ() + 0.5f), EntityType.ARMOR_STAND); - stand.setRotation(BlockUtils.yawFromBlockFace(facing), 0); - quality.apply(stand); - } - } - - public enum ArmorStandQuality - { - LEATHER(Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS), - IRON(Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS), - GOLD(Material.GOLDEN_HELMET, Material.GOLDEN_CHESTPLATE, Material.GOLDEN_LEGGINGS, Material.GOLDEN_BOOTS), - DIAMOND(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS); - private final Material[] pieces; - ArmorStandQuality(Material... pieces){ - this.pieces = pieces; - } - - public void apply(@NotNull ArmorStand entity) { - entity.getEquipment().setHelmet(new ItemStack(pieces[0])); - entity.getEquipment().setChestplate(new ItemStack(pieces[1])); - entity.getEquipment().setLeggings(new ItemStack(pieces[2])); - entity.getEquipment().setBoots(new ItemStack(pieces[3])); - } - - - public static @NotNull ArmorStandQuality rollQuality(@NotNull Random rand) { - int weight = rand.nextInt(100); - if(weight > 95) // 15% - return ArmorStandQuality.DIAMOND; - else if(weight > 60) // 35% - return ArmorStandQuality.IRON; - else if(weight > 30) // 30% - return ArmorStandQuality.GOLD; - else // 30% - return ArmorStandQuality.LEATHER; - } - } + public static void placeArmorStand(@NotNull SimpleBlock target, @NotNull BlockFace facing, @NotNull Random rand) { + placeArmorStand(target, facing, ArmorStandQuality.rollQuality(rand)); + } + + public static void placeArmorStand(@NotNull SimpleBlock target, + @NotNull BlockFace facing, + @NotNull ArmorStandQuality quality) + { + if (target.getPopData() instanceof PopulatorDataPostGen postGen) { + ArmorStand stand = (ArmorStand) postGen.getWorld().spawnEntity(new Location(postGen.getWorld(), + + target.getX() + 0.5f, target.getY(), target.getZ() + 0.5f + ), EntityType.ARMOR_STAND); + stand.setRotation(BlockUtils.yawFromBlockFace(facing), 0); + quality.apply(stand); + } + } + + public enum ArmorStandQuality { + LEATHER( + Material.LEATHER_HELMET, + Material.LEATHER_CHESTPLATE, + Material.LEATHER_LEGGINGS, + Material.LEATHER_BOOTS + ), + IRON(Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS), + GOLD(Material.GOLDEN_HELMET, Material.GOLDEN_CHESTPLATE, Material.GOLDEN_LEGGINGS, Material.GOLDEN_BOOTS), + DIAMOND(Material.DIAMOND_HELMET, + Material.DIAMOND_CHESTPLATE, + Material.DIAMOND_LEGGINGS, + Material.DIAMOND_BOOTS + ); + private final Material[] pieces; + + ArmorStandQuality(Material... pieces) { + this.pieces = pieces; + } + + public static @NotNull ArmorStandQuality rollQuality(@NotNull Random rand) { + int weight = rand.nextInt(100); + if (weight > 95) // 15% + { + return ArmorStandQuality.DIAMOND; + } + else if (weight > 60) // 35% + { + return ArmorStandQuality.IRON; + } + else if (weight > 30) // 30% + { + return ArmorStandQuality.GOLD; + } + else // 30% + { + return ArmorStandQuality.LEATHER; + } + } + + public void apply(@NotNull ArmorStand entity) { + entity.getEquipment().setHelmet(new ItemStack(pieces[0])); + entity.getEquipment().setChestplate(new ItemStack(pieces[1])); + entity.getEquipment().setLeggings(new ItemStack(pieces[2])); + entity.getEquipment().setBoots(new ItemStack(pieces[3])); + } + } } diff --git a/common/src/main/java/org/terraform/utils/BannerUtils.java b/common/src/main/java/org/terraform/utils/BannerUtils.java index 2ef12098..52d77c21 100644 --- a/common/src/main/java/org/terraform/utils/BannerUtils.java +++ b/common/src/main/java/org/terraform/utils/BannerUtils.java @@ -29,9 +29,9 @@ public class BannerUtils { PatternType.CURLY_BORDER, PatternType.DIAGONAL_LEFT, PatternType.DIAGONAL_RIGHT, -// PatternType.DIAGONAL_UP_LEFT, -// PatternType.DIAGONAL_UP_RIGHT, -// PatternType.FLOW, + // PatternType.DIAGONAL_UP_LEFT, + // PatternType.DIAGONAL_UP_RIGHT, + // PatternType.FLOW, PatternType.FLOWER, PatternType.GLOBE, PatternType.GRADIENT, @@ -78,7 +78,7 @@ public class BannerUtils { Material.BROWN_BANNER, Material.PINK_BANNER, Material.WHITE_BANNER, - }; + }; private static final Material[] WALL_BANNERS = { Material.RED_WALL_BANNER, Material.ORANGE_WALL_BANNER, @@ -93,75 +93,103 @@ public class BannerUtils { Material.BROWN_WALL_BANNER, Material.PINK_WALL_BANNER, Material.WHITE_WALL_BANNER, - }; - - public static void generateBanner(@NotNull SimpleBlock base, @NotNull BlockFace facing, @NotNull Material type, @Nullable ArrayList patterns) { + }; + + public static void generateBanner(@NotNull SimpleBlock base, + @NotNull BlockFace facing, + @NotNull Material type, + @Nullable ArrayList patterns) + { base.setType(type); Directional bd = ((Directional) base.getBlockData()); bd.setFacing(facing); base.setBlockData(bd); - - Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState(base.getX(), base.getY(), base.getZ()); - if(patterns == null) { + + Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState( + base.getX(), + base.getY(), + base.getZ() + ); + if (patterns == null) { patterns = new ArrayList<>(); } - + banner.setPatterns(patterns); banner.update(); } - - public static void generateBanner(@NotNull Random rand, @NotNull SimpleBlock base, @NotNull BlockFace facing, boolean wallBanner) { + + public static void generateBanner(@NotNull Random rand, + @NotNull SimpleBlock base, + @NotNull BlockFace facing, + boolean wallBanner) + { Material type = null; - if (wallBanner) + if (wallBanner) { type = BannerUtils.randomWallBannerMaterial(rand); - else + } + else { BannerUtils.randomBannerMaterial(rand); + } base.setType(type); if (!wallBanner) { Rotatable bd = ((Rotatable) base.getBlockData()); bd.setRotation(facing); base.setBlockData(bd); - } else { + } + else { Directional bd = ((Directional) base.getBlockData()); bd.setFacing(facing); base.setBlockData(bd); } - Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState(base.getX(), base.getY(), base.getZ()); + Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState( + base.getX(), + base.getY(), + base.getZ() + ); ArrayList patterns = new ArrayList<>(); for (int i = 1 + rand.nextInt(3); i < 4 + rand.nextInt(3); i++) { - patterns.add(new Pattern( - DyeColor.values()[rand.nextInt(DyeColor.values().length)], + patterns.add(new Pattern(DyeColor.values()[rand.nextInt(DyeColor.values().length)], PATTERNS[rand.nextInt(PATTERNS.length)] )); } banner.setPatterns(patterns); banner.update(); } - - public static void generatePillagerBanner(@NotNull SimpleBlock base, @NotNull BlockFace facing, boolean wallBanner) { + + public static void generatePillagerBanner(@NotNull SimpleBlock base, + @NotNull BlockFace facing, + boolean wallBanner) + { Material type; - if (wallBanner) + if (wallBanner) { type = Material.WHITE_WALL_BANNER; - else + } + else { type = Material.WHITE_BANNER; + } base.setType(type); if (!wallBanner) { Rotatable bd = ((Rotatable) base.getBlockData()); bd.setRotation(facing); base.setBlockData(bd); - } else { + } + else { Directional bd = ((Directional) base.getBlockData()); bd.setFacing(facing); base.setBlockData(bd); } - Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState(base.getX(), base.getY(), base.getZ()); - + Banner banner = (Banner) ((PopulatorDataPostGen) base.getPopData()).getBlockState( + base.getX(), + base.getY(), + base.getZ() + ); + banner.setPatterns(getOminousBannerPatterns()); banner.update(); } @@ -175,28 +203,28 @@ public static void randomBannerMaterial(@NotNull Random rand) { return WALL_BANNERS[rand.nextInt(WALL_BANNERS.length)]; } - /** + /** * kms * ... - Pattern:"mr",Color:CYAN - Pattern:"bs",Color:LIGHT_GRAY - Pattern:"cs",Color:GRAY - Pattern:"bo",Color:LIGHT_GRAY - Pattern:"ms",Color:BLACK - Pattern:"hh",Color:LIGHT_GRAY - Pattern:"mc",Color:LIGHT_GRAY - Pattern:"bo",Color:BLACK + * Pattern:"mr",Color:CYAN + * Pattern:"bs",Color:LIGHT_GRAY + * Pattern:"cs",Color:GRAY + * Pattern:"bo",Color:LIGHT_GRAY + * Pattern:"ms",Color:BLACK + * Pattern:"hh",Color:LIGHT_GRAY + * Pattern:"mc",Color:LIGHT_GRAY + * Pattern:"bo",Color:BLACK */ - public static @NotNull ArrayList getOminousBannerPatterns(){ - return new ArrayList<>() {{ - add(new Pattern(DyeColor.CYAN, OneTwentyFiveBlockHandler.RHOMBUS)); - add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.STRIPE_BOTTOM)); - add(new Pattern(DyeColor.GRAY, PatternType.STRIPE_CENTER)); - add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.BORDER)); - add(new Pattern(DyeColor.BLACK, PatternType.STRIPE_MIDDLE)); - add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.HALF_HORIZONTAL)); - add(new Pattern(DyeColor.LIGHT_GRAY, OneTwentyFiveBlockHandler.CIRCLE)); // - add(new Pattern(DyeColor.BLACK, PatternType.BORDER)); - }}; + public static @NotNull ArrayList getOminousBannerPatterns() { + return new ArrayList<>() {{ + add(new Pattern(DyeColor.CYAN, OneTwentyFiveBlockHandler.RHOMBUS)); + add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.STRIPE_BOTTOM)); + add(new Pattern(DyeColor.GRAY, PatternType.STRIPE_CENTER)); + add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.BORDER)); + add(new Pattern(DyeColor.BLACK, PatternType.STRIPE_MIDDLE)); + add(new Pattern(DyeColor.LIGHT_GRAY, PatternType.HALF_HORIZONTAL)); + add(new Pattern(DyeColor.LIGHT_GRAY, OneTwentyFiveBlockHandler.CIRCLE)); // + add(new Pattern(DyeColor.BLACK, PatternType.BORDER)); + }}; } } diff --git a/common/src/main/java/org/terraform/utils/BiomePainter.java b/common/src/main/java/org/terraform/utils/BiomePainter.java index 2b6965ef..71fc0564 100644 --- a/common/src/main/java/org/terraform/utils/BiomePainter.java +++ b/common/src/main/java/org/terraform/utils/BiomePainter.java @@ -21,7 +21,9 @@ public class BiomePainter extends JFrame { public BiomePainter() { super("Biome test"); // You can set the content pane of the frame to your custom class. - if(seed == 0) seed = new Random().nextInt(269286925); + if (seed == 0) { + seed = new Random().nextInt(269286925); + } setContentPane(new DrawPane()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(windowWidth, windowWidth); @@ -51,12 +53,12 @@ public DrawPane() { void draw(@NotNull Graphics g) { TerraformWorld world = TerraformWorld.get("world", seed); - for(int x = 0; x < windowWidth; x++) { - for(int z = 0; z < windowWidth; z++) { + for (int x = 0; x < windowWidth; x++) { + for (int z = 0; z < windowWidth; z++) { int realX = (int) Math.round((x / (double) windowWidth) * (double) inGameWidth + offsets); int realZ = (int) Math.round((z / (double) windowWidth) * (double) inGameWidth + offsets); BiomeBank biome = world.getBiomeBank(realX, realZ); - switch(biome) { + switch (biome) { case PLAINS: g.setColor(new Color(100, 150, 100)); break; @@ -95,11 +97,21 @@ void draw(@NotNull Graphics g) { break; } - if(biome.name().contains("OCEAN")) g.setColor(Color.blue); - else if(biome.name().contains("MOUNTAIN")) g.setColor(Color.gray); - else if(biome.name().contains("BEACH")) g.setColor(Color.yellow); - else if(biome.name().contains("ICY") || biome.name().contains("SNOWY")) g.setColor(Color.white); - else if(biome.name().contains("RIVER")) g.setColor(Color.blue); + if (biome.name().contains("OCEAN")) { + g.setColor(Color.blue); + } + else if (biome.name().contains("MOUNTAIN")) { + g.setColor(Color.gray); + } + else if (biome.name().contains("BEACH")) { + g.setColor(Color.yellow); + } + else if (biome.name().contains("ICY") || biome.name().contains("SNOWY")) { + g.setColor(Color.white); + } + else if (biome.name().contains("RIVER")) { + g.setColor(Color.blue); + } g.drawRect(x, z, 1, 1); } diff --git a/common/src/main/java/org/terraform/utils/BlockUtils.java b/common/src/main/java/org/terraform/utils/BlockUtils.java index 0b17f741..5f8ce8dc 100644 --- a/common/src/main/java/org/terraform/utils/BlockUtils.java +++ b/common/src/main/java/org/terraform/utils/BlockUtils.java @@ -1,28 +1,12 @@ package org.terraform.utils; -import org.bukkit.Axis; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.Tag; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.*; import org.bukkit.block.data.Bisected.Half; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Directional; -import org.bukkit.block.data.MultipleFacing; -import org.bukkit.block.data.Rail; import org.bukkit.block.data.Rail.Shape; -import org.bukkit.block.data.Rotatable; -import org.bukkit.block.data.Waterlogged; -import org.bukkit.block.data.type.Bed; -import org.bukkit.block.data.type.Candle; -import org.bukkit.block.data.type.CaveVinesPlant; -import org.bukkit.block.data.type.Door; -import org.bukkit.block.data.type.Leaves; -import org.bukkit.block.data.type.PointedDripstone; -import org.bukkit.block.data.type.Stairs; +import org.bukkit.block.data.type.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.coregen.bukkit.TerraformGenerator; @@ -47,33 +31,10 @@ import java.util.Set; public class BlockUtils { - - public static void initBlockUtils() { - // init ores - for(Material mat:Material.values()) { - if(mat.toString().endsWith("_ORE")) - { - if(!mat.toString().contains("NETHER")) - ores.add(mat); - stoneLike.add(mat); - } - } - - badlandsStoneLike.addAll(stoneLike); - caveCarveReplace.addAll(badlandsStoneLike); - caveCarveReplace.addAll(caveDecoratorMaterials); - - // init glass panes - for(Material mat:Material.values()) { - if(mat.toString().endsWith("_GLASS_PANE")) - glassPanes.add(mat); - } - } // This is needed as REPLACABLE_BY_TREES is a 1.20 tag. // Also this has mushrooms and saplings, snow and coral fans - public static final EnumSet replacableByTrees = EnumSet.of( - Material.ACACIA_SAPLING, + public static final EnumSet replacableByTrees = EnumSet.of(Material.ACACIA_SAPLING, Material.DARK_OAK_SAPLING, Material.BIRCH_SAPLING, Material.SPRUCE_SAPLING, @@ -134,59 +95,87 @@ public static void initBlockUtils() { Material.DEAD_HORN_CORAL_WALL_FAN, Material.DEAD_TUBE_CORAL_WALL_FAN ); - // N // W E // S public static final BlockFace[] xzPlaneBlockFaces = new BlockFace[] { - BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST + BlockFace.NORTH, + BlockFace.NORTH_EAST, + BlockFace.EAST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH, + BlockFace.SOUTH_WEST, + BlockFace.WEST, + BlockFace.NORTH_WEST }; - public static final EnumSet fluids = EnumSet.of(Material.WATER, Material.LAVA); - public static final EnumSet wetMaterials = EnumSet.of( - Material.WATER, - Material.KELP_PLANT, - Material.SEAGRASS, - Material.TALL_SEAGRASS + public static final EnumSet wetMaterials = EnumSet.of(Material.WATER, + Material.KELP_PLANT, + Material.SEAGRASS, + Material.TALL_SEAGRASS ); - - public static final EnumSet amethysts = EnumSet.of( - Material.AMETHYST_BLOCK, + public static final EnumSet amethysts = EnumSet.of(Material.AMETHYST_BLOCK, Material.AMETHYST_CLUSTER, Material.BUDDING_AMETHYST, Material.LARGE_AMETHYST_BUD, Material.MEDIUM_AMETHYST_BUD, Material.SMALL_AMETHYST_BUD ); - public static final BlockFace[] flatBlockFaces3x3 = { - BlockFace.SELF, BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST + BlockFace.SELF, + BlockFace.NORTH, + BlockFace.NORTH_EAST, + BlockFace.EAST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH, + BlockFace.SOUTH_WEST, + BlockFace.WEST, + BlockFace.NORTH_WEST }; - public static final BlockFace[] BLOCK_FACES = BlockFace.values(); - public static final BlockFace[] xzDiagonalPlaneBlockFaces = {BlockFace.NORTH_EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST, BlockFace.NORTH_WEST}; - public static final Material[] stoneBricks = {Material.STONE_BRICKS, Material.MOSSY_STONE_BRICKS, Material.CRACKED_STONE_BRICKS}; + public static final BlockFace[] xzDiagonalPlaneBlockFaces = { + BlockFace.NORTH_EAST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH_WEST, + BlockFace.NORTH_WEST + }; + public static final Material[] stoneBricks = { + Material.STONE_BRICKS, + Material.MOSSY_STONE_BRICKS, + Material.CRACKED_STONE_BRICKS + }; public static final Material[] stoneBrickSlabs = {Material.STONE_BRICK_SLAB, Material.MOSSY_STONE_BRICK_SLAB}; - public static final BlockFace[] directBlockFaces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}; - + public static final BlockFace[] directBlockFaces = { + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST + }; public static final BlockFace[][] cornerBlockFaces = { {BlockFace.NORTH, BlockFace.EAST}, {BlockFace.NORTH, BlockFace.WEST}, {BlockFace.SOUTH, BlockFace.EAST}, {BlockFace.SOUTH, BlockFace.WEST}, + }; + public static final BlockFace[] sixBlockFaces = { + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.UP, + BlockFace.DOWN }; - - public static final BlockFace[] sixBlockFaces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}; - /** * Everything here must be solid blocks that tend to generate * in the ground. */ - public static final EnumSet stoneLike = EnumSet.of( - Material.STONE, Material.COBBLESTONE, + public static final EnumSet stoneLike = EnumSet.of(Material.STONE, + Material.COBBLESTONE, Material.MOSSY_COBBLESTONE, - Material.GRANITE, Material.ANDESITE, - Material.DIORITE, Material.GRAVEL, + Material.GRANITE, + Material.ANDESITE, + Material.DIORITE, + Material.GRAVEL, Material.CLAY, Material.DEEPSLATE, Material.TUFF, @@ -195,18 +184,25 @@ public static void initBlockUtils() { Material.AMETHYST_BLOCK, Material.DRIPSTONE_BLOCK, Material.SMOOTH_BASALT, - Material.PACKED_ICE, Material.BLUE_ICE, - Material.DIRT, Material.PODZOL, Material.GRASS_BLOCK, Material.MYCELIUM, - Material.ROOTED_DIRT, Material.DIRT_PATH, + Material.PACKED_ICE, + Material.BLUE_ICE, + Material.DIRT, + Material.PODZOL, + Material.GRASS_BLOCK, + Material.MYCELIUM, + Material.ROOTED_DIRT, + Material.DIRT_PATH, OneOneNineBlockHandler.SCULK ); - - public static final EnumSet caveDecoratorMaterials = EnumSet.of( - Material.ANDESITE_WALL, Material.DIORITE_WALL, Material.GRANITE_WALL, - Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL, + public static final EnumSet caveDecoratorMaterials = EnumSet.of(Material.ANDESITE_WALL, + Material.DIORITE_WALL, + Material.GRANITE_WALL, + Material.COBBLESTONE_WALL, + Material.MOSSY_COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_SLAB, Material.COBBLED_DEEPSLATE_WALL, - Material.COBBLESTONE_SLAB, Material.STONE_SLAB, + Material.COBBLESTONE_SLAB, + Material.STONE_SLAB, Material.COBBLED_DEEPSLATE_SLAB, Material.MOSS_BLOCK, Material.MOSS_CARPET, @@ -218,8 +214,10 @@ public static void initBlockUtils() { Material.FLOWERING_AZALEA, Material.BIG_DRIPLEAF, Material.BIG_DRIPLEAF_STEM, - Material.GRASS, Material.TALL_GRASS, - Material.ICE, Material.PACKED_ICE, + Material.GRASS, + Material.TALL_GRASS, + Material.ICE, + Material.PACKED_ICE, Material.DRIPSTONE_BLOCK, Material.POINTED_DRIPSTONE, Material.AMETHYST_CLUSTER, @@ -231,27 +229,84 @@ public static void initBlockUtils() { Material.SPAWNER, Material.BROWN_MUSHROOM_BLOCK, Material.RED_MUSHROOM_BLOCK - ); - + ); // This enumset gets populated more in initBlockUtils - public static final EnumSet badlandsStoneLike = EnumSet.of( - Material.TERRACOTTA, Material.ORANGE_TERRACOTTA, - Material.RED_TERRACOTTA, Material.BROWN_TERRACOTTA, - Material.YELLOW_TERRACOTTA, Material.RED_SAND + public static final EnumSet badlandsStoneLike = EnumSet.of(Material.TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.RED_TERRACOTTA, + Material.BROWN_TERRACOTTA, + Material.YELLOW_TERRACOTTA, + Material.RED_SAND ); - public static final EnumSet caveCarveReplace = EnumSet.of(Material.NOTE_BLOCK); - // This enumset gets populated more in initBlockUtils public static final EnumSet ores = EnumSet.noneOf(Material.class); - public static final EnumSet airs = EnumSet.of(Material.AIR, Material.CAVE_AIR); - // This enumset gets populated more in initBlockUtils public static final EnumSet glassPanes = EnumSet.noneOf(Material.class); - - private static final PlantBuilder[] TALL_FLOWER = {PlantBuilder.LILAC, PlantBuilder.ROSE_BUSH, PlantBuilder.PEONY, PlantBuilder.LARGE_FERN, PlantBuilder.SUNFLOWER}; - private static final PlantBuilder[] FLOWER = {PlantBuilder.DANDELION, + public static final Material[] WOOLS = { + Material.WHITE_WOOL, + Material.BLACK_WOOL, + Material.BLUE_WOOL, + Material.BROWN_WOOL, + Material.CYAN_WOOL, + Material.GRAY_WOOL, + Material.GREEN_WOOL, + Material.LIGHT_BLUE_WOOL, + Material.LIGHT_GRAY_WOOL, + Material.LIME_WOOL, + Material.MAGENTA_WOOL, + Material.ORANGE_WOOL, + Material.PINK_WOOL, + Material.PURPLE_WOOL, + Material.RED_WOOL, + Material.YELLOW_WOOL + }; + public static final Material[] GLAZED_TERRACOTTA = { + Material.WHITE_GLAZED_TERRACOTTA, + Material.BLACK_GLAZED_TERRACOTTA, + Material.BLUE_GLAZED_TERRACOTTA, + Material.BROWN_GLAZED_TERRACOTTA, + Material.CYAN_GLAZED_TERRACOTTA, + Material.GRAY_GLAZED_TERRACOTTA, + Material.GREEN_GLAZED_TERRACOTTA, + Material.LIGHT_BLUE_GLAZED_TERRACOTTA, + Material.LIGHT_GRAY_GLAZED_TERRACOTTA, + Material.LIME_GLAZED_TERRACOTTA, + Material.MAGENTA_GLAZED_TERRACOTTA, + Material.ORANGE_GLAZED_TERRACOTTA, + Material.PINK_GLAZED_TERRACOTTA, + Material.PURPLE_GLAZED_TERRACOTTA, + Material.RED_GLAZED_TERRACOTTA, + Material.YELLOW_GLAZED_TERRACOTTA + }; + public static final Material[] TERRACOTTA = { + Material.WHITE_TERRACOTTA, + Material.BLACK_TERRACOTTA, + Material.BLUE_TERRACOTTA, + Material.BROWN_TERRACOTTA, + Material.CYAN_TERRACOTTA, + Material.GRAY_TERRACOTTA, + Material.GREEN_TERRACOTTA, + Material.LIGHT_BLUE_TERRACOTTA, + Material.LIGHT_GRAY_TERRACOTTA, + Material.LIME_TERRACOTTA, + Material.MAGENTA_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.PINK_TERRACOTTA, + Material.PURPLE_TERRACOTTA, + Material.RED_TERRACOTTA, + Material.YELLOW_TERRACOTTA + }; + private static final PlantBuilder[] TALL_FLOWER = { + PlantBuilder.LILAC, + PlantBuilder.ROSE_BUSH, + PlantBuilder.PEONY, + PlantBuilder.LARGE_FERN, + PlantBuilder.SUNFLOWER + }; + private static final PlantBuilder[] FLOWER = { + PlantBuilder.DANDELION, PlantBuilder.POPPY, PlantBuilder.WHITE_TULIP, PlantBuilder.ORANGE_TULIP, @@ -263,8 +318,7 @@ public static void initBlockUtils() { PlantBuilder.OXEYE_DAISY, PlantBuilder.CORNFLOWER, PlantBuilder.LILY_OF_THE_VALLEY, - }; - + }; private static final PlantBuilder[] POTTED = { PlantBuilder.POTTED_DANDELION, PlantBuilder.POTTED_POPPY, @@ -278,8 +332,7 @@ public static void initBlockUtils() { PlantBuilder.POTTED_OXEYE_DAISY, PlantBuilder.POTTED_CORNFLOWER, PlantBuilder.POTTED_LILY_OF_THE_VALLEY, - }; - + }; private static final Material[] CARPETS = { Material.WHITE_CARPET, Material.BLACK_CARPET, @@ -298,26 +351,6 @@ public static void initBlockUtils() { Material.RED_CARPET, Material.YELLOW_CARPET }; - - public static final Material[] WOOLS = { - Material.WHITE_WOOL, - Material.BLACK_WOOL, - Material.BLUE_WOOL, - Material.BROWN_WOOL, - Material.CYAN_WOOL, - Material.GRAY_WOOL, - Material.GREEN_WOOL, - Material.LIGHT_BLUE_WOOL, - Material.LIGHT_GRAY_WOOL, - Material.LIME_WOOL, - Material.MAGENTA_WOOL, - Material.ORANGE_WOOL, - Material.PINK_WOOL, - Material.PURPLE_WOOL, - Material.RED_WOOL, - Material.YELLOW_WOOL - }; - private static final Material[] BED = { Material.WHITE_BED, Material.BLACK_BED, @@ -336,47 +369,33 @@ public static void initBlockUtils() { Material.RED_BED, Material.YELLOW_BED }; + private static final HashMap deepslateMap = new HashMap<>(); - public static final Material[] GLAZED_TERRACOTTA = { - Material.WHITE_GLAZED_TERRACOTTA, - Material.BLACK_GLAZED_TERRACOTTA, - Material.BLUE_GLAZED_TERRACOTTA, - Material.BROWN_GLAZED_TERRACOTTA, - Material.CYAN_GLAZED_TERRACOTTA, - Material.GRAY_GLAZED_TERRACOTTA, - Material.GREEN_GLAZED_TERRACOTTA, - Material.LIGHT_BLUE_GLAZED_TERRACOTTA, - Material.LIGHT_GRAY_GLAZED_TERRACOTTA, - Material.LIME_GLAZED_TERRACOTTA, - Material.MAGENTA_GLAZED_TERRACOTTA, - Material.ORANGE_GLAZED_TERRACOTTA, - Material.PINK_GLAZED_TERRACOTTA, - Material.PURPLE_GLAZED_TERRACOTTA, - Material.RED_GLAZED_TERRACOTTA, - Material.YELLOW_GLAZED_TERRACOTTA - }; + public static void initBlockUtils() { + // init ores + for (Material mat : Material.values()) { + if (mat.toString().endsWith("_ORE")) { + if (!mat.toString().contains("NETHER")) { + ores.add(mat); + } + stoneLike.add(mat); + } + } - public static final Material[] TERRACOTTA = { - Material.WHITE_TERRACOTTA, - Material.BLACK_TERRACOTTA, - Material.BLUE_TERRACOTTA, - Material.BROWN_TERRACOTTA, - Material.CYAN_TERRACOTTA, - Material.GRAY_TERRACOTTA, - Material.GREEN_TERRACOTTA, - Material.LIGHT_BLUE_TERRACOTTA, - Material.LIGHT_GRAY_TERRACOTTA, - Material.LIME_TERRACOTTA, - Material.MAGENTA_TERRACOTTA, - Material.ORANGE_TERRACOTTA, - Material.PINK_TERRACOTTA, - Material.PURPLE_TERRACOTTA, - Material.RED_TERRACOTTA, - Material.YELLOW_TERRACOTTA - }; + badlandsStoneLike.addAll(stoneLike); + caveCarveReplace.addAll(badlandsStoneLike); + caveCarveReplace.addAll(caveDecoratorMaterials); + + // init glass panes + for (Material mat : Material.values()) { + if (mat.toString().endsWith("_GLASS_PANE")) { + glassPanes.add(mat); + } + } + } public static boolean isDirectBlockFace(@NotNull BlockFace facing) { - return switch(facing) { + return switch (facing) { case NORTH, SOUTH, EAST, WEST -> true; default -> false; }; @@ -405,16 +424,16 @@ public static boolean isDirectBlockFace(@NotNull BlockFace facing) { } return original; } - + /** * @return rotates original block face (XZ plane only) clockwise the specified number of times */ @SuppressWarnings("incomplete-switch") public static @NotNull BlockFace rotateXZPlaneBlockFace(@NotNull BlockFace original, int times) { // N - // W + E - // S - for (int i = 0; i < times; i++) { + // W + E + // S + for (int i = 0; i < times; i++) { switch (original) { case NORTH: original = BlockFace.NORTH_EAST; @@ -444,16 +463,16 @@ public static boolean isDirectBlockFace(@NotNull BlockFace facing) { } return original; } - + /** * @return rotates original block face (XZ plane only) clockwise the specified number of times */ @SuppressWarnings("incomplete-switch") public static @NotNull BlockFace rotateXZPlaneBlockFaceOppositeAngle(@NotNull BlockFace original, int times) { // N - // W + E - // S - for (int i = 0; i < times; i++) { + // W + E + // S + for (int i = 0; i < times; i++) { switch (original) { case NORTH: original = BlockFace.NORTH_EAST; @@ -483,12 +502,14 @@ public static boolean isDirectBlockFace(@NotNull BlockFace facing) { } return original; } - + public static BlockFace @NotNull [] getRandomBlockfaceAxis(@NotNull Random rand) { - if(rand.nextInt(2) == 0) - return new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}; - else - return new BlockFace[] {BlockFace.WEST, BlockFace.EAST}; + if (rand.nextInt(2) == 0) { + return new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH}; + } + else { + return new BlockFace[] {BlockFace.WEST, BlockFace.EAST}; + } } public static Material stoneBrick(@NotNull Random rand) { @@ -502,9 +523,9 @@ public static Material stoneBrickSlab(@NotNull Random rand) { public static BlockFace getXZPlaneBlockFace(@NotNull Random rand) { return xzPlaneBlockFaces[rand.nextInt(8)]; } - + public static @Nullable BlockFace getBlockFaceFromAxis(@NotNull Axis ax) { - return switch(ax) { + return switch (ax) { case X -> BlockFace.EAST; case Z -> BlockFace.SOUTH; case Y -> BlockFace.UP; @@ -512,16 +533,16 @@ public static BlockFace getXZPlaneBlockFace(@NotNull Random rand) { } public static @NotNull Axis getAxisFromBlockFace(@NotNull BlockFace face) { - return switch(face) { + return switch (face) { case NORTH, SOUTH -> Axis.Z; case EAST, WEST -> Axis.X; case UP, DOWN -> Axis.Y; default -> throw new IllegalArgumentException("Invalid block facing for axis: " + face); }; } - + public static @NotNull Axis getPerpendicularHorizontalPlaneAxis(@NotNull Axis x) { - return switch(x) { + return switch (x) { case X -> Axis.Z; case Z -> Axis.X; default -> x; @@ -532,14 +553,15 @@ public static BlockFace getXZPlaneBlockFace(@NotNull Random rand) { public static BlockFace getDirectBlockFace(@NotNull Random rand) { return directBlockFaces[rand.nextInt(4)]; } - + public static BlockFace getSixBlockFace(@NotNull Random rand) { - return sixBlockFaces[rand.nextInt(6)]; + return sixBlockFaces[rand.nextInt(6)]; } public static Material pickCarpet() { return GenUtils.randChoice(CARPETS); } + public static Material pickWool() { return GenUtils.randChoice(WOOLS); } @@ -563,6 +585,7 @@ public static PlantBuilder pickTallFlower() { public static void dropDownBlock(@NotNull SimpleBlock block) { dropDownBlock(block, Material.CAVE_AIR); } + public static void dropDownBlock(@NotNull SimpleBlock block, @NotNull Material fluid) { if (block.isSolid()) { Material type = block.getType(); @@ -571,13 +594,20 @@ public static void dropDownBlock(@NotNull SimpleBlock block, @NotNull Material f while (!block.isSolid()) { block = block.getDown(); depth++; - if (depth > 50) return; + if (depth > 50) { + return; + } } block.getUp().setType(type); } } - public static void horizontalGlazedTerracotta(@NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull Material glazedTerracotta) { + public static void horizontalGlazedTerracotta(@NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull Material glazedTerracotta) + { Directional terracotta = (Directional) Bukkit.createBlockData(glazedTerracotta); terracotta.setFacing(BlockFace.NORTH); data.setBlockData(x, y, z, terracotta); @@ -596,14 +626,18 @@ public static void horizontalGlazedTerracotta(@NotNull PopulatorDataAbstract dat } public static void setVines(@NotNull PopulatorDataAbstract data, int x, int y, int z, int maxLength) { - if ( !TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } SimpleBlock rel = new SimpleBlock(data, x, y, z); for (BlockFace face : directBlockFaces) { MultipleFacing dir = (MultipleFacing) Bukkit.createBlockData(Material.VINE); dir.setFace(face.getOppositeFace(), true); SimpleBlock vine = rel.getRelative(face); - if (vine.isSolid()) continue; + if (vine.isSolid()) { + continue; + } vine.setType(Material.VINE); vine.setBlockData(dir); @@ -625,7 +659,13 @@ public static void setDownUntilSolid(int x, int y, int z, @NotNull PopulatorData } } - public static void downPillar(int x, int y, int z, int height, @NotNull PopulatorDataAbstract data, Material... type) { + public static void downPillar(int x, + int y, + int z, + int height, + @NotNull PopulatorDataAbstract data, + Material... type) + { while (!data.getType(x, y, z).isSolid() && height > TerraformGeneratorPlugin.injector.getMinY()) { data.setType(x, y, z, GenUtils.randChoice(type)); height--; @@ -638,21 +678,29 @@ public static boolean isStoneLike(@NotNull Material mat) { } public static boolean isDirtLike(@NotNull Material mat) { - return switch(mat) { + return switch (mat) { case DIRT, GRASS_BLOCK, PODZOL, COARSE_DIRT, MYCELIUM -> true; - default -> mat == Material.DIRT_PATH || - mat == Material.ROOTED_DIRT; + default -> mat == Material.DIRT_PATH || mat == Material.ROOTED_DIRT; }; } public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if ( !TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } setPersistentLeaves(data, x, y, z, Material.OAK_LEAVES); } - public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull Material type) { - if ( !TConfigOption.arePlantsEnabled()) return; + public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull Material type) + { + if (!TConfigOption.arePlantsEnabled()) { + return; + } data.setType(x, y, z, Material.OAK_LEAVES); Leaves bd = (Leaves) Bukkit.createBlockData(type); @@ -660,8 +708,15 @@ public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, int data.setBlockData(x, y, z, bd); } - public static void setDoublePlant(@NotNull PopulatorDataAbstract data, int x, int y, int z, @NotNull Material doublePlant) { - if ( !TConfigOption.arePlantsEnabled()) return; + public static void setDoublePlant(@NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + @NotNull Material doublePlant) + { + if (!TConfigOption.arePlantsEnabled()) { + return; + } Bisected d = ((Bisected) Bukkit.createBlockData(doublePlant)); d.setHalf(Half.BOTTOM); @@ -681,7 +736,9 @@ public static boolean areAdjacentChunksLoaded(@NotNull Chunk middle) { for (int nz = -1; nz <= 1; nz++) { int x = middle.getX() + nx; int z = middle.getZ() + nz; - if (!middle.getWorld().isChunkLoaded(x, z)) return false; + if (!middle.getWorld().isChunkLoaded(x, z)) { + return false; + } } } return true; @@ -690,132 +747,192 @@ public static boolean areAdjacentChunksLoaded(@NotNull Chunk middle) { public static @NotNull Material getTerracotta(int height) { int mapped = (height + 10) % 17; - if (mapped == 2 || mapped == 9 || mapped == 13 || mapped == 16) return Material.TERRACOTTA; - if (mapped == 4 || mapped == 5 || mapped == 12 || mapped == 15) return Material.RED_TERRACOTTA; - if (mapped == 6) return Material.YELLOW_TERRACOTTA; - if (mapped == 8) return Material.BROWN_TERRACOTTA; + if (mapped == 2 || mapped == 9 || mapped == 13 || mapped == 16) { + return Material.TERRACOTTA; + } + if (mapped == 4 || mapped == 5 || mapped == 12 || mapped == 15) { + return Material.RED_TERRACOTTA; + } + if (mapped == 6) { + return Material.YELLOW_TERRACOTTA; + } + if (mapped == 8) { + return Material.BROWN_TERRACOTTA; + } return Material.ORANGE_TERRACOTTA; } - public static int spawnPillar(@NotNull Random rand, @NotNull PopulatorDataAbstract data, int x, int y, int z, Material type, int minHeight, int maxHeight) { + public static int spawnPillar(@NotNull Random rand, + @NotNull PopulatorDataAbstract data, + int x, + int y, + int z, + Material type, + int minHeight, + int maxHeight) + { // TODO: PlantBuilder int height = GenUtils.randInt(rand, minHeight, maxHeight); - for (int i = 0; i < height; i++) data.setType(x, y + i, z, type); + for (int i = 0; i < height; i++) { + data.setType(x, y + i, z, type); + } return height; } - public static void generateClayDeposit(int x, int y, int z, @NotNull PopulatorDataAbstract data, @NotNull Random random) { + public static void generateClayDeposit(int x, + int y, + int z, + @NotNull PopulatorDataAbstract data, + @NotNull Random random) + { // CLAY DEPOSIT - replaceCircularPatch(random.nextInt(9999), TConfigOption.BIOME_CLAY_DEPOSIT_SIZE.getFloat(), new SimpleBlock(data,x,y,z), Material.CLAY); + replaceCircularPatch( + random.nextInt(9999), + TConfigOption.BIOME_CLAY_DEPOSIT_SIZE.getFloat(), + new SimpleBlock(data, x, y, z), + Material.CLAY + ); } public static void vineUp(@NotNull SimpleBlock base, int maxLength) { - if (!TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } for (BlockFace face : directBlockFaces) { MultipleFacing dir = (MultipleFacing) Bukkit.createBlockData(Material.VINE); dir.setFace(face.getOppositeFace(), true); SimpleBlock vine = base.getRelative(face); - if (vine.isSolid()) continue; + if (vine.isSolid()) { + continue; + } vine.setType(Material.VINE); vine.setBlockData(dir); for (int i = 1; i < GenUtils.randInt(1, maxLength); i++) { SimpleBlock relative = vine.getRelative(0, -i, 0); - if (relative.getType() != Material.AIR) break; + if (relative.getType() != Material.AIR) { + break; + } relative.setType(Material.VINE); relative.setBlockData(dir); } } } - + /** * Places a noise-fuzzed circle of the defined material */ public static void replaceCircle(int seed, float radius, @NotNull SimpleBlock base, Material... type) { - if (radius <= 0) return; + if (radius <= 0) { + return; + } if (radius <= 0.5) { // block.setReplaceType(ReplaceType.ALL); base.setType(GenUtils.randChoice(new Random(seed), type)); return; } - + FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); - + for (float x = -radius; x <= radius; x++) { for (float z = -radius; z <= radius; z++) { SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); - + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ rel.lsetType(GenUtils.randChoice(type)); } } } - + } - + public static void replaceCircularPatch(int seed, float radius, @NotNull SimpleBlock base, Material... type) { - replaceCircularPatch(seed,radius,base,false,type); + replaceCircularPatch(seed, radius, base, false, type); } /** * Replaces the highest ground with a noise-fuzzed circle of the defined material */ - public static void replaceCircularPatch(int seed, float radius, @NotNull SimpleBlock base, boolean snowy, Material... type) { - if (radius <= 0) return; + public static void replaceCircularPatch(int seed, + float radius, + @NotNull SimpleBlock base, + boolean snowy, + Material... type) + { + if (radius <= 0) { + return; + } if (radius <= 0.5) { // block.setReplaceType(ReplaceType.ALL); base.setType(GenUtils.randChoice(new Random(seed), type)); return; } - + FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); - + for (float x = -radius; x <= radius; x++) { for (float z = -radius; z <= radius; z++) { SimpleBlock rel = base.getRelative(Math.round(x), 0, Math.round(z)); rel = rel.getGround(); - + // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); - double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); + double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) + Math.pow(z, 2) / Math.pow(radius, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ rel.setType(GenUtils.randChoice(type)); - if(snowy && rel.getUp().isAir()) - rel.getUp().setType(Material.SNOW); + if (snowy && rel.getUp().isAir()) { + rel.getUp().setType(Material.SNOW); + } } } } - + } - - public static void replaceSphere(int seed, float radius, @NotNull SimpleBlock base, boolean hardReplace, Material... type) { - if (radius > 0) replaceSphere(seed, radius, radius, radius, base, hardReplace, type); + + public static void replaceSphere(int seed, + float radius, + @NotNull SimpleBlock base, + boolean hardReplace, + Material... type) + { + if (radius > 0) { + replaceSphere(seed, radius, radius, radius, base, hardReplace, type); + } } - public static void replaceSphere(int seed, float rX, float rY, float rZ, @NotNull SimpleBlock block, boolean hardReplace, Material... type) { + public static void replaceSphere(int seed, + float rX, + float rY, + float rZ, + @NotNull SimpleBlock block, + boolean hardReplace, + Material... type) + { replaceSphere(seed, rX, rY, rZ, block, hardReplace, false, type); } public static void replaceWaterSphere(int seed, float radius, @NotNull SimpleBlock base) { - if (radius <= 0) return; + if (radius <= 0) { + return; + } if (radius <= 0.5) { // block.setReplaceType(ReplaceType.ALL); - if (base.getY() <= TerraformGenerator.seaLevel) - base.setType(Material.WATER); - else - base.setType(Material.AIR); + if (base.getY() <= TerraformGenerator.seaLevel) { + base.setType(Material.WATER); + } + else { + base.setType(Material.AIR); + } return; } @@ -830,38 +947,65 @@ public static void replaceWaterSphere(int seed, float radius, @NotNull SimpleBlo SimpleBlock rel = base.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double equationResult = Math.pow(x, 2) / Math.pow(radius, 2) - + Math.pow(y, 2) / Math.pow(radius, 2) - + Math.pow(z, 2) / Math.pow(radius, 2); + + Math.pow(y, 2) / Math.pow(radius, 2) + + Math.pow(z, 2) / Math.pow(radius, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if (rel.getY() <= TerraformGenerator.seaLevel) + if (rel.getY() <= TerraformGenerator.seaLevel) { rel.setType(Material.WATER); - else + } + else { rel.setType(Material.AIR); + } } } } } } - - public static void carveCaveAir(int seed, float rX, float rY, float rZ, @NotNull SimpleBlock block, boolean waterToAir, @NotNull EnumSet toReplace) + public static void carveCaveAir(int seed, + float rX, + float rY, + float rZ, + @NotNull SimpleBlock block, + boolean waterToAir, + @NotNull EnumSet toReplace) { - carveCaveAir(seed,rX,rY,rZ,0.09f, block,waterToAir, toReplace); + carveCaveAir(seed, rX, rY, rZ, 0.09f, block, waterToAir, toReplace); } - - public static void carveCaveAir(int seed, float rX, float rY, float rZ, float frequency, @NotNull SimpleBlock block, boolean waterToAir, @NotNull EnumSet toReplace) + + public static void carveCaveAir(int seed, + float rX, + float rY, + float rZ, + float frequency, + @NotNull SimpleBlock block, + boolean waterToAir, + @NotNull EnumSet toReplace) { - carveCaveAir(seed, rX, rY, rZ, frequency, block, false, waterToAir, toReplace); + carveCaveAir(seed, rX, rY, rZ, frequency, block, false, waterToAir, toReplace); } - + /** * Put barrier in toReplace to hard replace all solid blocks. */ - public static void carveCaveAir(int seed, float rX, float rY, float rZ, float frequency, @NotNull SimpleBlock block, boolean blockWaterHoles, boolean waterToAir, @NotNull EnumSet toReplace) { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + public static void carveCaveAir(int seed, + float rX, + float rY, + float rZ, + float frequency, + @NotNull SimpleBlock block, + boolean blockWaterHoles, + boolean waterToAir, + @NotNull EnumSet toReplace) + { + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { - if (waterToAir || block.getType() != Material.WATER) block.setType(Material.CAVE_AIR); + if (waterToAir || block.getType() != Material.WATER) { + block.setType(Material.CAVE_AIR); + } return; } @@ -869,49 +1013,63 @@ public static void carveCaveAir(int seed, float rX, float rY, float rZ, float fr noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(frequency); - for (float x = -rX*1.3f; x <= rX*1.3f; x++) { + for (float x = -rX * 1.3f; x <= rX * 1.3f; x++) { for (float y = -rY; y <= rY; y++) { - for (float z = -rZ*1.3f; z <= rZ*1.3f; z++) { + for (float z = -rZ * 1.3f; z <= rZ * 1.3f; z++) { SimpleBlock rel = block.getRelative(Math.round(x), Math.round(y), Math.round(z)); double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); double noiseVal = 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); if (equationResult <= noiseVal) { if (toReplace.contains(Material.BARRIER)) { // Blacklist - if (!toReplace.contains(rel.getType())) - if (!isWet(rel) || waterToAir) + if (!toReplace.contains(rel.getType())) { + if (!isWet(rel) || waterToAir) { rel.physicsSetType(Material.CAVE_AIR, false); + } + } - } else if (toReplace.contains(rel.getType())) { // Whitelist - if (!isWet(rel) || waterToAir) + } + else if (toReplace.contains(rel.getType())) { // Whitelist + if (!isWet(rel) || waterToAir) { rel.physicsSetType(Material.CAVE_AIR, false); + } - } else if (!rel.isSolid()) { - if (!isWet(rel) || waterToAir) + } + else if (!rel.isSolid()) { + if (!isWet(rel) || waterToAir) { rel.physicsSetType(Material.CAVE_AIR, false); + } } - + // Patches found water holes - if(blockWaterHoles) - for(BlockFace face:BlockUtils.sixBlockFaces) - { - SimpleBlock relrel = rel.getRelative(face); - if(isWet(relrel) || - relrel.getType() == Material.LAVA) - { - Material setMat = relrel.getY() < 0 ? Material.DEEPSLATE: Material.STONE; - relrel.physicsSetType(setMat, false); - } - } + if (blockWaterHoles) { + for (BlockFace face : BlockUtils.sixBlockFaces) { + SimpleBlock relrel = rel.getRelative(face); + if (isWet(relrel) || relrel.getType() == Material.LAVA) { + Material setMat = relrel.getY() < 0 ? Material.DEEPSLATE : Material.STONE; + relrel.physicsSetType(setMat, false); + } + } + } } } } } } - public static void replaceSphere(int seed, float rX, float rY, float rZ, @NotNull SimpleBlock block, boolean hardReplace, boolean snowy, Material... type) { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + public static void replaceSphere(int seed, + float rX, + float rY, + float rZ, + @NotNull SimpleBlock block, + boolean hardReplace, + boolean snowy, + Material... type) + { + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { // block.setReplaceType(ReplaceType.ALL); block.setType(GenUtils.randChoice(new Random(seed), type)); @@ -929,8 +1087,8 @@ public static void replaceSphere(int seed, float rX, float rY, float rZ, @NotNul SimpleBlock rel = block.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ if (hardReplace || !rel.isSolid()) { @@ -945,8 +1103,17 @@ public static void replaceSphere(int seed, float rX, float rY, float rZ, @NotNul } } - public static void replaceUpperSphere(int seed, float rX, float rY, float rZ, @NotNull SimpleBlock block, boolean hardReplace, Material... type) { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + public static void replaceUpperSphere(int seed, + float rX, + float rY, + float rZ, + @NotNull SimpleBlock block, + boolean hardReplace, + Material... type) + { + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { // block.setReplaceType(ReplaceType.ALL); block.setType(GenUtils.randChoice(new Random(seed), type)); @@ -964,20 +1131,31 @@ public static void replaceUpperSphere(int seed, float rX, float rY, float rZ, @N SimpleBlock rel = block.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if (hardReplace || !rel.isSolid()) rel.setType(GenUtils.randChoice(rand, type)); + if (hardReplace || !rel.isSolid()) { + rel.setType(GenUtils.randChoice(rand, type)); + } // rel.setReplaceType(ReplaceType.ALL); } } } } } - - public static void replaceLowerSphere(int seed, float rX, float rY, float rZ, @NotNull SimpleBlock block, boolean hardReplace, Material... type) { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + + public static void replaceLowerSphere(int seed, + float rX, + float rY, + float rZ, + @NotNull SimpleBlock block, + boolean hardReplace, + Material... type) + { + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { // block.setReplaceType(ReplaceType.ALL); block.setType(GenUtils.randChoice(new Random(seed), type)); @@ -995,11 +1173,13 @@ public static void replaceLowerSphere(int seed, float rX, float rY, float rZ, @N SimpleBlock rel = block.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); if (equationResult <= 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())) { // if(rel.getLocation().distanceSquared(block.getLocation()) <= radiusSquared){ - if (hardReplace || !rel.isSolid()) rel.setType(GenUtils.randChoice(rand, type)); + if (hardReplace || !rel.isSolid()) { + rel.setType(GenUtils.randChoice(rand, type)); + } // rel.setReplaceType(ReplaceType.ALL); } } @@ -1011,7 +1191,7 @@ public static void replaceLowerSphere(int seed, float rX, float rY, float rZ, @N // N // W E // S - return switch(original) { + return switch (original) { case EAST -> new BlockFace[] {BlockFace.SOUTH, BlockFace.NORTH}; case NORTH -> new BlockFace[] {BlockFace.EAST, BlockFace.WEST}; case SOUTH -> new BlockFace[] {BlockFace.WEST, BlockFace.EAST}; @@ -1042,44 +1222,49 @@ public static void correctMultifacingData(@NotNull SimpleBlock target) { for (BlockFace face : data.getAllowedFaces()) { Material type = target.getRelative(face).getType(); boolean facing = type.isSolid() - && !Tag.PRESSURE_PLATES.isTagged(type) - && !Tag.BANNERS.isTagged(type) - && !Tag.SLABS.isTagged(type) - && !Tag.TRAPDOORS.isTagged(type); - if(glassPanes.contains(target.getType()) - && (Tag.FENCE_GATES.isTagged(type) - || Tag.FENCES.isTagged(type))) - facing = false; + && !Tag.PRESSURE_PLATES.isTagged(type) + && !Tag.BANNERS.isTagged(type) + && !Tag.SLABS.isTagged(type) + && !Tag.TRAPDOORS.isTagged(type); + if (glassPanes.contains(target.getType()) && (Tag.FENCE_GATES.isTagged(type) + || Tag.FENCES.isTagged(type))) + { + facing = false; + } data.setFace(face, facing); - if(Tag.STAIRS.isTagged(type)) { - Stairs stairs = (Stairs) target.getRelative(face).getBlockData(); + if (Tag.STAIRS.isTagged(type)) { + Stairs stairs = (Stairs) target.getRelative(face).getBlockData(); data.setFace(face, stairs.getFacing() == face.getOppositeFace()); } } target.setBlockData(data); } - + public static boolean isExposedToNonSolid(@NotNull SimpleBlock target) { - for(BlockFace face:directBlockFaces) { - if(!target.getRelative(face).isSolid()) - return true; - } - return false; + for (BlockFace face : directBlockFaces) { + if (!target.getRelative(face).isSolid()) { + return true; + } + } + return false; } public static boolean isExposedToMaterial(@NotNull SimpleBlock target, @NotNull Set mats) { - for(BlockFace face:directBlockFaces) { - if(mats.contains(target.getRelative(face).getType())) + for (BlockFace face : directBlockFaces) { + if (mats.contains(target.getRelative(face).getType())) { return true; + } } return false; } + public static boolean isExposedToMaterial(@NotNull SimpleBlock target, Material mat) { - for(BlockFace face:directBlockFaces) { - if(target.getRelative(face).getType() == mat) - return true; - } - return false; + for (BlockFace face : directBlockFaces) { + if (target.getRelative(face).getType() == mat) { + return true; + } + } + return false; } /** @@ -1094,8 +1279,9 @@ public static void correctSurroundingMultifacingData(@NotNull SimpleBlock target } correctMultifacingData(target); - if(!(target.getBlockData() instanceof MultipleFacing data)) - return; + if (!(target.getBlockData() instanceof MultipleFacing data)) { + return; + } for (BlockFace face : data.getAllowedFaces()) { if (target.getRelative(face).getBlockData() instanceof MultipleFacing) { @@ -1113,8 +1299,9 @@ public static void correctStairData(@NotNull SimpleBlock target) { BlockFace right = BlockUtils.getRight(data.getFacing()); // Left is a stair and right isn't - if (Tag.STAIRS.isTagged(target.getRelative(left).getType()) - && !Tag.STAIRS.isTagged(target.getRelative(right).getType())) { + if (Tag.STAIRS.isTagged(target.getRelative(left).getType()) && !Tag.STAIRS.isTagged(target.getRelative(right) + .getType())) + { // Only adjust if the left side has the same facing. if (((Stairs) target.getRelative(left).getBlockData()).getFacing() == data.getFacing()) { @@ -1124,22 +1311,29 @@ public static void correctStairData(@NotNull SimpleBlock target) { // Only set if the back stair is facing a valid location if (((Stairs) target.getRelative(data.getFacing()).getBlockData()).getFacing() - == getLeft(data.getFacing())) + == getLeft(data.getFacing())) + { data.setShape(Stairs.Shape.OUTER_RIGHT); + } // Front is a stair - } else if (Tag.STAIRS.isTagged(target.getRelative(data.getFacing().getOppositeFace()).getType())) { + } + else if (Tag.STAIRS.isTagged(target.getRelative(data.getFacing().getOppositeFace()).getType())) { // Only set if the front stair is facing a valid location if (((Stairs) target.getRelative(data.getFacing().getOppositeFace()).getBlockData()).getFacing() - == getRight(data.getFacing())) + == getRight(data.getFacing())) + { data.setShape(Stairs.Shape.INNER_RIGHT); + } } } // Right is a stair and left isn't. - } else if (!Tag.STAIRS.isTagged(target.getRelative(left).getType()) - && Tag.STAIRS.isTagged(target.getRelative(right).getType())) { + } + else if (!Tag.STAIRS.isTagged(target.getRelative(left).getType()) && Tag.STAIRS.isTagged(target.getRelative( + right).getType())) + { // Only adjust if the right side has the same facing. if (((Stairs) target.getRelative(right).getBlockData()).getFacing() == data.getFacing()) { @@ -1149,16 +1343,21 @@ public static void correctStairData(@NotNull SimpleBlock target) { // Only set if the back stair is facing a valid location if (((Stairs) target.getRelative(data.getFacing()).getBlockData()).getFacing() - == getRight(data.getFacing())) + == getRight(data.getFacing())) + { data.setShape(Stairs.Shape.OUTER_LEFT); + } // Front is a stair - } else if (Tag.STAIRS.isTagged(target.getRelative(data.getFacing().getOppositeFace()).getType())) { + } + else if (Tag.STAIRS.isTagged(target.getRelative(data.getFacing().getOppositeFace()).getType())) { // Only set if the front stair is facing a valid location if (((Stairs) target.getRelative(data.getFacing().getOppositeFace()).getBlockData()).getFacing() - == getLeft(data.getFacing())) + == getLeft(data.getFacing())) + { data.setShape(Stairs.Shape.INNER_LEFT); + } } } @@ -1187,7 +1386,9 @@ private static boolean isMushroom(@NotNull SimpleBlock target) { } public static void correctMushroomData(@NotNull SimpleBlock target) { - if (!isMushroom(target)) return; + if (!isMushroom(target)) { + return; + } MultipleFacing data = (MultipleFacing) target.getBlockData(); for (BlockFace face : data.getAllowedFaces()) { data.setFace(face, !isMushroom(target.getRelative(face))); @@ -1198,14 +1399,22 @@ public static void correctMushroomData(@NotNull SimpleBlock target) { public static void correctSurroundingMushroomData(@NotNull SimpleBlock target) { correctMushroomData(target); - for (BlockFace face : sixBlockFaces) correctMushroomData(target.getRelative(face)); + for (BlockFace face : sixBlockFaces) { + correctMushroomData(target.getRelative(face)); + } } public static void placeDoor(@NotNull PopulatorDataAbstract data, @NotNull Material mat, @NotNull Wall w) { - placeDoor(data,mat,w.getX(),w.getY(),w.getZ(),w.getDirection()); + placeDoor(data, mat, w.getX(), w.getY(), w.getZ(), w.getDirection()); } - - public static void placeDoor(@NotNull PopulatorDataAbstract data, @NotNull Material mat, int x, int y, int z, @NotNull BlockFace dir) { + + public static void placeDoor(@NotNull PopulatorDataAbstract data, + @NotNull Material mat, + int x, + int y, + int z, + @NotNull BlockFace dir) + { data.setType(x, y, z, mat); data.setType(x, y + 1, z, mat); Door door = (Door) Bukkit.createBlockData(mat); @@ -1220,9 +1429,8 @@ public static void placeDoor(@NotNull PopulatorDataAbstract data, @NotNull Mater } public static void placeBed(@NotNull SimpleBlock block, @NotNull Material mat, @NotNull BlockFace dir) { - if(BlockUtils.isAir(block.getType()) && BlockUtils.isAir(block.getRelative(dir).getType())) - { - Bed bed = (Bed) Bukkit.createBlockData(mat); + if (BlockUtils.isAir(block.getType()) && BlockUtils.isAir(block.getRelative(dir).getType())) { + Bed bed = (Bed) Bukkit.createBlockData(mat); bed.setFacing(dir.getOppositeFace()); bed.setPart(Bed.Part.HEAD); block.setBlockData(bed); @@ -1233,15 +1441,15 @@ public static void placeBed(@NotNull SimpleBlock block, @NotNull Material mat, @ block.getRelative(dir).setBlockData(bed); } } - + public static BlockFace @NotNull [] getDirectFacesFromDiagonal(@NotNull BlockFace face) { - return switch(face) { + return switch (face) { case NORTH_EAST -> new BlockFace[] {BlockFace.NORTH, BlockFace.EAST}; case NORTH_WEST -> new BlockFace[] {BlockFace.NORTH, BlockFace.WEST}; case SOUTH_EAST -> new BlockFace[] {BlockFace.SOUTH, BlockFace.EAST}; case SOUTH_WEST -> new BlockFace[] {BlockFace.SOUTH, BlockFace.EAST}; - default -> - throw new UnsupportedOperationException("getDirectFacesFromDiagonal can only be used for XZ-Plane diagonals"); + default -> throw new UnsupportedOperationException( + "getDirectFacesFromDiagonal can only be used for XZ-Plane diagonals"); }; } @@ -1251,8 +1459,12 @@ public static void placeRail(@NotNull SimpleBlock block, @NotNull Material mat) BlockFace upperFace = null; for (BlockFace face : BlockUtils.directBlockFaces) { SimpleBlock relative = block.getRelative(face); - if (Tag.RAILS.isTagged(relative.getType())) faces.add(face); - if (Tag.RAILS.isTagged(relative.getUp().getType())) upperFace = face; + if (Tag.RAILS.isTagged(relative.getType())) { + faces.add(face); + } + if (Tag.RAILS.isTagged(relative.getUp().getType())) { + upperFace = face; + } } if (upperFace != null) { @@ -1272,16 +1484,21 @@ public static void placeRail(@NotNull SimpleBlock block, @NotNull Material mat) default: break; } - } else if (!faces.isEmpty()) { + } + else if (!faces.isEmpty()) { if (faces.contains(BlockFace.NORTH) && faces.contains(BlockFace.EAST)) { rail.setShape(Shape.NORTH_EAST); - } else if (faces.contains(BlockFace.NORTH) && faces.contains(BlockFace.WEST)) { + } + else if (faces.contains(BlockFace.NORTH) && faces.contains(BlockFace.WEST)) { rail.setShape(Shape.NORTH_WEST); - } else if (faces.contains(BlockFace.SOUTH) && faces.contains(BlockFace.EAST)) { + } + else if (faces.contains(BlockFace.SOUTH) && faces.contains(BlockFace.EAST)) { rail.setShape(Shape.SOUTH_EAST); - } else if (faces.contains(BlockFace.NORTH) || faces.contains(BlockFace.SOUTH)) { + } + else if (faces.contains(BlockFace.NORTH) || faces.contains(BlockFace.SOUTH)) { rail.setShape(Shape.NORTH_SOUTH); - } else if (faces.contains(BlockFace.EAST) || faces.contains(BlockFace.WEST)) { + } + else if (faces.contains(BlockFace.EAST) || faces.contains(BlockFace.WEST)) { rail.setShape(Shape.EAST_WEST); } } @@ -1290,27 +1507,31 @@ public static void placeRail(@NotNull SimpleBlock block, @NotNull Material mat) } public static void correctSurroundingRails(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Rail)) return; + if (!(target.getBlockData() instanceof Rail)) { + return; + } placeRail(target, target.getType()); for (BlockFace face : BlockUtils.directBlockFaces) { SimpleBlock relative = target.getRelative(face); - if (relative.getBlockData() instanceof Rail) + if (relative.getBlockData() instanceof Rail) { placeRail(relative, relative.getType()); - if (target.getRelative(face).getDown().getBlockData() instanceof Rail) + } + if (target.getRelative(face).getDown().getBlockData() instanceof Rail) { placeRail(relative.getDown(), target.getDown().getRelative(face).getType()); + } } } public static boolean emitsLight(@NotNull Material mat) { - return switch(mat) { + return switch (mat) { case TORCH, SEA_PICKLE, SEA_LANTERN, GLOWSTONE, LANTERN, LAVA, CAMPFIRE, REDSTONE_LAMP, FIRE -> true; default -> false; }; } public static @NotNull BlockData infestStone(@NotNull BlockData mat) { - return switch(mat.getMaterial()) { + return switch (mat.getMaterial()) { case STONE_BRICKS -> Bukkit.createBlockData(Material.INFESTED_STONE_BRICKS); case MOSSY_STONE_BRICKS -> Bukkit.createBlockData(Material.INFESTED_MOSSY_STONE_BRICKS); case CRACKED_STONE_BRICKS -> Bukkit.createBlockData(Material.INFESTED_CRACKED_STONE_BRICKS); @@ -1321,23 +1542,20 @@ public static boolean emitsLight(@NotNull Material mat) { }; } - public static void stairwayUntilSolid(@NotNull SimpleBlock start, @NotNull BlockFace extensionDir, Material[] downTypes, Material... stairTypes) { + public static void stairwayUntilSolid(@NotNull SimpleBlock start, + @NotNull BlockFace extensionDir, + Material[] downTypes, + Material... stairTypes) + { while (!start.isSolid()) { - new StairBuilder(stairTypes) - .setFacing(extensionDir.getOppositeFace()) - .apply(start); - BlockUtils.setDownUntilSolid( - start.getX(), - start.getY() - 1, - start.getZ(), - start.getPopData(), - downTypes); + new StairBuilder(stairTypes).setFacing(extensionDir.getOppositeFace()).apply(start); + BlockUtils.setDownUntilSolid(start.getX(), start.getY() - 1, start.getZ(), start.getPopData(), downTypes); start = start.getRelative(extensionDir).getDown(); } } - + public static boolean isAir(Material mat) { - return airs.contains(mat); + return airs.contains(mat); } public static @NotNull BlockData getRandomBarrel() { @@ -1345,40 +1563,37 @@ public static boolean isAir(Material mat) { barrel.setFacing(BlockUtils.sixBlockFaces[GenUtils.randInt(0, BlockUtils.sixBlockFaces.length - 1)]); return barrel; } - - public static void angledStairwayUntilSolid(@NotNull SimpleBlock start, BlockFace extensionDir, Material[] downTypes, Material... stairTypes) { + + public static void angledStairwayUntilSolid(@NotNull SimpleBlock start, + BlockFace extensionDir, + Material[] downTypes, + Material... stairTypes) + { int threshold = 5; - while (!start.isSolid()) { - - if(threshold == 0) - extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); - - new StairBuilder(stairTypes) - .setFacing(extensionDir.getOppositeFace()) - .apply(start); - BlockUtils.setDownUntilSolid( - start.getX(), - start.getY() - 1, - start.getZ(), - start.getPopData(), - downTypes); + while (!start.isSolid()) { + + if (threshold == 0) { + extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); + } + + new StairBuilder(stairTypes).setFacing(extensionDir.getOppositeFace()).apply(start); + BlockUtils.setDownUntilSolid(start.getX(), start.getY() - 1, start.getZ(), start.getPopData(), downTypes); threshold--; start = start.getRelative(extensionDir).getDown(); } } - + /** * Checks if the target is in a wet material, or if the material it is * in is waterlogged. */ public static boolean isWet(@NotNull SimpleBlock target) { - return BlockUtils.wetMaterials.contains(target.getType()) || - (target.getBlockData() instanceof Waterlogged - && ((Waterlogged) target.getBlockData()).isWaterlogged()); + return BlockUtils.wetMaterials.contains(target.getType()) || (target.getBlockData() instanceof Waterlogged + && ((Waterlogged) target.getBlockData()).isWaterlogged()); } - + public static float yawFromBlockFace(@NotNull BlockFace face) { - return switch(face) { + return switch (face) { case EAST -> -90.0f; case NORTH -> 180.0f; case SOUTH -> 0.0f; @@ -1388,22 +1603,32 @@ public static float yawFromBlockFace(@NotNull BlockFace face) { } public static void randRotateBlockData(@NotNull Random rand, BlockData data) { - if(data instanceof Directional) { - Set faces = ((Directional) data).getFaces(); - ((Directional) data).setFacing(faces.stream().skip((int) (faces.size() * rand.nextDouble())).findAny().get()); - }else if(data instanceof Rotatable) { - ((Rotatable) data).setRotation(BlockUtils.getXZPlaneBlockFace(rand)); - } + if (data instanceof Directional) { + Set faces = ((Directional) data).getFaces(); + ((Directional) data).setFacing(faces.stream() + .skip((int) (faces.size() * rand.nextDouble())) + .findAny() + .get()); + } + else if (data instanceof Rotatable) { + ((Rotatable) data).setRotation(BlockUtils.getXZPlaneBlockFace(rand)); + } } @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isOre(Material mat) { - for(Material ore:ores) - if(ore == mat) return true; - return false; + for (Material ore : ores) { + if (ore == mat) { + return true; + } + } + return false; } + public static void placeCandle(@NotNull SimpleBlock block, int numCandles, boolean lit) { - if ( !TConfigOption.areDecorationsEnabled()) return; + if (!TConfigOption.areDecorationsEnabled()) { + return; + } Candle candle = (Candle) Bukkit.createBlockData(Material.CANDLE); candle.setLit(lit); @@ -1413,26 +1638,34 @@ public static void placeCandle(@NotNull SimpleBlock block, int numCandles, boole } public static void downLPointedDripstone(int height, @NotNull SimpleBlock base) { - if ( !TConfigOption.areDecorationsEnabled()) return; + if (!TConfigOption.areDecorationsEnabled()) { + return; + } int realHeight = 0; - while(!base.getRelative(0,-realHeight,0).isSolid() && height > 0) { + while (!base.getRelative(0, -realHeight, 0).isSolid() && height > 0) { realHeight++; height--; } - if(base.getRelative(0,-realHeight,0).isSolid()) + if (base.getRelative(0, -realHeight, 0).isSolid()) { realHeight--; + } - if(realHeight <= 0) return; + if (realHeight <= 0) { + return; + } - for(int i = realHeight; i > 0; i--) { + for (int i = realHeight; i > 0; i--) { PointedDripstone.Thickness thickness = PointedDripstone.Thickness.MIDDLE; - if(i == 1) + if (i == 1) { thickness = PointedDripstone.Thickness.TIP; - if(i == 2) + } + if (i == 2) { thickness = PointedDripstone.Thickness.FRUSTUM; - if(i == realHeight && realHeight > 2) + } + if (i == realHeight && realHeight > 2) { thickness = PointedDripstone.Thickness.BASE; + } PointedDripstone dripstone = (PointedDripstone) Bukkit.createBlockData(Material.POINTED_DRIPSTONE); dripstone.setVerticalDirection(BlockFace.DOWN); @@ -1443,52 +1676,70 @@ public static void downLPointedDripstone(int height, @NotNull SimpleBlock base) public static Material stoneOrSlate(int y) { - return y > 0 ? Material.STONE : - y < -3 ? Material.DEEPSLATE : - GenUtils.randChoice(Material.STONE, Material.DEEPSLATE); + return y > 0 + ? Material.STONE + : y < -3 ? Material.DEEPSLATE : GenUtils.randChoice(Material.STONE, Material.DEEPSLATE); } + public static Material stoneOrSlateWall(int y) { - return y > 0 ? Material.COBBLESTONE_WALL : - y < -3 ? Material.COBBLED_DEEPSLATE_WALL : - GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.COBBLED_DEEPSLATE_WALL); + return y > 0 + ? Material.COBBLESTONE_WALL + : y < -3 + ? Material.COBBLED_DEEPSLATE_WALL + : GenUtils.randChoice(Material.COBBLESTONE_WALL, Material.COBBLED_DEEPSLATE_WALL); } public static void upLPointedDripstone(int height, @NotNull SimpleBlock base) { - if ( !TConfigOption.areDecorationsEnabled()) return; + if (!TConfigOption.areDecorationsEnabled()) { + return; + } int realHeight = 0; - while(!base.getRelative(0,realHeight,0).isSolid() && height > 0) { + while (!base.getRelative(0, realHeight, 0).isSolid() && height > 0) { realHeight++; height--; } - if(base.getRelative(0,realHeight,0).isSolid()) + if (base.getRelative(0, realHeight, 0).isSolid()) { realHeight--; + } - if(realHeight <= 0) return; + if (realHeight <= 0) { + return; + } - for(int i = 0; i < realHeight; i++) { + for (int i = 0; i < realHeight; i++) { PointedDripstone.Thickness thickness = PointedDripstone.Thickness.MIDDLE; - if(realHeight >= 4) { - if(i == realHeight-1) + if (realHeight >= 4) { + if (i == realHeight - 1) { thickness = PointedDripstone.Thickness.TIP; - if(i == realHeight-2) + } + if (i == realHeight - 2) { thickness = PointedDripstone.Thickness.FRUSTUM; - if(i == 0) + } + if (i == 0) { thickness = PointedDripstone.Thickness.BASE; - }else if(realHeight >= 3) { - if(i == realHeight-1) + } + } + else if (realHeight >= 3) { + if (i == realHeight - 1) { thickness = PointedDripstone.Thickness.TIP; - if(i == realHeight-2) + } + if (i == realHeight - 2) { thickness = PointedDripstone.Thickness.FRUSTUM; - if(i == 0) + } + if (i == 0) { thickness = PointedDripstone.Thickness.BASE; - }else if(realHeight >= 2) { + } + } + else if (realHeight >= 2) { thickness = PointedDripstone.Thickness.TIP; - if(i == 0) + if (i == 0) { thickness = PointedDripstone.Thickness.FRUSTUM; - }else { + } + } + else { thickness = PointedDripstone.Thickness.TIP; } @@ -1500,36 +1751,43 @@ public static void upLPointedDripstone(int height, @NotNull SimpleBlock base) { } public static void downLCaveVines(int height, @NotNull SimpleBlock base) { - if ( !TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } int realHeight = 0; - while(!base.getRelative(0,-realHeight,0).isSolid() && height > 0) { + while (!base.getRelative(0, -realHeight, 0).isSolid() && height > 0) { realHeight++; height--; } - if(base.getRelative(0,-realHeight,0).isSolid()) + if (base.getRelative(0, -realHeight, 0).isSolid()) { realHeight--; + } - if(realHeight <= 0) return; + if (realHeight <= 0) { + return; + } - for(int i = realHeight; i > 0; i--) { - CaveVinesPlant vines = (CaveVinesPlant) Bukkit.createBlockData(i == 1 ? Material.CAVE_VINES : Material.CAVE_VINES_PLANT); + for (int i = realHeight; i > 0; i--) { + CaveVinesPlant vines = (CaveVinesPlant) Bukkit.createBlockData(i == 1 + ? Material.CAVE_VINES + : Material.CAVE_VINES_PLANT); vines.setBerries(new Random().nextInt(3) == 0); base.getRelative(0, -(realHeight - i), 0).lsetBlockData(vines); } } - private static final HashMap deepslateMap = new HashMap<>(); public static @NotNull Material deepSlateVersion(@NotNull Material target) { - Material mat = deepslateMap.get("DEEPSLATE_"+ target); + Material mat = deepslateMap.get("DEEPSLATE_" + target); - if(mat == null) { - mat = Material.getMaterial("DEEPSLATE_"+ target); + if (mat == null) { + mat = Material.getMaterial("DEEPSLATE_" + target); } - if(mat == null) + if (mat == null) { return target; + } else { - deepslateMap.put("DEEPSLATE_"+ target, mat); + deepslateMap.put("DEEPSLATE_" + target, mat); return mat; } } diff --git a/common/src/main/java/org/terraform/utils/BoxBuilder.java b/common/src/main/java/org/terraform/utils/BoxBuilder.java index fdd46fde..f1b9c137 100644 --- a/common/src/main/java/org/terraform/utils/BoxBuilder.java +++ b/common/src/main/java/org/terraform/utils/BoxBuilder.java @@ -1,10 +1,5 @@ package org.terraform.utils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.NotNull; @@ -12,83 +7,96 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Random; + public class BoxBuilder { - - private final Random random; - private final int seed; - private float rX = 1f; - private float rY = 1f; - private float rZ = 1f; - private final SimpleBlock core; - private boolean hardReplace = false; - private final @NotNull Collection replaceWhitelist = new ArrayList<>(); - private Material[] types; - private Material[] upperType; - private Material[] lowerType; - private int staticWaterLevel = -9999; + + private final Random random; + private final int seed; + private final SimpleBlock core; + private final @NotNull Collection replaceWhitelist = new ArrayList<>(); + private float rX = 1f; + private float rY = 1f; + private float rZ = 1f; + private boolean hardReplace = false; + private Material[] types; + private Material[] upperType; + private Material[] lowerType; + private int staticWaterLevel = -9999; private BoxType boxType = BoxType.FULL_BOX; - - - public BoxBuilder(@NotNull Random random, SimpleBlock core, Material... types) { - this.random = random; - this.seed = random.nextInt(99999999); - this.types = types; - this.core = core; - } - - public @NotNull BoxBuilder setBoxType(BoxType sphereType) { - this.boxType = sphereType; - return this; - } - - public @NotNull BoxBuilder setUpperType(Material... upperType) { - this.upperType = upperType; - return this; - } - - public @NotNull BoxBuilder setLowerType(Material... lowerType) { - this.lowerType = lowerType; - return this; - } - - public @NotNull BoxBuilder setStaticWaterLevel(int staticWaterLevel) { - this.staticWaterLevel = staticWaterLevel; - return this; - } - - public @NotNull BoxBuilder addToWhitelist(Material @NotNull ... mats) { + + + public BoxBuilder(@NotNull Random random, SimpleBlock core, Material... types) { + this.random = random; + this.seed = random.nextInt(99999999); + this.types = types; + this.core = core; + } + + public @NotNull BoxBuilder setBoxType(BoxType sphereType) { + this.boxType = sphereType; + return this; + } + + public @NotNull BoxBuilder setUpperType(Material... upperType) { + this.upperType = upperType; + return this; + } + + public @NotNull BoxBuilder setLowerType(Material... lowerType) { + this.lowerType = lowerType; + return this; + } + + public @NotNull BoxBuilder setStaticWaterLevel(int staticWaterLevel) { + this.staticWaterLevel = staticWaterLevel; + return this; + } + + public @NotNull BoxBuilder addToWhitelist(Material @NotNull ... mats) { replaceWhitelist.addAll(Arrays.asList(mats)); - return this; - } - - public @NotNull BoxBuilder setRadius(float radius) { - this.rX = radius; this.rY = radius; this.rZ = radius; - return this; - } - - public @NotNull BoxBuilder setRX(float rX) { - this.rX = rX; - return this; - } - public @NotNull BoxBuilder setRZ(float rZ) { - this.rZ = rZ; - return this; - } - public @NotNull BoxBuilder setRY(float rY) { - this.rY = rY; - return this; - } - public @NotNull BoxBuilder setSnowy() { - this.upperType = new Material[] {Material.SNOW}; - return this; - } - public @NotNull BoxBuilder setHardReplace(boolean hardReplace) { - this.hardReplace = hardReplace; - return this; - } + return this; + } + + public @NotNull BoxBuilder setRadius(float radius) { + this.rX = radius; + this.rY = radius; + this.rZ = radius; + return this; + } + + public @NotNull BoxBuilder setRX(float rX) { + this.rX = rX; + return this; + } + + public @NotNull BoxBuilder setRZ(float rZ) { + this.rZ = rZ; + return this; + } + + public @NotNull BoxBuilder setRY(float rY) { + this.rY = rY; + return this; + } + + public @NotNull BoxBuilder setSnowy() { + this.upperType = new Material[] {Material.SNOW}; + return this; + } + + public @NotNull BoxBuilder setHardReplace(boolean hardReplace) { + this.hardReplace = hardReplace; + return this; + } public void build() { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { unitReplace(core); return; @@ -99,62 +107,82 @@ public void build() { noise.SetFrequency(0.12f); float effectiveRYLower = -rY; - if(boxType == BoxType.UPPER_SEMIBOX) effectiveRYLower = 0; + if (boxType == BoxType.UPPER_SEMIBOX) { + effectiveRYLower = 0; + } float effectiveRYUpper = rY; - if(boxType == BoxType.LOWER_SEMIBOX) effectiveRYUpper = 0; + if (boxType == BoxType.LOWER_SEMIBOX) { + effectiveRYUpper = 0; + } float fuzzMultiplier = 0.2f; - for (float y = effectiveRYLower*(1f+ fuzzMultiplier); y <= effectiveRYUpper*(1f+ fuzzMultiplier); y++) { - float yMultiplier = 1f - (Math.abs(y)/rY); - for (float x = -rX*(1f+ fuzzMultiplier)*yMultiplier; x <= rX*(1f+ fuzzMultiplier)*yMultiplier; x++) { - for (float z = -rZ*(1f+ fuzzMultiplier)*yMultiplier; z <= rZ*(1f+ fuzzMultiplier)*yMultiplier; z++) { + for (float y = effectiveRYLower * (1f + fuzzMultiplier); y <= effectiveRYUpper * (1f + fuzzMultiplier); y++) { + float yMultiplier = 1f - (Math.abs(y) / rY); + for (float x = -rX * (1f + fuzzMultiplier) * yMultiplier; + x <= rX * (1f + fuzzMultiplier) * yMultiplier; + x++) { + for (float z = -rZ * (1f + fuzzMultiplier) * yMultiplier; + z <= rZ * (1f + fuzzMultiplier) * yMultiplier; + z++) { SimpleBlock rel = core.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double noiseVal = Math.abs(noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())); - - if (Math.abs(x) <= rX * (1+(noiseVal* fuzzMultiplier)) - && Math.abs(y) <= rY * (1+(noiseVal* fuzzMultiplier)) - && Math.abs(z) <= rZ * (1+(noiseVal* fuzzMultiplier))) { + + if (Math.abs(x) <= rX * (1 + (noiseVal * fuzzMultiplier)) + && Math.abs(y) <= rY * (1 + (noiseVal + * fuzzMultiplier)) + && Math.abs(z) <= rZ * (1 + (noiseVal * fuzzMultiplier))) + { Material[] original = types; - if(rel.getY() <= staticWaterLevel) { - types = new Material[] {Material.WATER}; - for(BlockFace face:new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.DOWN}) - { - if(BlockUtils.isAir(rel.getRelative(face).getType())) { - types = new Material[] { Material.STONE}; - } - } + if (rel.getY() <= staticWaterLevel) { + types = new Material[] {Material.WATER}; + for (BlockFace face : new BlockFace[] { + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.DOWN + }) { + if (BlockUtils.isAir(rel.getRelative(face).getType())) { + types = new Material[] {Material.STONE}; + } + } } - unitReplace(rel); - types = original; + unitReplace(rel); + types = original; } } } } } - + private void unitReplace(@NotNull SimpleBlock rel) { - if(replaceWhitelist.isEmpty()) { - if (hardReplace || !rel.isSolid()) { + if (replaceWhitelist.isEmpty()) { + if (hardReplace || !rel.isSolid()) { rel.setType(GenUtils.randChoice(random, types)); } - else - return; - } else if(replaceWhitelist.contains(rel.getType())) { + else { + return; + } + } + else if (replaceWhitelist.contains(rel.getType())) { rel.setType(GenUtils.randChoice(random, types)); - } - else - return; - - if(rel.getDown().isSolid()) { - if(upperType != null) - rel.getUp().lsetType(upperType); - if(lowerType != null) - rel.getDown().setType(lowerType); - } + } + else { + return; + } + + if (rel.getDown().isSolid()) { + if (upperType != null) { + rel.getUp().lsetType(upperType); + } + if (lowerType != null) { + rel.getDown().setType(lowerType); + } + } } - public enum BoxType{ - UPPER_SEMIBOX, LOWER_SEMIBOX, FULL_BOX + public enum BoxType { + UPPER_SEMIBOX, LOWER_SEMIBOX, FULL_BOX } } diff --git a/common/src/main/java/org/terraform/utils/CoralGenerator.java b/common/src/main/java/org/terraform/utils/CoralGenerator.java index 308d8b09..437f110d 100644 --- a/common/src/main/java/org/terraform/utils/CoralGenerator.java +++ b/common/src/main/java/org/terraform/utils/CoralGenerator.java @@ -15,51 +15,68 @@ public class CoralGenerator { // private static final Material[] VALUES = Material.values(); - public static final Material[] CORAL_BLOCKS = { + public static final Material[] CORAL_BLOCKS = { Material.BRAIN_CORAL_BLOCK, Material.BUBBLE_CORAL_BLOCK, Material.FIRE_CORAL_BLOCK, Material.HORN_CORAL_BLOCK, Material.TUBE_CORAL_BLOCK, - }; + }; public static final Material[] CORAL_FANS = { Material.BRAIN_CORAL_FAN, Material.BUBBLE_CORAL_FAN, Material.FIRE_CORAL_FAN, Material.HORN_CORAL_FAN, Material.TUBE_CORAL_FAN, - }; + }; public static final Material[] CORAL_WALL_FANS = { Material.BRAIN_CORAL_WALL_FAN, Material.BUBBLE_CORAL_WALL_FAN, Material.FIRE_CORAL_WALL_FAN, Material.HORN_CORAL_WALL_FAN, Material.TUBE_CORAL_WALL_FAN, - }; + }; public static final BlockFace[] FACES = { - BlockFace.EAST, BlockFace.WEST, - BlockFace.NORTH, BlockFace.SOUTH, - BlockFace.EAST, BlockFace.WEST, - BlockFace.NORTH, BlockFace.SOUTH, - BlockFace.EAST, BlockFace.WEST, - BlockFace.NORTH, BlockFace.SOUTH, - BlockFace.UP, BlockFace.DOWN + BlockFace.EAST, + BlockFace.WEST, + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.UP, + BlockFace.DOWN }; /** * Creates a random coral + * * @param data refers to the block the coral will grow ON. */ public static void generateSingleCoral(@NotNull PopulatorDataAbstract data, int x, int y, int z) { BlockFace face = getRandomBlockFace(); - if (face == BlockFace.DOWN) face = BlockFace.UP; + if (face == BlockFace.DOWN) { + face = BlockFace.UP; + } Material coral = CORAL_FANS[GenUtils.randInt(0, CORAL_FANS.length - 1)]; - if (face != BlockFace.UP) coral = CORAL_WALL_FANS[GenUtils.randInt(0, CORAL_WALL_FANS.length - 1)]; + if (face != BlockFace.UP) { + coral = CORAL_WALL_FANS[GenUtils.randInt(0, CORAL_WALL_FANS.length - 1)]; + } attemptReplace(data, x + face.getModX(), y + face.getModY(), z + face.getModZ(), coral); if (face != BlockFace.UP) { - if (data.getBlockData(x + face.getModX(), y + face.getModY(), z + face.getModZ()) instanceof CoralWallFan bdata) { + if (data.getBlockData( + x + face.getModX(), + y + face.getModY(), + z + face.getModZ() + ) instanceof CoralWallFan bdata) + { bdata.setFacing(face); data.setBlockData(x + face.getModX(), y + face.getModY(), z + face.getModZ(), bdata); } @@ -69,32 +86,45 @@ public static void generateSingleCoral(@NotNull PopulatorDataAbstract data, int @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isSaturatedCoral(@NotNull SimpleBlock block) { for (BlockFace face : BlockUtils.directBlockFaces) { - if (block.getRelative(face).getType() == Material.WATER) return true; + if (block.getRelative(face).getType() == Material.WATER) { + return true; + } } return false; } /** * Generates a coral on a surface. + * * @param data refers to the block the coral will grow ON. */ public static void generateSingleCoral(@NotNull PopulatorDataAbstract data, int x, int y, int z, String coralType) { BlockFace face = getRandomBlockFace(); coralType = StringUtils.remove(coralType, "_BLOCK"); - if (face == BlockFace.DOWN) face = BlockFace.UP; - Material coral = Material.getMaterial(coralType + "_FAN");// coralFans().get(GenUtils.randInt(0, coralFans().size() - 1)); - if(new Random().nextBoolean()) - coral = Material.getMaterial(coralType); + if (face == BlockFace.DOWN) { + face = BlockFace.UP; + } + Material coral = Material.getMaterial(coralType + + "_FAN");// coralFans().get(GenUtils.randInt(0, coralFans().size() - 1)); + if (new Random().nextBoolean()) { + coral = Material.getMaterial(coralType); + } - if (face != BlockFace.UP) + if (face != BlockFace.UP) { coral = Material.getMaterial(coralType + "_WALL_FAN"); + } else if (GenUtils.chance(1, 5)) { generateSeaPickles(data, x, y + 1, z); return; } attemptReplace(data, x + face.getModX(), y + face.getModY(), z + face.getModZ(), coral); if (face != BlockFace.UP) { - if (data.getBlockData(x + face.getModX(), y + face.getModY(), z + face.getModZ()) instanceof CoralWallFan bdata) { + if (data.getBlockData( + x + face.getModX(), + y + face.getModY(), + z + face.getModZ() + ) instanceof CoralWallFan bdata) + { bdata.setFacing(face); data.setBlockData(x + face.getModX(), y + face.getModY(), z + face.getModZ(), bdata); } @@ -103,10 +133,13 @@ else if (GenUtils.chance(1, 5)) { /** * Creates a cluster of Sea Pickles. + * * @param data refers to the block to replace with sea pickles */ public static void generateSeaPickles(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } int fullSize = GenUtils.randInt(1, 4); if (attemptReplace(data, x, y, z, Material.SEA_PICKLE)) { @@ -119,21 +152,29 @@ public static void generateSeaPickles(@NotNull PopulatorDataAbstract data, int x /** * Generates a Kelp plant 3-10 blocks tall. Or sea grass. + * * @param data refers to the block ABOVE the floor (lowest block of the kelp plant) */ public static void generateKelpGrowth(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if ( !TConfigOption.arePlantsEnabled()) return; + if (!TConfigOption.arePlantsEnabled()) { + return; + } int fullSize = GenUtils.randInt(1, 2); - if (new Random().nextBoolean()) fullSize += GenUtils.randInt(1, 20); + if (new Random().nextBoolean()) { + fullSize += GenUtils.randInt(1, 20); + } if (fullSize == 1) { attemptReplace(data, x, y, z, Material.SEAGRASS); - } else if (fullSize == 2 && y < TerraformGenerator.seaLevel - 3) { + } + else if (fullSize == 2 && y < TerraformGenerator.seaLevel - 3) { BlockUtils.setDoublePlant(data, x, y, z, Material.TALL_SEAGRASS); - } else { + } + else { for (int size = 0; size < fullSize; size++) { - if (!attemptReplace(data, x, y, z, Material.KELP_PLANT)) + if (!attemptReplace(data, x, y, z, Material.KELP_PLANT)) { break; + } y++; } } @@ -141,13 +182,22 @@ public static void generateKelpGrowth(@NotNull PopulatorDataAbstract data, int x /** * Will replace the block if it was previously water or air. + * * @param data block to be replaced * @param newType type to replace with */ public static boolean attemptReplace(@NotNull PopulatorDataAbstract data, int x, int y, int z, Material newType) { - if (y >= TerraformGenerator.seaLevel) return false; + if (y >= TerraformGenerator.seaLevel) { + return false; + } Material type = data.getType(x, y, z); - if (type != Material.WATER && type != Material.SEAGRASS && type != Material.TALL_SEAGRASS && type != Material.KELP_PLANT) return false; + if (type != Material.WATER + && type != Material.SEAGRASS + && type != Material.TALL_SEAGRASS + && type != Material.KELP_PLANT) + { + return false; + } data.setType(x, y, z, newType); return true; } @@ -163,8 +213,12 @@ public static void generateCoral(@NotNull PopulatorDataAbstract data, int x, int for (int size = 0; size < fullSize; size++) { if (attemptReplace(data, middle[0], middle[1], middle[2], coral)) { - if (GenUtils.randInt(0, 100) < 20) generateSeaPickles(data, middle[0], middle[1] + 1, middle[2]); - if (GenUtils.randInt(0, 100) < 40) generateSingleCoral(data, middle[0], middle[1], middle[2]); + if (GenUtils.randInt(0, 100) < 20) { + generateSeaPickles(data, middle[0], middle[1] + 1, middle[2]); + } + if (GenUtils.randInt(0, 100) < 40) { + generateSingleCoral(data, middle[0], middle[1], middle[2]); + } } getRandomRelative(middle); } @@ -180,7 +234,9 @@ public static void generateSponge(@NotNull PopulatorDataAbstract data, int x, in for (int size = 0; size < fullSize; size++) { if (attemptReplace(data, middle[0], middle[1], middle[2], Material.WET_SPONGE)) { - if (GenUtils.randInt(0, 100) < 20) generateSeaPickles(data, middle[0], middle[1] + 1, middle[2]); + if (GenUtils.randInt(0, 100) < 20) { + generateSeaPickles(data, middle[0], middle[1] + 1, middle[2]); + } } getRandomRelative(middle); } diff --git a/common/src/main/java/org/terraform/utils/CylinderBuilder.java b/common/src/main/java/org/terraform/utils/CylinderBuilder.java index 7436f609..b93ed94e 100644 --- a/common/src/main/java/org/terraform/utils/CylinderBuilder.java +++ b/common/src/main/java/org/terraform/utils/CylinderBuilder.java @@ -1,93 +1,103 @@ package org.terraform.utils; -import java.util.Random; - import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.terraform.data.SimpleBlock; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; +import java.util.Random; + public class CylinderBuilder { - - private final Random random; - private final int seed; - private float rX = 1f; - private float rY = 1f; - private float rZ = 1f; - private float minRadius = 0f; - private final SimpleBlock core; - private boolean singleBlockY = false; + + private final Random random; + private final int seed; + private final SimpleBlock core; + private final Material[] types; + private float rX = 1f; + private float rY = 1f; + private float rZ = 1f; + private float minRadius = 0f; + private boolean singleBlockY = false; private boolean startFromZero = false; - private boolean hardReplace = false; - private final Material[] types; - private Material[] upperType; - private Material[] lowerType; - private float noiseMagnitude = 0.7f; - - public CylinderBuilder(@NotNull Random random, SimpleBlock core, Material... types) { - this.random = random; - this.seed = random.nextInt(99999999); - this.types = types; - this.core = core; - } + private boolean hardReplace = false; + private Material[] upperType; + private Material[] lowerType; + private float noiseMagnitude = 0.7f; + + public CylinderBuilder(@NotNull Random random, SimpleBlock core, Material... types) { + this.random = random; + this.seed = random.nextInt(99999999); + this.types = types; + this.core = core; + } public @NotNull CylinderBuilder setStartFromZero(boolean startFromZero) { this.startFromZero = startFromZero; return this; } - public @NotNull CylinderBuilder setNoiseMagnitude(float mag) { - this.noiseMagnitude = mag; - return this; - } - - public @NotNull CylinderBuilder setUpperType(Material... upperType) { - this.upperType = upperType; - return this; - } - - public @NotNull CylinderBuilder setLowerType(Material... lowerType) { - this.lowerType = lowerType; - return this; - } - - public @NotNull CylinderBuilder setRadius(float radius) { - this.rX = radius; this.rY = radius; this.rZ = radius; - return this; - } - - public @NotNull CylinderBuilder setMinRadius(float minRadius) { - this.minRadius = minRadius; - return this; - } - public @NotNull CylinderBuilder setRX(float rX) { - this.rX = rX; - return this; - } - public @NotNull CylinderBuilder setRZ(float rZ) { - this.rZ = rZ; - return this; - } - public @NotNull CylinderBuilder setRY(float rY) { - this.rY = rY; - return this; - } - public @NotNull CylinderBuilder setSnowy() { - this.upperType = new Material[] {Material.SNOW}; - return this; - } - public @NotNull CylinderBuilder setHardReplace(boolean hardReplace) { - this.hardReplace = hardReplace; - return this; - } - - public @NotNull CylinderBuilder setSingleBlockY(boolean singleBlockY) { - this.singleBlockY = singleBlockY; - return this; - } - + + public @NotNull CylinderBuilder setNoiseMagnitude(float mag) { + this.noiseMagnitude = mag; + return this; + } + + public @NotNull CylinderBuilder setUpperType(Material... upperType) { + this.upperType = upperType; + return this; + } + + public @NotNull CylinderBuilder setLowerType(Material... lowerType) { + this.lowerType = lowerType; + return this; + } + + public @NotNull CylinderBuilder setRadius(float radius) { + this.rX = radius; + this.rY = radius; + this.rZ = radius; + return this; + } + + public @NotNull CylinderBuilder setMinRadius(float minRadius) { + this.minRadius = minRadius; + return this; + } + + public @NotNull CylinderBuilder setRX(float rX) { + this.rX = rX; + return this; + } + + public @NotNull CylinderBuilder setRZ(float rZ) { + this.rZ = rZ; + return this; + } + + public @NotNull CylinderBuilder setRY(float rY) { + this.rY = rY; + return this; + } + + public @NotNull CylinderBuilder setSnowy() { + this.upperType = new Material[] {Material.SNOW}; + return this; + } + + public @NotNull CylinderBuilder setHardReplace(boolean hardReplace) { + this.hardReplace = hardReplace; + return this; + } + + public @NotNull CylinderBuilder setSingleBlockY(boolean singleBlockY) { + this.singleBlockY = singleBlockY; + return this; + } + public void build() { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { unitReplace(core); return; @@ -96,30 +106,37 @@ public void build() { FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); - + float effectiveRY = rY; - if(singleBlockY) effectiveRY = 0; - + if (singleBlockY) { + effectiveRY = 0; + } + for (float x = -rX; x <= rX; x++) { for (float y = startFromZero ? 0 : -effectiveRY; y <= effectiveRY; y++) { for (float z = -rZ; z <= rZ; z++) { SimpleBlock rel = core.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); float effectiveY = y; - - if(Math.abs(y)/rY <= 0.7) - effectiveY = 0; - + + if (Math.abs(y) / rY <= 0.7) { + effectiveY = 0; + } + double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(effectiveY, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(effectiveY, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); double noiseFuzz; - if(noiseMagnitude > 0) - noiseFuzz = 1 + noiseMagnitude * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); - else - noiseFuzz = 1; - - if(noiseFuzz < minRadius) noiseFuzz = minRadius; + if (noiseMagnitude > 0) { + noiseFuzz = 1 + noiseMagnitude * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); + } + else { + noiseFuzz = 1; + } + + if (noiseFuzz < minRadius) { + noiseFuzz = minRadius; + } if (equationResult <= noiseFuzz) { unitReplace(rel); } @@ -129,15 +146,17 @@ public void build() { } private void unitReplace(@NotNull SimpleBlock rel) { - if(!hardReplace && rel.isSolid()) { + if (!hardReplace && rel.isSolid()) { return; } rel.setType(GenUtils.randChoice(random, types)); - if(upperType != null) + if (upperType != null) { rel.getUp().lsetType(upperType); - if(lowerType != null && rel.getDown().isSolid()) + } + if (lowerType != null && rel.getDown().isSolid()) { rel.getDown().setType(lowerType); + } } } diff --git a/common/src/main/java/org/terraform/utils/GenUtils.java b/common/src/main/java/org/terraform/utils/GenUtils.java index 85d28f66..765be391 100644 --- a/common/src/main/java/org/terraform/utils/GenUtils.java +++ b/common/src/main/java/org/terraform/utils/GenUtils.java @@ -18,57 +18,55 @@ import org.terraform.small_items.PlantBuilder; import org.terraform.utils.noise.FastNoise; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.List; -import java.util.Random; +import java.util.*; public class GenUtils { public static final Random RANDOMIZER = new Random(); private static final EnumSet BLACKLIST_HIGHEST_GROUND = EnumSet.noneOf(Material.class); + public static LoadingCache> biomeQueryCache; + public static void initGenUtils() { - // Initialize highest ground blacklist - for(Material mat:Material.values()) { - if(mat.toString().contains("LEAVES") - || mat.toString().contains("LOG") - || mat.toString().contains("WOOD") - || mat.toString().contains("MUSHROOM") - || mat.toString().contains("FENCE") - || mat.toString().contains("WALL") - || mat.toString().contains("POTTED") - || mat.toString().contains("BRICK") - || mat.toString().contains("CHAIN") - || mat.toString().contains("CORAL") - || mat.toString().contains("POINTED_DRIPSTONE") - || mat.toString().contains("NETHERRACK") - || mat.toString().contains("MANGROVE") - || mat == Material.HAY_BLOCK - || mat == Material.ICE - || mat == Material.CACTUS - || mat == Material.BAMBOO - || mat == Material.BAMBOO_SAPLING - || mat == Material.IRON_BARS - || mat == Material.LANTERN - // || mat == Material.SNOW_BLOCK - // || mat == Material.PACKED_ICE - // || mat == Material.BLUE_ICE - ) { -// { -// "LEAVES", "LOG", -// "WOOD", "MUSHROOM", -// "FENCE", "WALL", -// "POTTED", "BRICK", -// "CHAIN", "CORAL", -// "POINTED_DRIPSTONE", -// "NETHERRACK" -// }; - BLACKLIST_HIGHEST_GROUND.add(mat); - } - } + // Initialize highest ground blacklist + for (Material mat : Material.values()) { + if (mat.toString().contains("LEAVES") + || mat.toString().contains("LOG") + || mat.toString().contains("WOOD") + || mat.toString().contains("MUSHROOM") + || mat.toString().contains("FENCE") + || mat.toString().contains("WALL") + || mat.toString().contains("POTTED") + || mat.toString().contains("BRICK") + || mat.toString().contains("CHAIN") + || mat.toString().contains("CORAL") + || mat.toString().contains("POINTED_DRIPSTONE") + || mat.toString().contains("NETHERRACK") + || mat.toString().contains("MANGROVE") + || mat == Material.HAY_BLOCK + || mat == Material.ICE + || mat == Material.CACTUS + || mat == Material.BAMBOO + || mat == Material.BAMBOO_SAPLING + || mat == Material.IRON_BARS + || mat == Material.LANTERN + // || mat == Material.SNOW_BLOCK + // || mat == Material.PACKED_ICE + // || mat == Material.BLUE_ICE + ) + { + // { + // "LEAVES", "LOG", + // "WOOD", "MUSHROOM", + // "FENCE", "WALL", + // "POTTED", "BRICK", + // "CHAIN", "CORAL", + // "POINTED_DRIPSTONE", + // "NETHERRACK" + // }; + BLACKLIST_HIGHEST_GROUND.add(mat); + } + } } - public static LoadingCache> biomeQueryCache; public static int getSign(@NotNull Random rand) { return rand.nextBoolean() ? 1 : -1; @@ -77,28 +75,43 @@ public static int getSign(@NotNull Random rand) { /** * This will now use StoneLike, and not just any solid block. */ - public static @NotNull Collection getCaveCeilFloors(PopulatorDataAbstract data, int x, int z, int minimumHeight) { - int y = data instanceof PopulatorDataSpigotAPI ? getTransformedHeight(data.getTerraformWorld(),x,z) : getHighestGround(data, x, z); + public static @NotNull Collection getCaveCeilFloors(PopulatorDataAbstract data, + int x, + int z, + int minimumHeight) + { + int y = data instanceof PopulatorDataSpigotAPI + ? getTransformedHeight(data.getTerraformWorld(), x, z) + : getHighestGround(data, x, z); int[] pair = {TerraformGeneratorPlugin.injector.getMinY() - 1, TerraformGeneratorPlugin.injector.getMinY() - 1}; List list = new ArrayList<>(); // Subtract one as the first cave floor cannot be the surface - for(int ny = y-1; ny > TerraformGeneratorPlugin.injector.getMinY(); ny--) { + for (int ny = y - 1; ny > TerraformGeneratorPlugin.injector.getMinY(); ny--) { Material type = data.getType(x, ny, z); - if(BlockUtils.isStoneLike(type)) { + if (BlockUtils.isStoneLike(type)) { pair[1] = ny; - if(pair[0] - pair[1] >= minimumHeight) list.add(pair); - pair = new int[] {TerraformGeneratorPlugin.injector.getMinY() - 1,TerraformGeneratorPlugin.injector.getMinY() - 1}; - } else if(pair[0] == TerraformGeneratorPlugin.injector.getMinY() - 1) + if (pair[0] - pair[1] >= minimumHeight) { + list.add(pair); + } + pair = new int[] { + TerraformGeneratorPlugin.injector.getMinY() - 1, + TerraformGeneratorPlugin.injector.getMinY() - 1 + }; + } + else if (pair[0] == TerraformGeneratorPlugin.injector.getMinY() - 1) { pair[0] = ny; + } } return list; } public static int[] randomCoords(@NotNull Random rand, int @NotNull [] lowBound, int @NotNull [] highBound) { - return new int[] {randInt(rand, lowBound[0], highBound[0]), + return new int[] { + randInt(rand, lowBound[0], highBound[0]), randInt(rand, lowBound[1], highBound[1]), - randInt(rand, lowBound[2], highBound[2])}; + randInt(rand, lowBound[2], highBound[2]) + }; } public static boolean chance(@NotNull Random rand, int chance, int outOf) { @@ -125,19 +138,26 @@ public static boolean chance(int chance, int outOf) { * * @return Position for the biome or null if no biomes found. */ - public static @Nullable Vector2f locateHeightDependentBiome(@NotNull TerraformWorld tw, @NotNull BiomeBank biome, @NotNull Vector2f center, int radius, int blockSkip) { - if(!BiomeBank.isBiomeEnabled(biome)) return null; - if(tw.getBiomeBank(Math.round(center.x), Math.round(center.y)) == biome) + public static @Nullable Vector2f locateHeightDependentBiome(@NotNull TerraformWorld tw, + @NotNull BiomeBank biome, + @NotNull Vector2f center, + int radius, + int blockSkip) + { + if (!BiomeBank.isBiomeEnabled(biome)) { + return null; + } + if (tw.getBiomeBank(Math.round(center.x), Math.round(center.y)) == biome) { return new Vector2f(center.x, center.y); + } int iter = 2; int x = (int) center.x; int z = (int) center.y; - while(Math.abs(center.x - x) < radius - || Math.abs(center.y - z) < radius) { - for(int i = 0; i < iter / 2; i++) { - switch(iter % 4) { + while (Math.abs(center.x - x) < radius || Math.abs(center.y - z) < radius) { + for (int i = 0; i < iter / 2; i++) { + switch (iter % 4) { case 0 -> x += blockSkip; case 1 -> z -= blockSkip; case 2 -> x -= blockSkip; @@ -145,42 +165,57 @@ public static boolean chance(int chance, int outOf) { } } - if(tw.getBiomeBank(x, z) == biome) return new Vector2f(x, z); + if (tw.getBiomeBank(x, z) == biome) { + return new Vector2f(x, z); + } iter++; } return null; } - + /** * Locates a biome with BiomeSection. * WILL NOT FIND RIVERS AND BEACHES. * Does not stop until biome is found, much like structure locate, because it should work. */ - public static @Nullable Vector2f locateHeightIndependentBiome(TerraformWorld tw, @NotNull BiomeBank biome, @NotNull Vector2f centerBlockLocation) { - if(!BiomeBank.isBiomeEnabled(biome)) return null; - - BiomeSection center = BiomeBank.getBiomeSectionFromBlockCoords(tw, (int) centerBlockLocation.x, (int) centerBlockLocation.y); - int radius = 0; - - while(true) { - for(BiomeSection sect:center.getRelativeSurroundingSections(radius)) { - if(sect.getBiomeBank() == biome) { - SimpleLocation sectionCenter = sect.getCenter(); - return new Vector2f(sectionCenter.getX(),sectionCenter.getZ()); - } - radius++; - } - } + public static @Nullable Vector2f locateHeightIndependentBiome(TerraformWorld tw, + @NotNull BiomeBank biome, + @NotNull Vector2f centerBlockLocation) + { + if (!BiomeBank.isBiomeEnabled(biome)) { + return null; + } + + BiomeSection center = BiomeBank.getBiomeSectionFromBlockCoords( + tw, + (int) centerBlockLocation.x, + (int) centerBlockLocation.y + ); + int radius = 0; + + while (true) { + for (BiomeSection sect : center.getRelativeSurroundingSections(radius)) { + if (sect.getBiomeBank() == biome) { + SimpleLocation sectionCenter = sect.getCenter(); + return new Vector2f(sectionCenter.getX(), sectionCenter.getZ()); + } + radius++; + } + } } public static Object weightedChoice(@NotNull Random rand, Object @NotNull ... candidates) { - if(candidates.length % 2 != 0) throw new IllegalArgumentException(); + if (candidates.length % 2 != 0) { + throw new IllegalArgumentException(); + } ArrayList types = new ArrayList<>(50); - for(int i = 0; i < candidates.length; i+=2) { + for (int i = 0; i < candidates.length; i += 2) { Object type = candidates[i]; - int freq = (int) candidates[i+1]; - for(int z = 0; z < freq; z++) types.add(type); + int freq = (int) candidates[i + 1]; + for (int z = 0; z < freq; z++) { + types.add(type); + } } return types.get(randInt(rand, 0, types.size() - 1)); @@ -196,7 +231,9 @@ public static Material weightedRandomMaterial(@NotNull Random rand, Object @NotN @SafeVarargs public static T randChoice(@NotNull Random rand, T @NotNull ... candidates) { - if(candidates.length == 1) return candidates[0]; // avoid invocation to randInt + if (candidates.length == 1) { + return candidates[0]; // avoid invocation to randInt + } return candidates[randInt(rand, 0, candidates.length - 1)]; } @@ -230,20 +267,24 @@ public static int[] randomSurfaceCoordinates(@NotNull Random rand, @NotNull Popu } public static int randInt(int min, int max) { - if(min == max) return min; + if (min == max) { + return min; + } return randInt(RANDOMIZER, min, max); } public static int randInt(@NotNull Random rand, int d, int max) { - if(d == max) return d; + if (d == max) { + return d; + } boolean negative = false; - if(d < 0 && max < 0) { + if (d < 0 && max < 0) { negative = true; d = -d; max = -max; } - if(max < d) { + if (max < d) { int temp = d; d = max; max = temp; @@ -258,8 +299,10 @@ public static int randInt(@NotNull Random rand, int d, int max) { */ public static int randOddInt(@NotNull Random rand, int min, int max) { int randomNum = rand.nextInt((max - min) + 1) + min; - if(randomNum % 2 == 0) { - if(randomNum++ > max) randomNum -= 2; + if (randomNum % 2 == 0) { + if (randomNum++ > max) { + randomNum -= 2; + } } return randomNum; } @@ -267,9 +310,12 @@ public static int randOddInt(@NotNull Random rand, int min, int max) { public static double randDouble(@NotNull Random rand, double min, double max) { return rand.nextDouble() * (max - min) + min; } + public static int getHighestX(@NotNull PopulatorDataAbstract data, int x, int z, Material X) { int y = TerraformGeneratorPlugin.injector.getMaxY() - 1; - while(y > TerraformGeneratorPlugin.injector.getMinY() && data.getType(x, y, z) != X) y--; + while (y > TerraformGeneratorPlugin.injector.getMinY() && data.getType(x, y, z) != X) { + y--; + } return y; } @@ -278,55 +324,61 @@ public static int getHighestX(@NotNull PopulatorDataAbstract data, int x, int z, * @return the highest solid block */ public static int getTrueHighestBlock(@NotNull PopulatorDataAbstract data, int x, int z) { - int y = TerraformGeneratorPlugin.injector.getMaxY()-1; - while(y > TerraformGeneratorPlugin.injector.getMinY() && !data.getType(x, y, z).isSolid()) y--; + int y = TerraformGeneratorPlugin.injector.getMaxY() - 1; + while (y > TerraformGeneratorPlugin.injector.getMinY() && !data.getType(x, y, z).isSolid()) { + y--; + } return y; } - + /** - * * @return the highest dry ground, or the sea level */ public static int getHighestGroundOrSeaLevel(PopulatorDataAbstract data, int x, int z) { - int y = getHighestGround(data,x,z); + int y = getHighestGround(data, x, z); return Math.max(y, TerraformGenerator.seaLevel); } - + /** * @return the highest solid block below y */ public static int getTrueHighestBlockBelow(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - while(y > TerraformGeneratorPlugin.injector.getMinY() && !data.getType(x, y, z).isSolid()) y--; + while (y > TerraformGeneratorPlugin.injector.getMinY() && !data.getType(x, y, z).isSolid()) { + y--; + } return y; } public static @NotNull SimpleBlock getTrueHighestBlockBelow(@NotNull SimpleBlock block) { int y = block.getY(); - while(y > TerraformGeneratorPlugin.injector.getMinY() && !block.getPopData().getType(block.getX(), y, block.getZ()).isSolid()) y--; + while (y > TerraformGeneratorPlugin.injector.getMinY() && !block.getPopData() + .getType(block.getX(), y, block.getZ()) + .isSolid()) { + y--; + } return new SimpleBlock(block.getPopData(), block.getX(), y, block.getZ()); } - public static boolean isGroundLike(@NotNull Material mat) { - // Ice is considered stone-like, but not in a million years is it ground. - if(BlockUtils.isStoneLike(mat) - && mat != Material.PACKED_ICE - && mat != Material.BLUE_ICE) - return true; - if(mat == Material.SAND - || mat == Material.RED_SAND - || mat == Material.GRAVEL) - return true; + public static boolean isGroundLike(@NotNull Material mat) { + // Ice is considered stone-like, but not in a million years is it ground. + if (BlockUtils.isStoneLike(mat) && mat != Material.PACKED_ICE && mat != Material.BLUE_ICE) { + return true; + } + if (mat == Material.SAND || mat == Material.RED_SAND || mat == Material.GRAVEL) { + return true; + } - if(mat.isSolid()) { - if(mat.isInteractable()) { + if (mat.isSolid()) { + if (mat.isInteractable()) { return false; } - if(Tag.SLABS.isTagged(mat)) { - return false; + if (Tag.SLABS.isTagged(mat)) { + return false; } return !BLACKLIST_HIGHEST_GROUND.contains(mat); - } else { + } + else { return false; } } @@ -340,10 +392,10 @@ public static boolean isGroundLike(@NotNull Material mat) { public static int getTransformedHeight(@NotNull TerraformWorld tw, int rawX, int rawZ) { ChunkCache cache = TerraformGenerator.getCache(tw, rawX, rawZ); - int cachedY = cache.getTransformedHeight(rawX&0xF, rawZ&0xF); - if(cachedY == TerraformGeneratorPlugin.injector.getMinY()-1){ - TerraformGenerator.buildFilledCache(tw, rawX>>4,rawZ>>4, cache); - cachedY = cache.getTransformedHeight(rawX&0xF, rawZ&0xF); + int cachedY = cache.getTransformedHeight(rawX & 0xF, rawZ & 0xF); + if (cachedY == TerraformGeneratorPlugin.injector.getMinY() - 1) { + TerraformGenerator.buildFilledCache(tw, rawX >> 4, rawZ >> 4, cache); + cachedY = cache.getTransformedHeight(rawX & 0xF, rawZ & 0xF); } return cachedY; } @@ -362,50 +414,62 @@ public static int getTransformedHeight(@NotNull TerraformWorld tw, int rawX, int */ public static int getHighestGround(PopulatorDataAbstract data, int x, int z) { // If you're too lazy to bother then just do this - if(data instanceof PopulatorDataSpigotAPI) - return getTransformedHeight(data.getTerraformWorld(),x,z); - - int y = TerraformGeneratorPlugin.injector.getMaxY()-1; - ChunkCache cache = TerraformGenerator.getCache(data.getTerraformWorld(), x, z); - int cachedY = cache.getHighestGround(x, z); - if(cachedY != TerraformGeneratorPlugin.injector.getMinY()-1) { - // Basic check to ensure block above is not ground - // and current block is ground. - // Will fail if the new ground is an overhang of some kind. - if(isGroundLike(data.getType(x, cachedY, z)) - && !isGroundLike(data.getType(x, cachedY+1, z))) { + if (data instanceof PopulatorDataSpigotAPI) { + return getTransformedHeight(data.getTerraformWorld(), x, z); + } + + int y = TerraformGeneratorPlugin.injector.getMaxY() - 1; + ChunkCache cache = TerraformGenerator.getCache(data.getTerraformWorld(), x, z); + int cachedY = cache.getHighestGround(x, z); + if (cachedY != TerraformGeneratorPlugin.injector.getMinY() - 1) { + // Basic check to ensure block above is not ground + // and current block is ground. + // Will fail if the new ground is an overhang of some kind. + if (isGroundLike(data.getType(x, cachedY, z)) && !isGroundLike(data.getType(x, cachedY + 1, z))) { return cache.getHighestGround(x, z); } - } + } - while(y > TerraformGeneratorPlugin.injector.getMinY()) { + while (y > TerraformGeneratorPlugin.injector.getMinY()) { Material block = data.getType(x, y, z); - if(!isGroundLike(block)) { - y--; - continue; + if (!isGroundLike(block)) { + y--; + continue; } break; } - if(y <= TerraformGeneratorPlugin.injector.getMinY()) { - TerraformGeneratorPlugin.logger.error("GetHighestGround returned less than " + TerraformGeneratorPlugin.injector.getMinY() + "! (" + y + ")"); - try { throw new Exception("GetHighestGround returned less than " + TerraformGeneratorPlugin.injector.getMinY() + "! (" + y + ")"); } + if (y <= TerraformGeneratorPlugin.injector.getMinY()) { + TerraformGeneratorPlugin.logger.error("GetHighestGround returned less than " + + TerraformGeneratorPlugin.injector.getMinY() + + "! (" + + y + + ")"); + try { + throw new Exception("GetHighestGround returned less than " + + TerraformGeneratorPlugin.injector.getMinY() + + "! (" + + y + + ")"); + } catch (Exception e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } - + // Y can be stored as a short, as there's no way world height will be 32k. cache.cacheHighestGround(x, z, Integer.valueOf(y).shortValue()); return y; } - public static Material @NotNull [] mergeArr(@NotNull Material[] ... arrs) { + public static Material @NotNull [] mergeArr(@NotNull Material[]... arrs) { int totalLength = 0, index = 0; - for(Material[] arr : arrs) totalLength += arr.length; + for (Material[] arr : arrs) { + totalLength += arr.length; + } Material[] res = new Material[totalLength]; - for(Material[] arr : arrs) { - for(Material mat : arr) { + for (Material[] arr : arrs) { + for (Material mat : arr) { res[index++] = mat; } } @@ -424,7 +488,12 @@ public static int getHighestGround(PopulatorDataAbstract data, int x, int z) { * @param maxPerturbation Max amount a point can move in each axis * @return Array of points */ - public static Vector2f @NotNull [] vectorRandomObjectPositions(int seed, int chunkX, int chunkZ, int distanceBetween, float maxPerturbation) { + public static Vector2f @NotNull [] vectorRandomObjectPositions(int seed, + int chunkX, + int chunkZ, + int distanceBetween, + float maxPerturbation) + { FastNoise noise = new FastNoise(seed); noise.SetFrequency(1); @@ -444,66 +513,101 @@ public static int getHighestGround(PopulatorDataAbstract data, int x, int z) { // Also checks if points from chunks close by are perturbed to this chunk for (int x = startX - distanceBetween; x < startX + 16 + distanceBetween; x += distanceBetween) { - for(int z = startZ - distanceBetween; z < startZ + 16 + distanceBetween; z += distanceBetween) { + for (int z = startZ - distanceBetween; z < startZ + 16 + distanceBetween; z += distanceBetween) { Vector2f v = new Vector2f(x, z); noise.GradientPerturb(v); v.x = Math.round(v.x); v.y = Math.round(v.y); // If perturbed vector is inside chunk - if (v.x >= (chunkX << 4) && v.x < (chunkX << 4) + 16 && - v.y >= (chunkZ << 4) && v.y < (chunkZ << 4) + 16 ) + if (v.x >= (chunkX << 4) + && v.x < (chunkX << 4) + 16 + && v.y >= (chunkZ << 4) + && v.y < (chunkZ << 4) + 16) + { positions.add(v); + } } } return positions.toArray(new Vector2f[0]); } - public static SimpleLocation @NotNull [] randomObjectPositions(@NotNull TerraformWorld world, int chunkX, int chunkZ, int distanceBetween) { - Vector2f[] vecs = vectorRandomObjectPositions((int)world.getSeed(), chunkX, chunkZ, distanceBetween, 0.35f * distanceBetween); + public static SimpleLocation @NotNull [] randomObjectPositions(@NotNull TerraformWorld world, + int chunkX, + int chunkZ, + int distanceBetween) + { + Vector2f[] vecs = vectorRandomObjectPositions( + (int) world.getSeed(), + chunkX, + chunkZ, + distanceBetween, + 0.35f * distanceBetween + ); SimpleLocation[] locs = new SimpleLocation[vecs.length]; - - for(int i = 0; i < vecs.length; i++) { - locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); - } - + + for (int i = 0; i < vecs.length; i++) { + locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); + } + return locs; } /** - * * @param pertubMultiplier is normally 0.35. */ - public static SimpleLocation @NotNull [] randomObjectPositions(@NotNull TerraformWorld world, int chunkX, int chunkZ, int distanceBetween, float pertubMultiplier) { - Vector2f[] vecs = vectorRandomObjectPositions((int)world.getSeed(), chunkX, chunkZ, distanceBetween, pertubMultiplier * distanceBetween); + public static SimpleLocation @NotNull [] randomObjectPositions(@NotNull TerraformWorld world, + int chunkX, + int chunkZ, + int distanceBetween, + float pertubMultiplier) + { + Vector2f[] vecs = vectorRandomObjectPositions( + (int) world.getSeed(), + chunkX, + chunkZ, + distanceBetween, + pertubMultiplier * distanceBetween + ); SimpleLocation[] locs = new SimpleLocation[vecs.length]; - - for(int i = 0; i < vecs.length; i++) { - locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); - } - + + for (int i = 0; i < vecs.length; i++) { + locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); + } + return locs; } - + /** - * - * @param seed for tighter control between points + * @param seed for tighter control between points * @param pertubMultiplier is normally 0.35. */ - public static SimpleLocation @NotNull [] randomObjectPositions(int seed, int chunkX, int chunkZ, int distanceBetween, float pertubMultiplier) { - Vector2f[] vecs = vectorRandomObjectPositions(seed, chunkX, chunkZ, distanceBetween, pertubMultiplier * distanceBetween); + public static SimpleLocation @NotNull [] randomObjectPositions(int seed, + int chunkX, + int chunkZ, + int distanceBetween, + float pertubMultiplier) + { + Vector2f[] vecs = vectorRandomObjectPositions( + seed, + chunkX, + chunkZ, + distanceBetween, + pertubMultiplier * distanceBetween + ); SimpleLocation[] locs = new SimpleLocation[vecs.length]; - - for(int i = 0; i < vecs.length; i++) { - locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); - } - + + for (int i = 0; i < vecs.length; i++) { + locs[i] = new SimpleLocation((int) vecs[i].x, 0, (int) vecs[i].y); + } + return locs; } /** * Random-angle + * * @return An angle between lowerBound*base to upperBound*base degrees in radians */ public static double randAngle(double base, double lowerBound, double upperBound) { @@ -512,18 +616,25 @@ public static double randAngle(double base, double lowerBound, double upperBound public static @Nullable T choice(@NotNull Random rand, T @NotNull [] array) { - if(array.length == 0) return null; - if(array.length == 1) return array[0]; + if (array.length == 0) { + return null; + } + if (array.length == 1) { + return array[0]; + } return array[rand.nextInt(array.length)]; } /** * Gets the center chunk of a hypothetically split limited region of 3x3 chunks + * * @return a chunk coordinate */ - public static int getTripleChunk(int chunkCoord){ - if(chunkCoord >= 0) return 1+3*(chunkCoord/3); + public static int getTripleChunk(int chunkCoord) { + if (chunkCoord >= 0) { + return 1 + 3 * (chunkCoord / 3); + } - return 1+3*(-1+(chunkCoord+1)/3); + return 1 + 3 * (-1 + (chunkCoord + 1) / 3); } } diff --git a/common/src/main/java/org/terraform/utils/MazeSpawner.java b/common/src/main/java/org/terraform/utils/MazeSpawner.java index 7431c63e..113ba771 100644 --- a/common/src/main/java/org/terraform/utils/MazeSpawner.java +++ b/common/src/main/java/org/terraform/utils/MazeSpawner.java @@ -9,25 +9,17 @@ import org.terraform.structure.room.PathPopulatorAbstract; import org.terraform.structure.room.PathPopulatorData; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Random; -import java.util.Set; -import java.util.Stack; public class MazeSpawner { + public final @NotNull List pathPopDatas = new ArrayList<>(); /** * A hashmap of raw location 2d x,z arrays to maze cells. * SIMPLE LOCATION HERE REFERS TO MAZECELL RELATIVE COORDINATES, * NOT REAL IN-WORLD COORDS. */ private final Map cellGrid = new HashMap<>(); - public final @NotNull List pathPopDatas = new ArrayList<>(); private SimpleBlock core; // Maze center private int widthX = -1; // Maze x width private int widthZ = -1; // Maze z width @@ -80,7 +72,7 @@ public void prepareMaze() { // Initialise the cellGrid int mazeCellsWidthX = widthX / (mazePathWidth + mazePeriod); int mazeCellsWidthZ = widthZ / (mazePathWidth + mazePeriod); - for (int x = -mazeCellsWidthX / 2; x <= mazeCellsWidthX / 2; x++) + for (int x = -mazeCellsWidthX / 2; x <= mazeCellsWidthX / 2; x++) { for (int z = -mazeCellsWidthZ / 2; z <= mazeCellsWidthZ / 2; z++) { MazeCell cell = new MazeCell(x, z); cellGrid.put(new SimpleLocation(x, core.getY(), z), cell); @@ -89,6 +81,7 @@ public void prepareMaze() { center = cell; } } + } // Bukkit.getLogger().info("CENTER: " + center.x + "," + center.z); @@ -109,17 +102,17 @@ public void prepareMaze() { // Dead end. Go backwards. // No items in stack, break out. - if (cellStack.isEmpty()) break; + if (cellStack.isEmpty()) { + break; + } currentCell = cellStack.pop(); continue; } // choose a random neighbouring cell and move into it. - @SuppressWarnings("unchecked") - Entry entry = (Entry) - neighbours.entrySet().toArray()[ - rand.nextInt(neighbours.size()) - ]; + @SuppressWarnings("unchecked") Entry entry = (Entry) neighbours.entrySet() + .toArray()[rand.nextInt( + neighbours.size())]; currentCell.knockDownWall(entry.getValue(), entry.getKey()); cellStack.push(currentCell); @@ -132,6 +125,7 @@ public void prepareMaze() { /** * Carve a maze according to the provided parameters + * * @param carveInSolid whether or not the maze is to be carved into a solid, or if walls must be created. * @materials if carveInSolid is false, supply a list of materials to use for walls. */ @@ -160,8 +154,10 @@ public void carveMaze(boolean carveInSolid, Material... materials) { // Connect for (BlockFace dir : BlockUtils.directBlockFaces) { - Wall startPoint = new Wall(core.getRelative(realWorldX, 0, realWorldZ), dir) - .getRelative(dir, cellRadius + 1); + Wall startPoint = new Wall(core.getRelative(realWorldX, 0, realWorldZ), dir).getRelative( + dir, + cellRadius + 1 + ); // Carve Pathway if (wallllllllless.contains(dir)) { @@ -179,15 +175,20 @@ public void carveMaze(boolean carveInSolid, Material... materials) { if (covered) { startPoint.getLeft(w).getDown().setType(GenUtils.randChoice(materials)); startPoint.getRight(w).getDown().setType(GenUtils.randChoice(materials)); - startPoint.getLeft(w).getRelative(0, mazeHeight, 0).setType(GenUtils.randChoice(materials)); - startPoint.getRight(w).getRelative(0, mazeHeight, 0).setType(GenUtils.randChoice(materials)); + startPoint.getLeft(w) + .getRelative(0, mazeHeight, 0) + .setType(GenUtils.randChoice(materials)); + startPoint.getRight(w) + .getRelative(0, mazeHeight, 0) + .setType(GenUtils.randChoice(materials)); } } startPoint.getLeft(cellRadius + 1).Pillar(mazeHeight, rand, materials); startPoint.getRight(cellRadius + 1).Pillar(mazeHeight, rand, materials); startPoint = startPoint.getRelative(dir); } - } else { // Set Wall + } + else { // Set Wall startPoint.Pillar(mazeHeight, rand, materials); for (int w = 1; w <= cellRadius; w++) { startPoint.getLeft(w).Pillar(mazeHeight, rand, materials); @@ -259,7 +260,9 @@ public int getMazePathWidth() { } public void setMazePathWidth(int mazePathWidth) { - if (mazePathWidth % 2 == 0) throw new IllegalArgumentException("Maze Path Width must be odd!"); + if (mazePathWidth % 2 == 0) { + throw new IllegalArgumentException("Maze Path Width must be odd!"); + } this.mazePathWidth = mazePathWidth; } @@ -311,14 +314,19 @@ public MazeCell(int x, int z) { public @NotNull Set getWalllessFaces() { Set faces = EnumSet.noneOf(BlockFace.class); for (Entry entry : walls.entrySet()) { - if (!entry.getValue()) faces.add(entry.getKey()); + if (!entry.getValue()) { + faces.add(entry.getKey()); + } } return faces; } public boolean hasAllWalls() { - for (Boolean bool : walls.values()) - if (!bool) return false; + for (Boolean bool : walls.values()) { + if (!bool) { + return false; + } + } return true; } diff --git a/common/src/main/java/org/terraform/utils/PaintingUtils.java b/common/src/main/java/org/terraform/utils/PaintingUtils.java index 170a18dd..cb408507 100644 --- a/common/src/main/java/org/terraform/utils/PaintingUtils.java +++ b/common/src/main/java/org/terraform/utils/PaintingUtils.java @@ -1,7 +1,5 @@ package org.terraform.utils; -import java.util.Random; - import org.bukkit.Art; import org.bukkit.Location; import org.bukkit.block.BlockFace; @@ -12,78 +10,72 @@ import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleBlock; +import java.util.Random; + public class PaintingUtils { - public static void placePainting(@NotNull SimpleBlock target, @NotNull BlockFace facing, @NotNull Art art) { - if(target.getPopData() instanceof PopulatorDataPostGen) { - try { - PopulatorDataPostGen postGen = ((PopulatorDataPostGen) target.getPopData()); - Painting painting = (Painting) postGen.getWorld().spawnEntity(new Location(postGen.getWorld(), - target.getX(), target.getY(), target.getZ()), EntityType.PAINTING); - painting.setFacingDirection(facing); - painting.setPersistent(true); - painting.setArt(art); - } - catch(IllegalArgumentException e) - { - // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(e); - // Area is occupied by another entity. Fail silently. - } - } - } - - public static @Nullable Art getArtFromDimensions(@NotNull Random rand, int sizeHor, int sizeVert) { - Art[] candidates = null; - if(sizeHor == 1 && sizeVert == 1) { - candidates = new Art[] { - Art.ALBAN, - Art.AZTEC, - Art.AZTEC2, - Art.BOMB, - Art.KEBAB, - Art.PLANT, - Art.WASTELAND - }; - }else if(sizeHor == 2 && sizeVert == 1) { - candidates = new Art[] { - Art.COURBET, - Art.POOL, - Art.SEA, - Art.CREEBET, - Art.SUNSET - }; - }else if(sizeHor == 1 && sizeVert == 2) { - candidates = new Art[] { - Art.GRAHAM, - Art.WANDERER - }; - }else if(sizeHor == 2 && sizeVert == 2) { - candidates = new Art[] { - Art.BUST, - Art.MATCH, - Art.SKULL_AND_ROSES, - Art.STAGE, - Art.VOID, - Art.WITHER - }; - }else if(sizeHor == 4 && sizeVert == 2) { - candidates = new Art[] { - Art.FIGHTERS - }; - }else if(sizeHor == 4 && sizeVert == 3) { - candidates = new Art[] { - Art.DONKEY_KONG, - Art.SKELETON - }; - }else if(sizeHor == 4 && sizeVert == 4) { - candidates = new Art[] { - Art.BURNING_SKULL, - Art.PIGSCENE, - Art.POINTER - }; - } - if(candidates == null) return null; - return candidates[rand.nextInt(candidates.length)]; - } - + public static void placePainting(@NotNull SimpleBlock target, @NotNull BlockFace facing, @NotNull Art art) { + if (target.getPopData() instanceof PopulatorDataPostGen) { + try { + PopulatorDataPostGen postGen = ((PopulatorDataPostGen) target.getPopData()); + Painting painting = (Painting) postGen.getWorld() + .spawnEntity(new Location(postGen.getWorld(), + target.getX(), + target.getY(), + target.getZ() + ), EntityType.PAINTING); + painting.setFacingDirection(facing); + painting.setPersistent(true); + painting.setArt(art); + } + catch (IllegalArgumentException e) { + // TerraformGeneratorPlugin.TerraformGeneratorPlugin.logger.stackTrace(e); + // Area is occupied by another entity. Fail silently. + } + } + } + + public static @Nullable Art getArtFromDimensions(@NotNull Random rand, int sizeHor, int sizeVert) { + Art[] candidates = null; + if (sizeHor == 1 && sizeVert == 1) { + candidates = new Art[] { + Art.ALBAN, Art.AZTEC, Art.AZTEC2, Art.BOMB, Art.KEBAB, Art.PLANT, Art.WASTELAND + }; + } + else if (sizeHor == 2 && sizeVert == 1) { + candidates = new Art[] { + Art.COURBET, Art.POOL, Art.SEA, Art.CREEBET, Art.SUNSET + }; + } + else if (sizeHor == 1 && sizeVert == 2) { + candidates = new Art[] { + Art.GRAHAM, Art.WANDERER + }; + } + else if (sizeHor == 2 && sizeVert == 2) { + candidates = new Art[] { + Art.BUST, Art.MATCH, Art.SKULL_AND_ROSES, Art.STAGE, Art.VOID, Art.WITHER + }; + } + else if (sizeHor == 4 && sizeVert == 2) { + candidates = new Art[] { + Art.FIGHTERS + }; + } + else if (sizeHor == 4 && sizeVert == 3) { + candidates = new Art[] { + Art.DONKEY_KONG, Art.SKELETON + }; + } + else if (sizeHor == 4 && sizeVert == 4) { + candidates = new Art[] { + Art.BURNING_SKULL, Art.PIGSCENE, Art.POINTER + }; + } + if (candidates == null) { + return null; + } + return candidates[rand.nextInt(candidates.length)]; + } + } diff --git a/common/src/main/java/org/terraform/utils/Range.java b/common/src/main/java/org/terraform/utils/Range.java index cd14278c..04094f68 100644 --- a/common/src/main/java/org/terraform/utils/Range.java +++ b/common/src/main/java/org/terraform/utils/Range.java @@ -37,29 +37,52 @@ */ public final class Range implements Serializable { - @SuppressWarnings({"rawtypes", "unchecked"}) - private enum ComparableComparator implements Comparator { - INSTANCE; - - /** - * Comparable based compare implementation. - * - * @param obj1 left hand side of comparison - * @param obj2 right hand side of comparison - * @return negative, 0, positive comparison value - */ - @Override - public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { - return ((Comparable) obj1).compareTo(obj2); - } - } - /** * Serialization version. * * @see java.io.Serializable */ private static final long serialVersionUID = 1L; + /** + * The ordering scheme used in this range. + */ + private final @NotNull Comparator comparator; + /** + * The maximum value in this range (inclusive). + */ + private final @NotNull T maximum; + /** + * The minimum value in this range (inclusive). + */ + private final @NotNull T minimum; + /** + * Cached output hashCode (class is immutable). + */ + private transient int hashCode; + /** + * Cached output toString (class is immutable). + */ + private transient String toString; + + /** + * Creates an instance. + * + * @param element1 the first element, not null + * @param element2 the second element, not null + * @param comp the comparator to be used, null for natural ordering + */ + @SuppressWarnings("unchecked") + private Range(final @NotNull T element1, final @NotNull T element2, final @Nullable Comparator comp) { + this.comparator = Objects.requireNonNullElse(comp, ComparableComparator.INSTANCE); + if (this.comparator.compare(element1, element2) < 1) { + this.minimum = element1; + this.maximum = element2; + } + else { + this.minimum = element2; + this.maximum = element1; + } + } /** *

    Obtains a range with the specified minimum and maximum values (both inclusive).

    @@ -70,14 +93,16 @@ public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { *

    The arguments may be passed in the order (min,max) or (max,min). * The getMinimum and getMaximum methods will return the correct values.

    * - * @param the type of the elements in this range - * @param fromInclusive the first value that defines the edge of the range, inclusive - * @param toInclusive the second value that defines the edge of the range, inclusive + * @param the type of the elements in this range + * @param fromInclusive the first value that defines the edge of the range, inclusive + * @param toInclusive the second value that defines the edge of the range, inclusive * @return the range object, not null * @throws IllegalArgumentException if either element is null - * @throws ClassCastException if the elements are not {@code Comparable} + * @throws ClassCastException if the elements are not {@code Comparable} */ - public static > @NotNull Range between(final @NotNull T fromInclusive, final @NotNull T toInclusive) { + public static > @NotNull Range between(final @NotNull T fromInclusive, + final @NotNull T toInclusive) + { return between(fromInclusive, toInclusive, null); } @@ -90,15 +115,18 @@ public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { *

    The arguments may be passed in the order (min,max) or (max,min). * The getMinimum and getMaximum methods will return the correct values.

    * - * @param the type of the elements in this range - * @param fromInclusive the first value that defines the edge of the range, inclusive - * @param toInclusive the second value that defines the edge of the range, inclusive - * @param comparator the comparator to be used, null for natural ordering + * @param the type of the elements in this range + * @param fromInclusive the first value that defines the edge of the range, inclusive + * @param toInclusive the second value that defines the edge of the range, inclusive + * @param comparator the comparator to be used, null for natural ordering * @return the range object, not null * @throws IllegalArgumentException if either element is null - * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} + * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} */ - public static @NotNull Range between(final @NotNull T fromInclusive, final @NotNull T toInclusive, @Nullable final Comparator comparator) { + public static @NotNull Range between(final @NotNull T fromInclusive, + final @NotNull T toInclusive, + @Nullable final Comparator comparator) + { return new Range<>(fromInclusive, toInclusive, comparator); } @@ -109,11 +137,11 @@ public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { *

    The range uses the natural ordering of the elements to determine where * values lie in the range.

    * - * @param the type of the elements in this range - * @param element the value to use for this range, not null + * @param the type of the elements in this range + * @param element the value to use for this range, not null * @return the range object, not null * @throws IllegalArgumentException if the element is null - * @throws ClassCastException if the element is not {@code Comparable} + * @throws ClassCastException if the element is not {@code Comparable} */ public static > @NotNull Range is(final @NotNull T element) { return between(element, element, null); @@ -126,65 +154,21 @@ public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { *

    The range uses the specified {@code Comparator} to determine where * values lie in the range.

    * - * @param the type of the elements in this range - * @param element the value to use for this range, must not be {@code null} - * @param comparator the comparator to be used, null for natural ordering + * @param the type of the elements in this range + * @param element the value to use for this range, must not be {@code null} + * @param comparator the comparator to be used, null for natural ordering * @return the range object, not null * @throws IllegalArgumentException if the element is null - * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} + * @throws ClassCastException if using natural ordering and the elements are not {@code Comparable} */ public static @NotNull Range is(final @NotNull T element, final Comparator comparator) { return between(element, element, comparator); } - /** - * The ordering scheme used in this range. - */ - private final @NotNull Comparator comparator; - - /** - * Cached output hashCode (class is immutable). - */ - private transient int hashCode; - - /** - * The maximum value in this range (inclusive). - */ - private final @NotNull T maximum; - - /** - * The minimum value in this range (inclusive). - */ - private final @NotNull T minimum; - - /** - * Cached output toString (class is immutable). - */ - private transient String toString; - - /** - * Creates an instance. - * - * @param element1 the first element, not null - * @param element2 the second element, not null - * @param comp the comparator to be used, null for natural ordering - */ - @SuppressWarnings("unchecked") - private Range(final @NotNull T element1, final @NotNull T element2, final @Nullable Comparator comp) { - this.comparator = Objects.requireNonNullElse(comp, ComparableComparator.INSTANCE); - if (this.comparator.compare(element1, element2) < 1) { - this.minimum = element1; - this.maximum = element2; - } else { - this.minimum = element2; - this.maximum = element1; - } - } - /** *

    Checks whether the specified element occurs within this range.

    * - * @param element the element to check for, null returns false + * @param element the element to check for, null returns false * @return true if the specified element occurs within this range */ public boolean contains(final @Nullable T element) { @@ -199,7 +183,7 @@ public boolean contains(final @Nullable T element) { * *

    This method may fail if the ranges have two different comparators or element types.

    * - * @param otherRange the range to check, null returns false + * @param otherRange the range to check, null returns false * @return true if this range contains the specified range * @throws RuntimeException if ranges cannot be compared */ @@ -207,8 +191,7 @@ public boolean containsRange(final @Nullable Range otherRange) { if (otherRange == null) { return false; } - return contains(otherRange.minimum) - && contains(otherRange.maximum); + return contains(otherRange.minimum) && contains(otherRange.maximum); } /** @@ -218,7 +201,7 @@ public boolean containsRange(final @Nullable Range otherRange) { * the element is before the range, {@code 0} if contained within the range and * {@code 1} if the element is after the range.

    * - * @param element the element to check for, not null + * @param element the element to check for, not null * @return -1, 0 or +1 depending on the element's location relative to the range */ public int elementCompareTo(final T element) { @@ -251,10 +234,8 @@ public boolean equals(final @Nullable Object obj) { return false; } @SuppressWarnings("unchecked") // OK because we checked the class above - final - Range range = (Range) obj; - return minimum.equals(range.minimum) && - maximum.equals(range.maximum); + final Range range = (Range) obj; + return minimum.equals(range.minimum) && maximum.equals(range.maximum); } /** @@ -274,6 +255,7 @@ public boolean equals(final @Nullable Object obj) { * range.fit(64) --> 64 * range.fit(99) --> 64 * + * * @param element the element to check for, not null * @return the minimum, the element, or the maximum depending on the element's location relative to the range * @since 3.10 @@ -340,6 +322,7 @@ public int hashCode() { /** * Calculate the intersection of {@code this} and an overlapping Range. + * * @param other overlapping Range * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal) * @throws IllegalArgumentException if {@code other} does not overlap {@code this} @@ -348,7 +331,9 @@ public int hashCode() { public @NotNull Range intersectionWith(final @NotNull Range other) { if (!this.isOverlappedBy(other)) { throw new IllegalArgumentException(String.format( - "Cannot calculate intersection with non-overlapping range %s", other)); + "Cannot calculate intersection with non-overlapping range %s", + other + )); } if (this.equals(other)) { return this; @@ -361,7 +346,7 @@ public int hashCode() { /** *

    Checks whether this range is after the specified element.

    * - * @param element the element to check for, null returns false + * @param element the element to check for, null returns false * @return true if this range is entirely after the specified element */ public boolean isAfter(final @Nullable T element) { @@ -376,7 +361,7 @@ public boolean isAfter(final @Nullable T element) { * *

    This method may fail if the ranges have two different comparators or element types.

    * - * @param otherRange the range to check, null returns false + * @param otherRange the range to check, null returns false * @return true if this range is completely after the specified range * @throws RuntimeException if ranges cannot be compared */ @@ -390,7 +375,7 @@ public boolean isAfterRange(final @Nullable Range otherRange) { /** *

    Checks whether this range is before the specified element.

    * - * @param element the element to check for, null returns false + * @param element the element to check for, null returns false * @return true if this range is entirely before the specified element */ public boolean isBefore(final @Nullable T element) { @@ -405,7 +390,7 @@ public boolean isBefore(final @Nullable T element) { * *

    This method may fail if the ranges have two different comparators or element types.

    * - * @param otherRange the range to check, null returns false + * @param otherRange the range to check, null returns false * @return true if this range is completely before the specified range * @throws RuntimeException if ranges cannot be compared */ @@ -419,7 +404,7 @@ public boolean isBeforeRange(final @Nullable Range otherRange) { /** *

    Checks whether this range ends with the specified element.

    * - * @param element the element to check for, null returns false + * @param element the element to check for, null returns false * @return true if the specified element occurs within this range */ public boolean isEndedBy(final @Nullable T element) { @@ -448,24 +433,22 @@ public boolean isNaturalOrdering() { * *

    This method may fail if the ranges have two different comparators or element types.

    * - * @param otherRange the range to test, null returns false + * @param otherRange the range to test, null returns false * @return true if the specified range overlaps with this - * range; otherwise, {@code false} + * range; otherwise, {@code false} * @throws RuntimeException if ranges cannot be compared */ public boolean isOverlappedBy(final @Nullable Range otherRange) { if (otherRange == null) { return false; } - return otherRange.contains(minimum) - || otherRange.contains(maximum) - || contains(otherRange.minimum); + return otherRange.contains(minimum) || otherRange.contains(maximum) || contains(otherRange.minimum); } /** *

    Checks whether this range starts with the specified element.

    * - * @param element the element to check for, null returns false + * @param element the element to check for, null returns false * @return true if the specified element occurs within this range */ public boolean isStartedBy(final @Nullable T element) { @@ -499,11 +482,28 @@ public boolean isStartedBy(final @Nullable T element) { * and {@code %3$s} for the comparator. * The default format used by {@code toString()} is {@code [%1$s..%2$s]}.

    * - * @param format the format string, optionally containing {@code %1$s}, {@code %2$s} and {@code %3$s}, not null + * @param format the format string, optionally containing {@code %1$s}, {@code %2$s} and {@code %3$s}, not null * @return the formatted string, not null */ public @NotNull String toString(final @NotNull String format) { return String.format(format, minimum, maximum, comparator); } + @SuppressWarnings({"rawtypes", "unchecked"}) + private enum ComparableComparator implements Comparator { + INSTANCE; + + /** + * Comparable based compare implementation. + * + * @param obj1 left hand side of comparison + * @param obj2 right hand side of comparison + * @return negative, 0, positive comparison value + */ + @Override + public int compare(final @NotNull Object obj1, final @NotNull Object obj2) { + return ((Comparable) obj1).compareTo(obj2); + } + } + } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/utils/SphereBuilder.java b/common/src/main/java/org/terraform/utils/SphereBuilder.java index 916aab2d..1eae48ac 100644 --- a/common/src/main/java/org/terraform/utils/SphereBuilder.java +++ b/common/src/main/java/org/terraform/utils/SphereBuilder.java @@ -1,10 +1,5 @@ package org.terraform.utils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Random; - import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.NotNull; @@ -12,130 +7,144 @@ import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Random; + public class SphereBuilder { - - private boolean isSmooth = false; - private final Random random; - private final int seed; - private float rX = 1f; - private float rY = 1f; - private float rZ = 1f; - private float padding = 0f; - private double minRadius = 0; - private double maxRadius = 100; - private final SimpleBlock core; - private boolean hardReplace = false; - private final @NotNull Collection replaceWhitelist = new ArrayList<>(); - private Material[] types; - private Material[] containmentMaterial = new Material[] {Material.STONE}; - private Material[] upperType; - private Material[] lowerType; - private int staticWaterLevel = -9999; - private float sphereFrequency = 0.09f; - private boolean doLiquidContainment = false; - private SphereType sphereType = SphereType.FULL_SPHERE; - - - public SphereBuilder(@NotNull Random random, SimpleBlock core, Material... types) { - this.random = random; - this.seed = random.nextInt(99999999); - this.types = types; - this.core = core; - } - - public @NotNull SphereBuilder setSphereType(SphereType sphereType) { - this.sphereType = sphereType; - return this; - } - - public @NotNull SphereBuilder setUpperType(Material... upperType) { - this.upperType = upperType; - return this; - } - - public @NotNull SphereBuilder setLowerType(Material... lowerType) { - this.lowerType = lowerType; - return this; - } - - public @NotNull SphereBuilder setStaticWaterLevel(int staticWaterLevel) { - this.staticWaterLevel = staticWaterLevel; - return this; - } - - public @NotNull SphereBuilder addToWhitelist(Material @NotNull ... mats) { + + private final Random random; + private final int seed; + private final SimpleBlock core; + private final @NotNull Collection replaceWhitelist = new ArrayList<>(); + private boolean isSmooth = false; + private float rX = 1f; + private float rY = 1f; + private float rZ = 1f; + private float padding = 0f; + private double minRadius = 0; + private double maxRadius = 100; + private boolean hardReplace = false; + private Material[] types; + private Material[] containmentMaterial = new Material[] {Material.STONE}; + private Material[] upperType; + private Material[] lowerType; + private int staticWaterLevel = -9999; + private float sphereFrequency = 0.09f; + private boolean doLiquidContainment = false; + private SphereType sphereType = SphereType.FULL_SPHERE; + + + public SphereBuilder(@NotNull Random random, SimpleBlock core, Material... types) { + this.random = random; + this.seed = random.nextInt(99999999); + this.types = types; + this.core = core; + } + + public @NotNull SphereBuilder setSphereType(SphereType sphereType) { + this.sphereType = sphereType; + return this; + } + + public @NotNull SphereBuilder setUpperType(Material... upperType) { + this.upperType = upperType; + return this; + } + + public @NotNull SphereBuilder setLowerType(Material... lowerType) { + this.lowerType = lowerType; + return this; + } + + public @NotNull SphereBuilder setStaticWaterLevel(int staticWaterLevel) { + this.staticWaterLevel = staticWaterLevel; + return this; + } + + public @NotNull SphereBuilder addToWhitelist(Material @NotNull ... mats) { replaceWhitelist.addAll(Arrays.asList(mats)); - return this; - } - - public @NotNull SphereBuilder setRadius(float radius) { - this.rX = radius; this.rY = radius; this.rZ = radius; - return this; - } - - public @NotNull SphereBuilder setSphereFrequency(float sphereFrequency) { - this.sphereFrequency = sphereFrequency; - return this; - } - - public @NotNull SphereBuilder setRX(float rX) { - this.rX = rX; - return this; - } - public @NotNull SphereBuilder setRZ(float rZ) { - this.rZ = rZ; - return this; - } - public @NotNull SphereBuilder setRY(float rY) { - this.rY = rY; - return this; - } - public @NotNull SphereBuilder setSnowy() { - this.upperType = new Material[] {Material.SNOW}; - return this; - } - public @NotNull SphereBuilder setHardReplace(boolean hardReplace) { - this.hardReplace = hardReplace; - return this; - } - public @NotNull SphereBuilder setDoLiquidContainment(boolean doLiquidContainment) { - this.doLiquidContainment = doLiquidContainment; - return this; - } - - public @NotNull SphereBuilder setCointainmentMaterials(Material... containmentMaterial) { - this.containmentMaterial = containmentMaterial; - return this; - } - - /** - * Refers to minimum percentage radius (0.0 to 1.0) + return this; + } + + public @NotNull SphereBuilder setRadius(float radius) { + this.rX = radius; + this.rY = radius; + this.rZ = radius; + return this; + } + + public @NotNull SphereBuilder setSphereFrequency(float sphereFrequency) { + this.sphereFrequency = sphereFrequency; + return this; + } + + public @NotNull SphereBuilder setRX(float rX) { + this.rX = rX; + return this; + } + + public @NotNull SphereBuilder setRZ(float rZ) { + this.rZ = rZ; + return this; + } + + public @NotNull SphereBuilder setRY(float rY) { + this.rY = rY; + return this; + } + + public @NotNull SphereBuilder setSnowy() { + this.upperType = new Material[] {Material.SNOW}; + return this; + } + + public @NotNull SphereBuilder setHardReplace(boolean hardReplace) { + this.hardReplace = hardReplace; + return this; + } + + public @NotNull SphereBuilder setDoLiquidContainment(boolean doLiquidContainment) { + this.doLiquidContainment = doLiquidContainment; + return this; + } + + public @NotNull SphereBuilder setCointainmentMaterials(Material... containmentMaterial) { + this.containmentMaterial = containmentMaterial; + return this; + } + + /** + * Refers to minimum percentage radius (0.0 to 1.0) + */ + public @NotNull SphereBuilder setMinRadius(double minRadius) { + this.minRadius = minRadius; + return this; + } + + /** + * Refers to minimum percentage radius (0.0 to 1.0) */ - public @NotNull SphereBuilder setMinRadius(double minRadius) { - this.minRadius = minRadius; - return this; - } - - /** - * Refers to minimum percentage radius (0.0 to 1.0) - */ - public @NotNull SphereBuilder setMaxRadius(double maxRadius) { - this.maxRadius = maxRadius; - return this; - } - - public @NotNull SphereBuilder setSmooth(boolean isSmooth) { - this.isSmooth = isSmooth; - return this; - } - - public @NotNull SphereBuilder setPadding(int padding) { - this.padding = padding; - return this; - } + public @NotNull SphereBuilder setMaxRadius(double maxRadius) { + this.maxRadius = maxRadius; + return this; + } + + public @NotNull SphereBuilder setSmooth(boolean isSmooth) { + this.isSmooth = isSmooth; + return this; + } + + public @NotNull SphereBuilder setPadding(int padding) { + this.padding = padding; + return this; + } public void build() { - if (rX <= 0 && rY <= 0 && rZ <= 0) return; + if (rX <= 0 && rY <= 0 && rZ <= 0) { + return; + } if (rX <= 0.5 && rY <= 0.5 && rZ <= 0.5) { unitReplace(core, core.getY()); return; @@ -146,73 +155,96 @@ public void build() { noise.SetFrequency(sphereFrequency); float effectiveRYLower = -rY; - if(sphereType == SphereType.UPPER_SEMISPHERE) effectiveRYLower = 0; + if (sphereType == SphereType.UPPER_SEMISPHERE) { + effectiveRYLower = 0; + } float effectiveRYUpper = rY; - if(sphereType == SphereType.LOWER_SEMISPHERE) effectiveRYUpper = 0; - - for (float x = -rX-padding; x <= rX+padding; x++) { + if (sphereType == SphereType.LOWER_SEMISPHERE) { + effectiveRYUpper = 0; + } + + for (float x = -rX - padding; x <= rX + padding; x++) { for (float y = effectiveRYLower; y <= effectiveRYUpper; y++) { - for (float z = -rZ-padding; z <= rZ+padding; z++) { + for (float z = -rZ - padding; z <= rZ + padding; z++) { SimpleBlock rel = core.getRelative(Math.round(x), Math.round(y), Math.round(z)); // double radiusSquared = Math.pow(trueRadius+noise.GetNoise(rel.getX(), rel.getY(), rel.getZ())*2,2); double equationResult = Math.pow(x, 2) / Math.pow(rX, 2) - + Math.pow(y, 2) / Math.pow(rY, 2) - + Math.pow(z, 2) / Math.pow(rZ, 2); + + Math.pow(y, 2) / Math.pow(rY, 2) + + Math.pow(z, 2) / Math.pow(rZ, 2); double noiseVal; - - if(!isSmooth) - noiseVal = 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); - else - noiseVal = 1; - - if(noiseVal < minRadius) noiseVal = minRadius; - if(noiseVal > maxRadius) noiseVal = maxRadius; - + + if (!isSmooth) { + noiseVal = 1 + 0.7 * noise.GetNoise(rel.getX(), rel.getY(), rel.getZ()); + } + else { + noiseVal = 1; + } + + if (noiseVal < minRadius) { + noiseVal = minRadius; + } + if (noiseVal > maxRadius) { + noiseVal = maxRadius; + } + if (equationResult <= noiseVal) { Material[] original = types; - if(rel.getY() <= staticWaterLevel) { - types = new Material[] {Material.WATER}; - for(BlockFace face:new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.DOWN}) - { - if(BlockUtils.isAir(rel.getRelative(face).getType())) { - types = new Material[] { Material.STONE}; - } - } + if (rel.getY() <= staticWaterLevel) { + types = new Material[] {Material.WATER}; + for (BlockFace face : new BlockFace[] { + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST, + BlockFace.DOWN + }) { + if (BlockUtils.isAir(rel.getRelative(face).getType())) { + types = new Material[] {Material.STONE}; + } + } } - unitReplace(rel, (int) (core.getY() + effectiveRYUpper)); - types = original; + unitReplace(rel, (int) (core.getY() + effectiveRYUpper)); + types = original; } } } } } - + private void unitReplace(@NotNull SimpleBlock rel, int effectiveRYUpper) { - if(replaceWhitelist.isEmpty()) { - if (hardReplace || !rel.isSolid()) { + if (replaceWhitelist.isEmpty()) { + if (hardReplace || !rel.isSolid()) { rel.setType(GenUtils.randChoice(random, types)); - if(this.doLiquidContainment) - rel.replaceAdjacentNonLiquids(new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}, types[0], containmentMaterial); + if (this.doLiquidContainment) { + rel.replaceAdjacentNonLiquids(new BlockFace[] { + BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST + }, types[0], containmentMaterial); + } } - } else if(replaceWhitelist.contains(rel.getType())) { + } + else if (replaceWhitelist.contains(rel.getType())) { rel.setType(GenUtils.randChoice(random, types)); - if(this.doLiquidContainment) - rel.replaceAdjacentNonLiquids(new BlockFace[]{BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}, types[0], containmentMaterial); - } + if (this.doLiquidContainment) { + rel.replaceAdjacentNonLiquids(new BlockFace[] { + BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST + }, types[0], containmentMaterial); + } + } - if(rel.isSolid()) { - if(upperType != null && rel.getY() == effectiveRYUpper) { - rel.getUp().lsetType(upperType); - } - if(lowerType != null) - rel.getDown().setType(lowerType); - } + if (rel.isSolid()) { + if (upperType != null && rel.getY() == effectiveRYUpper) { + rel.getUp().lsetType(upperType); + } + if (lowerType != null) { + rel.getDown().setType(lowerType); + } + } } - public enum SphereType{ - UPPER_SEMISPHERE, LOWER_SEMISPHERE, FULL_SPHERE + public enum SphereType { + UPPER_SEMISPHERE, LOWER_SEMISPHERE, FULL_SPHERE } } diff --git a/common/src/main/java/org/terraform/utils/StairwayBuilder.java b/common/src/main/java/org/terraform/utils/StairwayBuilder.java index fd5c64ef..3e92289f 100644 --- a/common/src/main/java/org/terraform/utils/StairwayBuilder.java +++ b/common/src/main/java/org/terraform/utils/StairwayBuilder.java @@ -12,201 +12,215 @@ /** * Used to generate 1-block wide stairways from a starting point - * */ public class StairwayBuilder { - - private final Material[] stairTypes; - private boolean carveAirSpace = true; - private BlockFace stairDirection = BlockFace.DOWN; - private Material[] downTypes; - private boolean stopAtWater = false; - private int stopAtY = Short.MIN_VALUE; - private boolean angled = false; - private int maxExtensionForward = 10; - private boolean upwardsCarveUntilNotSolid = true; - private boolean upwardsCarveUntilSolid = false; - - public StairwayBuilder(Material @NotNull ... stairTypes) { - this.stairTypes = stairTypes; - - // Infer downTypes - ArrayList downTypes = new ArrayList<>(); - for(Material mat:stairTypes) { - Material toAdd = Material.matchMaterial( - mat.toString().replace("_STAIRS", "")); - if(toAdd != null) downTypes.add(toAdd); - } - this.downTypes = new Material[downTypes.size()]; - - for(int i = 0; i < downTypes.size(); i++) - this.downTypes[i] = downTypes.get(i); - - } - - public @NotNull StairwayBuilder setStopAtY(int y) { - this.stopAtY = y; - return this; - } - - public @NotNull StairwayBuilder setCarveAirSpace(boolean carveAirSpace) { - this.carveAirSpace = carveAirSpace; - return this; - } - - public @NotNull StairwayBuilder setUpwardsCarveUntilSolid(boolean carve) { - this.upwardsCarveUntilSolid = carve; - return this; - } - - public @NotNull StairwayBuilder setUpwardsCarveUntilNotSolid(boolean carve) { - this.upwardsCarveUntilNotSolid = carve; - return this; - } - - public @NotNull StairwayBuilder setDownTypes(Material... mat) { - this.downTypes = mat; - return this; - } - - public @NotNull StairwayBuilder build(@NotNull Wall start) { - if(stairDirection == BlockFace.DOWN) { // Stairway extends downwards - int threshold = 5; - BlockFace extensionDir = start.getDirection(); - while (continueCondition(start)) { - - if(threshold == 0) { - start.setType(downTypes); - start.getDown().downUntilSolid(new Random(), downTypes); - extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); - start = start.getRelative(extensionDir); - } - - Material stairType = stairTypes[new Random().nextInt(stairTypes.length)]; - if(stairType.toString().endsWith("STAIRS")) - new StairBuilder(stairType) - .setFacing(extensionDir.getOppositeFace()) - .apply(start); - else - start.setType(stairType); - - start.getDown().downUntilSolid(new Random(), downTypes); - - if(angled) - threshold--; - start = start.getRelative(extensionDir).getDown(); - } - - // If it is on water, build a pathway forward. - // Hope that there's something there. - // Stop on oak slabs specifically too, because that's the path type - if(stopAtWater - && start.get().getType() != Material.OAK_SLAB - && BlockUtils.isWet(start.get())) { - for(int i = 0; i < maxExtensionForward; i++) { - if(start.isSolid()) - break; - - start.downUntilSolid(new Random(), downTypes); - start = start.getFront(); - } - } - }else if(stairDirection == BlockFace.UP){ // Stairway extends upwards - - int threshold = 5; - BlockFace extensionDir = start.getDirection(); - while (continueCondition(start)) { - - if(threshold == 0) { - start = start.getDown(); - if(carveAirSpace) - start.getUp().Pillar(3, new Random(), Material.AIR); - start.setType(downTypes); - start.getDown().downUntilSolid(new Random(), downTypes); - extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); - start = start.getRelative(extensionDir).getUp(); - } - - Material stairType = stairTypes[new Random().nextInt(stairTypes.length)]; - if(stairType.toString().endsWith("STAIRS")) - new StairBuilder(stairTypes) - .setFacing(extensionDir) - .apply(start); - else - start.setType(stairType); - - start.getDown().downUntilSolid(new Random(), downTypes); - - // This space is required for movement - if(carveAirSpace) - { - start.getUp().Pillar(3, new Random(), Material.AIR); - start.getUp(2).getRelative(extensionDir).setType(Material.AIR); - } - - if(angled) - threshold--; - start = start.getRelative(extensionDir).getUp(); - } - - }else { - TerraformGeneratorPlugin.logger.error("StairwayBuilder was told to spawn stairway with non up/down stair direction!"); - } - - - return this; + + private final Material[] stairTypes; + private boolean carveAirSpace = true; + private BlockFace stairDirection = BlockFace.DOWN; + private Material[] downTypes; + private boolean stopAtWater = false; + private int stopAtY = Short.MIN_VALUE; + private boolean angled = false; + private int maxExtensionForward = 10; + private boolean upwardsCarveUntilNotSolid = true; + private boolean upwardsCarveUntilSolid = false; + + public StairwayBuilder(Material @NotNull ... stairTypes) { + this.stairTypes = stairTypes; + + // Infer downTypes + ArrayList downTypes = new ArrayList<>(); + for (Material mat : stairTypes) { + Material toAdd = Material.matchMaterial(mat.toString().replace("_STAIRS", "")); + if (toAdd != null) { + downTypes.add(toAdd); + } + } + this.downTypes = new Material[downTypes.size()]; + + for (int i = 0; i < downTypes.size(); i++) { + this.downTypes[i] = downTypes.get(i); + } + + } + + public @NotNull StairwayBuilder setStopAtY(int y) { + this.stopAtY = y; + return this; + } + + public @NotNull StairwayBuilder setCarveAirSpace(boolean carveAirSpace) { + this.carveAirSpace = carveAirSpace; + return this; + } + + public @NotNull StairwayBuilder setUpwardsCarveUntilSolid(boolean carve) { + this.upwardsCarveUntilSolid = carve; + return this; + } + + public @NotNull StairwayBuilder setUpwardsCarveUntilNotSolid(boolean carve) { + this.upwardsCarveUntilNotSolid = carve; + return this; + } + + public @NotNull StairwayBuilder setDownTypes(Material... mat) { + this.downTypes = mat; + return this; + } + + public @NotNull StairwayBuilder build(@NotNull Wall start) { + if (stairDirection == BlockFace.DOWN) { // Stairway extends downwards + int threshold = 5; + BlockFace extensionDir = start.getDirection(); + while (continueCondition(start)) { + + if (threshold == 0) { + start.setType(downTypes); + start.getDown().downUntilSolid(new Random(), downTypes); + extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); + start = start.getRelative(extensionDir); + } + + Material stairType = stairTypes[new Random().nextInt(stairTypes.length)]; + if (stairType.toString().endsWith("STAIRS")) { + new StairBuilder(stairType).setFacing(extensionDir.getOppositeFace()).apply(start); + } + else { + start.setType(stairType); + } + + start.getDown().downUntilSolid(new Random(), downTypes); + + if (angled) { + threshold--; + } + start = start.getRelative(extensionDir).getDown(); + } + + // If it is on water, build a pathway forward. + // Hope that there's something there. + // Stop on oak slabs specifically too, because that's the path type + if (stopAtWater && start.get().getType() != Material.OAK_SLAB && BlockUtils.isWet(start.get())) { + for (int i = 0; i < maxExtensionForward; i++) { + if (start.isSolid()) { + break; + } + + start.downUntilSolid(new Random(), downTypes); + start = start.getFront(); + } + } + } + else if (stairDirection == BlockFace.UP) { // Stairway extends upwards + + int threshold = 5; + BlockFace extensionDir = start.getDirection(); + while (continueCondition(start)) { + + if (threshold == 0) { + start = start.getDown(); + if (carveAirSpace) { + start.getUp().Pillar(3, new Random(), Material.AIR); + } + start.setType(downTypes); + start.getDown().downUntilSolid(new Random(), downTypes); + extensionDir = BlockUtils.getTurnBlockFace(new Random(), extensionDir); + start = start.getRelative(extensionDir).getUp(); + } + + Material stairType = stairTypes[new Random().nextInt(stairTypes.length)]; + if (stairType.toString().endsWith("STAIRS")) { + new StairBuilder(stairTypes).setFacing(extensionDir).apply(start); + } + else { + start.setType(stairType); + } + + start.getDown().downUntilSolid(new Random(), downTypes); + + // This space is required for movement + if (carveAirSpace) { + start.getUp().Pillar(3, new Random(), Material.AIR); + start.getUp(2).getRelative(extensionDir).setType(Material.AIR); + } + + if (angled) { + threshold--; + } + start = start.getRelative(extensionDir).getUp(); + } + + } + else { + TerraformGeneratorPlugin.logger.error( + "StairwayBuilder was told to spawn stairway with non up/down stair direction!"); + } + + + return this; + } + + private boolean continueCondition(@NotNull Wall target) { + + if (this.stairDirection == BlockFace.DOWN) { + if (stopAtY != Short.MIN_VALUE) { + if (target.getY() == stopAtY) { + return false; + } + } + + if (stopAtWater && BlockUtils.isWet(target.get())) { + return false; + } + + return !target.isSolid(); + } + else { + if (stopAtY != Short.MIN_VALUE) { + if (target.getY() == stopAtY + 1) { + return false; + } + } + + // Continue carving upwards until the area isn't solid anymore. + if (upwardsCarveUntilNotSolid) { + return target.isSolid(); + } + + // Continue carving upwards until the area is solid anymore. + if (upwardsCarveUntilSolid) { + return !target.isSolid(); + } + + return true; + } } - - private boolean continueCondition(@NotNull Wall target) { - - if(this.stairDirection == BlockFace.DOWN) { - if(stopAtY != Short.MIN_VALUE) - if(target.getY() == stopAtY) return false; - - if(stopAtWater && BlockUtils.isWet(target.get())) - return false; - - return !target.isSolid(); - }else { - if(stopAtY != Short.MIN_VALUE) - if(target.getY() == stopAtY+1) - return false; - - // Continue carving upwards until the area isn't solid anymore. - if (upwardsCarveUntilNotSolid) - return target.isSolid(); - - // Continue carving upwards until the area is solid anymore. - if(upwardsCarveUntilSolid) - return !target.isSolid(); - - return true; - } - } - - /** - * Only used when stopAtWater is true. - * Refers to the maximum length of the pathway generated when - * the stairway hits water. + + /** + * Only used when stopAtWater is true. + * Refers to the maximum length of the pathway generated when + * the stairway hits water. */ - public @NotNull StairwayBuilder setMaxExtensionForward(int extension) { - this.maxExtensionForward = extension; - return this; - } - - public @NotNull StairwayBuilder setStairwayDirection(BlockFace stairDirection) { - this.stairDirection = stairDirection; - return this; - } - - public @NotNull StairwayBuilder setStopAtWater(boolean stopAtWater) { - this.stopAtWater = stopAtWater; - return this; - } - - public @NotNull StairwayBuilder setAngled(boolean angled) { - this.angled = angled; - return this; - } + public @NotNull StairwayBuilder setMaxExtensionForward(int extension) { + this.maxExtensionForward = extension; + return this; + } + + public @NotNull StairwayBuilder setStairwayDirection(BlockFace stairDirection) { + this.stairDirection = stairDirection; + return this; + } + + public @NotNull StairwayBuilder setStopAtWater(boolean stopAtWater) { + this.stopAtWater = stopAtWater; + return this; + } + + public @NotNull StairwayBuilder setAngled(boolean angled) { + this.angled = angled; + return this; + } } diff --git a/common/src/main/java/org/terraform/utils/StalactiteBuilder.java b/common/src/main/java/org/terraform/utils/StalactiteBuilder.java index e5c9d6f0..b970d83d 100644 --- a/common/src/main/java/org/terraform/utils/StalactiteBuilder.java +++ b/common/src/main/java/org/terraform/utils/StalactiteBuilder.java @@ -14,100 +14,120 @@ public class StalactiteBuilder { - private Material[] solidBlockType; - private Material[] wallType; - private boolean isFacingUp; - private int verticalSpace; + private Material[] solidBlockType; + private Material[] wallType; + private boolean isFacingUp; + private int verticalSpace; private float minRadius = 0; public StalactiteBuilder(Material... wallType) { - this.wallType = wallType; - } - - public void build(@NotNull Random rand, @NotNull Wall w) { - if (TConfigOption.areDecorationsEnabled()) return; - - if(verticalSpace < 6) return; - - int stalactiteHeight; - if(verticalSpace > 60) // massive cave - stalactiteHeight = GenUtils.randInt(rand, 6, 25); - else if(verticalSpace > 30) // large cave - stalactiteHeight = GenUtils.randInt(rand, 5, 17); - else if(verticalSpace > 15) // medium cave - stalactiteHeight = GenUtils.randInt(rand, 3, 10); - else // likely noodle cave - stalactiteHeight = GenUtils.randInt(rand, 1, 2); - - if(stalactiteHeight < 4) { - // tiny stalactite (1-3 blocks) - if(isFacingUp) - w.LPillar(stalactiteHeight, rand, wallType); - else - w.downLPillar(rand, stalactiteHeight, wallType); - } - else if(stalactiteHeight < 7) - { - // Bigger stalactite. (4-7 blocks) - if(isFacingUp) { - w.LPillar(stalactiteHeight, rand, wallType); - w.Pillar(GenUtils.randInt(rand, 2, 3), rand, solidBlockType); - }else { - w.downLPillar(rand, stalactiteHeight, wallType); - w.downPillar(GenUtils.randInt(rand, 2, 3), solidBlockType); - } - } - else - { - // Large stalactite (8+ blocks) - if(isFacingUp) - { - makeSpike(w.getDown(), - GenUtils.randDouble(rand, stalactiteHeight/6.0, stalactiteHeight/4.0), - stalactiteHeight, true); - } - else - { - makeSpike(w.getUp(), - GenUtils.randDouble(rand, stalactiteHeight/6.0, stalactiteHeight/4.0), - stalactiteHeight, false); - } - } - } - - public @NotNull StalactiteBuilder setSolidBlockType(Material... solidBlockType) { - this.solidBlockType = solidBlockType; - return this; - } - - public @NotNull StalactiteBuilder setWallType(Material... wallType) { - this.wallType = wallType; - return this; - } - - public @NotNull StalactiteBuilder setFacingUp(boolean isFacingUp) { - this.isFacingUp = isFacingUp; - return this; - } - - public @NotNull StalactiteBuilder setMinRadius(int minRadius) { - this.minRadius = minRadius; - return this; - } - - public @NotNull StalactiteBuilder setVerticalSpace(int verticalSpace) { - this.verticalSpace = verticalSpace; - return this; - } + this.wallType = wallType; + } + + public void build(@NotNull Random rand, @NotNull Wall w) { + if (TConfigOption.areDecorationsEnabled()) { + return; + } + + if (verticalSpace < 6) { + return; + } + + int stalactiteHeight; + if (verticalSpace > 60) // massive cave + { + stalactiteHeight = GenUtils.randInt(rand, 6, 25); + } + else if (verticalSpace > 30) // large cave + { + stalactiteHeight = GenUtils.randInt(rand, 5, 17); + } + else if (verticalSpace > 15) // medium cave + { + stalactiteHeight = GenUtils.randInt(rand, 3, 10); + } + else // likely noodle cave + { + stalactiteHeight = GenUtils.randInt(rand, 1, 2); + } + + if (stalactiteHeight < 4) { + // tiny stalactite (1-3 blocks) + if (isFacingUp) { + w.LPillar(stalactiteHeight, rand, wallType); + } + else { + w.downLPillar(rand, stalactiteHeight, wallType); + } + } + else if (stalactiteHeight < 7) { + // Bigger stalactite. (4-7 blocks) + if (isFacingUp) { + w.LPillar(stalactiteHeight, rand, wallType); + w.Pillar(GenUtils.randInt(rand, 2, 3), rand, solidBlockType); + } + else { + w.downLPillar(rand, stalactiteHeight, wallType); + w.downPillar(GenUtils.randInt(rand, 2, 3), solidBlockType); + } + } + else { + // Large stalactite (8+ blocks) + if (isFacingUp) { + makeSpike( + w.getDown(), + GenUtils.randDouble(rand, stalactiteHeight / 6.0, stalactiteHeight / 4.0), + stalactiteHeight, + true + ); + } + else { + makeSpike( + w.getUp(), + GenUtils.randDouble(rand, stalactiteHeight / 6.0, stalactiteHeight / 4.0), + stalactiteHeight, + false + ); + } + } + } + + public @NotNull StalactiteBuilder setSolidBlockType(Material... solidBlockType) { + this.solidBlockType = solidBlockType; + return this; + } + + public @NotNull StalactiteBuilder setWallType(Material... wallType) { + this.wallType = wallType; + return this; + } + + public @NotNull StalactiteBuilder setFacingUp(boolean isFacingUp) { + this.isFacingUp = isFacingUp; + return this; + } + + public @NotNull StalactiteBuilder setMinRadius(int minRadius) { + this.minRadius = minRadius; + return this; + } + + public @NotNull StalactiteBuilder setVerticalSpace(int verticalSpace) { + this.verticalSpace = verticalSpace; + return this; + } /** * Responsible for generating a stalactite or stalagmite. + * * @param facingUp generates stalagmites if true. If not, makes stalactites. */ - public void makeSpike(@NotNull SimpleBlock root, double baseRadius, int height, boolean facingUp) { + public void makeSpike(@NotNull SimpleBlock root, double baseRadius, int height, boolean facingUp) { // HEIGHT CANNOT BE LESS THAN 1. (1.0/0.0) DOES NOT THROW ARITHMETIC ERRORS - if(height < 8) return; + if (height < 8) { + return; + } float maxRadius = 3f; baseRadius = Math.min(maxRadius, Math.max(baseRadius, minRadius)); @@ -116,47 +136,48 @@ public void makeSpike(@NotNull SimpleBlock root, double baseRadius, int height, // each other. Should reduce chunk r/w ops // Assume that it will use slightly more than coneVolume blocks - Queue queue = new ArrayDeque<>((int) (Math.PI*Math.pow(baseRadius,2)*(height/2.5))); + Queue queue = new ArrayDeque<>((int) (Math.PI * Math.pow(baseRadius, 2) * (height / 2.5))); queue.add(root); HashSet seen = new HashSet<>(); seen.add(root); - while(!queue.isEmpty()) - { + while (!queue.isEmpty()) { SimpleBlock v = queue.remove(); v.setType(solidBlockType); // Place blocks for v - for(BlockFace rel:BlockUtils.sixBlockFaces) - { + for (BlockFace rel : BlockUtils.sixBlockFaces) { SimpleBlock neighbour = v.getRelative(rel); - if(seen.contains(neighbour)) continue; - - int yOffset = neighbour.getY()-root.getY(); - if(facingUp && (yOffset>height - || yOffset<0)) continue; - if(!facingUp && (yOffset<-height - || yOffset>0)) continue; + if (seen.contains(neighbour)) { + continue; + } + + int yOffset = neighbour.getY() - root.getY(); + if (facingUp && (yOffset > height || yOffset < 0)) { + continue; + } + if (!facingUp && (yOffset < -height || yOffset > 0)) { + continue; + } /* * x^2 + z^2 - ((y-h)/baseRadius)^2 = 0 */ double coneEqn = facingUp ? - // Stalagmites. Minus as it grows up - Math.pow(neighbour.getX()-root.getX(),2) - + Math.pow(neighbour.getZ()-root.getZ(),2) - - Math.pow((yOffset-height)/(height/baseRadius), 2) - : - // Stalactites. Plus as it grows down - Math.pow(neighbour.getX()-root.getX(),2) - + Math.pow(neighbour.getZ()-root.getZ(),2) - - Math.pow((yOffset+height)/(height/baseRadius), 2); + // Stalagmites. Minus as it grows up + Math.pow(neighbour.getX() - root.getX(), 2) + Math.pow(neighbour.getZ() - root.getZ(), + 2) - Math.pow((yOffset - height) / (height / baseRadius), 2) : + // Stalactites. Plus as it grows down + Math.pow(neighbour.getX() - root.getX(), 2) + Math.pow(neighbour.getZ() - root.getZ(), + 2) - Math.pow((yOffset + height) / (height / baseRadius), 2); // Only make cones larger, not smaller. This prevents blobs. // coneEqn -= Math.abs(noise.GetNoise(neighbour.getX(), neighbour.getZ())); - if(coneEqn > 0) continue; // <=0 is within the spike + if (coneEqn > 0) { + continue; // <=0 is within the spike + } queue.add(neighbour); seen.add(neighbour); } } - } - + } + } diff --git a/common/src/main/java/org/terraform/utils/Treetest.java b/common/src/main/java/org/terraform/utils/Treetest.java index 784f2306..91cf5f1f 100644 --- a/common/src/main/java/org/terraform/utils/Treetest.java +++ b/common/src/main/java/org/terraform/utils/Treetest.java @@ -1,2 +1,4 @@ -package org.terraform.utils;public class Treetest { +package org.terraform.utils; + +public class Treetest { } diff --git a/common/src/main/java/org/terraform/utils/Vector2f.java b/common/src/main/java/org/terraform/utils/Vector2f.java index 54f221d1..2bf1ec31 100644 --- a/common/src/main/java/org/terraform/utils/Vector2f.java +++ b/common/src/main/java/org/terraform/utils/Vector2f.java @@ -11,6 +11,7 @@ public class Vector2f implements java.io.Serializable { /** * Constructs and initializes a Vector2f from the specified xy coordinates. + * * @param x the x coordinate * @param y the y coordinate */ @@ -22,6 +23,7 @@ public Vector2f(float x, float y) { /** * Constructs and initializes a Vector2f from the specified array. + * * @param v the array of length 2 containing xy in order */ public Vector2f(float @NotNull [] v) { @@ -32,6 +34,7 @@ public Vector2f(float @NotNull [] v) { /** * Constructs and initializes a Vector2f from the specified Vector2f. + * * @param v1 the Vector2f containing the initialization x y data */ public Vector2f(@NotNull Vector2f v1) { @@ -49,6 +52,7 @@ public Vector2f() { /** * Computes the dot product of the this vector and vector v1. + * * @param v1 the other vector */ public final float dot(@NotNull Vector2f v1) { @@ -58,6 +62,7 @@ public final float dot(@NotNull Vector2f v1) { /** * Returns the length of this vector. + * * @return the length of this vector */ public final float length() { @@ -66,6 +71,7 @@ public final float length() { /** * Returns the squared length of this vector. + * * @return the squared length of this vector */ public final float lengthSquared() { @@ -74,6 +80,7 @@ public final float lengthSquared() { /** * Sets the value of this vector to the normalization of vector v1. + * * @param v1 the un-normalized vector */ public final void normalize(@NotNull Vector2f v1) { @@ -95,13 +102,18 @@ public final void normalize() { /** * Returns the angle in radians between this vector and the vector * parameter; the return value is constrained to the range [0,PI]. + * * @param v1 the other vector * @return the angle in radians in the range [0,PI] */ public final float angle(@NotNull Vector2f v1) { double vDot = this.dot(v1) / (this.length() * v1.length()); - if (vDot < -1.0) vDot = -1.0; - if (vDot > 1.0) vDot = 1.0; + if (vDot < -1.0) { + vDot = -1.0; + } + if (vDot > 1.0) { + vDot = 1.0; + } return (float) Math.acos(vDot); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/utils/Vector3f.java b/common/src/main/java/org/terraform/utils/Vector3f.java index 1a47ff0c..93369498 100644 --- a/common/src/main/java/org/terraform/utils/Vector3f.java +++ b/common/src/main/java/org/terraform/utils/Vector3f.java @@ -44,6 +44,7 @@ public class Vector3f implements java.io.Serializable { /** * Constructs and initializes a Vector3f from the specified xyz coordinates. + * * @param x the x coordinate * @param y the y coordinate * @param z the z coordinate @@ -57,6 +58,7 @@ public Vector3f(float x, float y, float z) { /** * Constructs and initializes a Vector3f from the array of length 3. + * * @param v the array of length 3 containing xyz in order */ public Vector3f(float @NotNull [] v) { @@ -68,6 +70,7 @@ public Vector3f(float @NotNull [] v) { /** * Constructs and initializes a Vector3f from the specified Vector3f. + * * @param v1 the Vector3f containing the initialization x y z data */ public Vector3f(@NotNull Vector3f v1) { @@ -86,6 +89,7 @@ public Vector3f() { /** * Returns the squared length of this vector. + * * @return the squared length of this vector */ public final float lengthSquared() { @@ -94,16 +98,17 @@ public final float lengthSquared() { /** * Returns the length of this vector. + * * @return the length of this vector */ public final float length() { - return (float) - Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + return (float) Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } /** * Sets this vector to be the vector cross product of vectors v1 and v2. + * * @param v1 the first vector * @param v2 the second vector */ @@ -115,6 +120,7 @@ public final void cross(@NotNull Vector3f v1, @NotNull Vector3f v2) { /** * Computes the dot product of this vector and vector v1. + * * @param v1 the other vector * @return the dot product of this vector and v1 */ @@ -124,6 +130,7 @@ public final float dot(@NotNull Vector3f v1) { /** * Sets the value of this vector to the normalization of vector v1. + * * @param v1 the un-normalized vector */ public final void normalize(@NotNull Vector3f v1) { @@ -147,13 +154,18 @@ public final void normalize() { /** * Returns the angle in radians between this vector and the vector * parameter; the return value is constrained to the range [0,PI]. + * * @param v1 the other vector * @return the angle in radians in the range [0,PI] */ public final float angle(@NotNull Vector3f v1) { double vDot = this.dot(v1) / (this.length() * v1.length()); - if (vDot < -1.0) vDot = -1.0; - if (vDot > 1.0) vDot = 1.0; + if (vDot < -1.0) { + vDot = -1.0; + } + if (vDot > 1.0) { + vDot = 1.0; + } return (float) Math.acos(vDot); } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/utils/WoodUtils.java b/common/src/main/java/org/terraform/utils/WoodUtils.java index f4d3f44d..109b3cf3 100644 --- a/common/src/main/java/org/terraform/utils/WoodUtils.java +++ b/common/src/main/java/org/terraform/utils/WoodUtils.java @@ -6,60 +6,9 @@ import org.terraform.biome.BiomeBank; public class WoodUtils { - - public enum WoodSpecies{ - OAK, SPRUCE, BIRCH, JUNGLE, ACACIA, DARK_OAK - } - - public enum WoodType{ - PLANKS("%WOOD%_PLANKS"), - SAPLING("%WOOD%_SAPLING"), - POTTED_SAPLING("POTTED_%WOOD%_SAPLING"), - LOG("%WOOD%_LOG"), - STRIPPED_LOG("STRIPPED_%WOOD%_LOG"), - WOOD("%WOOD%_WOOD"), - STRIPPED_WOOD("STRIPPED_%WOOD%_WOOD"), - LEAVES("%WOOD%_LEAVES"), - SLAB("%WOOD%_SLAB"), - PRESSURE_PLATE("%WOOD%_PRESSURE_PLATE"), - FENCE("%WOOD%_FENCE"), - TRAPDOOR("%WOOD%_TRAPDOOR"), - FENCE_GATE("%WOOD%_FENCE_GATE"), - STAIRS("%WOOD%_STAIRS"), - BUTTON("%WOOD%_BUTTON"), - DOOR("%WOOD%_DOOR"), - SIGN("%WOOD%_SIGN"), - WALL_SIGN("%WOOD%_WALL_SIGN"), - BOAT("%WOOD%_BOAT"), - ; - final String template; - WoodType(String template){ - this.template = template; - } - - /** - * Converts an oak material to a WoodType template. - * Do not use for any other wood. - *

    - * The dark oak check is there because schematics only check for the - * keyword "oak" - * @param oak material to convert to an WoodType enum - */ - public static @NotNull WoodType parse(@NotNull Material oak) { - return WoodType.valueOf(oak.toString() - .replace("DARK_OAK","OAK") - .replace("OAK_","")); - } - // I am the pinnacle of optimisation - // Fear my absolutely unbeatable timings - public @Nullable Material getWood(@NotNull WoodSpecies species) { - return Material.getMaterial(template.replace("%WOOD%", species.toString())); - } - } - public static @Nullable Material getWoodForBiome(@NotNull BiomeBank biome, @NotNull WoodType wood) { - return switch(biome) { + return switch (biome) { case BADLANDS, BADLANDS_RIVER, SAVANNA, DESERT_MOUNTAINS, DESERT, DESERT_RIVER, BADLANDS_BEACH, BADLANDS_CANYON -> wood.getWood(WoodSpecies.ACACIA); case BIRCH_MOUNTAINS, SCARLET_FOREST -> wood.getWood(WoodSpecies.BIRCH); @@ -76,4 +25,55 @@ public enum WoodType{ }; } + public enum WoodSpecies { + OAK, SPRUCE, BIRCH, JUNGLE, ACACIA, DARK_OAK + } + + public enum WoodType { + PLANKS("%WOOD%_PLANKS"), + SAPLING("%WOOD%_SAPLING"), + POTTED_SAPLING("POTTED_%WOOD%_SAPLING"), + LOG("%WOOD%_LOG"), + STRIPPED_LOG("STRIPPED_%WOOD%_LOG"), + WOOD("%WOOD%_WOOD"), + STRIPPED_WOOD("STRIPPED_%WOOD%_WOOD"), + LEAVES("%WOOD%_LEAVES"), + SLAB("%WOOD%_SLAB"), + PRESSURE_PLATE("%WOOD%_PRESSURE_PLATE"), + FENCE("%WOOD%_FENCE"), + TRAPDOOR("%WOOD%_TRAPDOOR"), + FENCE_GATE("%WOOD%_FENCE_GATE"), + STAIRS("%WOOD%_STAIRS"), + BUTTON("%WOOD%_BUTTON"), + DOOR("%WOOD%_DOOR"), + SIGN("%WOOD%_SIGN"), + WALL_SIGN("%WOOD%_WALL_SIGN"), + BOAT("%WOOD%_BOAT"), + ; + final String template; + + WoodType(String template) { + this.template = template; + } + + /** + * Converts an oak material to a WoodType template. + * Do not use for any other wood. + *

    + * The dark oak check is there because schematics only check for the + * keyword "oak" + * + * @param oak material to convert to an WoodType enum + */ + public static @NotNull WoodType parse(@NotNull Material oak) { + return WoodType.valueOf(oak.toString().replace("DARK_OAK", "OAK").replace("OAK_", "")); + } + + // I am the pinnacle of optimisation + // Fear my absolutely unbeatable timings + public @Nullable Material getWood(@NotNull WoodSpecies species) { + return Material.getMaterial(template.replace("%WOOD%", species.toString())); + } + } + } diff --git a/common/src/main/java/org/terraform/utils/blockdata/BarrelBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/BarrelBuilder.java index 2c0f0221..ffc8e70f 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/BarrelBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/BarrelBuilder.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.coregen.TerraLootTable; import org.terraform.data.SimpleBlock; + import java.util.Random; public class BarrelBuilder { @@ -30,8 +31,9 @@ public BarrelBuilder() { public @NotNull BarrelBuilder apply(@NotNull SimpleBlock block) { block.setBlockData(blockData); - if (lootTable != null) + if (lootTable != null) { block.getPopData().lootTableChest(block.getX(), block.getY(), block.getZ(), lootTable); + } return this; } diff --git a/common/src/main/java/org/terraform/utils/blockdata/BisectedBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/BisectedBuilder.java index 72254566..d6baa78d 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/BisectedBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/BisectedBuilder.java @@ -16,8 +16,8 @@ public BisectedBuilder(@NotNull Material mat) { } public @NotNull BisectedBuilder placeBoth(@NotNull SimpleBlock block) { - Bisected upper = (Bisected) blockData.clone(); - upper.setHalf(Half.TOP); + Bisected upper = (Bisected) blockData.clone(); + upper.setHalf(Half.TOP); Bisected lower = (Bisected) blockData.clone(); lower.setHalf(Half.BOTTOM); block.setBlockData(lower); diff --git a/common/src/main/java/org/terraform/utils/blockdata/ChestBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/ChestBuilder.java index 6b5e39a7..8dd4e63f 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/ChestBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/ChestBuilder.java @@ -44,53 +44,57 @@ public ChestBuilder(Material... mat) { public @NotNull ChestBuilder apply(@NotNull SimpleBlock block) { block.setBlockData(blockData); - if (lootTable != null) + if (lootTable != null) { block.getPopData().lootTableChest(block.getX(), block.getY(), block.getZ(), lootTable); + } return this; } - + public void extend(@NotNull SimpleBlock original, @NotNull SimpleBlock extended, boolean lootTableExtendedChest) { - extended.setBlockData(blockData); - Wall originalWall = new Wall(original, blockData.getFacing()); + extended.setBlockData(blockData); + Wall originalWall = new Wall(original, blockData.getFacing()); Chest originalChest, extendedChest; - try - { + try { originalChest = (Chest) original.getBlockData(); extendedChest = (Chest) extended.getBlockData(); } - catch(ClassCastException e) - { + catch (ClassCastException e) { original.setBlockData(blockData); extended.setBlockData(blockData); originalChest = (Chest) blockData.clone(); // original.getBlockData(); extendedChest = (Chest) blockData.clone(); // original.getBlockData(); } - - if(originalWall.getLeft().equals(extended)) { - originalChest.setType(Type.LEFT); - extendedChest.setType(Type.RIGHT); - }else if(originalWall.getRight().equals(extended)) { - originalChest.setType(Type.RIGHT); - extendedChest.setType(Type.LEFT); - } - else { - throw new IllegalArgumentException("A request to extend a doublechest was made, but an invalid location was specified."); - } - - original.setBlockData(originalChest); - extended.setBlockData(extendedChest); - - if (lootTable != null) - original.getPopData().lootTableChest(original.getX(), original.getY(), original.getZ(), lootTable); - if (lootTableExtendedChest && lootTable != null) - extended.getPopData().lootTableChest(extended.getX(), extended.getY(), extended.getZ(), lootTable); + + if (originalWall.getLeft().equals(extended)) { + originalChest.setType(Type.LEFT); + extendedChest.setType(Type.RIGHT); + } + else if (originalWall.getRight().equals(extended)) { + originalChest.setType(Type.RIGHT); + extendedChest.setType(Type.LEFT); + } + else { + throw new IllegalArgumentException( + "A request to extend a doublechest was made, but an invalid location was specified."); + } + + original.setBlockData(originalChest); + extended.setBlockData(extendedChest); + + if (lootTable != null) { + original.getPopData().lootTableChest(original.getX(), original.getY(), original.getZ(), lootTable); + } + if (lootTableExtendedChest && lootTable != null) { + extended.getPopData().lootTableChest(extended.getX(), extended.getY(), extended.getZ(), lootTable); + } } public @NotNull ChestBuilder apply(@NotNull PopulatorDataAbstract data, int x, int y, int z) { data.setBlockData(x, y, z, blockData); - if (lootTable != null) + if (lootTable != null) { data.lootTableChest(x, y, z, lootTable); + } return this; } diff --git a/common/src/main/java/org/terraform/utils/blockdata/OrientableBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/OrientableBuilder.java index da0a4ac5..a1c8c629 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/OrientableBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/OrientableBuilder.java @@ -44,20 +44,23 @@ public OrientableBuilder(Material... mat) { } public @NotNull OrientableBuilder lapply(@NotNull SimpleBlock block) { - if(!block.isSolid()) - block.setBlockData(blockData); + if (!block.isSolid()) { + block.setBlockData(blockData); + } return this; } public @NotNull OrientableBuilder lapply(@NotNull Wall block) { - if(!block.isSolid()) - block.setBlockData(blockData); + if (!block.isSolid()) { + block.setBlockData(blockData); + } return this; } public @NotNull OrientableBuilder lapply(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if(!data.getType(x, y, z).isSolid()) - data.setBlockData(x, y, z, blockData); + if (!data.getType(x, y, z).isSolid()) { + data.setBlockData(x, y, z, blockData); + } return this; } diff --git a/common/src/main/java/org/terraform/utils/blockdata/SlabBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/SlabBuilder.java index 81347b9b..a9e2e589 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/SlabBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/SlabBuilder.java @@ -47,26 +47,29 @@ public SlabBuilder(Material... mat) { } public @NotNull SlabBuilder lapply(@NotNull SimpleBlock block) { - if(block.isSolid()) - return this; + if (block.isSolid()) { + return this; + } block.setBlockData(blockData); return this; } public @NotNull SlabBuilder lapply(@NotNull Wall block) { - if(block.isSolid()) - return this; + if (block.isSolid()) { + return this; + } block.setBlockData(blockData); return this; } public @NotNull SlabBuilder lapply(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if(data.getType(x,y,z).isSolid()) - return this; + if (data.getType(x, y, z).isSolid()) { + return this; + } data.setBlockData(x, y, z, blockData); return this; } - + public @NotNull Slab get() { return blockData; } diff --git a/common/src/main/java/org/terraform/utils/blockdata/StairBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/StairBuilder.java index 962d0c48..3f31f05f 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/StairBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/StairBuilder.java @@ -16,17 +16,19 @@ public class StairBuilder { + @NotNull + final ArrayList placed = new ArrayList<>(); private final @NotNull Stairs blockData; public StairBuilder(@NotNull Material mat) { this.blockData = (Stairs) Bukkit.createBlockData(mat); } + public StairBuilder(Material... mat) { this.blockData = (Stairs) Bukkit.createBlockData(GenUtils.randChoice(mat)); } - public @NotNull StairBuilder setFacing(@NotNull BlockFace face) { this.blockData.setFacing(face); return this; @@ -54,33 +56,32 @@ public StairBuilder(Material... mat) { } public @NotNull StairBuilder lapply(@NotNull SimpleBlock block) { - if(block.isSolid()) - return this; - + if (block.isSolid()) { + return this; + } + block.setBlockData(blockData); placed.add(block); return this; } - + public @NotNull StairBuilder apply(@NotNull Wall block) { block.setBlockData(blockData); placed.add(block.get()); return this; } - - @NotNull - final - ArrayList placed = new ArrayList<>(); + public @NotNull StairBuilder apply(@NotNull PopulatorDataAbstract data, int x, int y, int z) { data.setBlockData(x, y, z, blockData); - placed.add(new SimpleBlock(data,x,y,z)); + placed.add(new SimpleBlock(data, x, y, z)); return this; } - + public @NotNull StairBuilder correct() { - for(SimpleBlock b:placed) - BlockUtils.correctSurroundingStairData(b); - return this; + for (SimpleBlock b : placed) { + BlockUtils.correctSurroundingStairData(b); + } + return this; } public @NotNull Stairs get() { diff --git a/common/src/main/java/org/terraform/utils/blockdata/TrapdoorBuilder.java b/common/src/main/java/org/terraform/utils/blockdata/TrapdoorBuilder.java index 5641cdb2..5355177a 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/TrapdoorBuilder.java +++ b/common/src/main/java/org/terraform/utils/blockdata/TrapdoorBuilder.java @@ -60,8 +60,9 @@ public TrapdoorBuilder(Material... mat) { } public @NotNull TrapdoorBuilder lapply(@NotNull Wall block) { - if(!block.isSolid()) - block.setBlockData(blockData); + if (!block.isSolid()) { + block.setBlockData(blockData); + } return this; } diff --git a/common/src/main/java/org/terraform/utils/blockdata/fixers/v1_16_R1_BlockDataFixer.java b/common/src/main/java/org/terraform/utils/blockdata/fixers/v1_16_R1_BlockDataFixer.java index 06544781..9e03e706 100644 --- a/common/src/main/java/org/terraform/utils/blockdata/fixers/v1_16_R1_BlockDataFixer.java +++ b/common/src/main/java/org/terraform/utils/blockdata/fixers/v1_16_R1_BlockDataFixer.java @@ -17,42 +17,53 @@ public class v1_16_R1_BlockDataFixer extends BlockDataFixerAbstract { // TODO: Investigate what this class is for. Seems quite random to have this around. public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - Material relType = target.getRelative(face).getType(); - if (relType.isSolid() - && !Tag.BANNERS.isTagged(relType) - && !Tag.PRESSURE_PLATES.isTagged(relType) - && !Tag.TRAPDOORS.isTagged(relType) - && !Tag.SLABS.isTagged(relType)) { + Material relType = target.getRelative(face).getType(); + if (relType.isSolid() + && !Tag.BANNERS.isTagged(relType) + && !Tag.PRESSURE_PLATES.isTagged(relType) + && !Tag.TRAPDOORS.isTagged(relType) + && !Tag.SLABS.isTagged(relType)) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } // Ensure that target panes do not join with relType fences and vice versa - if(BlockUtils.glassPanes.contains(target.getType()) - && (Tag.FENCE_GATES.isTagged(relType)||Tag.FENCES.isTagged(relType))) { - data.setHeight(face, Height.NONE); - }else if((Tag.FENCES.isTagged(target.getType())||Tag.FENCE_GATES.isTagged(target.getType())) - && (BlockUtils.glassPanes.contains(relType))) { - data.setHeight(face, Height.NONE); + if (BlockUtils.glassPanes.contains(target.getType()) && (Tag.FENCE_GATES.isTagged(relType) + || Tag.FENCES.isTagged(relType))) + { + data.setHeight(face, Height.NONE); + } + else if ((Tag.FENCES.isTagged(target.getType()) || Tag.FENCE_GATES.isTagged(target.getType())) + && (BlockUtils.glassPanes.contains(relType))) + { + data.setHeight(face, Height.NONE); } - } else - data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } } } @@ -63,7 +74,9 @@ public String updateSchematic(double schematicVersion, String schematic) { @Override public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); + if (data == null && b != null) { + data = b.getBlockData(); + } if (!hasFlushed && data instanceof Wall) { this.pushChanges(v); diff --git a/common/src/main/java/org/terraform/utils/bstats/Metrics.java b/common/src/main/java/org/terraform/utils/bstats/Metrics.java index e39029c0..6e969668 100644 --- a/common/src/main/java/org/terraform/utils/bstats/Metrics.java +++ b/common/src/main/java/org/terraform/utils/bstats/Metrics.java @@ -1,21 +1,19 @@ package org.terraform.utils.bstats; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.net.ssl.HttpsURLConnection; +import java.io.*; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -26,815 +24,832 @@ import java.util.logging.Level; import java.util.stream.Collectors; import java.util.zip.GZIPOutputStream; -import javax.net.ssl.HttpsURLConnection; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * Written by bStats author, pasted here because fuck shading * ... - * */ public class Metrics { - private final @NotNull Plugin plugin; - private final boolean enabled; - - private final @NotNull MetricsBase metricsBase; - - /** - * Creates a new Metrics instance. - * - * @param plugin Your plugin instance. - * @param serviceId The id of the service. It can be found at What is my plugin id? - */ - public Metrics(@NotNull JavaPlugin plugin, int serviceId) { - this.plugin = plugin; - // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); - File configFile = new File(bStatsFolder, "config.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - if (!config.isSet("serverUuid")) { - config.addDefault("enabled", true); - config.addDefault("serverUuid", UUID.randomUUID().toString()); - config.addDefault("logFailedRequests", false); - config.addDefault("logSentData", false); - config.addDefault("logResponseStatusText", false); - // Inform the server owners about bStats - config - .options() - .header( - "bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" - + "many people use their plugin and their total player count. It's recommended to keep bStats\n" - + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" - + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" - + "anonymous.") - .copyDefaults(true); - try { - config.save(configFile); - } catch (IOException ignored) { - } - } - // Load the data - enabled = config.getBoolean("enabled", true); - String serverUUID = config.getString("serverUuid"); - boolean logErrors = config.getBoolean("logFailedRequests", false); - boolean logSentData = config.getBoolean("logSentData", false); - boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false); - metricsBase = - new MetricsBase( - "bukkit", - serverUUID, - serviceId, - enabled, - this::appendPlatformData, - this::appendServiceData, - submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), - plugin::isEnabled, - (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), - (message) -> this.plugin.getLogger().log(Level.INFO, message), - logErrors, - logSentData, - logResponseStatusText); - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - metricsBase.addCustomChart(chart); - } - - public boolean isEnabled() { - return enabled; - } - - private void appendPlatformData(@NotNull JsonObjectBuilder builder) { - builder.appendField("playerAmount", getPlayerAmount()); - builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0); - builder.appendField("bukkitVersion", Bukkit.getVersion()); - builder.appendField("bukkitName", Bukkit.getName()); - builder.appendField("javaVersion", System.getProperty("java.version")); - builder.appendField("osName", System.getProperty("os.name")); - builder.appendField("osArch", System.getProperty("os.arch")); - builder.appendField("osVersion", System.getProperty("os.version")); - builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); - } - - private void appendServiceData(@NotNull JsonObjectBuilder builder) { - builder.appendField("pluginVersion", plugin.getDescription().getVersion()); - } - - private int getPlayerAmount() { - try { - // Around MC 1.8 the return type was changed from an array to a collection, - // This fixes java.lang.NoSuchMethodError: - // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - return onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { - // Just use the new method if the reflection failed - return Bukkit.getOnlinePlayers().size(); - } - } - - public static class MetricsBase { - - /** The version of the Metrics class. */ - public static final String METRICS_VERSION = "2.2.1"; - - private static final ScheduledExecutorService scheduler = - Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics")); - - private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; - - private final String platform; - - private final String serverUuid; - - private final int serviceId; - - private final Consumer appendPlatformDataConsumer; - - private final Consumer appendServiceDataConsumer; - - private final Consumer submitTaskConsumer; - - private final Supplier checkServiceEnabledSupplier; - - private final BiConsumer errorLogger; - - private final Consumer infoLogger; - - private final boolean logErrors; - - private final boolean logSentData; - - private final boolean logResponseStatusText; - - private final Set customCharts = new HashSet<>(); - + private final @NotNull Plugin plugin; private final boolean enabled; + private final @NotNull MetricsBase metricsBase; + /** - * Creates a new MetricsBase class instance. + * Creates a new Metrics instance. * - * @param platform The platform of the service. - * @param serviceId The id of the service. - * @param serverUuid The server uuid. - * @param enabled Whether or not data sending is enabled. - * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all platform-specific data. - * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all service-specific data. - * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be - * used to delegate the data collection to a another thread to prevent errors caused by - * concurrency. Can be {@code null}. - * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. - * @param errorLogger A consumer that accepts log message and an error. - * @param infoLogger A consumer that accepts info log messages. - * @param logErrors Whether or not errors should be logged. - * @param logSentData Whether or not the sent data should be logged. - * @param logResponseStatusText Whether or not the response status text should be logged. + * @param plugin Your plugin instance. + * @param serviceId The id of the service. It can be found at What is my plugin id? */ - public MetricsBase( - String platform, - String serverUuid, - int serviceId, - boolean enabled, - Consumer appendPlatformDataConsumer, - Consumer appendServiceDataConsumer, - Consumer submitTaskConsumer, - Supplier checkServiceEnabledSupplier, - BiConsumer errorLogger, - Consumer infoLogger, - boolean logErrors, - boolean logSentData, - boolean logResponseStatusText) { - this.platform = platform; - this.serverUuid = serverUuid; - this.serviceId = serviceId; - this.enabled = enabled; - this.appendPlatformDataConsumer = appendPlatformDataConsumer; - this.appendServiceDataConsumer = appendServiceDataConsumer; - this.submitTaskConsumer = submitTaskConsumer; - this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; - this.errorLogger = errorLogger; - this.infoLogger = infoLogger; - this.logErrors = logErrors; - this.logSentData = logSentData; - this.logResponseStatusText = logResponseStatusText; - checkRelocation(); - if (enabled) { - startSubmitting(); - } + public Metrics(@NotNull JavaPlugin plugin, int serviceId) { + this.plugin = plugin; + // Get the config file + File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + File configFile = new File(bStatsFolder, "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + if (!config.isSet("serverUuid")) { + config.addDefault("enabled", true); + config.addDefault("serverUuid", UUID.randomUUID().toString()); + config.addDefault("logFailedRequests", false); + config.addDefault("logSentData", false); + config.addDefault("logResponseStatusText", false); + // Inform the server owners about bStats + config.options() + .header("bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" + + "many people use their plugin and their total player count. It's recommended to keep bStats\n" + + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" + + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" + + "anonymous.") + .copyDefaults(true); + try { + config.save(configFile); + } + catch (IOException ignored) { + } + } + // Load the data + enabled = config.getBoolean("enabled", true); + String serverUUID = config.getString("serverUuid"); + boolean logErrors = config.getBoolean("logFailedRequests", false); + boolean logSentData = config.getBoolean("logSentData", false); + boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false); + metricsBase = new MetricsBase("bukkit", + serverUUID, + serviceId, + enabled, + this::appendPlatformData, + this::appendServiceData, + submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), + plugin::isEnabled, + (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), + (message) -> this.plugin.getLogger().log(Level.INFO, message), + logErrors, + logSentData, + logResponseStatusText + ); } + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ public void addCustomChart(CustomChart chart) { - this.customCharts.add(chart); + metricsBase.addCustomChart(chart); } - private void startSubmitting() { - final Runnable submitTask = - () -> { - if (!enabled || !checkServiceEnabledSupplier.get()) { - // Submitting data or service is disabled - scheduler.shutdown(); - return; - } - if (submitTaskConsumer != null) { - submitTaskConsumer.accept(this::submitData); - } else { - this.submitData(); - } - }; - // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution - // of requests on the - // bStats backend. To circumvent this problem, we introduce some randomness into the initial - // and second delay. - // WARNING: You must not modify and part of this Metrics class, including the submit delay or - // frequency! - // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it! - long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); - long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); - scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); - scheduler.scheduleAtFixedRate( - submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS); + public boolean isEnabled() { + return enabled; } - - private void submitData() { - final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); - appendPlatformDataConsumer.accept(baseJsonBuilder); - final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); - appendServiceDataConsumer.accept(serviceJsonBuilder); - JsonObjectBuilder.JsonObject[] chartData = - customCharts.stream() - .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors)) - .filter(Objects::nonNull) - .toArray(JsonObjectBuilder.JsonObject[]::new); - serviceJsonBuilder.appendField("id", serviceId); - serviceJsonBuilder.appendField("customCharts", chartData); - baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); - baseJsonBuilder.appendField("serverUUID", serverUuid); - baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); - JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); - scheduler.execute( - () -> { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logErrors) { - errorLogger.accept("Could not submit bStats metrics data", e); - } - } - }); + private void appendPlatformData(@NotNull JsonObjectBuilder builder) { + builder.appendField("playerAmount", getPlayerAmount()); + builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0); + builder.appendField("bukkitVersion", Bukkit.getVersion()); + builder.appendField("bukkitName", Bukkit.getName()); + builder.appendField("javaVersion", System.getProperty("java.version")); + builder.appendField("osName", System.getProperty("os.name")); + builder.appendField("osArch", System.getProperty("os.arch")); + builder.appendField("osVersion", System.getProperty("os.version")); + builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); } - private void sendData(JsonObjectBuilder.@NotNull JsonObject data) throws Exception { - if (logSentData) { - infoLogger.accept("Sent bStats metrics data: " + data); - } - String url = String.format(REPORT_URL, platform); - HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestProperty("User-Agent", "Metrics-Service/1"); - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(compressedData); - } - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - } - if (logResponseStatusText) { - infoLogger.accept("Sent data to bStats and received response: " + builder); - } + private void appendServiceData(@NotNull JsonObjectBuilder builder) { + builder.appendField("pluginVersion", plugin.getDescription().getVersion()); } - /** Checks that the class was properly relocated. */ - private void checkRelocation() { - // You can use the property to disable the check in your test environment - if (System.getProperty("bstats.relocatecheck") == null - || !System.getProperty("bstats.relocatecheck").equals("false")) { - // Maven's Relocate is clever and changes strings, too. So we have to use this little - // "trick" ... :D - final String defaultPackage = - new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); - final String examplePackage = - new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); - // We want to make sure no one just copy & pastes the example and uses the wrong package - // names - if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) - || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) { - throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); - } - } + private int getPlayerAmount() { + try { + // Around MC 1.8 the return type was changed from an array to a collection, + // This fixes java.lang.NoSuchMethodError: + // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + return onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } + catch (Exception e) { + // Just use the new method if the reflection failed + return Bukkit.getOnlinePlayers().size(); + } } - /** - * Gzips the given string. - * - * @param str The string to gzip. - * @return The gzipped string. - */ - private static byte[] compress(final @Nullable String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - } + public static class MetricsBase { + + /** + * The version of the Metrics class. + */ + public static final String METRICS_VERSION = "2.2.1"; + + private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool( + 1, + task -> new Thread(task, "bStats-Metrics") + ); + + private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; + + private final String platform; + + private final String serverUuid; + + private final int serviceId; + + private final Consumer appendPlatformDataConsumer; + + private final Consumer appendServiceDataConsumer; + + private final Consumer submitTaskConsumer; + + private final Supplier checkServiceEnabledSupplier; + + private final BiConsumer errorLogger; + + private final Consumer infoLogger; + + private final boolean logErrors; + + private final boolean logSentData; + + private final boolean logResponseStatusText; + + private final Set customCharts = new HashSet<>(); + + private final boolean enabled; + + /** + * Creates a new MetricsBase class instance. + * + * @param platform The platform of the service. + * @param serviceId The id of the service. + * @param serverUuid The server uuid. + * @param enabled Whether or not data sending is enabled. + * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all platform-specific data. + * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all service-specific data. + * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be + * used to delegate the data collection to a another thread to prevent errors caused by + * concurrency. Can be {@code null}. + * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. + * @param errorLogger A consumer that accepts log message and an error. + * @param infoLogger A consumer that accepts info log messages. + * @param logErrors Whether or not errors should be logged. + * @param logSentData Whether or not the sent data should be logged. + * @param logResponseStatusText Whether or not the response status text should be logged. + */ + public MetricsBase(String platform, + String serverUuid, + int serviceId, + boolean enabled, + Consumer appendPlatformDataConsumer, + Consumer appendServiceDataConsumer, + Consumer submitTaskConsumer, + Supplier checkServiceEnabledSupplier, + BiConsumer errorLogger, + Consumer infoLogger, + boolean logErrors, + boolean logSentData, + boolean logResponseStatusText) + { + this.platform = platform; + this.serverUuid = serverUuid; + this.serviceId = serviceId; + this.enabled = enabled; + this.appendPlatformDataConsumer = appendPlatformDataConsumer; + this.appendServiceDataConsumer = appendServiceDataConsumer; + this.submitTaskConsumer = submitTaskConsumer; + this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; + this.errorLogger = errorLogger; + this.infoLogger = infoLogger; + this.logErrors = logErrors; + this.logSentData = logSentData; + this.logResponseStatusText = logResponseStatusText; + checkRelocation(); + if (enabled) { + startSubmitting(); + } + } - public static class AdvancedBarChart extends CustomChart { + /** + * Gzips the given string. + * + * @param str The string to gzip. + * @return The gzipped string. + */ + private static byte[] compress(final @Nullable String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } - private final Callable> callable; + public void addCustomChart(CustomChart chart) { + this.customCharts.add(chart); + } - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(@NotNull String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } + private void startSubmitting() { + final Runnable submitTask = () -> { + if (!enabled || !checkServiceEnabledSupplier.get()) { + // Submitting data or service is disabled + scheduler.shutdown(); + return; + } + if (submitTaskConsumer != null) { + submitTaskConsumer.accept(this::submitData); + } + else { + this.submitData(); + } + }; + // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution + // of requests on the + // bStats backend. To circumvent this problem, we introduce some randomness into the initial + // and second delay. + // WARNING: You must not modify and part of this Metrics class, including the submit delay or + // frequency! + // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it! + long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); + long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); + scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); + scheduler.scheduleAtFixedRate( + submitTask, + initialDelay + secondDelay, + 1000 * 60 * 30, + TimeUnit.MILLISECONDS + ); + } + + private void submitData() { + final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); + appendPlatformDataConsumer.accept(baseJsonBuilder); + final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); + appendServiceDataConsumer.accept(serviceJsonBuilder); + JsonObjectBuilder.JsonObject[] chartData = customCharts.stream() + .map(customChart -> customChart.getRequestJsonObject( + errorLogger, + logErrors + )) + .filter(Objects::nonNull) + .toArray(JsonObjectBuilder.JsonObject[]::new); + serviceJsonBuilder.appendField("id", serviceId); + serviceJsonBuilder.appendField("customCharts", chartData); + baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); + baseJsonBuilder.appendField("serverUUID", serverUuid); + baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); + JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); + scheduler.execute(() -> { + try { + // Send the data + sendData(data); + } + catch (Exception e) { + // Something went wrong! :( + if (logErrors) { + errorLogger.accept("Could not submit bStats metrics data", e); + } + } + }); + } + + private void sendData(JsonObjectBuilder.@NotNull JsonObject data) throws Exception { + if (logSentData) { + infoLogger.accept("Sent bStats metrics data: " + data); + } + String url = String.format(REPORT_URL, platform); + HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("User-Agent", "Metrics-Service/1"); + connection.setDoOutput(true); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + if (logResponseStatusText) { + infoLogger.accept("Sent data to bStats and received response: " + builder); + } + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + /** + * Checks that the class was properly relocated. + */ + private void checkRelocation() { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck") + .equals("false")) + { + // Maven's Relocate is clever and changes strings, too. So we have to use this little + // "trick" ... :D + final String defaultPackage = new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); + final String examplePackage = new String(new byte[] { + 'y', + 'o', + 'u', + 'r', + '.', + 'p', + 'a', + 'c', + 'k', + 'a', + 'g', + 'e' + }); + // We want to make sure no one just copy & pastes the example and uses the wrong package + // names + if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) + || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) + { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } } - } - public static class SimpleBarChart extends CustomChart { + public static class AdvancedBarChart extends CustomChart { - private final Callable> callable; + private final Callable> callable; - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(@NotNull String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedBarChart(@NotNull String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()}); - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue().length == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } } - } - public static class MultiLineChart extends CustomChart { + public static class SimpleBarChart extends CustomChart { - private final Callable> callable; + private final Callable> callable; - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(@NotNull String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimpleBarChart(@NotNull String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + for (Map.Entry entry : map.entrySet()) { + valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()}); + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } } - } - public static class AdvancedPie extends CustomChart { + public static class MultiLineChart extends CustomChart { - private final Callable> callable; + private final Callable> callable; - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(@NotNull String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public MultiLineChart(@NotNull String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - // Skip this invalid - continue; - } - allSkipped = false; - valuesBuilder.appendField(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } } - } - public abstract static class CustomChart { + public static class AdvancedPie extends CustomChart { - private final @NotNull String chartId; + private final Callable> callable; - protected CustomChart(@NotNull String chartId) { - this.chartId = chartId; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public AdvancedPie(@NotNull String chartId, Callable> callable) { + super(chartId); + this.callable = callable; + } - public JsonObjectBuilder.@Nullable JsonObject getRequestJsonObject( - @NotNull BiConsumer errorLogger, boolean logErrors) { - JsonObjectBuilder builder = new JsonObjectBuilder(); - builder.appendField("chartId", chartId); - try { - JsonObjectBuilder.JsonObject data = getChartData(); - if (data == null) { - // If the data is null we don't send the chart. - return null; - } - builder.appendField("data", data); - } catch (Throwable t) { - if (logErrors) { - errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); - } - return null; - } - return builder.build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean allSkipped = true; + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() == 0) { + // Skip this invalid + continue; + } + allSkipped = false; + valuesBuilder.appendField(entry.getKey(), entry.getValue()); + } + if (allSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } } - protected abstract JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception; - } + public abstract static class CustomChart { - public static class SingleLineChart extends CustomChart { + private final @NotNull String chartId; - private final Callable callable; + protected CustomChart(@NotNull String chartId) { + this.chartId = chartId; + } - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(@NotNull String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } + public JsonObjectBuilder.@Nullable JsonObject getRequestJsonObject(@NotNull BiConsumer errorLogger, + boolean logErrors) + { + JsonObjectBuilder builder = new JsonObjectBuilder(); + builder.appendField("chartId", chartId); + try { + JsonObjectBuilder.JsonObject data = getChartData(); + if (data == null) { + // If the data is null we don't send the chart. + return null; + } + builder.appendField("data", data); + } + catch (Throwable t) { + if (logErrors) { + errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); + } + return null; + } + return builder.build(); + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - int value = callable.call(); - if (value == 0) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("value", value).build(); + protected abstract JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception; } - } - public static class SimplePie extends CustomChart { + public static class SingleLineChart extends CustomChart { - private final Callable callable; + private final Callable callable; - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(@NotNull String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SingleLineChart(@NotNull String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } - @Override - protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - String value = callable.call(); - if (value == null || value.isEmpty()) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("value", value).build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + int value = callable.call(); + if (value == 0) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } } - } - public static class DrilldownPie extends CustomChart { + public static class SimplePie extends CustomChart { - private final Callable>> callable; + private final Callable callable; - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(@NotNull String chartId, Callable>> callable) { - super(chartId); - this.callable = callable; - } + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public SimplePie(@NotNull String chartId, Callable callable) { + super(chartId); + this.callable = callable; + } - @Override - public JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { - valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) { - reallyAllSkipped = false; - valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); - } - } - if (reallyAllSkipped) { - // Null = skip the chart - return null; - } - return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + @Override + protected JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + String value = callable.call(); + if (value == null || value.isEmpty()) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("value", value).build(); + } } - } - /** - * An extremely simple JSON builder. - * - *

    While this class is neither feature-rich nor the most performant one, it's sufficient enough - * for its use-case. - */ - public static class JsonObjectBuilder { + public static class DrilldownPie extends CustomChart { - private @Nullable StringBuilder builder = new StringBuilder(); + private final Callable>> callable; - private boolean hasAtLeastOneField = false; + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(@NotNull String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } - public JsonObjectBuilder() { - builder.append("{"); + @Override + public JsonObjectBuilder.@Nullable JsonObject getChartData() throws Exception { + JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); + } } /** - * Appends a null field to the JSON. + * An extremely simple JSON builder. * - * @param key The key of the field. - * @return A reference to this object. + *

    While this class is neither feature-rich nor the most performant one, it's sufficient enough + * for its use-case. */ - public @NotNull JsonObjectBuilder appendNull(@NotNull String key) { - appendFieldUnescaped(key, "null"); - return this; - } + public static class JsonObjectBuilder { - /** - * Appends a string field to the JSON. - * - * @param key The key of the field. - * @param value The value of the field. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, @NotNull String value) { - appendFieldUnescaped(key, "\"" + escape(value) + "\""); - return this; - } + private @Nullable StringBuilder builder = new StringBuilder(); - /** - * Appends an integer field to the JSON. - * - * @param key The key of the field. - * @param value The value of the field. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, int value) { - appendFieldUnescaped(key, String.valueOf(value)); - return this; - } + private boolean hasAtLeastOneField = false; - /** - * Appends an object to the JSON. - * - * @param key The key of the field. - * @param object The object. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, @NotNull JsonObject object) { - appendFieldUnescaped(key, object.toString()); - return this; - } + public JsonObjectBuilder() { + builder.append("{"); + } - /** - * Appends a string array to the JSON. - * - * @param key The key of the field. - * @param values The string array. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, String @NotNull [] values) { - String escapedValues = - Arrays.stream(values) - .map(value -> "\"" + escape(value) + "\"") - .collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } + /** + * Escapes the given string like stated in .... + * + *

    This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. + * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). + * + * @param value The value to escape. + * @return The escaped value. + */ + private static @NotNull String escape(@NotNull String value) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (c == '"') { + builder.append("\\\""); + } + else if (c == '\\') { + builder.append("\\\\"); + } + else if (c <= '\u000F') { + builder.append("\\u000").append(Integer.toHexString(c)); + } + else if (c <= '\u001F') { + builder.append("\\u00").append(Integer.toHexString(c)); + } + else { + builder.append(c); + } + } + return builder.toString(); + } - /** - * Appends an integer array to the JSON. - * - * @param key The key of the field. - * @param values The integer array. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, int @NotNull [] values) { - String escapedValues = - Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } + /** + * Appends a null field to the JSON. + * + * @param key The key of the field. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendNull(@NotNull String key) { + appendFieldUnescaped(key, "null"); + return this; + } - /** - * Appends an object array to the JSON. - * - * @param key The key of the field. - * @param values The integer array. - * @return A reference to this object. - */ - public @NotNull JsonObjectBuilder appendField(@NotNull String key, JsonObject @NotNull [] values) { - String escapedValues = - Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(",")); - appendFieldUnescaped(key, "[" + escapedValues + "]"); - return this; - } + /** + * Appends a string field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, @NotNull String value) { + appendFieldUnescaped(key, "\"" + escape(value) + "\""); + return this; + } - /** - * Appends a field to the object. - * - * @param key The key of the field. - * @param escapedValue The escaped value of the field. - */ - private void appendFieldUnescaped(@NotNull String key, String escapedValue) { - if (builder == null) { - throw new IllegalStateException("JSON has already been built"); - } - if (hasAtLeastOneField) { - builder.append(","); - } - builder.append("\"").append(escape(key)).append("\":").append(escapedValue); - hasAtLeastOneField = true; - } + /** + * Appends an integer field to the JSON. + * + * @param key The key of the field. + * @param value The value of the field. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, int value) { + appendFieldUnescaped(key, String.valueOf(value)); + return this; + } - /** - * Builds the JSON string and invalidates this builder. - * - * @return The built JSON string. - */ - public @NotNull JsonObject build() { - if (builder == null) { - throw new IllegalStateException("JSON has already been built"); - } - JsonObject object = new JsonObject(builder.append("}").toString()); - builder = null; - return object; - } + /** + * Appends an object to the JSON. + * + * @param key The key of the field. + * @param object The object. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, @NotNull JsonObject object) { + appendFieldUnescaped(key, object.toString()); + return this; + } - /** - * Escapes the given string like stated in .... - * - *

    This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. - * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). - * - * @param value The value to escape. - * @return The escaped value. - */ - private static @NotNull String escape(@NotNull String value) { - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < value.length(); i++) { - char c = value.charAt(i); - if (c == '"') { - builder.append("\\\""); - } else if (c == '\\') { - builder.append("\\\\"); - } else if (c <= '\u000F') { - builder.append("\\u000").append(Integer.toHexString(c)); - } else if (c <= '\u001F') { - builder.append("\\u00").append(Integer.toHexString(c)); - } else { - builder.append(c); - } - } - return builder.toString(); - } - /** - * A super simple representation of a JSON object. - * - *

    This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not - * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, - * JsonObject)}. - */ - public static class JsonObject { + /** + * Appends a string array to the JSON. + * + * @param key The key of the field. + * @param values The string array. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, String @NotNull [] values) { + String escapedValues = Arrays.stream(values) + .map(value -> "\"" + escape(value) + "\"") + .collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an integer array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, int @NotNull [] values) { + String escapedValues = Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends an object array to the JSON. + * + * @param key The key of the field. + * @param values The integer array. + * @return A reference to this object. + */ + public @NotNull JsonObjectBuilder appendField(@NotNull String key, JsonObject @NotNull [] values) { + String escapedValues = Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(",")); + appendFieldUnescaped(key, "[" + escapedValues + "]"); + return this; + } + + /** + * Appends a field to the object. + * + * @param key The key of the field. + * @param escapedValue The escaped value of the field. + */ + private void appendFieldUnescaped(@NotNull String key, String escapedValue) { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + if (hasAtLeastOneField) { + builder.append(","); + } + builder.append("\"").append(escape(key)).append("\":").append(escapedValue); + hasAtLeastOneField = true; + } + + /** + * Builds the JSON string and invalidates this builder. + * + * @return The built JSON string. + */ + public @NotNull JsonObject build() { + if (builder == null) { + throw new IllegalStateException("JSON has already been built"); + } + JsonObject object = new JsonObject(builder.append("}").toString()); + builder = null; + return object; + } + + /** + * A super simple representation of a JSON object. + * + *

    This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not + * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, + * JsonObject)}. + */ + public static class JsonObject { - private final String value; + private final String value; - private JsonObject(String value) { - this.value = value; - } + private JsonObject(String value) { + this.value = value; + } - @Override - public String toString() { - return value; - } + @Override + public String toString() { + return value; + } + } } - } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java b/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java index 52566fea..7f19a1a6 100644 --- a/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java +++ b/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java @@ -10,19 +10,25 @@ public TerraformGeneratorMetricsHandler(@NotNull TerraformGeneratorPlugin plugin int pluginId = 13968; Metrics metrics = new Metrics(plugin, pluginId); - - if(metrics.isEnabled()) { - metrics.addCustomChart(new Metrics.SimplePie("onlyUseLogsNoWood", () -> TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean() + "")); - metrics.addCustomChart(new Metrics.SimplePie("megaChunkNumBiomeSections", () -> TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt() + "")); - metrics.addCustomChart(new Metrics.SimplePie("biomeSectionBitshifts", () -> TConfigOption.BIOME_SECTION_BITSHIFTS.getInt() + "")); - TerraformGeneratorPlugin.logger.stdout("&abStats Metrics enabled."); + + if (metrics.isEnabled()) { + metrics.addCustomChart(new Metrics.SimplePie("onlyUseLogsNoWood", + () -> TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean() + "" + )); + metrics.addCustomChart(new Metrics.SimplePie("megaChunkNumBiomeSections", + () -> TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt() + "" + )); + metrics.addCustomChart(new Metrics.SimplePie("biomeSectionBitshifts", + () -> TConfigOption.BIOME_SECTION_BITSHIFTS.getInt() + "" + )); + TerraformGeneratorPlugin.logger.stdout("&abStats Metrics enabled."); + } + else { + TerraformGeneratorPlugin.logger.stdout("&cbStats Metrics disabled."); } - else - TerraformGeneratorPlugin.logger.stdout("&cbStats Metrics disabled."); - - - } - - - + + + } + + } diff --git a/common/src/main/java/org/terraform/utils/noise/BezierCurve.java b/common/src/main/java/org/terraform/utils/noise/BezierCurve.java index d088e6f5..56c750f9 100644 --- a/common/src/main/java/org/terraform/utils/noise/BezierCurve.java +++ b/common/src/main/java/org/terraform/utils/noise/BezierCurve.java @@ -5,9 +5,9 @@ // https://www.youtube.com/watch?v=dXECQRlmIaE :) public class BezierCurve { - Vector2f point1 = new Vector2f(0, 0); final Vector2f control1; final Vector2f control2; + Vector2f point1 = new Vector2f(0, 0); Vector2f point2 = new Vector2f(1, 1); /** @@ -28,23 +28,29 @@ public BezierCurve(Vector2f start, Vector2f control1, Vector2f control2, Vector2 /** * Cubic Bezier curve with two control points. + * * @param progress Value between 0 and 1 * @param point1 1st point * @param control1 1st control point * @param control2 2nd control point * @param point2 2nd point */ - public static @NotNull Vector2f cubic(float progress, @NotNull Vector2f point1, @NotNull Vector2f control1, @NotNull Vector2f control2, @NotNull Vector2f point2) { + public static @NotNull Vector2f cubic(float progress, + @NotNull Vector2f point1, + @NotNull Vector2f control1, + @NotNull Vector2f control2, + @NotNull Vector2f point2) + { float progressBw = 1 - progress; - double x = Math.pow(progressBw, 3) * point1.x + - Math.pow(progressBw, 2) * 3 * progress * control1.x + - progressBw * 3 * progress * progress * control2.x + - progress * progress * progress * point2.x; - double y = Math.pow(progressBw, 3) * point1.y + - Math.pow(progressBw, 2) * 3 * progress * control1.y + - progressBw * 3 * progress * progress * control2.y + - progress * progress * progress * point2.y; + double x = Math.pow(progressBw, 3) * point1.x + + Math.pow(progressBw, 2) * 3 * progress * control1.x + + progressBw * 3 * progress * progress * control2.x + + progress * progress * progress * point2.x; + double y = Math.pow(progressBw, 3) * point1.y + + Math.pow(progressBw, 2) * 3 * progress * control1.y + + progressBw * 3 * progress * progress * control2.y + + progress * progress * progress * point2.y; return new Vector2f((float) x, (float) y); } diff --git a/common/src/main/java/org/terraform/utils/noise/BresenhamLine.java b/common/src/main/java/org/terraform/utils/noise/BresenhamLine.java index 4c37fd79..f4ace523 100644 --- a/common/src/main/java/org/terraform/utils/noise/BresenhamLine.java +++ b/common/src/main/java/org/terraform/utils/noise/BresenhamLine.java @@ -1,11 +1,11 @@ package org.terraform.utils.noise; -import java.util.ArrayList; -import java.util.List; - import org.jetbrains.annotations.NotNull; import org.terraform.utils.Vector2f; +import java.util.ArrayList; +import java.util.List; + public class BresenhamLine { final Vector2f point1; final Vector2f point2; @@ -34,7 +34,9 @@ public BresenhamLine(Vector2f point1, Vector2f point2) { while (true) { line.add(new Vector2f(x0, y0)); - if (x0 == x1 && y0 == y1) break; + if (x0 == x1 && y0 == y1) { + break; + } e2 = 2 * err; if (e2 > -dy) { diff --git a/common/src/main/java/org/terraform/utils/noise/FastNoise.java b/common/src/main/java/org/terraform/utils/noise/FastNoise.java index f52b3661..a088787c 100644 --- a/common/src/main/java/org/terraform/utils/noise/FastNoise.java +++ b/common/src/main/java/org/terraform/utils/noise/FastNoise.java @@ -33,238 +33,549 @@ public class FastNoise { private static final Float2[] GRAD_2D = { - new Float2(-1, -1), new Float2(1, -1), new Float2(-1, 1), new Float2(1, 1), - new Float2(0, -1), new Float2(-1, 0), new Float2(0, 1), new Float2(1, 0), - }; + new Float2(-1, -1), + new Float2(1, -1), + new Float2(-1, 1), + new Float2(1, 1), + new Float2(0, -1), + new Float2(-1, 0), + new Float2(0, 1), + new Float2(1, 0), + }; private static final Float3[] GRAD_3D = { - new Float3(1, 1, 0), new Float3(-1, 1, 0), new Float3(1, -1, 0), new Float3(-1, -1, 0), - new Float3(1, 0, 1), new Float3(-1, 0, 1), new Float3(1, 0, -1), new Float3(-1, 0, -1), - new Float3(0, 1, 1), new Float3(0, -1, 1), new Float3(0, 1, -1), new Float3(0, -1, -1), - new Float3(1, 1, 0), new Float3(0, -1, 1), new Float3(-1, 1, 0), new Float3(0, -1, -1), - }; + new Float3(1, 1, 0), + new Float3(-1, 1, 0), + new Float3(1, -1, 0), + new Float3(-1, -1, 0), + new Float3(1, 0, 1), + new Float3(-1, 0, 1), + new Float3(1, 0, -1), + new Float3(-1, 0, -1), + new Float3(0, 1, 1), + new Float3(0, -1, 1), + new Float3(0, 1, -1), + new Float3(0, -1, -1), + new Float3(1, 1, 0), + new Float3(0, -1, 1), + new Float3(-1, 1, 0), + new Float3(0, -1, -1), + }; private static final Float2[] CELL_2D = { - new Float2(-0.4313539279f, 0.1281943404f), new Float2(-0.1733316799f, 0.415278375f), new Float2(-0.2821957395f, -0.3505218461f), - new Float2(-0.2806473808f, 0.3517627718f), new Float2(0.3125508975f, -0.3237467165f), new Float2(0.3383018443f, -0.2967353402f), - new Float2(-0.4393982022f, -0.09710417025f), new Float2(-0.4460443703f, -0.05953502905f), new Float2(-0.302223039f, 0.3334085102f), - new Float2(-0.212681052f, -0.3965687458f), new Float2(-0.2991156529f, 0.3361990872f), new Float2(0.2293323691f, 0.3871778202f), - new Float2(0.4475439151f, -0.04695150755f), new Float2(0.1777518f, 0.41340573f), new Float2(0.1688522499f, -0.4171197882f), - new Float2(-0.0976597166f, 0.4392750616f), new Float2(0.08450188373f, 0.4419948321f), new Float2(-0.4098760448f, -0.1857461384f), new Float2(0.3476585782f, - -0.2857157906f), new Float2(-0.3350670039f, - -0.30038326f), new Float2(0.2298190031f, -0.3868891648f), new Float2(-0.01069924099f, 0.449872789f), new Float2(-0.4460141246f, -0.05976119672f), + new Float2(-0.4313539279f, 0.1281943404f), + new Float2(-0.1733316799f, 0.415278375f), + new Float2(-0.2821957395f, -0.3505218461f), + new Float2(-0.2806473808f, 0.3517627718f), + new Float2(0.3125508975f, -0.3237467165f), + new Float2(0.3383018443f, -0.2967353402f), + new Float2(-0.4393982022f, -0.09710417025f), + new Float2(-0.4460443703f, -0.05953502905f), + new Float2(-0.302223039f, 0.3334085102f), + new Float2(-0.212681052f, -0.3965687458f), + new Float2(-0.2991156529f, 0.3361990872f), + new Float2(0.2293323691f, 0.3871778202f), + new Float2(0.4475439151f, -0.04695150755f), + new Float2(0.1777518f, 0.41340573f), + new Float2(0.1688522499f, -0.4171197882f), + new Float2(-0.0976597166f, 0.4392750616f), + new Float2(0.08450188373f, 0.4419948321f), + new Float2(-0.4098760448f, -0.1857461384f), + new Float2(0.3476585782f, -0.2857157906f), + new Float2(-0.3350670039f, -0.30038326f), + new Float2(0.2298190031f, -0.3868891648f), + new Float2(-0.01069924099f, 0.449872789f), + new Float2(-0.4460141246f, -0.05976119672f), new Float2(0.3650293864f, 0.2631606867f), - new Float2(-0.349479423f, 0.2834856838f), new Float2(-0.4122720642f, 0.1803655873f), new Float2(-0.267327811f, 0.3619887311f), new Float2(0.322124041f, - -0.3142230135f), new Float2(0.2880445931f, -0.3457315612f), new Float2(0.3892170926f, -0.2258540565f), new Float2(0.4492085018f, -0.02667811596f), + new Float2(-0.349479423f, 0.2834856838f), + new Float2(-0.4122720642f, 0.1803655873f), + new Float2(-0.267327811f, 0.3619887311f), + new Float2(0.322124041f, -0.3142230135f), + new Float2(0.2880445931f, -0.3457315612f), + new Float2(0.3892170926f, -0.2258540565f), + new Float2(0.4492085018f, -0.02667811596f), new Float2(-0.4497724772f, 0.01430799601f), - new Float2(0.1278175387f, -0.4314657307f), new Float2(-0.03572100503f, 0.4485799926f), new Float2(-0.4297407068f, -0.1335025276f), new Float2(-0.3217817723f, - 0.3145735065f), new Float2(-0.3057158873f, 0.3302087162f), new Float2(-0.414503978f, 0.1751754899f), new Float2(-0.3738139881f, 0.2505256519f), + new Float2(0.1278175387f, -0.4314657307f), + new Float2(-0.03572100503f, 0.4485799926f), + new Float2(-0.4297407068f, -0.1335025276f), + new Float2(-0.3217817723f, 0.3145735065f), + new Float2(-0.3057158873f, 0.3302087162f), + new Float2(-0.414503978f, 0.1751754899f), + new Float2(-0.3738139881f, 0.2505256519f), new Float2(0.2236891408f, -0.3904653228f), - new Float2(0.002967775577f, -0.4499902136f), new Float2(0.1747128327f, -0.4146991995f), new Float2(-0.4423772489f, -0.08247647938f), - new Float2(-0.2763960987f, -0.355112935f), new Float2(-0.4019385906f, -0.2023496216f), new Float2(0.3871414161f, -0.2293938184f), new Float2(-0.430008727f, - 0.1326367019f), new Float2(-0.03037574274f, -0.4489736231f), - new Float2(-0.3486181573f, 0.2845441624f), new Float2(0.04553517144f, -0.4476902368f), new Float2(-0.0375802926f, 0.4484280562f), new Float2(0.3266408905f, - 0.3095250049f), new Float2(0.06540017593f, -0.4452222108f), new Float2(0.03409025829f, 0.448706869f), new Float2(-0.4449193635f, 0.06742966669f), + new Float2(0.002967775577f, -0.4499902136f), + new Float2(0.1747128327f, -0.4146991995f), + new Float2(-0.4423772489f, -0.08247647938f), + new Float2(-0.2763960987f, -0.355112935f), + new Float2(-0.4019385906f, -0.2023496216f), + new Float2(0.3871414161f, -0.2293938184f), + new Float2(-0.430008727f, 0.1326367019f), + new Float2(-0.03037574274f, -0.4489736231f), + new Float2(-0.3486181573f, 0.2845441624f), + new Float2(0.04553517144f, -0.4476902368f), + new Float2(-0.0375802926f, 0.4484280562f), + new Float2(0.3266408905f, 0.3095250049f), + new Float2(0.06540017593f, -0.4452222108f), + new Float2(0.03409025829f, 0.448706869f), + new Float2(-0.4449193635f, 0.06742966669f), new Float2(-0.4255936157f, -0.1461850686f), - new Float2(0.449917292f, 0.008627302568f), new Float2(0.05242606404f, 0.4469356864f), new Float2(-0.4495305179f, -0.02055026661f), new Float2(-0.1204775703f, - 0.4335725488f), new Float2(-0.341986385f, -0.2924813028f), new Float2(0.3865320182f, 0.2304191809f), new Float2(0.04506097811f, -0.447738214f), + new Float2(0.449917292f, 0.008627302568f), + new Float2(0.05242606404f, 0.4469356864f), + new Float2(-0.4495305179f, -0.02055026661f), + new Float2(-0.1204775703f, 0.4335725488f), + new Float2(-0.341986385f, -0.2924813028f), + new Float2(0.3865320182f, 0.2304191809f), + new Float2(0.04506097811f, -0.447738214f), new Float2(-0.06283465979f, 0.4455915232f), - new Float2(0.3932600341f, -0.2187385324f), new Float2(0.4472261803f, -0.04988730975f), new Float2(0.3753571011f, -0.2482076684f), new Float2(-0.273662295f, - 0.357223947f), new Float2(0.1700461538f, 0.4166344988f), new Float2(0.4102692229f, 0.1848760794f), new Float2(0.323227187f, -0.3130881435f), + new Float2(0.3932600341f, -0.2187385324f), + new Float2(0.4472261803f, -0.04988730975f), + new Float2(0.3753571011f, -0.2482076684f), + new Float2(-0.273662295f, 0.357223947f), + new Float2(0.1700461538f, 0.4166344988f), + new Float2(0.4102692229f, 0.1848760794f), + new Float2(0.323227187f, -0.3130881435f), new Float2(-0.2882310238f, -0.3455761521f), - new Float2(0.2050972664f, 0.4005435199f), new Float2(0.4414085979f, -0.08751256895f), new Float2(-0.1684700334f, 0.4172743077f), new Float2(-0.003978032396f, - 0.4499824166f), new Float2(-0.2055133639f, 0.4003301853f), new Float2(-0.006095674897f, -0.4499587123f), new Float2(-0.1196228124f, -0.4338091548f), + new Float2(0.2050972664f, 0.4005435199f), + new Float2(0.4414085979f, -0.08751256895f), + new Float2(-0.1684700334f, 0.4172743077f), + new Float2(-0.003978032396f, 0.4499824166f), + new Float2(-0.2055133639f, 0.4003301853f), + new Float2(-0.006095674897f, -0.4499587123f), + new Float2(-0.1196228124f, -0.4338091548f), new Float2(0.3901528491f, -0.2242337048f), - new Float2(0.01723531752f, 0.4496698165f), new Float2(-0.3015070339f, 0.3340561458f), new Float2(-0.01514262423f, -0.4497451511f), new Float2(-0.4142574071f, - -0.1757577897f), new Float2(-0.1916377265f, -0.4071547394f), new Float2(0.3749248747f, 0.2488600778f), new Float2(-0.2237774255f, 0.3904147331f), + new Float2(0.01723531752f, 0.4496698165f), + new Float2(-0.3015070339f, 0.3340561458f), + new Float2(-0.01514262423f, -0.4497451511f), + new Float2(-0.4142574071f, -0.1757577897f), + new Float2(-0.1916377265f, -0.4071547394f), + new Float2(0.3749248747f, 0.2488600778f), + new Float2(-0.2237774255f, 0.3904147331f), new Float2(-0.4166343106f, -0.1700466149f), - new Float2(0.3619171625f, 0.267424695f), new Float2(0.1891126846f, -0.4083336779f), new Float2(-0.3127425077f, 0.323561623f), new Float2(-0.3281807787f, - 0.307891826f), new Float2(-0.2294806661f, 0.3870899429f), new Float2(-0.3445266136f, 0.2894847362f), new Float2(-0.4167095422f, -0.1698621719f), + new Float2(0.3619171625f, 0.267424695f), + new Float2(0.1891126846f, -0.4083336779f), + new Float2(-0.3127425077f, 0.323561623f), + new Float2(-0.3281807787f, 0.307891826f), + new Float2(-0.2294806661f, 0.3870899429f), + new Float2(-0.3445266136f, 0.2894847362f), + new Float2(-0.4167095422f, -0.1698621719f), new Float2(-0.257890321f, -0.3687717212f), - new Float2(-0.3612037825f, 0.2683874578f), new Float2(0.2267996491f, 0.3886668486f), new Float2(0.207157062f, 0.3994821043f), new Float2(0.08355176718f, - -0.4421754202f), new Float2(-0.4312233307f, 0.1286329626f), new Float2(0.3257055497f, 0.3105090899f), new Float2(0.177701095f, -0.4134275279f), + new Float2(-0.3612037825f, 0.2683874578f), + new Float2(0.2267996491f, 0.3886668486f), + new Float2(0.207157062f, 0.3994821043f), + new Float2(0.08355176718f, -0.4421754202f), + new Float2(-0.4312233307f, 0.1286329626f), + new Float2(0.3257055497f, 0.3105090899f), + new Float2(0.177701095f, -0.4134275279f), new Float2(-0.445182522f, 0.06566979625f), - new Float2(0.3955143435f, 0.2146355146f), new Float2(-0.4264613988f, 0.1436338239f), new Float2(-0.3793799665f, -0.2420141339f), new Float2(0.04617599081f, - -0.4476245948f), new Float2(-0.371405428f, -0.2540826796f), new Float2(0.2563570295f, -0.3698392535f), new Float2(0.03476646309f, 0.4486549822f), + new Float2(0.3955143435f, 0.2146355146f), + new Float2(-0.4264613988f, 0.1436338239f), + new Float2(-0.3793799665f, -0.2420141339f), + new Float2(0.04617599081f, -0.4476245948f), + new Float2(-0.371405428f, -0.2540826796f), + new Float2(0.2563570295f, -0.3698392535f), + new Float2(0.03476646309f, 0.4486549822f), new Float2(-0.3065454405f, 0.3294387544f), - new Float2(-0.2256979823f, 0.3893076172f), new Float2(0.4116448463f, -0.1817925206f), new Float2(-0.2907745828f, -0.3434387019f), new Float2(0.2842278468f, - -0.348876097f), new Float2(0.3114589359f, -0.3247973695f), new Float2(0.4464155859f, -0.0566844308f), new Float2(-0.3037334033f, -0.3320331606f), + new Float2(-0.2256979823f, 0.3893076172f), + new Float2(0.4116448463f, -0.1817925206f), + new Float2(-0.2907745828f, -0.3434387019f), + new Float2(0.2842278468f, -0.348876097f), + new Float2(0.3114589359f, -0.3247973695f), + new Float2(0.4464155859f, -0.0566844308f), + new Float2(-0.3037334033f, -0.3320331606f), new Float2(0.4079607166f, 0.1899159123f), - new Float2(-0.3486948919f, -0.2844501228f), new Float2(0.3264821436f, 0.3096924441f), new Float2(0.3211142406f, 0.3152548881f), new Float2(0.01183382662f, - 0.4498443737f), new Float2(0.4333844092f, 0.1211526057f), new Float2(0.3118668416f, 0.324405723f), new Float2(-0.272753471f, 0.3579183483f), + new Float2(-0.3486948919f, -0.2844501228f), + new Float2(0.3264821436f, 0.3096924441f), + new Float2(0.3211142406f, 0.3152548881f), + new Float2(0.01183382662f, 0.4498443737f), + new Float2(0.4333844092f, 0.1211526057f), + new Float2(0.3118668416f, 0.324405723f), + new Float2(-0.272753471f, 0.3579183483f), new Float2(-0.422228622f, -0.1556373694f), - new Float2(-0.1009700099f, -0.4385260051f), new Float2(-0.2741171231f, -0.3568750521f), new Float2(-0.1465125133f, 0.4254810025f), new Float2(0.2302279044f, - -0.3866459777f), new Float2(-0.3699435608f, 0.2562064828f), new Float2(0.105700352f, -0.4374099171f), new Float2(-0.2646713633f, 0.3639355292f), + new Float2(-0.1009700099f, -0.4385260051f), + new Float2(-0.2741171231f, -0.3568750521f), + new Float2(-0.1465125133f, 0.4254810025f), + new Float2(0.2302279044f, -0.3866459777f), + new Float2(-0.3699435608f, 0.2562064828f), + new Float2(0.105700352f, -0.4374099171f), + new Float2(-0.2646713633f, 0.3639355292f), new Float2(0.3521828122f, 0.2801200935f), - new Float2(-0.1864187807f, -0.4095705534f), new Float2(0.1994492955f, -0.4033856449f), new Float2(0.3937065066f, 0.2179339044f), new Float2(-0.3226158377f, - 0.3137180602f), new Float2(0.3796235338f, 0.2416318948f), new Float2(0.1482921929f, 0.4248640083f), new Float2(-0.407400394f, 0.1911149365f), + new Float2(-0.1864187807f, -0.4095705534f), + new Float2(0.1994492955f, -0.4033856449f), + new Float2(0.3937065066f, 0.2179339044f), + new Float2(-0.3226158377f, 0.3137180602f), + new Float2(0.3796235338f, 0.2416318948f), + new Float2(0.1482921929f, 0.4248640083f), + new Float2(-0.407400394f, 0.1911149365f), new Float2(0.4212853031f, 0.1581729856f), - new Float2(-0.2621297173f, 0.3657704353f), new Float2(-0.2536986953f, -0.3716678248f), new Float2(-0.2100236383f, 0.3979825013f), new Float2(0.3624152444f, - 0.2667493029f), new Float2(-0.3645038479f, -0.2638881295f), new Float2(0.2318486784f, 0.3856762766f), new Float2(-0.3260457004f, 0.3101519002f), + new Float2(-0.2621297173f, 0.3657704353f), + new Float2(-0.2536986953f, -0.3716678248f), + new Float2(-0.2100236383f, 0.3979825013f), + new Float2(0.3624152444f, 0.2667493029f), + new Float2(-0.3645038479f, -0.2638881295f), + new Float2(0.2318486784f, 0.3856762766f), + new Float2(-0.3260457004f, 0.3101519002f), new Float2(-0.2130045332f, -0.3963950918f), - new Float2(0.3814998766f, -0.2386584257f), new Float2(-0.342977305f, 0.2913186713f), new Float2(-0.4355865605f, 0.1129794154f), new Float2(-0.2104679605f, - 0.3977477059f), new Float2(0.3348364681f, -0.3006402163f), new Float2(0.3430468811f, 0.2912367377f), new Float2(-0.2291836801f, -0.3872658529f), + new Float2(0.3814998766f, -0.2386584257f), + new Float2(-0.342977305f, 0.2913186713f), + new Float2(-0.4355865605f, 0.1129794154f), + new Float2(-0.2104679605f, 0.3977477059f), + new Float2(0.3348364681f, -0.3006402163f), + new Float2(0.3430468811f, 0.2912367377f), + new Float2(-0.2291836801f, -0.3872658529f), new Float2(0.2547707298f, -0.3709337882f), - new Float2(0.4236174945f, -0.151816397f), new Float2(-0.15387742f, 0.4228731957f), new Float2(-0.4407449312f, 0.09079595574f), new Float2(-0.06805276192f, - -0.444824484f), new Float2(0.4453517192f, -0.06451237284f), new Float2(0.2562464609f, -0.3699158705f), new Float2(0.3278198355f, -0.3082761026f), + new Float2(0.4236174945f, -0.151816397f), + new Float2(-0.15387742f, 0.4228731957f), + new Float2(-0.4407449312f, 0.09079595574f), + new Float2(-0.06805276192f, -0.444824484f), + new Float2(0.4453517192f, -0.06451237284f), + new Float2(0.2562464609f, -0.3699158705f), + new Float2(0.3278198355f, -0.3082761026f), new Float2(-0.4122774207f, -0.1803533432f), - new Float2(0.3354090914f, -0.3000012356f), new Float2(0.446632869f, -0.05494615882f), new Float2(-0.1608953296f, 0.4202531296f), new Float2(-0.09463954939f, - 0.4399356268f), new Float2(-0.02637688324f, -0.4492262904f), new Float2(0.447102804f, -0.05098119915f), new Float2(-0.4365670908f, 0.1091291678f), + new Float2(0.3354090914f, -0.3000012356f), + new Float2(0.446632869f, -0.05494615882f), + new Float2(-0.1608953296f, 0.4202531296f), + new Float2(-0.09463954939f, 0.4399356268f), + new Float2(-0.02637688324f, -0.4492262904f), + new Float2(0.447102804f, -0.05098119915f), + new Float2(-0.4365670908f, 0.1091291678f), new Float2(-0.3959858651f, 0.2137643437f), - new Float2(-0.4240048207f, -0.1507312575f), new Float2(-0.3882794568f, 0.2274622243f), new Float2(-0.4283652566f, -0.1378521198f), new Float2(0.3303888091f, - 0.305521251f), new Float2(0.3321434919f, -0.3036127481f), new Float2(-0.413021046f, -0.1786438231f), new Float2(0.08403060337f, -0.4420846725f), + new Float2(-0.4240048207f, -0.1507312575f), + new Float2(-0.3882794568f, 0.2274622243f), + new Float2(-0.4283652566f, -0.1378521198f), + new Float2(0.3303888091f, 0.305521251f), + new Float2(0.3321434919f, -0.3036127481f), + new Float2(-0.413021046f, -0.1786438231f), + new Float2(0.08403060337f, -0.4420846725f), new Float2(-0.3822882919f, 0.2373934748f), - new Float2(-0.3712395594f, -0.2543249683f), new Float2(0.4472363971f, -0.04979563372f), new Float2(-0.4466591209f, 0.05473234629f), new Float2(0.0486272539f, - -0.4473649407f), new Float2(-0.4203101295f, -0.1607463688f), new Float2(0.2205360833f, 0.39225481f), new Float2(-0.3624900666f, 0.2666476169f), + new Float2(-0.3712395594f, -0.2543249683f), + new Float2(0.4472363971f, -0.04979563372f), + new Float2(-0.4466591209f, 0.05473234629f), + new Float2(0.0486272539f, -0.4473649407f), + new Float2(-0.4203101295f, -0.1607463688f), + new Float2(0.2205360833f, 0.39225481f), + new Float2(-0.3624900666f, 0.2666476169f), new Float2(-0.4036086833f, -0.1989975647f), - new Float2(0.2152727807f, 0.3951678503f), new Float2(-0.4359392962f, -0.1116106179f), new Float2(0.4178354266f, 0.1670735057f), new Float2(0.2007630161f, - 0.4027334247f), new Float2(-0.07278067175f, -0.4440754146f), new Float2(0.3644748615f, -0.2639281632f), new Float2(-0.4317451775f, 0.126870413f), + new Float2(0.2152727807f, 0.3951678503f), + new Float2(-0.4359392962f, -0.1116106179f), + new Float2(0.4178354266f, 0.1670735057f), + new Float2(0.2007630161f, 0.4027334247f), + new Float2(-0.07278067175f, -0.4440754146f), + new Float2(0.3644748615f, -0.2639281632f), + new Float2(-0.4317451775f, 0.126870413f), new Float2(-0.297436456f, 0.3376855855f), - new Float2(-0.2998672222f, 0.3355289094f), new Float2(-0.2673674124f, 0.3619594822f), new Float2(0.2808423357f, 0.3516071423f), new Float2(0.3498946567f, - 0.2829730186f), new Float2(-0.2229685561f, 0.390877248f), new Float2(0.3305823267f, 0.3053118493f), new Float2(-0.2436681211f, -0.3783197679f), + new Float2(-0.2998672222f, 0.3355289094f), + new Float2(-0.2673674124f, 0.3619594822f), + new Float2(0.2808423357f, 0.3516071423f), + new Float2(0.3498946567f, 0.2829730186f), + new Float2(-0.2229685561f, 0.390877248f), + new Float2(0.3305823267f, 0.3053118493f), + new Float2(-0.2436681211f, -0.3783197679f), new Float2(-0.03402776529f, 0.4487116125f), - new Float2(-0.319358823f, 0.3170330301f), new Float2(0.4454633477f, -0.06373700535f), new Float2(0.4483504221f, 0.03849544189f), new Float2(-0.4427358436f, - -0.08052932871f), new Float2(0.05452298565f, 0.4466847255f), new Float2(-0.2812560807f, 0.3512762688f), new Float2(0.1266696921f, 0.4318041097f), + new Float2(-0.319358823f, 0.3170330301f), + new Float2(0.4454633477f, -0.06373700535f), + new Float2(0.4483504221f, 0.03849544189f), + new Float2(-0.4427358436f, -0.08052932871f), + new Float2(0.05452298565f, 0.4466847255f), + new Float2(-0.2812560807f, 0.3512762688f), + new Float2(0.1266696921f, 0.4318041097f), new Float2(-0.3735981243f, 0.2508474468f), - new Float2(0.2959708351f, -0.3389708908f), new Float2(-0.3714377181f, 0.254035473f), new Float2(-0.404467102f, -0.1972469604f), new Float2(0.1636165687f, - -0.419201167f), new Float2(0.3289185495f, -0.3071035458f), new Float2(-0.2494824991f, -0.3745109914f), new Float2(0.03283133272f, 0.4488007393f), + new Float2(0.2959708351f, -0.3389708908f), + new Float2(-0.3714377181f, 0.254035473f), + new Float2(-0.404467102f, -0.1972469604f), + new Float2(0.1636165687f, -0.419201167f), + new Float2(0.3289185495f, -0.3071035458f), + new Float2(-0.2494824991f, -0.3745109914f), + new Float2(0.03283133272f, 0.4488007393f), new Float2(-0.166306057f, -0.4181414777f), - new Float2(-0.106833179f, 0.4371346153f), new Float2(0.06440260376f, -0.4453676062f), new Float2(-0.4483230967f, 0.03881238203f), new Float2(-0.421377757f, - -0.1579265206f), new Float2(0.05097920662f, -0.4471030312f), new Float2(0.2050584153f, -0.4005634111f), new Float2(0.4178098529f, -0.167137449f), + new Float2(-0.106833179f, 0.4371346153f), + new Float2(0.06440260376f, -0.4453676062f), + new Float2(-0.4483230967f, 0.03881238203f), + new Float2(-0.421377757f, -0.1579265206f), + new Float2(0.05097920662f, -0.4471030312f), + new Float2(0.2050584153f, -0.4005634111f), + new Float2(0.4178098529f, -0.167137449f), new Float2(-0.3565189504f, -0.2745801121f), - new Float2(0.4478398129f, 0.04403977727f), new Float2(-0.3399999602f, -0.2947881053f), new Float2(0.3767121994f, 0.2461461331f), new Float2(-0.3138934434f, - 0.3224451987f), new Float2(-0.1462001792f, -0.4255884251f), new Float2(0.3970290489f, -0.2118205239f), new Float2(0.4459149305f, -0.06049689889f), + new Float2(0.4478398129f, 0.04403977727f), + new Float2(-0.3399999602f, -0.2947881053f), + new Float2(0.3767121994f, 0.2461461331f), + new Float2(-0.3138934434f, 0.3224451987f), + new Float2(-0.1462001792f, -0.4255884251f), + new Float2(0.3970290489f, -0.2118205239f), + new Float2(0.4459149305f, -0.06049689889f), new Float2(-0.4104889426f, -0.1843877112f), - new Float2(0.1475103971f, -0.4251360756f), new Float2(0.09258030352f, 0.4403735771f), new Float2(-0.1589664637f, -0.4209865359f), new Float2(0.2482445008f, - 0.3753327428f), new Float2(0.4383624232f, -0.1016778537f), new Float2(0.06242802956f, 0.4456486745f), new Float2(0.2846591015f, -0.3485243118f), + new Float2(0.1475103971f, -0.4251360756f), + new Float2(0.09258030352f, 0.4403735771f), + new Float2(-0.1589664637f, -0.4209865359f), + new Float2(0.2482445008f, 0.3753327428f), + new Float2(0.4383624232f, -0.1016778537f), + new Float2(0.06242802956f, 0.4456486745f), + new Float2(0.2846591015f, -0.3485243118f), new Float2(-0.344202744f, -0.2898697484f), - new Float2(0.1198188883f, -0.4337550392f), new Float2(-0.243590703f, 0.3783696201f), new Float2(0.2958191174f, -0.3391033025f), new Float2(-0.1164007991f, - 0.4346847754f), new Float2(0.1274037151f, -0.4315881062f), new Float2(0.368047306f, 0.2589231171f), new Float2(0.2451436949f, 0.3773652989f), + new Float2(0.1198188883f, -0.4337550392f), + new Float2(-0.243590703f, 0.3783696201f), + new Float2(0.2958191174f, -0.3391033025f), + new Float2(-0.1164007991f, 0.4346847754f), + new Float2(0.1274037151f, -0.4315881062f), + new Float2(0.368047306f, 0.2589231171f), + new Float2(0.2451436949f, 0.3773652989f), new Float2(-0.4314509715f, 0.12786735f), - }; + }; private static final Float3[] CELL_3D = { - new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Float3(0.2877979582f, - -0.02606483451f, -0.3449535616f), new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), - new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), new Float3(0.4000921098f, -0.2034056362f, - 0.03244149937f), - new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Float3(0.2623596946f, - -0.2354852944f, 0.2796677792f), new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), - new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Float3(-0.2806854217f, -0.266996757f - , 0.2289725438f), - new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Float3(-0.1024352839f, 0.2128044156f, - -0.3830421561f), new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Float3(0.344678154f - , -0.1944240454f, -0.2142341261f), new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f), - new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Float3(-0.1852067326f, - -0.3454119342f, -0.2211087107f), new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), - new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Float3(-0.03801098351f, - 0.3277859044f, 0.3059600725f), - new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Float3(0.01985147278f, - -0.01503183293f, -0.4493105419f), new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), - new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Float3(0.01582798878f, - 0.4263894424f, 0.1429738373f), - new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Float3(-0.08974491322f, - 0.229148752f, -0.3767448739f), new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), - new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Float3(0.2396452163f, - 0.06803600538f, -0.3747549496f), - new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Float3(0.2709690528f, 0.1412648683f, - -0.3303331794f), new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Float3(-0.1986155616f - , 0.3836276443f, -0.1260225743f), new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f), - new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Float3(-0.3230334656f, - 0.201549922f, -0.2398478873f), new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), - new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Float3(-0.2890436293f, -0.3418179959f - , -0.04598084447f), - new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Float3(0.2204718095f, - 0.02654238946f, -0.391391981f), new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), - new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Float3(0.4032618332f, - -0.1124593585f, 0.1650235939f), - new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Float3(0.118937202f, -0.2875221847f, 0.325092195f), new Float3(0.02167047076f, - -0.03284630549f, -0.4482761547f), new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), - new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Float3(-0.2461455173f, - 0.02020282325f, -0.3761704803f), - new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Float3(-0.1347522818f, - -0.02720848277f, -0.4284874806f), new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), - new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Float3(0.2993663085f, -0.2619918095f - , -0.2103333191f), - new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Float3(0.05240429123f, 0.4335128183f - , -0.1087217856f), new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), - new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Float3(0.06413433865f, - 0.1708718512f, 0.4113266307f), - new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Float3(-0.1986120739f, - -0.3391173584f, 0.2192091725f), new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), - new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Float3(0.1444476522f, 0.1069184044f - , 0.4125570634f), - new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Float3(0.165872923f, - -0.3136808464f, -0.2767498872f), new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), - new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Float3(-0.3269323334f, - 0.3036542563f, 0.05838957105f), - new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), new Float3(0.3024892441f, -0.1009990293f, - -0.3174892964f), new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Float3(-0.3008872161f - , -0.333040905f, -0.03241355801f), new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f), - new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), new Float3(0.145016715f, -0.0398992945f - , 0.4241205002f), new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), new Float3(0.1028907093f, -0.361266869f, 0.247789732f), new Float3(0.2683057049f - , -0.07076041213f, -0.3542668666f), new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f), - new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Float3(-0.1707002821f, - 0.2215845691f, 0.3525077196f), new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), - new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Float3(-0.3529503428f, - -0.2472893463f, -0.129514612f), - new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Float3(-0.05635805671f, - 0.1485737441f, 0.4210102279f), new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), - new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Float3(-0.2733604046f, - 0.1973770973f, -0.2980207554f), - new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), new Float3(-0.03222023115f, -0.3331161506f, - -0.300824678f), new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), - new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Float3(-0.03767771199f, - -0.2290351443f, 0.3855169162f), - new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Float3(-0.1044637494f, - 0.4168128432f, -0.1336202785f), new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), - new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Float3(-0.2160686338f, 0.05376451292f, - -0.3910546287f), - new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Float3(-0.120167831f, 0.4017266681f, - 0.1633259825f), new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), - new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Float3(0.2822734956f, - 0.03754421121f, -0.3484423997f), - new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Float3(0.2933396046f, 0.3031973659f, - 0.1565989581f), new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), - new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Float3(0.09326603877f, -0.3170108894f - , 0.3054595587f), - new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Float3(0.1991339479f, 0.3820341668f - , -0.1299829458f), new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), - new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Float3(-0.4277366384f, 0.132066775f, - 0.04582286686f), - new Float3(0.240131882f, -0.1612516055f, 0.344723946f), new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Float3(-0.3837065682f, -0.2206398454f, - 0.08116235683f), new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), - new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Float3(-0.1580694418f, 0.4162931958f, - -0.06491553533f), - new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Float3(0.07365265219f, - -0.1666159848f, 0.411478311f), new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), - new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Float3(0.363398169f, -0.2310190248f - , 0.1306597909f), - new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Float3(0.2874852279f, 0.1642275508f - , -0.304764754f), new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), - new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Float3(0.1069384374f, - 0.3491024667f, -0.2630430352f), - new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Float3(0.3265787872f, 0.1871229129f - , 0.2466400438f), new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Float3(0.298137964f - , 0.2852657134f, 0.179547284f), new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f), - new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Float3(0.3182823114f, -0.307355516f, - -0.08203022006f), new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), - new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Float3(0.4330734858f, - -0.118868561f, -0.02859407492f), - new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Float3(-0.2687330705f, - 0.322686276f, -0.1617284888f), new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), - new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Float3(0.3664988455f, - 0.2550543014f, -0.05590974511f), - new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Float3(-0.2391566239f, - -0.2577696514f, -0.2808182972f), new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), - new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Float3(-0.01730330376f, - 0.2978486637f, -0.3368779738f), - new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Float3(-0.2669545963f, - 0.2599343665f, -0.2523278991f), new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), - new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Float3(-0.3026215288f, - -0.3001537679f, -0.1443188342f), - new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Float3(-0.03855010448f, - 0.09795110726f, 0.4375151083f), new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), - new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Float3(-0.07527055435f, - -0.425643481f, -0.1251477955f), - }; + new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), + new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), + new Float3(0.2877979582f, -0.02606483451f, -0.3449535616f), + new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), + new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), + new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), + new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), + new Float3(0.4000921098f, -0.2034056362f, 0.03244149937f), + new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), + new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), + new Float3(0.2623596946f, -0.2354852944f, 0.2796677792f), + new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), + new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), + new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), + new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), + new Float3(-0.2806854217f, -0.266996757f, 0.2289725438f), + new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), + new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), + new Float3(-0.1024352839f, 0.2128044156f, -0.3830421561f), + new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), + new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), + new Float3(0.344678154f, -0.1944240454f, -0.2142341261f), + new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), + new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f), + new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), + new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), + new Float3(-0.1852067326f, -0.3454119342f, -0.2211087107f), + new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), + new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), + new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), + new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), + new Float3(-0.03801098351f, 0.3277859044f, 0.3059600725f), + new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), + new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), + new Float3(0.01985147278f, -0.01503183293f, -0.4493105419f), + new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), + new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), + new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), + new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), + new Float3(0.01582798878f, 0.4263894424f, 0.1429738373f), + new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), + new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), + new Float3(-0.08974491322f, 0.229148752f, -0.3767448739f), + new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), + new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), + new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), + new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), + new Float3(0.2396452163f, 0.06803600538f, -0.3747549496f), + new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), + new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), + new Float3(0.2709690528f, 0.1412648683f, -0.3303331794f), + new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), + new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), + new Float3(-0.1986155616f, 0.3836276443f, -0.1260225743f), + new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), + new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f), + new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), + new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), + new Float3(-0.3230334656f, 0.201549922f, -0.2398478873f), + new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), + new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), + new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), + new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), + new Float3(-0.2890436293f, -0.3418179959f, -0.04598084447f), + new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), + new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), + new Float3(0.2204718095f, 0.02654238946f, -0.391391981f), + new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), + new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), + new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), + new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), + new Float3(0.4032618332f, -0.1124593585f, 0.1650235939f), + new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), + new Float3(0.118937202f, -0.2875221847f, 0.325092195f), + new Float3(0.02167047076f, -0.03284630549f, -0.4482761547f), + new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), + new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), + new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), + new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), + new Float3(-0.2461455173f, 0.02020282325f, -0.3761704803f), + new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), + new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), + new Float3(-0.1347522818f, -0.02720848277f, -0.4284874806f), + new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), + new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), + new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), + new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), + new Float3(0.2993663085f, -0.2619918095f, -0.2103333191f), + new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), + new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), + new Float3(0.05240429123f, 0.4335128183f, -0.1087217856f), + new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), + new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), + new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), + new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), + new Float3(0.06413433865f, 0.1708718512f, 0.4113266307f), + new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), + new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), + new Float3(-0.1986120739f, -0.3391173584f, 0.2192091725f), + new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), + new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), + new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), + new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), + new Float3(0.1444476522f, 0.1069184044f, 0.4125570634f), + new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), + new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), + new Float3(0.165872923f, -0.3136808464f, -0.2767498872f), + new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), + new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), + new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), + new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), + new Float3(-0.3269323334f, 0.3036542563f, 0.05838957105f), + new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), + new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), + new Float3(0.3024892441f, -0.1009990293f, -0.3174892964f), + new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), + new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), + new Float3(-0.3008872161f, -0.333040905f, -0.03241355801f), + new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), + new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f), + new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), + new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), + new Float3(0.145016715f, -0.0398992945f, 0.4241205002f), + new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), + new Float3(0.1028907093f, -0.361266869f, 0.247789732f), + new Float3(0.2683057049f, -0.07076041213f, -0.3542668666f), + new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), + new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f), + new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), + new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), + new Float3(-0.1707002821f, 0.2215845691f, 0.3525077196f), + new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), + new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), + new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), + new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), + new Float3(-0.3529503428f, -0.2472893463f, -0.129514612f), + new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), + new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), + new Float3(-0.05635805671f, 0.1485737441f, 0.4210102279f), + new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), + new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), + new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), + new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), + new Float3(-0.2733604046f, 0.1973770973f, -0.2980207554f), + new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), + new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), + new Float3(-0.03222023115f, -0.3331161506f, -0.300824678f), + new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), + new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), + new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), + new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), + new Float3(-0.03767771199f, -0.2290351443f, 0.3855169162f), + new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), + new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), + new Float3(-0.1044637494f, 0.4168128432f, -0.1336202785f), + new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), + new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), + new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), + new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), + new Float3(-0.2160686338f, 0.05376451292f, -0.3910546287f), + new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), + new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), + new Float3(-0.120167831f, 0.4017266681f, 0.1633259825f), + new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), + new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), + new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), + new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), + new Float3(0.2822734956f, 0.03754421121f, -0.3484423997f), + new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), + new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), + new Float3(0.2933396046f, 0.3031973659f, 0.1565989581f), + new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), + new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), + new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), + new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), + new Float3(0.09326603877f, -0.3170108894f, 0.3054595587f), + new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), + new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), + new Float3(0.1991339479f, 0.3820341668f, -0.1299829458f), + new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), + new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), + new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), + new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), + new Float3(-0.4277366384f, 0.132066775f, 0.04582286686f), + new Float3(0.240131882f, -0.1612516055f, 0.344723946f), + new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), + new Float3(-0.3837065682f, -0.2206398454f, 0.08116235683f), + new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), + new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), + new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), + new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), + new Float3(-0.1580694418f, 0.4162931958f, -0.06491553533f), + new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), + new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), + new Float3(0.07365265219f, -0.1666159848f, 0.411478311f), + new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), + new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), + new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), + new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), + new Float3(0.363398169f, -0.2310190248f, 0.1306597909f), + new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), + new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), + new Float3(0.2874852279f, 0.1642275508f, -0.304764754f), + new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), + new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), + new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), + new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), + new Float3(0.1069384374f, 0.3491024667f, -0.2630430352f), + new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), + new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), + new Float3(0.3265787872f, 0.1871229129f, 0.2466400438f), + new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), + new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), + new Float3(0.298137964f, 0.2852657134f, 0.179547284f), + new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), + new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f), + new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), + new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), + new Float3(0.3182823114f, -0.307355516f, -0.08203022006f), + new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), + new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), + new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), + new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), + new Float3(0.4330734858f, -0.118868561f, -0.02859407492f), + new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), + new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), + new Float3(-0.2687330705f, 0.322686276f, -0.1617284888f), + new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), + new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), + new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), + new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), + new Float3(0.3664988455f, 0.2550543014f, -0.05590974511f), + new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), + new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), + new Float3(-0.2391566239f, -0.2577696514f, -0.2808182972f), + new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), + new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), + new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), + new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), + new Float3(-0.01730330376f, 0.2978486637f, -0.3368779738f), + new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), + new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), + new Float3(-0.2669545963f, 0.2599343665f, -0.2523278991f), + new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), + new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), + new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), + new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), + new Float3(-0.3026215288f, -0.3001537679f, -0.1443188342f), + new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), + new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), + new Float3(-0.03855010448f, 0.09795110726f, 0.4375151083f), + new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), + new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), + new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), + new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), + new Float3(-0.07527055435f, -0.425643481f, -0.1251477955f), + }; // Hashing private static final int X_PRIME = 1619; private static final int Y_PRIME = 31337; @@ -276,14 +587,262 @@ public class FastNoise { private static final float F2 = (float) (1.0 / 2.0); private static final float G2 = (float) (1.0 / 4.0); private static final byte[] SIMPLEX_4D = { - 0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, - 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, - 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, - 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 + 0, + 1, + 2, + 3, + 0, + 1, + 3, + 2, + 0, + 0, + 0, + 0, + 0, + 2, + 3, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 2, + 3, + 0, + 0, + 2, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 3, + 1, + 2, + 0, + 3, + 2, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 3, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 2, + 0, + 3, + 0, + 0, + 0, + 0, + 1, + 3, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 3, + 0, + 1, + 2, + 3, + 1, + 0, + 1, + 0, + 2, + 3, + 1, + 0, + 3, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 0, + 3, + 1, + 0, + 0, + 0, + 0, + 2, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 0, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 3, + 0, + 1, + 2, + 3, + 0, + 2, + 1, + 0, + 0, + 0, + 0, + 3, + 1, + 2, + 0, + 2, + 1, + 0, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 3, + 1, + 0, + 2, + 0, + 0, + 0, + 0, + 3, + 2, + 0, + 1, + 3, + 2, + 1, + 0 }; private static final float F4 = (float) ((2.23606797 - 1.0) / 4.0); private static final float G4 = (float) ((5.0 - 2.23606797) / 20.0); @@ -492,14 +1051,16 @@ private static float SingleSimplex(int seed, float x, float y, float z) { i2 = 1; j2 = 1; k2 = 0; - } else if (x0 >= z0) { + } + else if (x0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; - } else // x0 < z0 + } + else // x0 < z0 { i1 = 0; j1 = 0; @@ -508,7 +1069,8 @@ private static float SingleSimplex(int seed, float x, float y, float z) { j2 = 0; k2 = 1; } - } else // x0 < y0 + } + else // x0 < y0 { if (y0 < z0) { i1 = 0; @@ -517,14 +1079,16 @@ private static float SingleSimplex(int seed, float x, float y, float z) { i2 = 0; j2 = 1; k2 = 1; - } else if (x0 < z0) { + } + else if (x0 < z0) { i1 = 0; j1 = 1; k1 = 0; i2 = 0; j2 = 1; k2 = 1; - } else // x0 >= z0 + } + else // x0 >= z0 { i1 = 0; j1 = 1; @@ -548,28 +1112,36 @@ private static float SingleSimplex(int seed, float x, float y, float z) { float n0, n1, n2, n3; t = (float) 0.6 - x0 * x0 - y0 * y0 - z0 * z0; - if (t < 0) n0 = 0; + if (t < 0) { + n0 = 0; + } else { t *= t; n0 = t * t * GradCoord3D(seed, i, j, k, x0, y0, z0); } t = (float) 0.6 - x1 * x1 - y1 * y1 - z1 * z1; - if (t < 0) n1 = 0; + if (t < 0) { + n1 = 0; + } else { t *= t; n1 = t * t * GradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1); } t = (float) 0.6 - x2 * x2 - y2 * y2 - z2 * z2; - if (t < 0) n2 = 0; + if (t < 0) { + n2 = 0; + } else { t *= t; n2 = t * t * GradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2); } t = (float) 0.6 - x3 * x3 - y3 * y3 - z3 * z3; - if (t < 0) n3 = 0; + if (t < 0) { + n3 = 0; + } else { t *= t; n3 = t * t * GradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3); @@ -594,7 +1166,8 @@ private static float SingleSimplex(int seed, float x, float y) { if (x0 > y0) { i1 = 1; j1 = 0; - } else { + } + else { i1 = 0; j1 = 1; } @@ -607,21 +1180,27 @@ private static float SingleSimplex(int seed, float x, float y) { float n0, n1, n2; t = (float) 0.5 - x0 * x0 - y0 * y0; - if (t < 0) n0 = 0; + if (t < 0) { + n0 = 0; + } else { t *= t; n0 = t * t * GradCoord2D(seed, i, j, x0, y0); } t = (float) 0.5 - x1 * x1 - y1 * y1; - if (t < 0) n1 = 0; + if (t < 0) { + n1 = 0; + } else { t *= t; n1 = t * t * GradCoord2D(seed, i + i1, j + j1, x1, y1); } t = (float) 0.5 - x2 * x2 - y2 * y2; - if (t < 0) n2 = 0; + if (t < 0) { + n2 = 0; + } else { t *= t; n2 = t * t * GradCoord2D(seed, i + 1, j + 1, x2, y2); @@ -686,31 +1265,41 @@ private static float SingleSimplex(int seed, float x, float y, float z, float w) float w4 = w0 - 1 + 4 * G4; t = (float) 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0; - if (t < 0) n0 = 0; + if (t < 0) { + n0 = 0; + } else { t *= t; n0 = t * t * GradCoord4D(seed, i, j, k, l, x0, y0, z0, w0); } t = (float) 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1; - if (t < 0) n1 = 0; + if (t < 0) { + n1 = 0; + } else { t *= t; n1 = t * t * GradCoord4D(seed, i + i1, j + j1, k + k1, l + l1, x1, y1, z1, w1); } t = (float) 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2; - if (t < 0) n2 = 0; + if (t < 0) { + n2 = 0; + } else { t *= t; n2 = t * t * GradCoord4D(seed, i + i2, j + j2, k + k2, l + l2, x2, y2, z2, w2); } t = (float) 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3; - if (t < 0) n3 = 0; + if (t < 0) { + n3 = 0; + } else { t *= t; n3 = t * t * GradCoord4D(seed, i + i3, j + j3, k + k3, l + l3, x3, y3, z3, w3); } t = (float) 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4; - if (t < 0) n4 = 0; + if (t < 0) { + n4 = 0; + } else { t *= t; n4 = t * t * GradCoord4D(seed, i + 1, j + 1, k + 1, l + 1, x4, y4, z4, w4); @@ -738,32 +1327,111 @@ private static float SingleCubic(int seed, float x, float y, float z) { float ys = y - (float) y1; float zs = z - (float) z1; - return CubicLerp( - CubicLerp( - CubicLerp(ValCoord3D(seed, x0, y0, z0), ValCoord3D(seed, x1, y0, z0), ValCoord3D(seed, x2, y0, z0), ValCoord3D(seed, x3, y0, z0), xs), - CubicLerp(ValCoord3D(seed, x0, y1, z0), ValCoord3D(seed, x1, y1, z0), ValCoord3D(seed, x2, y1, z0), ValCoord3D(seed, x3, y1, z0), xs), - CubicLerp(ValCoord3D(seed, x0, y2, z0), ValCoord3D(seed, x1, y2, z0), ValCoord3D(seed, x2, y2, z0), ValCoord3D(seed, x3, y2, z0), xs), - CubicLerp(ValCoord3D(seed, x0, y3, z0), ValCoord3D(seed, x1, y3, z0), ValCoord3D(seed, x2, y3, z0), ValCoord3D(seed, x3, y3, z0), xs), - ys), - CubicLerp( - CubicLerp(ValCoord3D(seed, x0, y0, z1), ValCoord3D(seed, x1, y0, z1), ValCoord3D(seed, x2, y0, z1), ValCoord3D(seed, x3, y0, z1), xs), - CubicLerp(ValCoord3D(seed, x0, y1, z1), ValCoord3D(seed, x1, y1, z1), ValCoord3D(seed, x2, y1, z1), ValCoord3D(seed, x3, y1, z1), xs), - CubicLerp(ValCoord3D(seed, x0, y2, z1), ValCoord3D(seed, x1, y2, z1), ValCoord3D(seed, x2, y2, z1), ValCoord3D(seed, x3, y2, z1), xs), - CubicLerp(ValCoord3D(seed, x0, y3, z1), ValCoord3D(seed, x1, y3, z1), ValCoord3D(seed, x2, y3, z1), ValCoord3D(seed, x3, y3, z1), xs), - ys), - CubicLerp( - CubicLerp(ValCoord3D(seed, x0, y0, z2), ValCoord3D(seed, x1, y0, z2), ValCoord3D(seed, x2, y0, z2), ValCoord3D(seed, x3, y0, z2), xs), - CubicLerp(ValCoord3D(seed, x0, y1, z2), ValCoord3D(seed, x1, y1, z2), ValCoord3D(seed, x2, y1, z2), ValCoord3D(seed, x3, y1, z2), xs), - CubicLerp(ValCoord3D(seed, x0, y2, z2), ValCoord3D(seed, x1, y2, z2), ValCoord3D(seed, x2, y2, z2), ValCoord3D(seed, x3, y2, z2), xs), - CubicLerp(ValCoord3D(seed, x0, y3, z2), ValCoord3D(seed, x1, y3, z2), ValCoord3D(seed, x2, y3, z2), ValCoord3D(seed, x3, y3, z2), xs), - ys), - CubicLerp( - CubicLerp(ValCoord3D(seed, x0, y0, z3), ValCoord3D(seed, x1, y0, z3), ValCoord3D(seed, x2, y0, z3), ValCoord3D(seed, x3, y0, z3), xs), - CubicLerp(ValCoord3D(seed, x0, y1, z3), ValCoord3D(seed, x1, y1, z3), ValCoord3D(seed, x2, y1, z3), ValCoord3D(seed, x3, y1, z3), xs), - CubicLerp(ValCoord3D(seed, x0, y2, z3), ValCoord3D(seed, x1, y2, z3), ValCoord3D(seed, x2, y2, z3), ValCoord3D(seed, x3, y2, z3), xs), - CubicLerp(ValCoord3D(seed, x0, y3, z3), ValCoord3D(seed, x1, y3, z3), ValCoord3D(seed, x2, y3, z3), ValCoord3D(seed, x3, y3, z3), xs), - ys), - zs) * CUBIC_3D_BOUNDING; + return CubicLerp(CubicLerp(CubicLerp( + ValCoord3D(seed, x0, y0, z0), + ValCoord3D(seed, x1, y0, z0), + ValCoord3D(seed, x2, y0, z0), + ValCoord3D(seed, x3, y0, z0), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y1, z0), + ValCoord3D(seed, x1, y1, z0), + ValCoord3D(seed, x2, y1, z0), + ValCoord3D(seed, x3, y1, z0), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y2, z0), + ValCoord3D(seed, x1, y2, z0), + ValCoord3D(seed, x2, y2, z0), + ValCoord3D(seed, x3, y2, z0), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y3, z0), + ValCoord3D(seed, x1, y3, z0), + ValCoord3D(seed, x2, y3, z0), + ValCoord3D(seed, x3, y3, z0), + xs + ), + ys + ), CubicLerp(CubicLerp( + ValCoord3D(seed, x0, y0, z1), + ValCoord3D(seed, x1, y0, z1), + ValCoord3D(seed, x2, y0, z1), + ValCoord3D(seed, x3, y0, z1), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y1, z1), + ValCoord3D(seed, x1, y1, z1), + ValCoord3D(seed, x2, y1, z1), + ValCoord3D(seed, x3, y1, z1), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y2, z1), + ValCoord3D(seed, x1, y2, z1), + ValCoord3D(seed, x2, y2, z1), + ValCoord3D(seed, x3, y2, z1), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y3, z1), + ValCoord3D(seed, x1, y3, z1), + ValCoord3D(seed, x2, y3, z1), + ValCoord3D(seed, x3, y3, z1), + xs + ), + ys + ), CubicLerp(CubicLerp( + ValCoord3D(seed, x0, y0, z2), + ValCoord3D(seed, x1, y0, z2), + ValCoord3D(seed, x2, y0, z2), + ValCoord3D(seed, x3, y0, z2), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y1, z2), + ValCoord3D(seed, x1, y1, z2), + ValCoord3D(seed, x2, y1, z2), + ValCoord3D(seed, x3, y1, z2), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y2, z2), + ValCoord3D(seed, x1, y2, z2), + ValCoord3D(seed, x2, y2, z2), + ValCoord3D(seed, x3, y2, z2), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y3, z2), + ValCoord3D(seed, x1, y3, z2), + ValCoord3D(seed, x2, y3, z2), + ValCoord3D(seed, x3, y3, z2), + xs + ), + ys + ), CubicLerp(CubicLerp( + ValCoord3D(seed, x0, y0, z3), + ValCoord3D(seed, x1, y0, z3), + ValCoord3D(seed, x2, y0, z3), + ValCoord3D(seed, x3, y0, z3), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y1, z3), + ValCoord3D(seed, x1, y1, z3), + ValCoord3D(seed, x2, y1, z3), + ValCoord3D(seed, x3, y1, z3), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y2, z3), + ValCoord3D(seed, x1, y2, z3), + ValCoord3D(seed, x2, y2, z3), + ValCoord3D(seed, x3, y2, z3), + xs + ), + CubicLerp(ValCoord3D(seed, x0, y3, z3), + ValCoord3D(seed, x1, y3, z3), + ValCoord3D(seed, x2, y3, z3), + ValCoord3D(seed, x3, y3, z3), + xs + ), + ys + ), zs) * CUBIC_3D_BOUNDING; } private static float SingleCubic(int seed, float x, float y) { @@ -780,16 +1448,27 @@ private static float SingleCubic(int seed, float x, float y) { float xs = x - (float) x1; float ys = y - (float) y1; - return CubicLerp( - CubicLerp(ValCoord2D(seed, x0, y0), ValCoord2D(seed, x1, y0), ValCoord2D(seed, x2, y0), ValCoord2D(seed, x3, y0), - xs), - CubicLerp(ValCoord2D(seed, x0, y1), ValCoord2D(seed, x1, y1), ValCoord2D(seed, x2, y1), ValCoord2D(seed, x3, y1), - xs), - CubicLerp(ValCoord2D(seed, x0, y2), ValCoord2D(seed, x1, y2), ValCoord2D(seed, x2, y2), ValCoord2D(seed, x3, y2), - xs), - CubicLerp(ValCoord2D(seed, x0, y3), ValCoord2D(seed, x1, y3), ValCoord2D(seed, x2, y3), ValCoord2D(seed, x3, y3), - xs), - ys) * CUBIC_2D_BOUNDING; + return CubicLerp(CubicLerp(ValCoord2D(seed, x0, y0), + ValCoord2D(seed, x1, y0), + ValCoord2D(seed, x2, y0), + ValCoord2D(seed, x3, y0), + xs + ), CubicLerp(ValCoord2D(seed, x0, y1), + ValCoord2D(seed, x1, y1), + ValCoord2D(seed, x2, y1), + ValCoord2D(seed, x3, y1), + xs + ), CubicLerp(ValCoord2D(seed, x0, y2), + ValCoord2D(seed, x1, y2), + ValCoord2D(seed, x2, y2), + ValCoord2D(seed, x3, y2), + xs + ), CubicLerp(ValCoord2D(seed, x0, y3), + ValCoord2D(seed, x1, y3), + ValCoord2D(seed, x2, y3), + ValCoord2D(seed, x3, y3), + xs + ), ys) * CUBIC_2D_BOUNDING; } // Returns the seed used by this object @@ -898,7 +1577,7 @@ public float GetNoise(float x, float y, float z) { case Value: return SingleValue(m_seed, x, y, z); case ValueFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleValueFractalFBM(x, y, z); case Billow -> SingleValueFractalBillow(x, y, z); case RigidMulti -> SingleValueFractalRigidMulti(x, y, z); @@ -907,7 +1586,7 @@ public float GetNoise(float x, float y, float z) { case Perlin: return SinglePerlin(m_seed, x, y, z); case PerlinFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SinglePerlinFractalFBM(x, y, z); case Billow -> SinglePerlinFractalBillow(x, y, z); case RigidMulti -> SinglePerlinFractalRigidMulti(x, y, z); @@ -916,14 +1595,14 @@ public float GetNoise(float x, float y, float z) { case Simplex: return SingleSimplex(m_seed, x, y, z); case SimplexFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleSimplexFractalFBM(x, y, z); case Billow -> SingleSimplexFractalBillow(x, y, z); case RigidMulti -> SingleSimplexFractalRigidMulti(x, y, z); default -> 0; }; case Cellular: - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue, NoiseLookup, Distance -> SingleCellular(x, y, z); default -> SingleCellular2Edge(x, y, z); }; @@ -932,7 +1611,7 @@ public float GetNoise(float x, float y, float z) { case Cubic: return SingleCubic(m_seed, x, y, z); case CubicFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleCubicFractalFBM(x, y, z); case Billow -> SingleCubicFractalBillow(x, y, z); case RigidMulti -> SingleCubicFractalRigidMulti(x, y, z); @@ -951,7 +1630,7 @@ public float GetNoise(float x, float y) { case Value: return SingleValue(m_seed, x, y); case ValueFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleValueFractalFBM(x, y); case Billow -> SingleValueFractalBillow(x, y); case RigidMulti -> SingleValueFractalRigidMulti(x, y); @@ -960,7 +1639,7 @@ public float GetNoise(float x, float y) { case Perlin: return SinglePerlin(m_seed, x, y); case PerlinFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SinglePerlinFractalFBM(x, y); case Billow -> SinglePerlinFractalBillow(x, y); case RigidMulti -> SinglePerlinFractalRigidMulti(x, y); @@ -969,14 +1648,14 @@ public float GetNoise(float x, float y) { case Simplex: return SingleSimplex(m_seed, x, y); case SimplexFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleSimplexFractalFBM(x, y); case Billow -> SingleSimplexFractalBillow(x, y); case RigidMulti -> SingleSimplexFractalRigidMulti(x, y); default -> 0; }; case Cellular: - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue, NoiseLookup, Distance -> SingleCellular(x, y); default -> SingleCellular2Edge(x, y); }; @@ -985,7 +1664,7 @@ public float GetNoise(float x, float y) { case Cubic: return SingleCubic(m_seed, x, y); case CubicFractal: - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleCubicFractalFBM(x, y); case Billow -> SingleCubicFractalBillow(x, y); case RigidMulti -> SingleCubicFractalRigidMulti(x, y); @@ -1038,7 +1717,7 @@ public float GetValueFractal(float x, float y, float z) { y *= m_frequency; z *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleValueFractalFBM(x, y, z); case Billow -> SingleValueFractalBillow(x, y, z); case RigidMulti -> SingleValueFractalRigidMulti(x, y, z); @@ -1144,7 +1823,7 @@ public float GetValueFractal(float x, float y) { x *= m_frequency; y *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleValueFractalFBM(x, y); case Billow -> SingleValueFractalBillow(x, y); case RigidMulti -> SingleValueFractalRigidMulti(x, y); @@ -1210,7 +1889,7 @@ private float SingleValue(int seed, float x, float y) { int y1 = y0 + 1; float xs, ys; - ys = switch(m_interp) { + ys = switch (m_interp) { default -> { xs = x - x0; yield y - y0; @@ -1237,7 +1916,7 @@ public float GetPerlinFractal(float x, float y, float z) { y *= m_frequency; z *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SinglePerlinFractalFBM(x, y, z); case Billow -> SinglePerlinFractalBillow(x, y, z); case RigidMulti -> SinglePerlinFractalRigidMulti(x, y, z); @@ -1335,10 +2014,26 @@ private float SinglePerlin(int seed, float x, float y, float z) { float yd1 = yd0 - 1; float zd1 = zd0 - 1; - float xf00 = Lerp(GradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs); - float xf10 = Lerp(GradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs); - float xf01 = Lerp(GradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs); - float xf11 = Lerp(GradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs); + float xf00 = Lerp( + GradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), + GradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), + xs + ); + float xf10 = Lerp( + GradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), + GradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), + xs + ); + float xf01 = Lerp( + GradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), + GradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), + xs + ); + float xf11 = Lerp( + GradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), + GradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), + xs + ); float yf0 = Lerp(xf00, xf10, ys); float yf1 = Lerp(xf01, xf11, ys); @@ -1350,7 +2045,7 @@ public float GetPerlinFractal(float x, float y) { x *= m_frequency; y *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SinglePerlinFractalFBM(x, y); case Billow -> SinglePerlinFractalBillow(x, y); case RigidMulti -> SinglePerlinFractalRigidMulti(x, y); @@ -1417,7 +2112,7 @@ private float SinglePerlin(int seed, float x, float y) { int y1 = y0 + 1; float xs, ys; - ys = switch(m_interp) { + ys = switch (m_interp) { default -> { xs = x - x0; yield y - y0; @@ -1449,7 +2144,7 @@ public float GetSimplexFractal(float x, float y, float z) { y *= m_frequency; z *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleSimplexFractalFBM(x, y, z); case Billow -> SingleSimplexFractalBillow(x, y, z); case RigidMulti -> SingleSimplexFractalRigidMulti(x, y, z); @@ -1516,7 +2211,7 @@ public float GetSimplexFractal(float x, float y) { x *= m_frequency; y *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleSimplexFractalFBM(x, y); case Billow -> SingleSimplexFractalBillow(x, y); case RigidMulti -> SingleSimplexFractalRigidMulti(x, y); @@ -1586,7 +2281,7 @@ public float GetCubicFractal(float x, float y, float z) { y *= m_frequency; z *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleCubicFractalFBM(x, y, z); case Billow -> SingleCubicFractalBillow(x, y, z); case RigidMulti -> SingleCubicFractalRigidMulti(x, y, z); @@ -1656,7 +2351,7 @@ public float GetCubicFractal(float x, float y) { x *= m_frequency; y *= m_frequency; - return switch(m_fractalType) { + return switch (m_fractalType) { case FBM -> SingleCubicFractalFBM(x, y); case Billow -> SingleCubicFractalBillow(x, y); case RigidMulti -> SingleCubicFractalRigidMulti(x, y); @@ -1728,7 +2423,7 @@ public float GetCellular(float x, float y, float z) { y *= m_frequency; z *= m_frequency; - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue, NoiseLookup, Distance -> SingleCellular(x, y, z); default -> SingleCellular2Edge(x, y, z); }; @@ -1797,7 +2492,9 @@ private float SingleCellular(float x, float y, float z) { float vecY = yi - y + vec.y; float vecZ = zi - z + vec.z; - float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ); + float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + + vecY * vecY + + vecZ * vecZ); if (newDistance < distance) { distance = newDistance; @@ -1811,7 +2508,7 @@ private float SingleCellular(float x, float y, float z) { break; } - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue -> ValCoord3D(0, xc, yc, zc); case NoiseLookup -> { Float3 vec = CELL_3D[Hash3D(m_seed, xc, yc, zc) & 255]; @@ -1877,7 +2574,9 @@ private float SingleCellular2Edge(float x, float y, float z) { float vecY = yi - y + vec.y; float vecZ = zi - z + vec.z; - float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ); + float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + + vecY * vecY + + vecZ * vecZ); distance2 = Math.max(Math.min(distance2, newDistance), distance); distance = Math.min(distance, newDistance); @@ -1889,7 +2588,7 @@ private float SingleCellular2Edge(float x, float y, float z) { break; } - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case Distance2 -> distance2 - 1; case Distance2Add -> distance2 + distance - 1; case Distance2Sub -> distance2 - distance - 1; @@ -1903,7 +2602,7 @@ public float GetCellular(float x, float y) { x *= m_frequency; y *= m_frequency; - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue, NoiseLookup, Distance -> SingleCellular(x, y); default -> SingleCellular2Edge(x, y); }; @@ -1974,7 +2673,7 @@ private float SingleCellular(float x, float y) { break; } - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case CellValue -> ValCoord2D(0, xc, yc); case NoiseLookup -> { Float2 vec = CELL_2D[Hash2D(m_seed, xc, yc) & 255]; @@ -2041,7 +2740,7 @@ private float SingleCellular2Edge(float x, float y) { break; } - return switch(m_cellularReturnType) { + return switch (m_cellularReturnType) { case Distance2 -> distance2 - 1; case Distance2Add -> distance2 + distance - 1; case Distance2Sub -> distance2 - distance - 1; @@ -2166,7 +2865,7 @@ private void SingleGradientPerturb(int seed, float perturbAmp, float frequency, int y1 = y0 + 1; float xs, ys; - ys = switch(m_interp) { + ys = switch (m_interp) { default -> { xs = xf - x0; yield yf - y0; @@ -2211,11 +2910,24 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (this == obj) return true; + if (this == obj) { + return true; + } return obj instanceof FastNoise; } - public enum NoiseType {Value, ValueFractal, Perlin, PerlinFractal, Simplex, SimplexFractal, Cellular, WhiteNoise, Cubic, CubicFractal} + public enum NoiseType { + Value, + ValueFractal, + Perlin, + PerlinFractal, + Simplex, + SimplexFractal, + Cellular, + WhiteNoise, + Cubic, + CubicFractal + } public enum Interp {Linear, Hermite, Quintic} @@ -2223,7 +2935,16 @@ public enum FractalType {FBM, Billow, RigidMulti} public enum CellularDistanceFunction {Euclidean, Manhattan, Natural} - public enum CellularReturnType {CellValue, NoiseLookup, Distance, Distance2, Distance2Add, Distance2Sub, Distance2Mul, Distance2Div} + public enum CellularReturnType { + CellValue, + NoiseLookup, + Distance, + Distance2, + Distance2Add, + Distance2Sub, + Distance2Mul, + Distance2Div + } private record Float2(float x, float y) { } diff --git a/common/src/main/java/org/terraform/utils/noise/NoiseCacheHandler.java b/common/src/main/java/org/terraform/utils/noise/NoiseCacheHandler.java index b644b494..56f1698c 100644 --- a/common/src/main/java/org/terraform/utils/noise/NoiseCacheHandler.java +++ b/common/src/main/java/org/terraform/utils/noise/NoiseCacheHandler.java @@ -1,162 +1,165 @@ package org.terraform.utils.noise; -import java.util.function.Function; - +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.terraform.data.TerraformWorld; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; +import java.util.function.Function; /** * To help handle noise object caching throughout the entire plugin. * No more stupid hashmap caches all over the place. - * */ -public class NoiseCacheHandler{ - - public enum NoiseCacheEntry{ - TW_TEMPERATURE, - TW_MOISTURE, - TW_OCEANIC, - TW_MOUNTAINOUS, - - CARVER_STANDARD, - - HEIGHTMAP_CORE, - HEIGHTMAP_RIVER, - // HEIGHTMAP_MOUNTAINOUS, - HEIGHTMAP_ATTRITION, - - BIOME_BEACH_HEIGHT, - - BIOME_MUDDYBOG_HEIGHTMAP, - - BIOME_BADLANDS_PLATEAU_DISTORTEDCIRCLE, - BIOME_BADLANDS_PLATEAUNOISE, - BIOME_BADLANDS_WALLNOISE, - BIOME_BADLANDS_PLATEAUDETAILS, - - BIOME_PAINTEDHILLS_NOISE, - BIOME_PAINTEDHILLS_ROCKS_NOISE, - +public class NoiseCacheHandler { + + private static final LoadingCache NOISE_CACHE = CacheBuilder.newBuilder() + .maximumSize( + 300) + .build(new NoiseCacheLoader()); + + public static @NotNull FastNoise getNoise(TerraformWorld world, + NoiseCacheEntry entry, + @NotNull Function noiseFunction) + { + NoiseCacheKey key = new NoiseCacheKey(world, entry); + FastNoise noise = NOISE_CACHE.getIfPresent(key); + if (noise == null) { + noise = noiseFunction.apply(world); + NOISE_CACHE.put(key, noise); + } + return noise; + + } + + public enum NoiseCacheEntry { + TW_TEMPERATURE, + TW_MOISTURE, + TW_OCEANIC, + TW_MOUNTAINOUS, + + CARVER_STANDARD, + + HEIGHTMAP_CORE, + HEIGHTMAP_RIVER, + // HEIGHTMAP_MOUNTAINOUS, + HEIGHTMAP_ATTRITION, + + BIOME_BEACH_HEIGHT, + + BIOME_MUDDYBOG_HEIGHTMAP, + + BIOME_BADLANDS_PLATEAU_DISTORTEDCIRCLE, + BIOME_BADLANDS_PLATEAUNOISE, + BIOME_BADLANDS_WALLNOISE, + BIOME_BADLANDS_PLATEAUDETAILS, + + BIOME_PAINTEDHILLS_NOISE, + BIOME_PAINTEDHILLS_ROCKS_NOISE, + BIOME_DESERT_LUSH_RIVER, - BIOME_BAMBOOFOREST_PATHNOISE, + BIOME_BAMBOOFOREST_PATHNOISE, + + BIOME_GORGE_CLIFFNOISE, + BIOME_GORGE_DETAILS, + + BIOME_ARCHEDCLIFFS_PLATFORMNOISE, + BIOME_ARCHEDCLIFFS_PILLARNOISE, + + BIOME_ERODEDPLAINS_CLIFFNOISE, + BIOME_ERODEDPLAINS_DETAILS, - BIOME_GORGE_CLIFFNOISE, - BIOME_GORGE_DETAILS, - - BIOME_ARCHEDCLIFFS_PLATFORMNOISE, - BIOME_ARCHEDCLIFFS_PILLARNOISE, + BIOME_PETRIFIEDCLIFFS_CLIFFNOISE, + BIOME_PETRIFIEDCLIFFS_INNERNOISE, - BIOME_ERODEDPLAINS_CLIFFNOISE, - BIOME_ERODEDPLAINS_DETAILS, + BIOME_MUSHROOMISLAND_CIRCLE, + BIOME_LAKE_CIRCLE, - BIOME_PETRIFIEDCLIFFS_CLIFFNOISE, - BIOME_PETRIFIEDCLIFFS_INNERNOISE, - - BIOME_MUSHROOMISLAND_CIRCLE, - BIOME_LAKE_CIRCLE, - - BIOME_FOREST_PATHNOISE, + BIOME_FOREST_PATHNOISE, BIOME_TAIGA_BERRY_BUSHNOISE, - BIOME_JUNGLE_GROUNDWOOD, - BIOME_JUNGLE_GROUNDLEAVES, - BIOME_JUNGLE_LILYPADS, - - BIOME_DESERT_DUNENOISE, - - BIOME_BADLANDS_CANYON_NOISE, - - BIOME_SWAMP_MUDNOISE, - - BIOME_CAVECLUSTER_CIRCLENOISE, - - BIOME_JAGGED_PEAKSNOISE, - - BIOME_SHATTERED_SAVANNANOISE, + BIOME_JUNGLE_GROUNDWOOD, + BIOME_JUNGLE_GROUNDLEAVES, + BIOME_JUNGLE_LILYPADS, + + BIOME_DESERT_DUNENOISE, + + BIOME_BADLANDS_CANYON_NOISE, + + BIOME_SWAMP_MUDNOISE, + + BIOME_CAVECLUSTER_CIRCLENOISE, + + BIOME_JAGGED_PEAKSNOISE, + + BIOME_SHATTERED_SAVANNANOISE, BIOME_SHATTERED_Y_SAVANNANOISE, CAVE_FLUID_NOISE, CAVE_CHEESE_NOISE, CAVE_XRAVINE_NOISE, CAVE_XRAVINE_DETAILS, - - STRUCTURE_LARGECAVE_CARVER, - - STRUCTURE_LARGECAVE_RAISEDGROUNDNOISE, - - STRUCTURE_PYRAMID_BASEELEVATOR, - STRUCTURE_PYRAMID_BASEFUZZER, - - STRUCTURE_ANCIENTCITY_RUINS, - - STRUCTURE_ANIMALFARM_FIELDNOISE, - STRUCTURE_ANIMALFARM_RADIUSNOISE, - - STRUCTURE_RUINEDPORTAL_FISSURES, - - GENUTILS_RANDOMOBJ_NOISE, - - FRACTALTREES_LEAVES_NOISE, - FRACTALTREES_BASE_NOISE, + + STRUCTURE_LARGECAVE_CARVER, + + STRUCTURE_LARGECAVE_RAISEDGROUNDNOISE, + + STRUCTURE_PYRAMID_BASEELEVATOR, + STRUCTURE_PYRAMID_BASEFUZZER, + + STRUCTURE_ANCIENTCITY_RUINS, + + STRUCTURE_ANIMALFARM_FIELDNOISE, + STRUCTURE_ANIMALFARM_RADIUSNOISE, + + STRUCTURE_RUINEDPORTAL_FISSURES, + + GENUTILS_RANDOMOBJ_NOISE, + + FRACTALTREES_LEAVES_NOISE, + FRACTALTREES_BASE_NOISE, } - - private static final LoadingCache NOISE_CACHE = - CacheBuilder.newBuilder() - .maximumSize(300).build(new NoiseCacheLoader()); - - public static @NotNull FastNoise getNoise(TerraformWorld world, NoiseCacheEntry entry, @NotNull Function noiseFunction) { - NoiseCacheKey key = new NoiseCacheKey(world,entry); - FastNoise noise = NOISE_CACHE.getIfPresent(key); - if(noise == null) { - noise = noiseFunction.apply(world); - NOISE_CACHE.put(key, noise); + + public static class NoiseCacheLoader extends CacheLoader { + /** + * Does not do loading. + * If this is null, the caller is responsible for inserting it. + */ + @Override + public @Nullable FastNoise load(@NotNull NoiseCacheKey key) { + return null; } - return noise; - } - - public static class NoiseCacheLoader extends CacheLoader { - /** - * Does not do loading. - * If this is null, the caller is responsible for inserting it. - */ - @Override - public @Nullable FastNoise load(@NotNull NoiseCacheKey key) { - return null; - } - } - - public static class NoiseCacheKey { - private final TerraformWorld tw; - private final NoiseCacheEntry entry; - - public NoiseCacheKey(TerraformWorld world, NoiseCacheEntry entry) { - this.tw = world; - this.entry = entry; - } - - @Override - public int hashCode() { - return tw.hashCode() ^ (entry.hashCode() * 31); - } - - @Override - public boolean equals(Object other) { - if(other instanceof NoiseCacheKey o) { - if(!o.tw.getName().equals(tw.getName())) - return false; - return entry == o.entry; - } - return false; - } - } - + + public static class NoiseCacheKey { + private final TerraformWorld tw; + private final NoiseCacheEntry entry; + + public NoiseCacheKey(TerraformWorld world, NoiseCacheEntry entry) { + this.tw = world; + this.entry = entry; + } + + @Override + public int hashCode() { + return tw.hashCode() ^ (entry.hashCode() * 31); + } + + @Override + public boolean equals(Object other) { + if (other instanceof NoiseCacheKey o) { + if (!o.tw.getName().equals(tw.getName())) { + return false; + } + return entry == o.entry; + } + return false; + } + } + } diff --git a/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java b/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java index 9ecee65e..0fc3342b 100644 --- a/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java +++ b/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java @@ -10,20 +10,16 @@ public class BeeHiveSpawner { public static void spawnFullBeeNest(@NotNull SimpleBlock block) { - try - { - if(block.getPopData() instanceof IPopulatorDataBeehiveEditor ipopdata) - { + try { + if (block.getPopData() instanceof IPopulatorDataBeehiveEditor ipopdata) { ipopdata.setBeehiveWithBee(block.getX(), block.getY(), block.getZ()); } - else - { + else { block.setType(Material.BEE_NEST); block.getPopData().addEntity(block.getX(), block.getY(), block.getZ(), EntityType.BEE); } } - catch(NullPointerException e) - { + catch (NullPointerException e) { TerraformGeneratorPlugin.logger.info("Beehive null silently ignored"); } } diff --git a/common/src/main/java/org/terraform/utils/version/OneOneNineBlockHandler.java b/common/src/main/java/org/terraform/utils/version/OneOneNineBlockHandler.java index bd57794b..6edd1436 100644 --- a/common/src/main/java/org/terraform/utils/version/OneOneNineBlockHandler.java +++ b/common/src/main/java/org/terraform/utils/version/OneOneNineBlockHandler.java @@ -1,81 +1,91 @@ package org.terraform.utils.version; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; -import org.bukkit.Bukkit; -import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class OneOneNineBlockHandler { - // public static final EntityType FROG = getEntityType("FROG", "FISH"); - - public static final EntityType ALLAY = getEntityType(); - - public static final @Nullable Material MUD = !Version.isAtLeast(19) ? - Material.getMaterial("PODZOL") : Material.getMaterial("MUD"); - - public static final @Nullable Material MUD_BRICKS = !Version.isAtLeast(19) ? - Material.getMaterial("BRICKS") : Material.getMaterial("MUD_BRICKS"); - - public static final @Nullable Material REINFORCED_DEEPSLATE = !Version.isAtLeast(19) ? - Material.getMaterial("POLISHED_DIORITE") : Material.getMaterial("REINFORCED_DEEPSLATE"); - - - public static final @Nullable Material MANGROVE_LEAVES = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_LEAVES") : Material.getMaterial("MANGROVE_LEAVES"); - public static final @Nullable Material MANGROVE_LOG = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_LOG") : Material.getMaterial("MANGROVE_LOG"); - public static final @Nullable Material MANGROVE_WOOD = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_WOOD") : Material.getMaterial("MANGROVE_WOOD"); - public static final @Nullable Material MANGROVE_PROPAGULE = !Version.isAtLeast(19) ? - Material.getMaterial("AIR") : Material.getMaterial("MANGROVE_PROPAGULE"); - public static final @Nullable Material MANGROVE_ROOTS = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_WOOD") : Material.getMaterial("MANGROVE_ROOTS"); - public static final @Nullable Material MUDDY_MANGROVE_ROOTS = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_WOOD") : Material.getMaterial("MUDDY_MANGROVE_ROOTS"); - - public static final @Nullable Material MANGROVE_FENCE = !Version.isAtLeast(19) ? - Material.getMaterial("OAK_FENCE") : Material.getMaterial("MANGROVE_FENCE"); - - // Pre-1.19 versions WILL NOT have any sculk related spawns. - public static final @Nullable Material SCULK_VEIN = Material.getMaterial("SCULK_VEIN"); - public static final @Nullable Material SCULK = !Version.isAtLeast(19) ? - Material.getMaterial("STONE") : Material.getMaterial("SCULK"); - public static final @Nullable Material SCULK_CATALYST = Material.getMaterial("SCULK_CATALYST"); - public static final @Nullable Material SCULK_SHRIEKER = Material.getMaterial("SCULK_SHRIEKER"); - public static final @Nullable Material SCULK_SENSOR = Material.getMaterial("SCULK_SENSOR"); - - - public static final Biome MANGROVE_SWAMP = getBiome("MANGROVE_SWAMP", "SWAMP"); - public static final Biome DEEP_DARK = getBiome("DEEP_DARK", "PLAINS"); - - private static @NotNull Biome getBiome(String name, String fallback) { - try { - return Biome.valueOf(name); - } - catch(IllegalArgumentException e) { - return Biome.valueOf(fallback); - } - } - private static @NotNull EntityType getEntityType() { - try { - return EntityType.valueOf("ALLAY"); - } - catch(IllegalArgumentException e) { - return EntityType.valueOf("CHICKEN"); - } - } - - private static final String shriekerDataString = "minecraft:sculk_shrieker[can_summon=true,shrieking=false,waterlogged=false]"; - public static @NotNull BlockData getActiveSculkShrieker() { - return Bukkit.createBlockData(shriekerDataString); - } - - private static final String propaguleDataString = "minecraft:mangrove_propagule[hanging=true,age=4,waterlogged=false]"; - public static @NotNull BlockData getHangingMangrovePropagule() { - return Bukkit.createBlockData(propaguleDataString); - } + // public static final EntityType FROG = getEntityType("FROG", "FISH"); + + public static final EntityType ALLAY = getEntityType(); + + public static final @Nullable Material MUD = !Version.isAtLeast(19) + ? Material.getMaterial("PODZOL") + : Material.getMaterial("MUD"); + + public static final @Nullable Material MUD_BRICKS = !Version.isAtLeast(19) + ? Material.getMaterial("BRICKS") + : Material.getMaterial("MUD_BRICKS"); + + public static final @Nullable Material REINFORCED_DEEPSLATE = !Version.isAtLeast(19) ? Material.getMaterial( + "POLISHED_DIORITE") : Material.getMaterial("REINFORCED_DEEPSLATE"); + + + public static final @Nullable Material MANGROVE_LEAVES = !Version.isAtLeast(19) + ? Material.getMaterial("OAK_LEAVES") + : Material.getMaterial("MANGROVE_LEAVES"); + public static final @Nullable Material MANGROVE_LOG = !Version.isAtLeast(19) + ? Material.getMaterial("OAK_LOG") + : Material.getMaterial("MANGROVE_LOG"); + public static final @Nullable Material MANGROVE_WOOD = !Version.isAtLeast(19) + ? Material.getMaterial("OAK_WOOD") + : Material.getMaterial("MANGROVE_WOOD"); + public static final @Nullable Material MANGROVE_PROPAGULE = !Version.isAtLeast(19) + ? Material.getMaterial("AIR") + : Material.getMaterial("MANGROVE_PROPAGULE"); + public static final @Nullable Material MANGROVE_ROOTS = !Version.isAtLeast(19) + ? Material.getMaterial("OAK_WOOD") + : Material.getMaterial("MANGROVE_ROOTS"); + public static final @Nullable Material MUDDY_MANGROVE_ROOTS = !Version.isAtLeast(19) ? Material.getMaterial( + "OAK_WOOD") : Material.getMaterial("MUDDY_MANGROVE_ROOTS"); + + public static final @Nullable Material MANGROVE_FENCE = !Version.isAtLeast(19) + ? Material.getMaterial("OAK_FENCE") + : Material.getMaterial("MANGROVE_FENCE"); + + // Pre-1.19 versions WILL NOT have any sculk related spawns. + public static final @Nullable Material SCULK_VEIN = Material.getMaterial("SCULK_VEIN"); + public static final @Nullable Material SCULK = !Version.isAtLeast(19) + ? Material.getMaterial("STONE") + : Material.getMaterial("SCULK"); + public static final @Nullable Material SCULK_CATALYST = Material.getMaterial("SCULK_CATALYST"); + public static final @Nullable Material SCULK_SHRIEKER = Material.getMaterial("SCULK_SHRIEKER"); + public static final @Nullable Material SCULK_SENSOR = Material.getMaterial("SCULK_SENSOR"); + + + public static final Biome MANGROVE_SWAMP = getBiome("MANGROVE_SWAMP", "SWAMP"); + public static final Biome DEEP_DARK = getBiome("DEEP_DARK", "PLAINS"); + private static final String shriekerDataString = "minecraft:sculk_shrieker[can_summon=true,shrieking=false,waterlogged=false]"; + private static final String propaguleDataString = "minecraft:mangrove_propagule[hanging=true,age=4,waterlogged=false]"; + + private static @NotNull Biome getBiome(String name, String fallback) { + try { + return Biome.valueOf(name); + } + catch (IllegalArgumentException e) { + return Biome.valueOf(fallback); + } + } + + private static @NotNull EntityType getEntityType() { + try { + return EntityType.valueOf("ALLAY"); + } + catch (IllegalArgumentException e) { + return EntityType.valueOf("CHICKEN"); + } + } + + public static @NotNull BlockData getActiveSculkShrieker() { + return Bukkit.createBlockData(shriekerDataString); + } + + public static @NotNull BlockData getHangingMangrovePropagule() { + return Bukkit.createBlockData(propaguleDataString); + } } diff --git a/common/src/main/java/org/terraform/utils/version/OneTwentyBlockHandler.java b/common/src/main/java/org/terraform/utils/version/OneTwentyBlockHandler.java index bd4d3718..8bbe19cf 100644 --- a/common/src/main/java/org/terraform/utils/version/OneTwentyBlockHandler.java +++ b/common/src/main/java/org/terraform/utils/version/OneTwentyBlockHandler.java @@ -12,33 +12,45 @@ import java.util.Random; public class OneTwentyBlockHandler { - public static final @Nullable Material PITCHER_PLANT = !Version.isAtLeast(20) ? - Material.TALL_GRASS : Material.getMaterial("PITCHER_PLANT"); - public static final @Nullable Material CHERRY_LOG = !Version.isAtLeast(20) ? - Material.DARK_OAK_LOG : Material.getMaterial("CHERRY_LOG"); - public static final @Nullable Material CHERRY_WOOD = !Version.isAtLeast(20) ? - Material.DARK_OAK_WOOD : Material.getMaterial("CHERRY_WOOD"); - public static final @Nullable Material CHERRY_LEAVES = !Version.isAtLeast(20) ? - Material.DARK_OAK_LEAVES : Material.getMaterial("CHERRY_LEAVES"); - public static final @Nullable Material CHERRY_SAPLING = !Version.isAtLeast(20) ? - Material.DARK_OAK_SAPLING : Material.getMaterial("CHERRY_SAPLING"); - public static final @Nullable Material PINK_PETALS = !Version.isAtLeast(20) ? - Material.AIR : Material.getMaterial("PINK_PETALS"); - public static final @Nullable Material SUSPICIOUS_SAND = !Version.isAtLeast(20) ? - Material.SAND : Material.getMaterial("SUSPICIOUS_SAND"); - public static final @Nullable Material SUSPICIOUS_GRAVEL = !Version.isAtLeast(20) ? - Material.GRAVEL : Material.getMaterial("SUSPICIOUS_GRAVEL"); + public static final @Nullable Material PITCHER_PLANT = !Version.isAtLeast(20) + ? Material.TALL_GRASS + : Material.getMaterial("PITCHER_PLANT"); + public static final @Nullable Material CHERRY_LOG = !Version.isAtLeast(20) + ? Material.DARK_OAK_LOG + : Material.getMaterial("CHERRY_LOG"); + public static final @Nullable Material CHERRY_WOOD = !Version.isAtLeast(20) + ? Material.DARK_OAK_WOOD + : Material.getMaterial("CHERRY_WOOD"); + public static final @Nullable Material CHERRY_LEAVES = !Version.isAtLeast(20) + ? Material.DARK_OAK_LEAVES + : Material.getMaterial("CHERRY_LEAVES"); + public static final @Nullable Material CHERRY_SAPLING = !Version.isAtLeast(20) + ? Material.DARK_OAK_SAPLING + : Material.getMaterial("CHERRY_SAPLING"); + public static final @Nullable Material PINK_PETALS = !Version.isAtLeast(20) + ? Material.AIR + : Material.getMaterial("PINK_PETALS"); + public static final @Nullable Material SUSPICIOUS_SAND = !Version.isAtLeast(20) + ? Material.SAND + : Material.getMaterial("SUSPICIOUS_SAND"); + public static final @Nullable Material SUSPICIOUS_GRAVEL = !Version.isAtLeast(20) + ? Material.GRAVEL + : Material.getMaterial("SUSPICIOUS_GRAVEL"); public static final @Nullable EntityType CAMEL = getCamel(); public static @NotNull BlockData getPinkPetalData(int count) { - return Bukkit.createBlockData("pink_petals[flower_amount=" + count + ",facing=" + BlockUtils.getDirectBlockFace(new Random()).toString().toLowerCase(Locale.ENGLISH) + "]"); + return Bukkit.createBlockData("pink_petals[flower_amount=" + count + ",facing=" + BlockUtils.getDirectBlockFace( + new Random()).toString().toLowerCase(Locale.ENGLISH) + "]"); } - private static @Nullable EntityType getCamel(){ - try{ + private static @Nullable EntityType getCamel() { + try { return EntityType.valueOf("CAMEL"); - }catch(Exception e){ return null; } + } + catch (Exception e) { + return null; + } } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/utils/version/OneTwentyFiveBlockHandler.java b/common/src/main/java/org/terraform/utils/version/OneTwentyFiveBlockHandler.java index 95c53070..78de6a8c 100644 --- a/common/src/main/java/org/terraform/utils/version/OneTwentyFiveBlockHandler.java +++ b/common/src/main/java/org/terraform/utils/version/OneTwentyFiveBlockHandler.java @@ -4,11 +4,14 @@ import org.bukkit.entity.EntityType; public class OneTwentyFiveBlockHandler { - public static final PatternType RHOMBUS = !Version.isAtLeast(20.5) ? - PatternType.valueOf("RHOMBUS_MIDDLE") : PatternType.valueOf("RHOMBUS"); - public static final PatternType CIRCLE = !Version.isAtLeast(20.5) ? - PatternType.valueOf("CIRCLE_MIDDLE") : PatternType.valueOf("CIRCLE"); + public static final PatternType RHOMBUS = !Version.isAtLeast(20.5) + ? PatternType.valueOf("RHOMBUS_MIDDLE") + : PatternType.valueOf("RHOMBUS"); + public static final PatternType CIRCLE = !Version.isAtLeast(20.5) + ? PatternType.valueOf("CIRCLE_MIDDLE") + : PatternType.valueOf("CIRCLE"); - public static final EntityType ARMADILLO = !Version.isAtLeast(20.5) ? - EntityType.PIG : EntityType.valueOf("ARMADILLO"); + public static final EntityType ARMADILLO = !Version.isAtLeast(20.5) + ? EntityType.PIG + : EntityType.valueOf("ARMADILLO"); } diff --git a/common/src/main/java/org/terraform/utils/version/Version.java b/common/src/main/java/org/terraform/utils/version/Version.java index 05e780c8..427105a8 100644 --- a/common/src/main/java/org/terraform/utils/version/Version.java +++ b/common/src/main/java/org/terraform/utils/version/Version.java @@ -9,35 +9,6 @@ public class Version { - public enum SupportedVersion { - V_1_18_R2("v1_18_R2",18.2), - V_1_19_R3("v1_19_R3",19.4), - V_1_20_R1("v1_20_R1",20, 20.1), - V_1_20_R2("v1_20_R2",20.2), - V_1_20_R3("v1_20_R3",20.3,20.4), - V_1_20_R4("v1_20_R4",20.5,20.6), - V_1_21_R1("v1_21_R1",21.0,21.1), - ; - private final double[] versionDouble; - private final String packageName; - - SupportedVersion(String packageName, double... versionDouble) { - this.versionDouble = versionDouble; - this.packageName = packageName; - } - - public static @Nullable NMSInjectorAbstract getInjector() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - for(SupportedVersion sv:SupportedVersion.values()) - { - for(double versionDouble:sv.versionDouble){ - if(versionDouble != Version.DOUBLE) continue; - return (NMSInjectorAbstract) Class.forName("org.terraform." + sv.packageName+ ".NMSInjector").getDeclaredConstructor().newInstance(); - } - } - return null; - } - } - public static final String VERSION = Bukkit.getServer().getBukkitVersion().split("-")[0]; public static final double DOUBLE = toVersionDouble(VERSION); @@ -56,11 +27,48 @@ public static String getVersionPackage() { } /** - * * @param version a string like "1.20.4" * @return e.g. substrings "1." away and returns 20.4 for 1.20.4 */ public static double toVersionDouble(@NotNull String version) { return Double.parseDouble(version.substring(2)); } + + public enum SupportedVersion { + V_1_18_R2("v1_18_R2", 18.2), + V_1_19_R3("v1_19_R3", 19.4), + V_1_20_R1("v1_20_R1", 20, 20.1), + V_1_20_R2("v1_20_R2", 20.2), + V_1_20_R3("v1_20_R3", 20.3, 20.4), + V_1_20_R4("v1_20_R4", 20.5, 20.6), + V_1_21_R1("v1_21_R1", 21.0, 21.1), + ; + private final double[] versionDouble; + private final String packageName; + + SupportedVersion(String packageName, double... versionDouble) { + this.versionDouble = versionDouble; + this.packageName = packageName; + } + + public static @Nullable NMSInjectorAbstract getInjector() throws + ClassNotFoundException, + NoSuchMethodException, + InvocationTargetException, + InstantiationException, + IllegalAccessException + { + for (SupportedVersion sv : SupportedVersion.values()) { + for (double versionDouble : sv.versionDouble) { + if (versionDouble != Version.DOUBLE) { + continue; + } + return (NMSInjectorAbstract) Class.forName("org.terraform." + sv.packageName + ".NMSInjector") + .getDeclaredConstructor() + .newInstance(); + } + } + return null; + } + } } \ No newline at end of file diff --git a/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java b/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java index 342510b0..6b6b92a7 100644 --- a/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java +++ b/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java @@ -1,67 +1,76 @@ package org.terraform.watchdog; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import org.jetbrains.annotations.Nullable; import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.main.config.TConfigOption; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + public class TfgWatchdogSuppressant { - @Nullable + @Nullable Field instanceField = null; - @Nullable + @Nullable Field lastTickField = null; - @Nullable + @Nullable Class watchdogThreadClass = null; - @Nullable + @Nullable Method tickMethod = null; - @Nullable + @Nullable Object watchdogThreadInstance = null; - - public TfgWatchdogSuppressant(){ - if(TConfigOption.DEVSTUFF_SUPPRESS_WATCHDOG.getBoolean()) - try { - TerraformGeneratorPlugin.logger.info("[NOTICE] TerraformGenerator will suppress the server's watchdog " - + "while generating chunks to prevent unnecessary stacktrace warnings. Unless you specifically need the" - + "watchdog now (to take aikar timings or debug lag), you don't need to take any action."); - TerraformGeneratorPlugin.logger.info("It is recommended to pregenerate to reduce lag problems."); - Class watchdogThreadClass = Class.forName("org.spigotmc.WatchdogThread"); - - instanceField = watchdogThreadClass.getDeclaredField("instance"); - instanceField.setAccessible(true); - - lastTickField = watchdogThreadClass.getDeclaredField("lastTick"); - lastTickField.setAccessible(true); - - tickMethod = watchdogThreadClass.getDeclaredMethod("tick"); - tickMethod.setAccessible(true); - - watchdogThreadInstance = this.instanceField.get(null); - TerraformGeneratorPlugin.logger.info("Watchdog Thread hooked."); - } - catch(SecurityException | NoSuchFieldException | ClassNotFoundException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException e) { - TerraformGeneratorPlugin.logger.info("Watchdog instance could not be found."); - TerraformGeneratorPlugin.logger.stackTrace(e); - instanceField = null; - lastTickField = null; - watchdogThreadClass = null; - watchdogThreadInstance = null; - tickMethod = null; - } - } - - public void tickWatchdog() { - if(watchdogThreadInstance == null) return; + + public TfgWatchdogSuppressant() { + if (TConfigOption.DEVSTUFF_SUPPRESS_WATCHDOG.getBoolean()) { + try { + TerraformGeneratorPlugin.logger.info("[NOTICE] TerraformGenerator will suppress the server's watchdog " + + "while generating chunks to prevent unnecessary stacktrace warnings. Unless you specifically need the" + + "watchdog now (to take aikar timings or debug lag), you don't need to take any action."); + TerraformGeneratorPlugin.logger.info("It is recommended to pregenerate to reduce lag problems."); + Class watchdogThreadClass = Class.forName("org.spigotmc.WatchdogThread"); + + instanceField = watchdogThreadClass.getDeclaredField("instance"); + instanceField.setAccessible(true); + + lastTickField = watchdogThreadClass.getDeclaredField("lastTick"); + lastTickField.setAccessible(true); + + tickMethod = watchdogThreadClass.getDeclaredMethod("tick"); + tickMethod.setAccessible(true); + + watchdogThreadInstance = this.instanceField.get(null); + TerraformGeneratorPlugin.logger.info("Watchdog Thread hooked."); + } + catch (SecurityException | + NoSuchFieldException | + ClassNotFoundException | + NoSuchMethodException | + IllegalArgumentException | + IllegalAccessException e) { + TerraformGeneratorPlugin.logger.info("Watchdog instance could not be found."); + TerraformGeneratorPlugin.logger.stackTrace(e); + instanceField = null; + lastTickField = null; + watchdogThreadClass = null; + watchdogThreadInstance = null; + tickMethod = null; + } + } + } + + public void tickWatchdog() { + if (watchdogThreadInstance == null) { + return; + } try { if ((long) lastTickField.get(watchdogThreadInstance) != 0) { - tickMethod.invoke(watchdogThreadInstance); + tickMethod.invoke(watchdogThreadInstance); } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); + } + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); TerraformGeneratorPlugin.logger.info("Failed to tick watchdog"); } } - + } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/BlockDataFixer.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/BlockDataFixer.java index a772eab2..97a239e0 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/BlockDataFixer.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/BlockDataFixer.java @@ -15,10 +15,47 @@ public class BlockDataFixer extends BlockDataFixerAbstract { + // --------[1.16 stuff] + public static void correctWallData(@NotNull SimpleBlock target) { + if (!(target.getBlockData() instanceof Wall data)) { + return; + } + for (BlockFace face : BlockUtils.directBlockFaces) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { + data.setHeight(face, Height.LOW); + if (target.getRelative(BlockFace.UP).isSolid()) { + data.setHeight(face, Height.TALL); + } + } + else { + data.setHeight(face, Height.NONE); + } + } + + // target.setBlockData(data); + } + + public static void correctSurroundingWallData(@NotNull SimpleBlock target) { + if (!(target.getBlockData() instanceof Wall)) { + return; + } + + correctWallData(target); + for (BlockFace face : BlockUtils.directBlockFaces) { + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { + correctWallData(target.getRelative(face)); + } + } + } + @Override public @Nullable String updateSchematic(double schematicVersion, String schematic) { - if(schematicVersion > 18) { + if (schematicVersion > 18) { // No waterlogged leaves in 1.18 schematic = StringUtils.replace(schematic, "persistent=true,waterlogged=false]", "persistent=true]"); @@ -28,10 +65,12 @@ public class BlockDataFixer extends BlockDataFixerAbstract { } return schematic; } - + @Override public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); + if (data == null && b != null) { + data = b.getBlockData(); + } if (!hasFlushed && data instanceof Wall) { this.pushChanges(v); @@ -43,31 +82,5 @@ public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData correctSurroundingWallData(b); } } - - // --------[1.16 stuff] - public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; - for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { - data.setHeight(face, Height.LOW); - if (target.getRelative(BlockFace.UP).isSolid()) { - data.setHeight(face, Height.TALL); - } - } else data.setHeight(face, Height.NONE); - } - -// target.setBlockData(data); - } - - public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; - - correctWallData(target); - for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) - correctWallData(target.getRelative(face)); - } - } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/CustomBiomeHandler.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/CustomBiomeHandler.java index 8f3eacc3..7cba0c2f 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/CustomBiomeHandler.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/CustomBiomeHandler.java @@ -1,17 +1,6 @@ package org.terraform.v1_18_R2; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Locale; - -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.jetbrains.annotations.NotNull; -import org.terraform.biome.custombiomes.CustomBiomeType; -import org.terraform.main.TerraformGeneratorPlugin; - import com.mojang.serialization.Lifecycle; - import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryWritable; import net.minecraft.core.RegistryMaterials; @@ -19,144 +8,168 @@ import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.jetbrains.annotations.NotNull; +import org.terraform.biome.custombiomes.CustomBiomeType; +import org.terraform.main.TerraformGeneratorPlugin; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Locale; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); - - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - - // aP is BIOME_REGISTRY - // aU is registryAccess - // b is ownedRegistryOrThrow - IRegistryWritable registrywritable = (IRegistryWritable) dedicatedserver.aU().b(IRegistry.aP); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - try { - Field frozen = RegistryMaterials.class.getDeclaredField("bL"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.h); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("bL"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + + // aP is BIOME_REGISTRY + // aU is registryAccess + // b is ownedRegistryOrThrow + IRegistryWritable registrywritable = (IRegistryWritable) dedicatedserver.aU() + .b(IRegistry.aP); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + try { + Field frozen = RegistryMaterials.class.getDeclaredField("bL"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.h); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("bL"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, @NotNull DedicatedServer dedicatedserver, IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - - ResourceKey newKey = ResourceKey.a(IRegistry.aP, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); - - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // l is biomeCategory - Field f = BiomeBase.class.getDeclaredField("l"); - f.setAccessible(true); - newBiomeBuilder.a((BiomeBase.Geography) f.get(forestbiome)); - newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); - - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + @NotNull DedicatedServer dedicatedserver, + IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + + ResourceKey newKey = ResourceKey.a( + IRegistry.aP, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); + + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); + + // l is biomeCategory + Field f = BiomeBase.class.getDeclaredField("l"); + f.setAccessible(true); + newBiomeBuilder.a((BiomeBase.Geography) f.get(forestbiome)); + newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation + + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); + + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.k():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.l():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) - - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.g():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - RegistryGeneration.a(RegistryGeneration.i, newKey, biome); - - // Inject into the biome registry - // aP is BIOME_REGISTRY - // aU is registryAccess - // b is ownedRegistryOrThrow - RegistryMaterials registry = ((RegistryMaterials)dedicatedserver.aU().b(IRegistry.aP)); - - // a is ownedRegistryOrThrow - registry.a(newKey, biome, Lifecycle.stable()); - - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.f() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.k() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.l() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) + + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.g() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + + // Inject into the biome registry + // aP is BIOME_REGISTRY + // aU is registryAccess + // b is ownedRegistryOrThrow + RegistryMaterials registry = ((RegistryMaterials) dedicatedserver.aU().b(IRegistry.aP)); + + // a is ownedRegistryOrThrow + registry.a(newKey, biome, Lifecycle.stable()); + + terraformGenBiomeRegistry.put(biomeType, newKey); + + } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/EntityTypeMapper.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/EntityTypeMapper.java index 2990e6cf..f3e3aa50 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/EntityTypeMapper.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/EntityTypeMapper.java @@ -6,239 +6,239 @@ public class EntityTypeMapper { - public static @NotNull String getObfsNameFromBukkitEntityType(@NotNull EntityType e){ - switch(e) { - case AREA_EFFECT_CLOUD: - return "b"; - case ARMOR_STAND: - return "c"; - case ARROW: - return "d"; - case AXOLOTL: - return "e"; - case BAT: - return "f"; - case BEE: - return "g"; - case BLAZE: - return "h"; - case BOAT: - return "i"; - case CAT: - return "j"; - case CAVE_SPIDER: - return "k"; - case CHICKEN: - return "l"; - case COD: - return "m"; - case COW: - return "n"; - case CREEPER: - return "o"; - case DOLPHIN: - return "p"; - case DONKEY: - return "q"; - case DRAGON_FIREBALL: - return "r"; - case DROWNED: - return "s"; - case ELDER_GUARDIAN: - return "t"; - case ENDER_CRYSTAL: - return "u"; - case ENDER_DRAGON: - return "v"; - case ENDERMAN: - return "w"; - case ENDERMITE: - return "x"; - case EVOKER: - return "y"; - case EVOKER_FANGS: - return "z"; - case EXPERIENCE_ORB: - return "A"; -// case : -// return "B"; - case FALLING_BLOCK: - return "C"; - case FIREWORK: - return "D"; - case FOX: - return "E"; - case GHAST: - return "F"; - case GIANT: - return "G"; - case GLOW_ITEM_FRAME: - return "H"; - case GLOW_SQUID: - return "I"; - case GOAT: - return "J"; - case GUARDIAN: - return "K"; - case HOGLIN: - return "L"; - case HORSE: - return "M"; - case HUSK: - return "N"; - case ILLUSIONER: - return "O"; - case IRON_GOLEM: - return "P"; - case DROPPED_ITEM: - return "Q"; - case ITEM_FRAME: - return "R"; - case FIREBALL: - return "S"; - case LEASH_HITCH: - return "T"; - case LIGHTNING: - return "U"; - case LLAMA: - return "V"; - case LLAMA_SPIT: - return "W"; - case MAGMA_CUBE: - return "X"; - case MARKER: - return "Y"; - case MINECART: - return "Z"; - case MINECART_CHEST: - return "aa"; - case MINECART_COMMAND: - return "ab"; - case MINECART_FURNACE: - return "ac"; - case MINECART_HOPPER: - return "ad"; - case MINECART_MOB_SPAWNER: - return "ae"; - case MINECART_TNT: - return "af"; - case MULE: - return "ag"; - case MUSHROOM_COW: - return "ah"; - case OCELOT: - return "ai"; - case PAINTING: - return "aj"; - case PANDA: - return "ak"; - case PARROT: - return "al"; - case PHANTOM: - return "am"; - case PIG: - return "an"; - case PIGLIN: - return "ao"; - case PIGLIN_BRUTE: - return "ap"; - case PILLAGER: - return "aq"; - case POLAR_BEAR: - return "ar"; - case PRIMED_TNT: - return "as"; - case PUFFERFISH: - return "at"; - case RABBIT: - return "au"; - case RAVAGER: - return "av"; - case SALMON: - return "aw"; - case SHEEP: - return "ax"; - case SHULKER: - return "ay"; - case SHULKER_BULLET: - return "az"; - case SILVERFISH: - return "aA"; - case SKELETON: - return "aB"; - case SKELETON_HORSE: - return "aC"; - case SLIME: - return "aD"; - case SMALL_FIREBALL: - return "aE"; - case SNOWMAN: - return "aF"; - case SNOWBALL: - return "aG"; - case SPECTRAL_ARROW: - return "aH"; - case SPIDER: - return "aI"; - case SQUID: - return "aJ"; - case STRAY: - return "aK"; - case STRIDER: - return "aL"; - case EGG: - return "aM"; - case ENDER_PEARL: - return "aN"; - case THROWN_EXP_BOTTLE: - return "aO"; - case SPLASH_POTION: - return "aP"; - case TRIDENT: - return "aQ"; - case TRADER_LLAMA: - return "aR"; - case TROPICAL_FISH: - return "aS"; - case TURTLE: - return "aT"; - case VEX: - return "aU"; - case VILLAGER: - return "aV"; - case VINDICATOR: - return "aW"; - case WANDERING_TRADER: - return "aX"; - case WITCH: - return "aY"; - case WITHER: - return "aZ"; - case WITHER_SKELETON: - return "ba"; - case WITHER_SKULL: - return "bb"; - case WOLF: - return "bc"; - case ZOGLIN: - return "bd"; - case ZOMBIE: - return "be"; - case ZOMBIE_HORSE: - return "bf"; - case ZOMBIE_VILLAGER: - return "bg"; - case ZOMBIFIED_PIGLIN: - return "bh"; - case PLAYER: - return "bi"; - case FISHING_HOOK: - return "bj"; - case ENDER_SIGNAL: - case UNKNOWN: - break; - } - TerraformGeneratorPlugin.logger.error("INVALID ENTITY REQUESTED: " + e); - return ""; - } + public static @NotNull String getObfsNameFromBukkitEntityType(@NotNull EntityType e) { + switch (e) { + case AREA_EFFECT_CLOUD: + return "b"; + case ARMOR_STAND: + return "c"; + case ARROW: + return "d"; + case AXOLOTL: + return "e"; + case BAT: + return "f"; + case BEE: + return "g"; + case BLAZE: + return "h"; + case BOAT: + return "i"; + case CAT: + return "j"; + case CAVE_SPIDER: + return "k"; + case CHICKEN: + return "l"; + case COD: + return "m"; + case COW: + return "n"; + case CREEPER: + return "o"; + case DOLPHIN: + return "p"; + case DONKEY: + return "q"; + case DRAGON_FIREBALL: + return "r"; + case DROWNED: + return "s"; + case ELDER_GUARDIAN: + return "t"; + case ENDER_CRYSTAL: + return "u"; + case ENDER_DRAGON: + return "v"; + case ENDERMAN: + return "w"; + case ENDERMITE: + return "x"; + case EVOKER: + return "y"; + case EVOKER_FANGS: + return "z"; + case EXPERIENCE_ORB: + return "A"; + // case : + // return "B"; + case FALLING_BLOCK: + return "C"; + case FIREWORK: + return "D"; + case FOX: + return "E"; + case GHAST: + return "F"; + case GIANT: + return "G"; + case GLOW_ITEM_FRAME: + return "H"; + case GLOW_SQUID: + return "I"; + case GOAT: + return "J"; + case GUARDIAN: + return "K"; + case HOGLIN: + return "L"; + case HORSE: + return "M"; + case HUSK: + return "N"; + case ILLUSIONER: + return "O"; + case IRON_GOLEM: + return "P"; + case DROPPED_ITEM: + return "Q"; + case ITEM_FRAME: + return "R"; + case FIREBALL: + return "S"; + case LEASH_HITCH: + return "T"; + case LIGHTNING: + return "U"; + case LLAMA: + return "V"; + case LLAMA_SPIT: + return "W"; + case MAGMA_CUBE: + return "X"; + case MARKER: + return "Y"; + case MINECART: + return "Z"; + case MINECART_CHEST: + return "aa"; + case MINECART_COMMAND: + return "ab"; + case MINECART_FURNACE: + return "ac"; + case MINECART_HOPPER: + return "ad"; + case MINECART_MOB_SPAWNER: + return "ae"; + case MINECART_TNT: + return "af"; + case MULE: + return "ag"; + case MUSHROOM_COW: + return "ah"; + case OCELOT: + return "ai"; + case PAINTING: + return "aj"; + case PANDA: + return "ak"; + case PARROT: + return "al"; + case PHANTOM: + return "am"; + case PIG: + return "an"; + case PIGLIN: + return "ao"; + case PIGLIN_BRUTE: + return "ap"; + case PILLAGER: + return "aq"; + case POLAR_BEAR: + return "ar"; + case PRIMED_TNT: + return "as"; + case PUFFERFISH: + return "at"; + case RABBIT: + return "au"; + case RAVAGER: + return "av"; + case SALMON: + return "aw"; + case SHEEP: + return "ax"; + case SHULKER: + return "ay"; + case SHULKER_BULLET: + return "az"; + case SILVERFISH: + return "aA"; + case SKELETON: + return "aB"; + case SKELETON_HORSE: + return "aC"; + case SLIME: + return "aD"; + case SMALL_FIREBALL: + return "aE"; + case SNOWMAN: + return "aF"; + case SNOWBALL: + return "aG"; + case SPECTRAL_ARROW: + return "aH"; + case SPIDER: + return "aI"; + case SQUID: + return "aJ"; + case STRAY: + return "aK"; + case STRIDER: + return "aL"; + case EGG: + return "aM"; + case ENDER_PEARL: + return "aN"; + case THROWN_EXP_BOTTLE: + return "aO"; + case SPLASH_POTION: + return "aP"; + case TRIDENT: + return "aQ"; + case TRADER_LLAMA: + return "aR"; + case TROPICAL_FISH: + return "aS"; + case TURTLE: + return "aT"; + case VEX: + return "aU"; + case VILLAGER: + return "aV"; + case VINDICATOR: + return "aW"; + case WANDERING_TRADER: + return "aX"; + case WITCH: + return "aY"; + case WITHER: + return "aZ"; + case WITHER_SKELETON: + return "ba"; + case WITHER_SKULL: + return "bb"; + case WOLF: + return "bc"; + case ZOGLIN: + return "bd"; + case ZOMBIE: + return "be"; + case ZOMBIE_HORSE: + return "bf"; + case ZOMBIE_VILLAGER: + return "bg"; + case ZOMBIFIED_PIGLIN: + return "bh"; + case PLAYER: + return "bi"; + case FISHING_HOOK: + return "bj"; + case ENDER_SIGNAL: + case UNKNOWN: + break; + } + TerraformGeneratorPlugin.logger.error("INVALID ENTITY REQUESTED: " + e); + return ""; + } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java index 8a2e0199..bd2b73fa 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java @@ -3,11 +3,7 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; import net.minecraft.SystemUtils; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; -import net.minecraft.core.IRegistry; -import net.minecraft.core.IRegistryCustom; +import net.minecraft.core.*; import net.minecraft.server.level.RegionLimitedWorldAccess; import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.BlockColumn; @@ -43,16 +39,16 @@ import java.util.concurrent.Executor; public class NMSChunkGenerator extends ChunkGenerator { - private final @NotNull ChunkGenerator delegate; + private static boolean biomeDebug = false; + private final @NotNull ChunkGenerator delegate; private final @NotNull TerraformWorld tw; - - public NMSChunkGenerator(String worldname, long seed, - @NotNull ChunkGenerator delegate) { - super( - delegate.b,// b is structureSets - delegate.e,// e is structureOverrides - new TerraformWorldProviderBiome(TerraformWorld.get(worldname,seed), - delegate.e())); // Last arg is WorldChunkManager + + public NMSChunkGenerator(String worldname, long seed, @NotNull ChunkGenerator delegate) { + super( + delegate.b,// b is structureSets + delegate.e,// e is structureOverrides + new TerraformWorldProviderBiome(TerraformWorld.get(worldname, seed), delegate.e()) + ); // Last arg is WorldChunkManager tw = TerraformWorld.get(worldname, seed); this.delegate = delegate; @@ -60,84 +56,115 @@ public NMSChunkGenerator(String worldname, long seed, @Override // getBiomeSource public WorldChunkManager e() { - // d is runtimeBiomeSource - if(!(d instanceof TerraformWorldProviderBiome)) - TerraformGeneratorPlugin.logger.error("d was not an instance of TerraformWorldProviderBiome!"); + // d is runtimeBiomeSource + if (!(d instanceof TerraformWorldProviderBiome)) { + TerraformGeneratorPlugin.logger.error("d was not an instance of TerraformWorldProviderBiome!"); + } return this.d; } - + public @NotNull TerraformWorld getTerraformWorld() { return tw; } // createBiomes @Override - public @NotNull CompletableFuture a(IRegistry iregistry, Executor executor, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) { - - return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { - return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers - }), SystemUtils.f()); - } - - @Override // findNearestMapFeature -// // StructureManager is StructureFeatureManager, NOT StructureManager. Spigot remapped it. - // (spigot) StructureGenerator is (mojang) StructureFeature - // (spigot) StructureFeature is (mojang) ConfiguredStructureFeature - public Pair>> a(WorldServer worldserver, @NotNull HolderSet> holderset, @NotNull BlockPosition blockposition, int i, boolean flag) + public @NotNull CompletableFuture a(IRegistry iregistry, + Executor executor, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) { -// net.minecraft.world.level.levelgen.feature.StructureFeature PILLAGER_OUTPOST -> b -// net.minecraft.world.level.levelgen.feature.StructureFeature MINESHAFT -> c -// net.minecraft.world.level.levelgen.feature.StructureFeature WOODLAND_MANSION -> d -// net.minecraft.world.level.levelgen.feature.StructureFeature JUNGLE_TEMPLE -> e -// net.minecraft.world.level.levelgen.feature.StructureFeature DESERT_PYRAMID -> f -// net.minecraft.world.level.levelgen.feature.StructureFeature IGLOO -> g -// net.minecraft.world.level.levelgen.feature.StructureFeature RUINED_PORTAL -> h -// net.minecraft.world.level.levelgen.feature.StructureFeature SHIPWRECK -> i -// net.minecraft.world.level.levelgen.feature.StructureFeature SWAMP_HUT -> j -// net.minecraft.world.level.levelgen.feature.StructureFeature STRONGHOLD -> k -// net.minecraft.world.level.levelgen.feature.StructureFeature OCEAN_MONUMENT -> l -// net.minecraft.world.level.levelgen.feature.StructureFeature OCEAN_RUIN -> m -// net.minecraft.world.level.levelgen.feature.StructureFeature FORTRESS -> n -// net.minecraft.world.level.levelgen.feature.StructureFeature END_CITY -> o -// net.minecraft.world.level.levelgen.feature.StructureFeature BURIED_TREASURE -> p -// net.minecraft.world.level.levelgen.feature.StructureFeature VILLAGE -> q -// net.minecraft.world.level.levelgen.feature.StructureFeature NETHER_FOSSIL -> r -// net.minecraft.world.level.levelgen.feature.StructureFeature BASTION_REMNANT -> s - - int pX = blockposition.u(); // getX + + return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { + return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers + }), SystemUtils.f()); + } + + @Override // findNearestMapFeature + // // StructureManager is StructureFeatureManager, NOT StructureManager. Spigot remapped it. + // (spigot) StructureGenerator is (mojang) StructureFeature + // (spigot) StructureFeature is (mojang) ConfiguredStructureFeature + public Pair>> a(WorldServer worldserver, + @NotNull HolderSet> holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) + { + // net.minecraft.world.level.levelgen.feature.StructureFeature PILLAGER_OUTPOST -> b + // net.minecraft.world.level.levelgen.feature.StructureFeature MINESHAFT -> c + // net.minecraft.world.level.levelgen.feature.StructureFeature WOODLAND_MANSION -> d + // net.minecraft.world.level.levelgen.feature.StructureFeature JUNGLE_TEMPLE -> e + // net.minecraft.world.level.levelgen.feature.StructureFeature DESERT_PYRAMID -> f + // net.minecraft.world.level.levelgen.feature.StructureFeature IGLOO -> g + // net.minecraft.world.level.levelgen.feature.StructureFeature RUINED_PORTAL -> h + // net.minecraft.world.level.levelgen.feature.StructureFeature SHIPWRECK -> i + // net.minecraft.world.level.levelgen.feature.StructureFeature SWAMP_HUT -> j + // net.minecraft.world.level.levelgen.feature.StructureFeature STRONGHOLD -> k + // net.minecraft.world.level.levelgen.feature.StructureFeature OCEAN_MONUMENT -> l + // net.minecraft.world.level.levelgen.feature.StructureFeature OCEAN_RUIN -> m + // net.minecraft.world.level.levelgen.feature.StructureFeature FORTRESS -> n + // net.minecraft.world.level.levelgen.feature.StructureFeature END_CITY -> o + // net.minecraft.world.level.levelgen.feature.StructureFeature BURIED_TREASURE -> p + // net.minecraft.world.level.levelgen.feature.StructureFeature VILLAGE -> q + // net.minecraft.world.level.levelgen.feature.StructureFeature NETHER_FOSSIL -> r + // net.minecraft.world.level.levelgen.feature.StructureFeature BASTION_REMNANT -> s + + int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - - for(Holder> holder:holderset) { - StructureFeature feature = holder.a(); - StructureGenerator structuregenerator = feature.d; - TerraformGeneratorPlugin.logger.info("Vanilla locate for " + structuregenerator.getClass().getName() + " invoked."); + + for (Holder> holder : holderset) { + StructureFeature feature = holder.a(); + StructureGenerator structuregenerator = feature.d; + TerraformGeneratorPlugin.logger.info("Vanilla locate for " + + structuregenerator.getClass().getName() + + " invoked."); if (structuregenerator == StructureGenerator.k) { // stronghold int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); - return new Pair<> - (new BlockPosition(coords[0], 20, coords[1]), holder); - } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { - if (structuregenerator == StructureGenerator.l) { // Monument - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (structuregenerator == StructureGenerator.d) { // Mansion - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (structuregenerator.getClass().getName().equals("net.minecraft.world.level.levelgen.feature.WorldGenBuriedTreasure")) { - // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); + } + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + if (structuregenerator == StructureGenerator.l) { // Monument + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (structuregenerator == StructureGenerator.d) { // Mansion + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (structuregenerator.getClass() + .getName() + .equals("net.minecraft.world.level.levelgen.feature.WorldGenBuriedTreasure")) + { + // Buried Treasure + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -145,17 +172,26 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { - delegate.a(generatoraccessseed, ichunkaccess, structuremanager); + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { + delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long var2, BiomeManager var4, StructureManager var5, @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features var7) { + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long var2, + BiomeManager var4, + StructureManager var5, + @NotNull IChunkAccess ichunkaccess, + WorldGenStage.Features var7) + { - // POPULATES BIOMES. IMPORTANT - // ichunkaccess.fillBiomesFromNoise(this.runtimeBiomeSource::getNoiseBiome, this.climateSampler()) - ichunkaccess.a(this.e(), null); - delegate.a(regionlimitedworldaccess, var2, var4, var5, ichunkaccess, var7); + // POPULATES BIOMES. IMPORTANT + // ichunkaccess.fillBiomesFromNoise(this.runtimeBiomeSource::getNoiseBiome, this.climateSampler()) + ichunkaccess.a(this.e(), null); + delegate.a(regionlimitedworldaccess, var2, var4, var5, ichunkaccess, var7); } @Override // getSeaLevel @@ -164,101 +200,110 @@ public int g() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, StructureManager structuremanager, IChunkAccess ichunkaccess, DefinedStructureManager definedstructuremanager, - long i) { - + public void a(IRegistryCustom iregistrycustom, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + DefinedStructureManager definedstructuremanager, + long i) + { + } @Override // getSpawnHeight public int a(LevelHeightAccessor levelheightaccessor) { return 64; - } + } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, StructureManager structuremanager, IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, structuremanager, ichunkaccess); - } - + public CompletableFuture a(Executor executor, + Blender blender, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, structuremanager, ichunkaccess); + } -// @SuppressWarnings("unchecked") + // @SuppressWarnings("unchecked") @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, IChunkAccess ichunkaccess) { + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { delegate.a(regionlimitedworldaccess, structuremanager, ichunkaccess); } - - @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) - { - delegate.a(gas, manager, ica); - } + + @Override // createReferences. Idk what this is + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) + { + delegate.a(gas, manager, ica); + } @Override protected Codec b() { return ChunkGeneratorAbstract.a; } - @Override // getBaseColumn - public BlockColumn a(int var0, int var1, LevelHeightAccessor var2) { - - return this.delegate.a(var0, var1, var2); - } - - @Override // withSeed - public @NotNull ChunkGenerator a(long seed) { - return new NMSChunkGenerator(this.tw.getName(), (int) seed, this.delegate); - } - - // spawnOriginalMobs - public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { - this.delegate.a(regionlimitedworldaccess); - } - // getGenDepth - public int f() { - return this.delegate.f(); - } - // climateSampler - public Sampler d() { - return this.delegate.d(); - } - - // getMinY - @Override - public int h() { - return this.delegate.h(); - } - - @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor) { - return this.a(i, j, heightmap_type, levelheightaccessor); - } - - - @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor) { - return this.a(i, j, heightmap_type, levelheightaccessor) - 1; - } + @Override // getBaseColumn + public BlockColumn a(int var0, int var1, LevelHeightAccessor var2) { + + return this.delegate.a(var0, var1, var2); + } + + @Override // withSeed + public @NotNull ChunkGenerator a(long seed) { + return new NMSChunkGenerator(this.tw.getName(), (int) seed, this.delegate); + } + + // spawnOriginalMobs + public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { + this.delegate.a(regionlimitedworldaccess); + } + + // getGenDepth + public int f() { + return this.delegate.f(); + } + + // climateSampler + public Sampler d() { + return this.delegate.d(); + } + + // getMinY + @Override + public int h() { + return this.delegate.h(); + } + + @Override // getFirstFreeHeight + public int b(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor) { + return this.a(i, j, heightmap_type, levelheightaccessor); + } + + @Override // getFirstOccupiedHeight + public int c(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor) { + return this.a(i, j, heightmap_type, levelheightaccessor) - 1; + } @Override // getBaseHeight public int a(int x, int z, HeightMap.Type var2, LevelHeightAccessor var3) { // return delegate.a(x, z, var2, var3); - return 100; - // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); + return 100; + // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); } - - private static boolean biomeDebug = false; - + @Override - public Holder getNoiseBiome(int x, int y, int z) { - if(!biomeDebug) { - biomeDebug = true; - TerraformGeneratorPlugin.logger.info("[getNoiseBiome] called for " + x + "," + y + "," + z); - } - return this.c.getNoiseBiome(x, y, z, null); + public Holder getNoiseBiome(int x, int y, int z) { + if (!biomeDebug) { + biomeDebug = true; + TerraformGeneratorPlugin.logger.info("[getNoiseBiome] called for " + x + "," + y + "," + z); + } + return this.c.getNoiseBiome(x, y, z, null); + } + + @Override // addDebugScreenInfo + public void a(List arg0, BlockPosition arg1) { + } - @Override // addDebugScreenInfo - public void a(List arg0, BlockPosition arg1) { - - } - } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSInjector.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSInjector.java index 8959c492..cd69dc51 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSInjector.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSInjector.java @@ -1,11 +1,12 @@ package org.terraform.v1_18_R2; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Beehive; @@ -25,21 +26,22 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; public class NMSInjector extends NMSInjectorAbstract { - - // private boolean heightInjectSuccess = true; - - @Override - public void startupTasks() { + + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; + + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } - + } + @Override public @NotNull BlockDataFixerAbstract getBlockDataFixer() { return new BlockDataFixer(); @@ -49,56 +51,60 @@ public void startupTasks() { public boolean attemptInject(@NotNull World world) { CraftWorld cw = (CraftWorld) world; WorldServer ws = cw.getHandle(); - + // Force world to correct height TerraformWorld.get(world).minY = -64; TerraformWorld.get(world).maxY = 320; - + // String worldname, // int seed, // WorldChunkManager worldchunkmanager, // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), - ws.k().g());// , // k is getChunkProvider, g is getChunkGenerator() - // old, - // old, - // ws.k().g().d(), - // world.getSeed()); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + ws.k().g().getClass().getSimpleName()); - - if(ws.k().g() instanceof CustomChunkGenerator) { + ws.k().g() + );// , // k is getChunkProvider, g is getChunkGenerator() + // old, + // old, + // ws.k().g().d(), + // world.getSeed()); + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + ws.k() + .g() + .getClass() + .getSimpleName()); + + if (ws.k().g() instanceof CustomChunkGenerator) { try { - ChunkGenerator delegate; - Field f = CustomChunkGenerator.class.getDeclaredField("delegate"); - f.setAccessible(true); - delegate = (ChunkGenerator) f.get(ws.k().g()); - TerraformGeneratorPlugin.logger.info("CustomChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); + ChunkGenerator delegate; + Field f = CustomChunkGenerator.class.getDeclaredField("delegate"); + f.setAccessible(true); + delegate = (ChunkGenerator) f.get(ws.k().g()); + TerraformGeneratorPlugin.logger.info("CustomChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); } - catch(Exception e) { - TerraformGeneratorPlugin.logger.stackTrace(e); + catch (Exception e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } } // For Changing DimensionManager height - TerraformGeneratorPlugin.logger.info("- minY " + ws.q_().k() + " " + world.getMinHeight()); - TerraformGeneratorPlugin.logger.info("- Height " + ws.q_().l() + " " + world.getMaxHeight()); - TerraformGeneratorPlugin.logger.info("- LogicalHeight " + ws.q_().m() + " " + world.getLogicalHeight()); - - // Inject TerraformGenerator NMS chunk generator - + TerraformGeneratorPlugin.logger.info("- minY " + ws.q_().k() + " " + world.getMinHeight()); + TerraformGeneratorPlugin.logger.info("- Height " + ws.q_().l() + " " + world.getMaxHeight()); + TerraformGeneratorPlugin.logger.info("- LogicalHeight " + ws.q_().m() + " " + world.getLogicalHeight()); + + // Inject TerraformGenerator NMS chunk generator + PlayerChunkMap pcm = ws.k().a; // getChunkProvider().PlayerChunkMap try { - TerraformGeneratorPlugin.privateFieldHandler.injectField( - pcm, "u", bpg); // chunkGenerator - } catch (Throwable e) { + TerraformGeneratorPlugin.privateFieldHandler.injectField(pcm, "u", bpg); // chunkGenerator + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } - + return true; } @@ -107,7 +113,7 @@ public boolean attemptInject(@NotNull World world) { IChunkAccess ica = ((CraftChunk) chunk).getHandle(); CraftWorld cw = (CraftWorld) chunk.getWorld(); WorldServer ws = cw.getHandle(); - + TerraformWorld tw = TerraformWorld.get(chunk.getWorld()); // return new PopulatorData(new RegionLimitedWorldAccess(ws, list), null, chunk.getX(), chunk.getZ()); return new PopulatorDataICA(new PopulatorDataPostGen(chunk), tw, ws, ica, chunk.getX(), chunk.getZ()); @@ -120,20 +126,26 @@ public boolean attemptInject(@NotNull World world) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.D()); // C is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } @@ -144,19 +156,20 @@ public void storeBee(Beehive hive) { // TileEntityBeehive.storeBee teb.a(nbttagcompound, 0, false); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java index f7965e09..1772dd01 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java @@ -1,7 +1,17 @@ package org.terraform.v1_18_R2; -import java.util.HashMap; - +import net.minecraft.core.BlockPosition; +import net.minecraft.core.IRegistry; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.entity.*; +import net.minecraft.world.level.GeneratorAccessSeed; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.HeightMap; +import net.minecraft.world.level.storage.loot.LootTables; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -17,98 +27,140 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; - -import net.minecraft.core.BlockPosition; -import net.minecraft.core.IRegistry; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.EnumMobSpawn; -import net.minecraft.world.entity.GroupDataEntity; -import net.minecraft.world.level.GeneratorAccessSeed; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.HeightMap; -import net.minecraft.world.level.storage.loot.LootTables; import org.terraform.main.config.TConfigOption; +import java.util.HashMap; + public class PopulatorData extends PopulatorDataAbstract implements IPopulatorDataBaseHeightAccess { + private static final HashMap> entityTypesDict = new HashMap<>(); + final GeneratorAccessSeed rlwa; + final IChunkAccess ica; private final int chunkX; private final int chunkZ; - private int radius = 1; private final NMSChunkGenerator gen; - final GeneratorAccessSeed rlwa; - final IChunkAccess ica; - - private static final HashMap> entityTypesDict = new HashMap<>(); - + private int radius = 1; + public PopulatorData(GeneratorAccessSeed rlwa, IChunkAccess ica, NMSChunkGenerator gen, int chunkX, int chunkZ) { this.rlwa = rlwa; this.chunkX = chunkX; this.chunkZ = chunkZ; this.gen = gen; this.ica = ica; - - if(entityTypesDict.isEmpty()) { - for(EntityType type:EntityType.values()) { - if(type == EntityType.ENDER_SIGNAL) continue; - if(type == EntityType.UNKNOWN) continue; - try { - EntityTypes et = (EntityTypes) EntityTypes.class.getDeclaredField(EntityTypeMapper.getObfsNameFromBukkitEntityType(type)).get(null); - entityTypesDict.put(type, et); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException - | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + + if (entityTypesDict.isEmpty()) { + for (EntityType type : EntityType.values()) { + if (type == EntityType.ENDER_SIGNAL) { + continue; + } + if (type == EntityType.UNKNOWN) { + continue; + } + try { + EntityTypes et = (EntityTypes) EntityTypes.class.getDeclaredField(EntityTypeMapper.getObfsNameFromBukkitEntityType( + type)).get(null); + entityTypesDict.put(type, et); + } + catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } } - + public void setRadius(int radius) { - this.radius = radius; + this.radius = radius; } public Material getType(int x, int y, int z) { - try { - // return rlwa.getType(x, y, z); - return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); - }catch(Exception e) { - Bukkit.getLogger().info("Error chunk: " + chunkX + "," + chunkZ + "--- Block Coords: " + 16*chunkX + "," + 16*chunkZ + " for coords " + x + "," + y + "," + z); - TerraformGeneratorPlugin.logger.stackTrace(e); + try { + // return rlwa.getType(x, y, z); + return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); + } + catch (Exception e) { + Bukkit.getLogger() + .info("Error chunk: " + + chunkX + + "," + + chunkZ + + "--- Block Coords: " + + 16 * chunkX + + "," + + 16 * chunkZ + + " for coords " + + x + + "," + + y + + "," + + z); + TerraformGeneratorPlugin.logger.stackTrace(e); } - return null; + return null; } public BlockData getBlockData(int x, int y, int z) { // return rlwa.getBlockData(x,y,z); - return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); + return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, Bukkit.createBlockData(type)); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + Bukkit.createBlockData(type) + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), 0); - } + } } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, data); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { - rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + data + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { + rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); } } @@ -127,52 +179,70 @@ public int getChunkX() { public int getChunkZ() { return chunkZ; } - + @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { - TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); - return; - } - try { - EntityTypes et = entityTypesDict.get(type); - Entity e = et.a(rlwa.getMinecraftWorld()); - // o is setPosRaw - e.o((double) rawX + 0.5D, rawY, (double) rawZ + 0.5D); - if (e instanceof EntityInsentient) { + if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { + TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); + return; + } + try { + EntityTypes et = entityTypesDict.get(type); + Entity e = et.a(rlwa.getMinecraftWorld()); + // o is setPosRaw + e.o((double) rawX + 0.5D, rawY, (double) rawZ + 0.5D); + if (e instanceof EntityInsentient) { - ((EntityInsentient)e).a(rlwa, rlwa.d_(new BlockPosition(rawX + 0.5D, rawY, rawZ + 0.5D)), EnumMobSpawn.n, (GroupDataEntity)null, (NBTTagCompound)null); - } - // b is addFreshEntity - rlwa.b(e); - } catch (IllegalArgumentException | SecurityException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - // rlwa.spawnEntity(new Location(gen.getTerraformWorld().getWorld(), rawX, rawY, rawZ), type); + ((EntityInsentient) e).a( + rlwa, + rlwa.d_(new BlockPosition(rawX + 0.5D, rawY, rawZ + 0.5D)), + EnumMobSpawn.n, + (GroupDataEntity) null, + (NBTTagCompound) null + ); + } + // b is addFreshEntity + rlwa.b(e); + } + catch (IllegalArgumentException | SecurityException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + // rlwa.spawnEntity(new Location(gen.getTerraformWorld().getWorld(), rawX, rawY, rawZ), type); } @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); - + setType(rawX, rawY, rawZ, Material.SPAWNER); TileEntity tileentity = rlwa.c_(pos); if (tileentity instanceof TileEntityMobSpawner) { try { - // Fetch from ENTITY_TYPE_REGISTRY (m)'s map - @SuppressWarnings("deprecation") - // W is ENTITY_TYPE - EntityTypes nmsEntity = IRegistry.W.a(new MinecraftKey(type.getName())); + // Fetch from ENTITY_TYPE_REGISTRY (m)'s map + @SuppressWarnings("deprecation") + // W is ENTITY_TYPE + EntityTypes nmsEntity = IRegistry.W.a(new MinecraftKey(type.getName())); ((TileEntityMobSpawner) tileentity).d().a(nmsEntity); - } catch (IllegalArgumentException | SecurityException e) { + } + catch (IllegalArgumentException | SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - } else { - TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + "," + rawX + "," + rawY + "," + rawZ + ")"); + } + else { + TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + + "," + + rawX + + "," + + rawY + + "," + + rawZ + + ")"); } } @@ -183,7 +253,7 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { } private @Nullable MinecraftKey getLootTable(@NotNull TerraLootTable table) { - return switch(table) { + return switch (table) { case EMPTY -> LootTables.a; case SPAWN_BONUS_CHEST -> LootTables.b; case END_CITY_TREASURE -> LootTables.c; @@ -223,87 +293,87 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { case PILLAGER_OUTPOST -> LootTables.K; case RUINED_PORTAL -> LootTables.P; default -> -// case SHEEP_WHITE: -// return LootTables.Q; -// case SHEEP_ORANGE: -// return LootTables.R; -// case SHEEP_MAGENTA: -// return LootTables.S; -// case SHEEP_LIGHT_BLUE: -// return LootTables.T; -// case SHEEP_YELLOW: -// return LootTables.U; -// case SHEEP_LIME: -// return LootTables.V; -// case SHEEP_PINK: -// return LootTables.W; -// case SHEEP_GRAY: -// return LootTables.X; -// case SHEEP_LIGHT_GRAY: -// return LootTables.Y; -// case SHEEP_CYAN: -// return LootTables.Z; -// case SHEEP_PURPLE: -// return LootTables.aa; -// case SHEEP_BLUE: -// return LootTables.ab; -// case SHEEP_BROWN: -// return LootTables.ac; -// case SHEEP_GREEN: -// return LootTables.ad; -// case SHEEP_RED: -// return LootTables.ae; -// case SHEEP_BLACK: -// return LootTables.af; -// case FISHING: -// return LootTables.ag; -// case FISHING_JUNK: -// return LootTables.ah; -// case FISHING_TREASURE: -// return LootTables.ai; -// case FISHING_FISH: -// return LootTables.aj; -// case CAT_MORNING_GIFT: -// return LootTables.ak; -// case ARMORER_GIFT: -// return LootTables.al; -// case BUTCHER_GIFT: -// return LootTables.am; -// case CARTOGRAPHER_GIFT: -// return LootTables.an; -// case CLERIC_GIFT: -// return LootTables.ao; -// case FARMER_GIFT: -// return LootTables.ap; -// case FISHERMAN_GIFT: -// return LootTables.aq; -// case FLETCHER_GIFT: -// return LootTables.ar; -// case LEATHERWORKER_GIFT: -// return LootTables.as; -// case LIBRARIAN_GIFT: -// return LootTables.at; -// case MASON_GIFT: -// return LootTables.au; -// case SHEPHERD_GIFT: -// return LootTables.av; -// case TOOLSMITH_GIFT: -// return LootTables.aw; -// case WEAPONSMITH_GIFT: -// return LootTables.ax; -// case PIGLIN_BARTERING: -// return LootTables.ay + // case SHEEP_WHITE: + // return LootTables.Q; + // case SHEEP_ORANGE: + // return LootTables.R; + // case SHEEP_MAGENTA: + // return LootTables.S; + // case SHEEP_LIGHT_BLUE: + // return LootTables.T; + // case SHEEP_YELLOW: + // return LootTables.U; + // case SHEEP_LIME: + // return LootTables.V; + // case SHEEP_PINK: + // return LootTables.W; + // case SHEEP_GRAY: + // return LootTables.X; + // case SHEEP_LIGHT_GRAY: + // return LootTables.Y; + // case SHEEP_CYAN: + // return LootTables.Z; + // case SHEEP_PURPLE: + // return LootTables.aa; + // case SHEEP_BLUE: + // return LootTables.ab; + // case SHEEP_BROWN: + // return LootTables.ac; + // case SHEEP_GREEN: + // return LootTables.ad; + // case SHEEP_RED: + // return LootTables.ae; + // case SHEEP_BLACK: + // return LootTables.af; + // case FISHING: + // return LootTables.ag; + // case FISHING_JUNK: + // return LootTables.ah; + // case FISHING_TREASURE: + // return LootTables.ai; + // case FISHING_FISH: + // return LootTables.aj; + // case CAT_MORNING_GIFT: + // return LootTables.ak; + // case ARMORER_GIFT: + // return LootTables.al; + // case BUTCHER_GIFT: + // return LootTables.am; + // case CARTOGRAPHER_GIFT: + // return LootTables.an; + // case CLERIC_GIFT: + // return LootTables.ao; + // case FARMER_GIFT: + // return LootTables.ap; + // case FISHERMAN_GIFT: + // return LootTables.aq; + // case FLETCHER_GIFT: + // return LootTables.ar; + // case LEATHERWORKER_GIFT: + // return LootTables.as; + // case LIBRARIAN_GIFT: + // return LootTables.at; + // case MASON_GIFT: + // return LootTables.au; + // case SHEPHERD_GIFT: + // return LootTables.av; + // case TOOLSMITH_GIFT: + // return LootTables.aw; + // case WEAPONSMITH_GIFT: + // return LootTables.ax; + // case PIGLIN_BARTERING: + // return LootTables.ay null; }; } - @Override - public TerraformWorld getTerraformWorld() { - return gen.getTerraformWorld(); - } + @Override + public TerraformWorld getTerraformWorld() { + return gen.getTerraformWorld(); + } - @Override - public int getBaseHeight(int rawX, int rawZ) { - return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); - } + @Override + public int getBaseHeight(int rawX, int rawZ) { + return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); + } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorDataICA.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorDataICA.java index da38dc2d..3cb47892 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorDataICA.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorDataICA.java @@ -1,24 +1,5 @@ package org.terraform.v1_18_R2; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.bukkit.entity.EntityType; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.terraform.biome.custombiomes.CustomBiomeType; -import org.terraform.coregen.NaturalSpawnType; -import org.terraform.coregen.TerraLootTable; -import org.terraform.coregen.populatordata.PopulatorDataAbstract; -import org.terraform.coregen.populatordata.PopulatorDataICABiomeWriterAbstract; -import org.terraform.data.TerraformWorld; -import org.terraform.main.TerraformGeneratorPlugin; - import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; import net.minecraft.core.Holder; @@ -35,27 +16,47 @@ import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.IStructureAccess; import net.minecraft.world.level.levelgen.feature.StructureFeature; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.WorldGenMonumentPieces; +import net.minecraft.world.level.levelgen.structure.*; import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; import net.minecraft.world.level.storage.loot.LootTables; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_18_R2.CraftServer; +import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock; +import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.terraform.biome.custombiomes.CustomBiomeType; +import org.terraform.coregen.NaturalSpawnType; +import org.terraform.coregen.TerraLootTable; +import org.terraform.coregen.populatordata.PopulatorDataAbstract; +import org.terraform.coregen.populatordata.PopulatorDataICABiomeWriterAbstract; +import org.terraform.data.TerraformWorld; +import org.terraform.main.TerraformGeneratorPlugin; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,67 +64,68 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); - IRegistry biomeRegistry = dedicatedserver.aU().b(IRegistry.aP); + + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); + IRegistry biomeRegistry = dedicatedserver.aU().b(IRegistry.aP); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - targetBiome = biomeRegistry.g(rkey); // getHolderOrThrow - if(targetBiome == null) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + targetBiome = biomeRegistry.g(rkey); // getHolderOrThrow + if (targetBiome == null) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -151,64 +153,65 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey> structureKey = switch(type) { + ResourceKey> structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; // Monument - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - IRegistry> featureRegistry = dedicatedserver.aU().b(IRegistry.aL); - - StructureFeature structureFeature = featureRegistry.a(structureKey); - - StructurePiece customBoundPiece = new WorldGenMonumentPieces - .WorldGenMonumentPiece1(new Random(), x0, z0, - EnumDirection.a); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + IRegistry> featureRegistry = dedicatedserver.aU().b(IRegistry.aL); + + StructureFeature structureFeature = featureRegistry.a(structureKey); + + StructurePiece customBoundPiece = new WorldGenMonumentPieces.WorldGenMonumentPiece1(new Random(), + x0, + z0, + EnumDirection.a + ); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ add(customBoundPiece); }}); - StructureStart start = new StructureStart( - structureFeature, - new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); + StructureStart start = new StructureStart(structureFeature, + new ChunkCoordIntPair(chunkX, chunkZ), + 0, + container + ); - try { - Field i = StructureStart.class.getDeclaredField("g"); - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + try { + Field i = StructureStart.class.getDeclaredField("g"); + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - IStructureAccess sa = ica; // IStructureAccess is FeatureAccess + catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + + IStructureAccess sa = ica; // IStructureAccess is FeatureAccess sa.a( // setStartForFeature - structureFeature, - start); - + structureFeature, start); + // addReferenceForFeature sa.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, @NotNull TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(getLootTable(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - + private @Nullable MinecraftKey getLootTable(@NotNull TerraLootTable table) { - return switch(table) { + return switch (table) { case EMPTY -> LootTables.a; case SPAWN_BONUS_CHEST -> LootTables.b; case END_CITY_TREASURE -> LootTables.c; @@ -248,82 +251,82 @@ public void spawnMinecartWithChest(int x, int y, int z, @NotNull TerraLootTable case PILLAGER_OUTPOST -> LootTables.K; case RUINED_PORTAL -> LootTables.P; default -> -// case SHEEP_WHITE: -// return LootTables.Q; -// case SHEEP_ORANGE: -// return LootTables.R; -// case SHEEP_MAGENTA: -// return LootTables.S; -// case SHEEP_LIGHT_BLUE: -// return LootTables.T; -// case SHEEP_YELLOW: -// return LootTables.U; -// case SHEEP_LIME: -// return LootTables.V; -// case SHEEP_PINK: -// return LootTables.W; -// case SHEEP_GRAY: -// return LootTables.X; -// case SHEEP_LIGHT_GRAY: -// return LootTables.Y; -// case SHEEP_CYAN: -// return LootTables.Z; -// case SHEEP_PURPLE: -// return LootTables.aa; -// case SHEEP_BLUE: -// return LootTables.ab; -// case SHEEP_BROWN: -// return LootTables.ac; -// case SHEEP_GREEN: -// return LootTables.ad; -// case SHEEP_RED: -// return LootTables.ae; -// case SHEEP_BLACK: -// return LootTables.af; -// case FISHING: -// return LootTables.ag; -// case FISHING_JUNK: -// return LootTables.ah; -// case FISHING_TREASURE: -// return LootTables.ai; -// case FISHING_FISH: -// return LootTables.aj; -// case CAT_MORNING_GIFT: -// return LootTables.ak; -// case ARMORER_GIFT: -// return LootTables.al; -// case BUTCHER_GIFT: -// return LootTables.am; -// case CARTOGRAPHER_GIFT: -// return LootTables.an; -// case CLERIC_GIFT: -// return LootTables.ao; -// case FARMER_GIFT: -// return LootTables.ap; -// case FISHERMAN_GIFT: -// return LootTables.aq; -// case FLETCHER_GIFT: -// return LootTables.ar; -// case LEATHERWORKER_GIFT: -// return LootTables.as; -// case LIBRARIAN_GIFT: -// return LootTables.at; -// case MASON_GIFT: -// return LootTables.au; -// case SHEPHERD_GIFT: -// return LootTables.av; -// case TOOLSMITH_GIFT: -// return LootTables.aw; -// case WEAPONSMITH_GIFT: -// return LootTables.ax; -// case PIGLIN_BARTERING: -// return LootTables.ay + // case SHEEP_WHITE: + // return LootTables.Q; + // case SHEEP_ORANGE: + // return LootTables.R; + // case SHEEP_MAGENTA: + // return LootTables.S; + // case SHEEP_LIGHT_BLUE: + // return LootTables.T; + // case SHEEP_YELLOW: + // return LootTables.U; + // case SHEEP_LIME: + // return LootTables.V; + // case SHEEP_PINK: + // return LootTables.W; + // case SHEEP_GRAY: + // return LootTables.X; + // case SHEEP_LIGHT_GRAY: + // return LootTables.Y; + // case SHEEP_CYAN: + // return LootTables.Z; + // case SHEEP_PURPLE: + // return LootTables.aa; + // case SHEEP_BLUE: + // return LootTables.ab; + // case SHEEP_BROWN: + // return LootTables.ac; + // case SHEEP_GREEN: + // return LootTables.ad; + // case SHEEP_RED: + // return LootTables.ae; + // case SHEEP_BLACK: + // return LootTables.af; + // case FISHING: + // return LootTables.ag; + // case FISHING_JUNK: + // return LootTables.ah; + // case FISHING_TREASURE: + // return LootTables.ai; + // case FISHING_FISH: + // return LootTables.aj; + // case CAT_MORNING_GIFT: + // return LootTables.ak; + // case ARMORER_GIFT: + // return LootTables.al; + // case BUTCHER_GIFT: + // return LootTables.am; + // case CARTOGRAPHER_GIFT: + // return LootTables.an; + // case CLERIC_GIFT: + // return LootTables.ao; + // case FARMER_GIFT: + // return LootTables.ap; + // case FISHERMAN_GIFT: + // return LootTables.aq; + // case FLETCHER_GIFT: + // return LootTables.ar; + // case LEATHERWORKER_GIFT: + // return LootTables.as; + // case LIBRARIAN_GIFT: + // return LootTables.at; + // case MASON_GIFT: + // return LootTables.au; + // case SHEPHERD_GIFT: + // return LootTables.av; + // case TOOLSMITH_GIFT: + // return LootTables.aw; + // case WEAPONSMITH_GIFT: + // return LootTables.ax; + // case PIGLIN_BARTERING: + // return LootTables.ay null; }; } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/TerraformWorldProviderBiome.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/TerraformWorldProviderBiome.java index cd8b590e..a7bec8e9 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/TerraformWorldProviderBiome.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/TerraformWorldProviderBiome.java @@ -1,8 +1,13 @@ package org.terraform.v1_18_R2; -import java.util.ArrayList; -import java.util.List; - +import com.mojang.serialization.Codec; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.Climate.Sampler; +import net.minecraft.world.level.biome.WorldChunkManager; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_18_R2.CraftServer; @@ -14,91 +19,92 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import com.mojang.serialization.Codec; - -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.biome.WorldChunkManager; +import java.util.ArrayList; +import java.util.List; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { + super(biomeListToBiomeBaseList(((CraftServer) Bukkit.getServer()).getServer().aU().b(IRegistry.aP))); + this.tw = tw; + this.registry = ((CraftServer) Bukkit.getServer()).getServer().aU().b(IRegistry.aP); + } + private static @NotNull List> biomeListToBiomeBaseList(@NotNull IRegistry registry) { List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome)); } - - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); - // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); - Holder holder = registry.g(rkey); - if(holder != null) - biomeBases.add(holder); + + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); + // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); + Holder holder = registry.g(rkey); + if (holder != null) { + biomeBases.add(holder); + } } return biomeBases; } - - public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { - super(biomeListToBiomeBaseList(((CraftServer) Bukkit.getServer()).getServer().aU().b(IRegistry.aP))); - this.tw = tw; - this.registry = ((CraftServer) Bukkit.getServer()).getServer().aU().b(IRegistry.aP); + + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); + } + + @Override + public WorldChunkManager a(long arg0) { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - - @Override - public WorldChunkManager a(long arg0) { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // For vanilla cave biome positioning. However, doesn't work now. -// BiomeBase delegateCandidate = delegate.getNoiseBiome(x, y, z, arg3); -// if(CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.LUSH_CAVES -// || CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.DRIPSTONE_CAVES) -// return delegateCandidate; - - // Left shift x and z - BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); - + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // For vanilla cave biome positioning. However, doesn't work now. + // BiomeBase delegateCandidate = delegate.getNoiseBiome(x, y, z, arg3); + // if(CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.LUSH_CAVES + // || CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.DRIPSTONE_CAVES) + // return delegateCandidate; + + // Left shift x and z + BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); + DedicatedServer dedicatedserver = ((CraftServer) Bukkit.getServer()).getServer(); + IRegistry iregistry = dedicatedserver.aU().b(IRegistry.aP); - - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { - - return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); - Holder holder = iregistry.g(rkey); // g is getHolderOrThrow - if(holder == null) { + + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + + return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + Holder holder = iregistry.g(rkey); // g is getHolderOrThrow + if (holder == null) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - } - - if(holder != null) { - return holder; - } - else - return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); - } - } + } + + if (holder != null) { + return holder; + } + else { + return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); + } + } + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/BlockDataFixer.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/BlockDataFixer.java index 22ddbfd3..a31f51fb 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/BlockDataFixer.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/BlockDataFixer.java @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/CustomBiomeHandler.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/CustomBiomeHandler.java index cfdce267..7a5c68ea 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/CustomBiomeHandler.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/CustomBiomeHandler.java @@ -9,12 +9,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_19_R3.CraftServer; import org.jetbrains.annotations.NotNull; @@ -27,141 +23,158 @@ import java.util.Locale; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { return MinecraftServer.getServer().aX().d(Registries.an); } - @SuppressWarnings("deprecation") - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - MinecraftServer minecraftServer = MinecraftServer.getServer(); - // an is BIOMES - // aX is registryAccess - // d is registryOrThrow - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + @SuppressWarnings("deprecation") + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + MinecraftServer minecraftServer = MinecraftServer.getServer(); + // an is BIOMES + // aX is registryAccess + // d is registryOrThrow + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { - ResourceKey newKey = ResourceKey.a(Registries.an, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); + ResourceKey newKey = ResourceKey.a( + Registries.an, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - // i is climateSettings + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); + + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // c is containsKey - if(registrywritable.c(newKey)) - { + if (registrywritable.c(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -180,8 +193,8 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder registrywritable.f(biome); - // a is RegistryMaterials.register - registrywritable.a(newKey, biome, Lifecycle.stable()); + // a is RegistryMaterials.register + registrywritable.a(newKey, biome, Lifecycle.stable()); // Make unregisteredIntrusiveHolders null again to remove potential for undefined behaviour unregisteredIntrusiveHolders.set(registrywritable, null); @@ -190,7 +203,7 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/EntityTypeMapper.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/EntityTypeMapper.java index bcb76a1c..784f3807 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/EntityTypeMapper.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/EntityTypeMapper.java @@ -9,7 +9,7 @@ @SuppressWarnings("UnstableApiUsage") public class EntityTypeMapper { - private static final HashMap obsNames = new HashMap<>(){{ + private static final HashMap obsNames = new HashMap<>() {{ put(EntityType.ALLAY, "b"); put(EntityType.AREA_EFFECT_CLOUD, "c"); put(EntityType.ARMOR_STAND, "d"); @@ -135,12 +135,13 @@ public class EntityTypeMapper { put(EntityType.PLAYER, "bt"); put(EntityType.FISHING_HOOK, "bu"); }}; - public static @NotNull String getObfsNameFromBukkitEntityType(@NotNull EntityType e){ + + public static @NotNull String getObfsNameFromBukkitEntityType(@NotNull EntityType e) { String name = obsNames.get(e); - if(name == null) { + if (name == null) { TerraformGeneratorPlugin.logger.error("INVALID ENTITY REQUESTED: " + e); return ""; } return name; - } + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java index 7662de0d..739f0e14 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java @@ -44,76 +44,100 @@ import java.util.concurrent.Executor; public class NMSChunkGenerator extends ChunkGenerator { - private final @NotNull ChunkGenerator delegate; + private final @NotNull ChunkGenerator delegate; private final @NotNull TerraformWorld tw; private final @NotNull TerraformWorldProviderBiome twpb; - - public NMSChunkGenerator(String worldname, long seed, - @NotNull ChunkGenerator delegate) { - super( + + public NMSChunkGenerator(String worldname, long seed, @NotNull ChunkGenerator delegate) { + super( delegate.c(), // WorldChunkManager c() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldname, seed); this.delegate = delegate; twpb = new TerraformWorldProviderBiome(tw, delegate.c()); } - + @Override // getBiomeSource public @NotNull WorldChunkManager c() { - return twpb; + return twpb; } - + public @NotNull TerraformWorld getTerraformWorld() { return tw; } @Override // createBiomes - public @NotNull CompletableFuture a(Executor executor, RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(Executor executor, + RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) + { + return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { + return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers + }), SystemUtils.f()); + } + + @Override // findNearestMapFeature + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) { - return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { - return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers - }), SystemUtils.f()); - } - - @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { - - int pX = blockposition.u(); // getX + + int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - - for(Holder holder:holderset) { - Structure feature = holder.a(); - // StructureGenerator structuregenerator = feature.; - TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); + + for (Holder holder : holderset) { + Structure feature = holder.a(); + // StructureGenerator structuregenerator = feature.; + TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); if (holder.a().getClass() == StrongholdStructure.class) { // stronghold int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); - return new Pair<> - (new BlockPosition(coords[0], 20, coords[1]), holder); - } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { - if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { - // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); + } + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { + // Buried Treasure + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -121,21 +145,35 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { - delegate.a(generatoraccessseed, ichunkaccess, structuremanager); + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { + delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { - // POPULATES BIOMES. IMPORTANT - // (net.minecraft.world.level.biome.BiomeResolver,net.minecraft.world.level.biome.Climate$Sampler) + // POPULATES BIOMES. IMPORTANT + // (net.minecraft.world.level.biome.BiomeResolver,net.minecraft.world.level.biome.Climate$Sampler) ichunkaccess.a(twpb, null); // This can be null as its passed into twpd - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @@ -145,89 +183,113 @@ public int e() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { - + public void a(IRegistryCustom iregistrycustom, + ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { + } @Override // getSpawnHeight public int a(LevelHeightAccessor levelheightaccessor) { return 64; - } + } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, - randomstate, structuremanager, - ichunkaccess); - } - - -// @SuppressWarnings("unchecked") + public CompletableFuture a(Executor executor, + Blender blender, + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, randomstate, structuremanager, ichunkaccess); + } + + + // @SuppressWarnings("unchecked") @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) { + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) + { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } - - @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) - { - delegate.a(gas, manager, ica); - } + + @Override // createReferences. Idk what this is + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) + { + delegate.a(gas, manager, ica); + } @Override protected Codec a() { return Codec.unit(null); } - @Override // getBaseColumn - public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); - } + @Override // getBaseColumn + public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + return this.delegate.a(i, j, levelheightaccessor, randomstate); + } // spawnOriginalMobs - public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { - this.delegate.a(regionlimitedworldaccess); - } - // getGenDepth - public int d() { - return this.delegate.d(); - } - - - // getMinY - @Override - public int f() { - return this.delegate.f(); - } - - @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); - } - - - @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; - } + public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { + this.delegate.a(regionlimitedworldaccess); + } + + // getGenDepth + public int d() { + return this.delegate.d(); + } + + + // getMinY + @Override + public int f() { + return this.delegate.f(); + } + + @Override // getFirstFreeHeight + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { + return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); + } + + + @Override // getFirstOccupiedHeight + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { + return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; + } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); - return 100; - // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); + return 100; + // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); } - + // private static boolean biomeDebug = false; - - @Override // addDebugScreenInfo - public void a(List list, RandomState randomstate, BlockPosition blockposition) { - - } - + + @Override // addDebugScreenInfo + public void a(List list, RandomState randomstate, BlockPosition blockposition) { + + } + } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSInjector.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSInjector.java index d2dfc19f..9c4df638 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSInjector.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSInjector.java @@ -1,8 +1,13 @@ package org.terraform.v1_19_R3; + import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Beehive; @@ -21,24 +26,21 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class NMSInjector extends NMSInjectorAbstract { - - // private boolean heightInjectSuccess = true; - - @Override - public void startupTasks() { + + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; + + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } - + } + @Override public @NotNull BlockDataFixerAbstract getBlockDataFixer() { return new BlockDataFixer(); @@ -48,7 +50,7 @@ public void startupTasks() { public boolean attemptInject(@NotNull World world) { CraftWorld cw = (CraftWorld) world; WorldServer ws = cw.getHandle(); - + // Force world to correct height TerraformWorld.get(world).minY = -64; TerraformWorld.get(world).maxY = 320; @@ -56,34 +58,32 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkProvider, g is getChunkGenerator() ChunkGenerator delegate = ws.k().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); - + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); + // String worldname, // int seed, // WorldChunkManager worldchunkmanager, // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); - // old, - // old, - // ws.k().g().d(), - // world.getSeed()); - - // Inject TerraformGenerator NMS chunk generator + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); + // old, + // old, + // ws.k().g().d(), + // world.getSeed()); + + // Inject TerraformGenerator NMS chunk generator PlayerChunkMap pcm = ws.k().a; // getChunkProvider().PlayerChunkMap try { - TerraformGeneratorPlugin.privateFieldHandler.injectField( - pcm, "u", bpg); // chunkGenerator - } catch (Throwable e) { + TerraformGeneratorPlugin.privateFieldHandler.injectField(pcm, "u", bpg); // chunkGenerator + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } - + return true; } @@ -93,13 +93,12 @@ public boolean attemptInject(@NotNull World world) { IChunkAccess ica = ((CraftChunk) chunk).getHandle(ChunkStatus.o); CraftWorld cw = (CraftWorld) chunk.getWorld(); WorldServer ws = cw.getHandle(); - + TerraformWorld tw = TerraformWorld.get(chunk.getWorld()); // return new PopulatorData(new RegionLimitedWorldAccess(ws, list), null, chunk.getX(), chunk.getZ()); return new PopulatorDataICA(new PopulatorDataPostGen(chunk), tw, ws, ica, chunk.getX(), chunk.getZ()); } - @Override public PopulatorDataICAAbstract getICAData(PopulatorDataAbstract data) { // This is for the damn bees @@ -107,20 +106,26 @@ public PopulatorDataICAAbstract getICAData(PopulatorDataAbstract data) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.A()); // C is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } @@ -131,19 +136,20 @@ public void storeBee(Beehive hive) { // TileEntityBeehive.storeBee teb.a(nbttagcompound, 0, false); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java index 25453cd9..c2ccaba1 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java @@ -38,79 +38,139 @@ import java.util.Optional; import java.util.Random; -public class PopulatorData extends PopulatorDataAbstract implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor { +public class PopulatorData extends PopulatorDataAbstract + implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor +{ + private static final HashMap> entityTypesDict = new HashMap<>(); + final GeneratorAccessSeed rlwa; + final IChunkAccess ica; private final int chunkX; private final int chunkZ; - private int radius = 1; private final NMSChunkGenerator gen; - final GeneratorAccessSeed rlwa; - final IChunkAccess ica; - - private static final HashMap> entityTypesDict = new HashMap<>(); - + private int radius = 1; + public PopulatorData(GeneratorAccessSeed rlwa, IChunkAccess ica, NMSChunkGenerator gen, int chunkX, int chunkZ) { this.rlwa = rlwa; this.chunkX = chunkX; this.chunkZ = chunkZ; this.gen = gen; this.ica = ica; - - if(entityTypesDict.isEmpty()) { - for(EntityType type:EntityType.values()) { - if(type == EntityType.ENDER_SIGNAL) continue; - if(type == EntityType.UNKNOWN) continue; - try { + + if (entityTypesDict.isEmpty()) { + for (EntityType type : EntityType.values()) { + if (type == EntityType.ENDER_SIGNAL) { + continue; + } + if (type == EntityType.UNKNOWN) { + continue; + } + try { // EntityTypes.byString - Optional> et = EntityTypes.a("minecraft:"+type.toString().toLowerCase(Locale.ENGLISH)); + Optional> et = EntityTypes.a("minecraft:" + type.toString() + .toLowerCase(Locale.ENGLISH)); et.ifPresent(entityTypes -> entityTypesDict.put(type, entityTypes)); - } catch (IllegalArgumentException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + } + catch (IllegalArgumentException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } } - + public void setRadius(int radius) { - this.radius = radius; + this.radius = radius; } public Material getType(int x, int y, int z) { - try { - // return rlwa.getType(x, y, z); - return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); - }catch(Exception e) { - Bukkit.getLogger().info("Error chunk: " + chunkX + "," + chunkZ + "--- Block Coords: " + 16*chunkX + "," + 16*chunkZ + " for coords " + x + "," + y + "," + z); - TerraformGeneratorPlugin.logger.stackTrace(e); + try { + // return rlwa.getType(x, y, z); + return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); } - return null; + catch (Exception e) { + Bukkit.getLogger() + .info("Error chunk: " + + chunkX + + "," + + chunkZ + + "--- Block Coords: " + + 16 * chunkX + + "," + + 16 * chunkZ + + " for coords " + + x + + "," + + y + + "," + + z); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + return null; } public BlockData getBlockData(int x, int y, int z) { // return rlwa.getBlockData(x,y,z); - return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); + return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, Bukkit.createBlockData(type)); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + Bukkit.createBlockData(type) + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), 0); - } + } } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, data); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { - rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + data + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { + rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); } } @@ -129,59 +189,79 @@ public int getChunkX() { public int getChunkZ() { return chunkZ; } - + @Override public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { - TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); - return; - } - - // Use this method for thread safety. - CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); - net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(),rawX,rawY,rawZ), - type.getEntityClass()); - rlwa.b(e); - // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); + if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { + TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); + return; + } + + // Use this method for thread safety. + CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); + net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(), + rawX, + rawY, + rawZ), type.getEntityClass()); + rlwa.b(e); + // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); } @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); - + setType(rawX, rawY, rawZ, Material.SPAWNER); TileEntity tileentity = rlwa.c_(pos); if (tileentity instanceof TileEntityMobSpawner) { try { // Refer to WorldGenDungeons -// TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; -// -// tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); + // TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; + // + // tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); // Fetch from ENTITY_TYPE (Q)'s map - // q is ENTITY_TYPE - EntityTypes nmsEntity = entityTypesDict.get(type); - if(nmsEntity == null) TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + // q is ENTITY_TYPE + EntityTypes nmsEntity = entityTypesDict.get(type); + if (nmsEntity == null) { + TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + } ((TileEntityMobSpawner) tileentity).a(nmsEntity, new RandomSourceWrapper(new Random())); - } catch (IllegalArgumentException | SecurityException e) { + } + catch (IllegalArgumentException | SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - } else { - TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + "," + rawX + "," + rawY + "," + rawZ + ")"); + } + else { + TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + + "," + + rawX + + "," + + rawY + + "," + + rawZ + + ")"); } } @Override public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { BlockPosition pos = new BlockPosition(x, y, z); - TileEntityLootable.a(rlwa, RandomSource.a(gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()), pos, getLootTable(table)); + TileEntityLootable.a( + rlwa, + RandomSource.a(gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()), + pos, + getLootTable(table) + ); } private @Nullable MinecraftKey getLootTable(@NotNull TerraLootTable table) { - return switch(table) { + return switch (table) { case EMPTY -> LootTables.a; case SPAWN_BONUS_CHEST -> LootTables.b; case END_CITY_TREASURE -> LootTables.c; @@ -219,84 +299,84 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { case SHIPWRECK_SUPPLY -> LootTables.I; case SHIPWRECK_TREASURE -> LootTables.J; case PILLAGER_OUTPOST -> LootTables.K; -// case BASTION_TREASURE: -// return LootTables.L; -// case BASTION_OTHER: -// return LootTables.M; -// case BASTION_BRIDGE: -// return LootTables.N; -// case BASTION_HOGLIN_STABLE: -// return LootTables.O; -// case SHEEP_WHITE: -// return LootTables.Q; -// case SHEEP_ORANGE: -// return LootTables.R; -// case SHEEP_MAGENTA: -// return LootTables.S; -// case SHEEP_LIGHT_BLUE: -// return LootTables.T; -// case SHEEP_YELLOW: -// return LootTables.U; -// case SHEEP_LIME: -// return LootTables.V; -// case SHEEP_PINK: -// return LootTables.W; -// case SHEEP_GRAY: -// return LootTables.X; -// case SHEEP_LIGHT_GRAY: -// return LootTables.Y; -// case SHEEP_CYAN: -// return LootTables.Z; -// case SHEEP_PURPLE: -// return LootTables.aa; -// case SHEEP_BLUE: -// return LootTables.ab; -// case SHEEP_BROWN: -// return LootTables.ac; -// case SHEEP_GREEN: -// return LootTables.ad; -// case SHEEP_RED: -// return LootTables.ae; -// case SHEEP_BLACK: -// return LootTables.af; -// case FISHING: -// return LootTables.ag; -// case FISHING_JUNK: -// return LootTables.ah; -// case FISHING_TREASURE: -// return LootTables.ai; -// case FISHING_FISH: -// return LootTables.aj; -// case CAT_MORNING_GIFT: -// return LootTables.ak; -// case ARMORER_GIFT: -// return LootTables.al; -// case BUTCHER_GIFT: -// return LootTables.am; -// case CARTOGRAPHER_GIFT: -// return LootTables.an; -// case CLERIC_GIFT: -// return LootTables.ao; -// case FARMER_GIFT: -// return LootTables.ap; -// case FISHERMAN_GIFT: -// return LootTables.aq; -// case FLETCHER_GIFT: -// return LootTables.ar; -// case LEATHERWORKER_GIFT: -// return LootTables.as; -// case LIBRARIAN_GIFT: -// return LootTables.at; -// case MASON_GIFT: -// return LootTables.au; -// case SHEPHERD_GIFT: -// return LootTables.av; -// case TOOLSMITH_GIFT: -// return LootTables.aw; -// case WEAPONSMITH_GIFT: -// return LootTables.ax; -// case PIGLIN_BARTERING: -// return LootTables.ay + // case BASTION_TREASURE: + // return LootTables.L; + // case BASTION_OTHER: + // return LootTables.M; + // case BASTION_BRIDGE: + // return LootTables.N; + // case BASTION_HOGLIN_STABLE: + // return LootTables.O; + // case SHEEP_WHITE: + // return LootTables.Q; + // case SHEEP_ORANGE: + // return LootTables.R; + // case SHEEP_MAGENTA: + // return LootTables.S; + // case SHEEP_LIGHT_BLUE: + // return LootTables.T; + // case SHEEP_YELLOW: + // return LootTables.U; + // case SHEEP_LIME: + // return LootTables.V; + // case SHEEP_PINK: + // return LootTables.W; + // case SHEEP_GRAY: + // return LootTables.X; + // case SHEEP_LIGHT_GRAY: + // return LootTables.Y; + // case SHEEP_CYAN: + // return LootTables.Z; + // case SHEEP_PURPLE: + // return LootTables.aa; + // case SHEEP_BLUE: + // return LootTables.ab; + // case SHEEP_BROWN: + // return LootTables.ac; + // case SHEEP_GREEN: + // return LootTables.ad; + // case SHEEP_RED: + // return LootTables.ae; + // case SHEEP_BLACK: + // return LootTables.af; + // case FISHING: + // return LootTables.ag; + // case FISHING_JUNK: + // return LootTables.ah; + // case FISHING_TREASURE: + // return LootTables.ai; + // case FISHING_FISH: + // return LootTables.aj; + // case CAT_MORNING_GIFT: + // return LootTables.ak; + // case ARMORER_GIFT: + // return LootTables.al; + // case BUTCHER_GIFT: + // return LootTables.am; + // case CARTOGRAPHER_GIFT: + // return LootTables.an; + // case CLERIC_GIFT: + // return LootTables.ao; + // case FARMER_GIFT: + // return LootTables.ap; + // case FISHERMAN_GIFT: + // return LootTables.aq; + // case FLETCHER_GIFT: + // return LootTables.ar; + // case LEATHERWORKER_GIFT: + // return LootTables.as; + // case LIBRARIAN_GIFT: + // return LootTables.at; + // case MASON_GIFT: + // return LootTables.au; + // case SHEPHERD_GIFT: + // return LootTables.av; + // case TOOLSMITH_GIFT: + // return LootTables.aw; + // case WEAPONSMITH_GIFT: + // return LootTables.ax; + // case PIGLIN_BARTERING: + // return LootTables.ay case ANCIENT_CITY -> LootTables.P; case ANCIENT_CITY_ICE_BOX -> LootTables.Q; case RUINED_PORTAL -> LootTables.R; @@ -304,31 +384,30 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { }; } - @Override - public TerraformWorld getTerraformWorld() { - return gen.getTerraformWorld(); - } + @Override + public TerraformWorld getTerraformWorld() { + return gen.getTerraformWorld(); + } - @Override - public int getBaseHeight(int rawX, int rawZ) { - // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) - return 100; - // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); - } + @Override + public int getBaseHeight(int rawX, int rawZ) { + // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) + return 100; + // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); + } - @Override - public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { - BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); + @Override + public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { + BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); // TerraformGeneratorPlugin.logger.info(IRegistry.X.b(EntityTypes.h).toString()); setType(rawX, rawY, rawZ, Material.BEE_NEST); try { // TerraformGeneratorPlugin.logger.error("Failed to set beehive at (" + rawX + "," + rawY + "," + rawZ + ") " + BuiltInRegistries.h.b(entityTypesDict.get(EntityType.BEE))); TileEntityBeehive tileentity = (TileEntityBeehive) rlwa.c_(pos); - if(tileentity == null) - { // retry? - setType(rawX, rawY, rawZ, Material.BEE_NEST); - tileentity = (TileEntityBeehive) rlwa.c_(pos); + if (tileentity == null) { // retry? + setType(rawX, rawY, rawZ, Material.BEE_NEST); + tileentity = (TileEntityBeehive) rlwa.c_(pos); } NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -337,8 +416,9 @@ public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee tileentity.a(nbttagcompound, 0, false); - } catch (NullPointerException | IllegalArgumentException | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); } - } + catch (NullPointerException | IllegalArgumentException | SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorDataICA.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorDataICA.java index 7847d61b..cd84e484 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorDataICA.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorDataICA.java @@ -1,27 +1,10 @@ package org.terraform.v1_19_R3; -import net.minecraft.core.registries.Registries; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; -import org.bukkit.entity.EntityType; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.jetbrains.annotations.NotNull; -import org.terraform.biome.custombiomes.CustomBiomeType; -import org.terraform.coregen.NaturalSpawnType; -import org.terraform.coregen.TerraLootTable; -import org.terraform.coregen.populatordata.PopulatorDataAbstract; -import org.terraform.coregen.populatordata.PopulatorDataICABiomeWriterAbstract; -import org.terraform.data.TerraformWorld; -import org.terraform.main.TerraformGeneratorPlugin; - import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -33,14 +16,26 @@ import net.minecraft.world.level.block.entity.TileEntityLootable; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.*; import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import net.minecraft.world.level.storage.loot.LootTables; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock; +import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.jetbrains.annotations.NotNull; +import org.terraform.biome.custombiomes.CustomBiomeType; +import org.terraform.coregen.NaturalSpawnType; +import org.terraform.coregen.TerraLootTable; +import org.terraform.coregen.populatordata.PopulatorDataAbstract; +import org.terraform.coregen.populatordata.PopulatorDataICABiomeWriterAbstract; +import org.terraform.data.TerraformWorld; +import org.terraform.main.TerraformGeneratorPlugin; import java.lang.reflect.Field; import java.util.ArrayList; @@ -48,14 +43,20 @@ import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public @NotNull Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -151,60 +154,58 @@ public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) { } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; // ax is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().aX().d(Registries.ax); - - Structure structureFeature = featureRegistry.a(structureKey); - - StructurePiece customBoundPiece = new OceanMonumentPieces - .h(RandomSource.a(), x0, z0, - EnumDirection.a); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + IRegistry featureRegistry = MinecraftServer.getServer().aX().d(Registries.ax); + + Structure structureFeature = featureRegistry.a(structureKey); + + StructurePiece customBoundPiece = new OceanMonumentPieces.h(RandomSource.a(), x0, z0, EnumDirection.a); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ add(customBoundPiece); }}); - StructureStart start = new StructureStart( - structureFeature, - new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); + StructureStart start = new StructureStart(structureFeature, + new ChunkCoordIntPair(chunkX, chunkZ), + 0, + container + ); - try { - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + try { + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + } + catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - ica.a(structureFeature, start); - ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong + ica.a(structureFeature, start); + ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, @NotNull TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(getLootTable(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - + private MinecraftKey getLootTable(@NotNull TerraLootTable table) { - return switch(table) { + return switch (table) { case SPAWN_BONUS_CHEST -> LootTables.b; case END_CITY_TREASURE -> LootTables.c; case SIMPLE_DUNGEON -> LootTables.d; @@ -248,8 +249,8 @@ private MinecraftKey getLootTable(@NotNull TerraLootTable table) { }; } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/TerraformWorldProviderBiome.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/TerraformWorldProviderBiome.java index cfcf03a6..1250ae6a 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/TerraformWorldProviderBiome.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/TerraformWorldProviderBiome.java @@ -1,11 +1,13 @@ package org.terraform.v1_19_R3; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Stream; - +import com.mojang.serialization.Codec; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.BiomeResolver; +import net.minecraft.world.level.biome.Climate.Sampler; +import net.minecraft.world.level.biome.WorldChunkManager; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock; import org.jetbrains.annotations.NotNull; @@ -15,68 +17,58 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import com.mojang.serialization.Codec; - -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeResolver; -import net.minecraft.world.level.biome.Climate.Sampler; -import net.minecraft.world.level.biome.WorldChunkManager; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { - // Idk what this is for - public static class TerraformBiomeResolverProxy implements BiomeResolver{ - final TerraformWorldProviderBiome delegate; - public TerraformBiomeResolverProxy(TerraformWorldProviderBiome delegate) { - this.delegate = delegate; - } - - @Override - public @Nullable Holder getNoiseBiome(int arg0, int arg1, int arg2, Sampler arg3) { - return delegate.getNoiseBiome(arg0, arg1, arg2, arg3); - } - } - + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; + private final Set> biomeList; + + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { + // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); + this.biomeList = biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); + this.tw = tw; + this.registry = CustomBiomeHandler.getBiomeRegistry(); + } private static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); - // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); + + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); + // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. - Optional> holder = registry.b(rkey); + Optional> holder = registry.b(rkey); holder.ifPresent(biomeBases::add); } return Set.copyOf(biomeBases); } - private final Set> biomeList; - public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { - // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); - this.biomeList = biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); - this.tw = tw; - this.registry = CustomBiomeHandler.getBiomeRegistry(); - } - @Override public Stream> b() { @@ -84,46 +76,60 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - - - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // For vanilla cave biome positioning. However, doesn't work now. -// BiomeBase delegateCandidate = delegate.getNoiseBiome(x, y, z, arg3); -// if(CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.LUSH_CAVES -// || CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.DRIPSTONE_CAVES) -// return delegateCandidate; - - // Left shift x and z - BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { - - return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); - Optional> holder = registry.b(rkey); // g is getHolderOrThrow - if(holder.isEmpty()) { + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); + } + + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // For vanilla cave biome positioning. However, doesn't work now. + // BiomeBase delegateCandidate = delegate.getNoiseBiome(x, y, z, arg3); + // if(CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.LUSH_CAVES + // || CraftBlock.biomeBaseToBiome(registry, delegateCandidate) == Biome.DRIPSTONE_CAVES) + // return delegateCandidate; + + // Left shift x and z + BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); + + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + + return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + Optional> holder = registry.b(rkey); // g is getHolderOrThrow + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - } - - if(holder.isPresent()) { - return holder.get(); - } - else - return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); - } - } + } + + if (holder.isPresent()) { + return holder.get(); + } + else { + return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); + } + } + } + + // Idk what this is for + public static class TerraformBiomeResolverProxy implements BiomeResolver { + final TerraformWorldProviderBiome delegate; + + public TerraformBiomeResolverProxy(TerraformWorldProviderBiome delegate) { + this.delegate = delegate; + } + + @Override + public @Nullable Holder getNoiseBiome(int arg0, int arg1, int arg2, Sampler arg3) { + return delegate.getNoiseBiome(arg0, arg1, arg2, arg3); + } + } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/BlockDataFixer.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/BlockDataFixer.java index 2fb852ec..b78370ca 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/BlockDataFixer.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/BlockDataFixer.java @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/CustomBiomeHandler.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/CustomBiomeHandler.java index 9aa14a4c..61f31ca1 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/CustomBiomeHandler.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/CustomBiomeHandler.java @@ -10,12 +10,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_20_R1.CraftServer; @@ -27,152 +23,173 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; +import java.util.*; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { return MinecraftServer.getServer().aV().d(Registries.ap); } - @SuppressWarnings("deprecation") - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - MinecraftServer minecraftServer = MinecraftServer.getServer(); - // ap is BIOME - // aV is registryAccess - // d is registryOrThrow - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + @SuppressWarnings("deprecation") + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + MinecraftServer minecraftServer = MinecraftServer.getServer(); + // ap is BIOME + // aV is registryAccess + // d is registryOrThrow + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | + SecurityException | + IllegalArgumentException | + IllegalAccessException | + NoSuchMethodException | + InvocationTargetException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) throws + NoSuchFieldException, + SecurityException, + IllegalArgumentException, + IllegalAccessException, + NoSuchMethodException, + InvocationTargetException + { + + ResourceKey newKey = ResourceKey.a( + Registries.ap, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); - ResourceKey newKey = ResourceKey.a(Registries.ap, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); - // i is climateSettings + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // c is containsKey - if(registrywritable.c(newKey)) - { + if (registrywritable.c(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -192,9 +209,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder // registrywritable.f(biome); - // a is RegistryMaterials.register + // a is RegistryMaterials.register // Holder.c is Holder.Reference - Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); + Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); // Holder.Reference.bindValue Method bindValue = Holder.c.class.getDeclaredMethod("b", Object.class); @@ -208,9 +225,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { @@ -218,17 +235,22 @@ public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry< List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBlock.biomeToBiomeBase(registry, biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/LootTableTranslator.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/LootTableTranslator.java index 9bd0fec2..df2041ac 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/LootTableTranslator.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/LootTableTranslator.java @@ -10,7 +10,7 @@ public class LootTableTranslator { // I am indeed formally trained to properly structure my code // I have however elected to completely ignore said training here - public static final HashMap translationMap = new HashMap<>(){{ + public static final HashMap translationMap = new HashMap<>() {{ put(TerraLootTable.EMPTY, LootTables.a); put(TerraLootTable.SPAWN_BONUS_CHEST, LootTables.b); put(TerraLootTable.END_CITY_TREASURE, LootTables.c); diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java index 5576584a..81c9e661 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java @@ -1,26 +1,28 @@ package org.terraform.v1_20_R1; -import java.util.Set; -import java.util.stream.Stream; - -import org.bukkit.block.Biome; -import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock; -import org.terraform.coregen.HeightMap; -import org.terraform.data.TerraformWorld; - import com.mojang.serialization.Codec; - import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.biome.Climate.Sampler; import net.minecraft.world.level.biome.WorldChunkManager; +import org.bukkit.block.Biome; +import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock; +import org.terraform.coregen.HeightMap; +import org.terraform.data.TerraformWorld; import org.terraform.main.config.TConfigOption; +import java.util.Set; +import java.util.stream.Stream; + public class MapRenderWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; - private final Set> biomeList; + private final Holder river; + private final Holder plains; + public MapRenderWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -37,29 +39,24 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); - } + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); + } - private final Holder river; - private final Holder plains; - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // Used to be attempted for cave gen. That didn't work, so now, this is + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // Used to be attempted for cave gen. That didn't work, so now, this is // for optimising cartographers and buried treasure. // This will return river or plains depending on whether or not // the area is submerged. - return HeightMap.getBlockHeight(tw, x,z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? - river : plains; - } + return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java index 6056de07..a14fa1b3 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java @@ -49,11 +49,11 @@ public class NMSChunkGenerator extends ChunkGenerator { private final @NotNull MapRenderWorldProviderBiome mapRendererBS; private final @NotNull TerraformWorldProviderBiome twBS; - public NMSChunkGenerator(String worldName, long seed, - @NotNull ChunkGenerator delegate) { + public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) { super( delegate.c(), // WorldChunkManager c() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldName, seed); this.delegate = delegate; @@ -74,7 +74,11 @@ public NMSChunkGenerator(String worldName, long seed, } @Override // createBiomes - public @NotNull CompletableFuture a(Executor executor, RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(Executor executor, + RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) { return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers @@ -82,13 +86,17 @@ public NMSChunkGenerator(String worldName, long seed, } @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) + { int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - for(Holder holder:holderset) { + for (Holder holder : holderset) { Structure feature = holder.a(); // StructureGenerator structuregenerator = feature.; TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); @@ -97,26 +105,43 @@ public Pair> a(WorldServer worldserver, @NotNul int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -124,14 +149,20 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { // POPULATES BIOMES. IMPORTANT @@ -141,7 +172,15 @@ public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, ichunkaccess.a(twBS, null); // This can be null as its passed into twBS // Call delegate applyCarvers to apply spigot ChunkGenerator; - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @Override // getSeaLevel @@ -150,7 +189,12 @@ public int e() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { + public void a(IRegistryCustom iregistrycustom, + ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { } @Override // getSpawnHeight @@ -159,22 +203,26 @@ public int a(LevelHeightAccessor levelheightaccessor) { } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, - randomstate, structuremanager, - ichunkaccess); + public CompletableFuture a(Executor executor, + Blender blender, + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, randomstate, structuremanager, ichunkaccess); } @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) { delegate.a(gas, manager, ica); } @@ -186,13 +234,14 @@ protected Codec a() { @Override // getBaseColumn public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); + return this.delegate.a(i, j, levelheightaccessor, randomstate); } // spawnOriginalMobs public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { this.delegate.a(regionlimitedworldaccess); } + // getGenDepth public int d() { return this.delegate.d(); @@ -206,20 +255,33 @@ public int f() { } @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); } @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); return 100; // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSInjector.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSInjector.java index c3133ae7..c43aac26 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSInjector.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSInjector.java @@ -1,8 +1,13 @@ package org.terraform.v1_20_R1; + import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Beehive; @@ -21,24 +26,21 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class NMSInjector extends NMSInjectorAbstract { - - // private boolean heightInjectSuccess = true; - - @Override - public void startupTasks() { + + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; + + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } - + } + @Override public @NotNull BlockDataFixerAbstract getBlockDataFixer() { return new BlockDataFixer(); @@ -48,7 +50,7 @@ public void startupTasks() { public boolean attemptInject(@NotNull World world) { CraftWorld cw = (CraftWorld) world; WorldServer ws = cw.getHandle(); - + // Force world to correct height TerraformWorld.get(world).minY = -64; TerraformWorld.get(world).maxY = 320; @@ -56,34 +58,32 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkProvider, g is getChunkGenerator() ChunkGenerator delegate = ws.k().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); - + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); + // String worldname, // int seed, // WorldChunkManager worldchunkmanager, // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); - // old, - // old, - // ws.k().g().d(), - // world.getSeed()); - - // Inject TerraformGenerator NMS chunk generator + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); + // old, + // old, + // ws.k().g().d(), + // world.getSeed()); + + // Inject TerraformGenerator NMS chunk generator PlayerChunkMap pcm = ws.k().a; // getChunkProvider().PlayerChunkMap try { - TerraformGeneratorPlugin.privateFieldHandler.injectField( - pcm, "t", bpg); // chunkGenerator - } catch (Throwable e) { + TerraformGeneratorPlugin.privateFieldHandler.injectField(pcm, "t", bpg); // chunkGenerator + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } - + return true; } @@ -93,7 +93,7 @@ public boolean attemptInject(@NotNull World world) { IChunkAccess ica = ((CraftChunk) chunk).getHandle(ChunkStatus.n); CraftWorld cw = (CraftWorld) chunk.getWorld(); WorldServer ws = cw.getHandle(); - + TerraformWorld tw = TerraformWorld.get(chunk.getWorld()); // return new PopulatorData(new RegionLimitedWorldAccess(ws, list), null, chunk.getX(), chunk.getZ()); return new PopulatorDataICA(new PopulatorDataPostGen(chunk), tw, ws, ica, chunk.getX(), chunk.getZ()); @@ -106,20 +106,26 @@ public PopulatorDataICAAbstract getICAData(PopulatorDataAbstract data) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.A()); // B is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } @@ -130,19 +136,20 @@ public void storeBee(Beehive hive) { // TileEntityBeehive.storeBee teb.a(nbttagcompound, 0, false); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/PopulatorDataICA.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/PopulatorDataICA.java index 803f496f..f789a080 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/PopulatorDataICA.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/PopulatorDataICA.java @@ -1,8 +1,25 @@ package org.terraform.v1_20_R1; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.EnumDirection; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.vehicle.EntityMinecartChest; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.structure.*; +import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; +import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -20,42 +37,26 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.EnumDirection; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; -import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Optional; import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBlock.biomeToBiomeBase(ica.biomeRegistry, fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBlock.biomeToBiomeBase(ica.biomeRegistry, biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -136,7 +139,7 @@ public int getChunkZ() { @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - parent.addEntity(rawX, rawY, rawZ, type); + parent.addEntity(rawX, rawY, rawZ, type); } @Override @@ -150,72 +153,77 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = ica.c_(pos); - if(te instanceof TileEntityLootable) - TileEntityLootable.a(ica, RandomSource.a(tw.getHashedRand(x, y, z).nextLong()), pos, LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - tw.getHashedRand(x, y, z).nextLong()); + if (te instanceof TileEntityLootable) { + TileEntityLootable.a(ica, + RandomSource.a(tw.getHashedRand(x, y, z).nextLong()), + pos, + LootTableTranslator.translationMap.get(table) + ); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + tw.getHashedRand(x, y, z).nextLong() + ); + } } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; // ax is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().aV().d(Registries.az); - - Structure structureFeature = featureRegistry.a(structureKey); - - StructurePiece customBoundPiece = new OceanMonumentPieces - .h(RandomSource.a(), x0, z0, - EnumDirection.a); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + IRegistry featureRegistry = MinecraftServer.getServer().aV().d(Registries.az); + + Structure structureFeature = featureRegistry.a(structureKey); + + StructurePiece customBoundPiece = new OceanMonumentPieces.h(RandomSource.a(), x0, z0, EnumDirection.a); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ add(customBoundPiece); }}); - StructureStart start = new StructureStart( - structureFeature, - new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); + StructureStart start = new StructureStart(structureFeature, + new ChunkCoordIntPair(chunkX, chunkZ), + 0, + container + ); - try { - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + try { + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + } + catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - ica.a(structureFeature, start); - ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong + ica.a(structureFeature, start); + ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(LootTableTranslator.translationMap.get(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/TerraformWorldProviderBiome.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/TerraformWorldProviderBiome.java index f14f9022..59e44eac 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/TerraformWorldProviderBiome.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/TerraformWorldProviderBiome.java @@ -19,11 +19,12 @@ import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; - - private final Set> biomeList; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -38,37 +39,41 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); + } + + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // Used for biome generation in NMSChunkGenerator. // Left shift x and z BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); Optional> holder = registry.b(rkey); // g is getHolderOrThrow - if(holder.isEmpty()) + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + } - if(holder.isPresent()) { + if (holder.isPresent()) { return holder.get(); - } else + } + else { return CraftBlock.biomeToBiomeBase(registry, bank.getHandler().getBiome()); + } } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/BlockDataFixer.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/BlockDataFixer.java index 529e0022..5842351f 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/BlockDataFixer.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/BlockDataFixer.java @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/CustomBiomeHandler.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/CustomBiomeHandler.java index 6ff7fa6d..d55e4a8c 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/CustomBiomeHandler.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/CustomBiomeHandler.java @@ -10,12 +10,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_20_R2.CraftServer; @@ -27,16 +23,11 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; +import java.util.*; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { @@ -46,133 +37,159 @@ public static IRegistry getBiomeRegistry() return MinecraftServer.getServer().aU().d(Registries.ap); } - @SuppressWarnings("deprecation") - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - MinecraftServer minecraftServer = MinecraftServer.getServer(); - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + @SuppressWarnings("deprecation") + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + MinecraftServer minecraftServer = MinecraftServer.getServer(); + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | + SecurityException | + IllegalArgumentException | + IllegalAccessException | + NoSuchMethodException | + InvocationTargetException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) throws + NoSuchFieldException, + SecurityException, + IllegalArgumentException, + IllegalAccessException, + NoSuchMethodException, + InvocationTargetException + { - ResourceKey newKey = ResourceKey.a(Registries.ap, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); + ResourceKey newKey = ResourceKey.a( + Registries.ap, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - // i is climateSettings + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); + + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // c is containsKey - if(registrywritable.c(newKey)) - { + if (registrywritable.c(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -192,9 +209,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder // registrywritable.f(biome); - // a is RegistryMaterials.register + // a is RegistryMaterials.register // Holder.c is Holder.Reference - Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); + Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); // Holder.Reference.bindValue Method bindValue = Holder.c.class.getDeclaredMethod("b", Object.class); @@ -208,9 +225,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { @@ -218,17 +235,22 @@ public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry< List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/LootTableTranslator.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/LootTableTranslator.java index d8d109a4..c3f201cb 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/LootTableTranslator.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/LootTableTranslator.java @@ -10,7 +10,7 @@ public class LootTableTranslator { // I am indeed formally trained to properly structure my code // I have however elected to completely ignore said training here - public static final HashMap translationMap = new HashMap<>(){{ + public static final HashMap translationMap = new HashMap<>() {{ put(TerraLootTable.EMPTY, LootTables.a); put(TerraLootTable.SPAWN_BONUS_CHEST, LootTables.b); put(TerraLootTable.END_CITY_TREASURE, LootTables.c); diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java index 18a40f7d..b7b5b69c 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java @@ -16,9 +16,13 @@ import java.util.stream.Stream; public class MapRenderWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; - private final Set> biomeList; + private final Holder river; + private final Holder plains; + public MapRenderWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -35,29 +39,24 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); - } + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); + } - private final Holder river; - private final Holder plains; - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // Used to be attempted for cave gen. That didn't work, so now, this is + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // Used to be attempted for cave gen. That didn't work, so now, this is // for optimising cartographers and buried treasure. // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x,z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? - river : plains; - } + return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java index 9d5dcd97..4243ec4d 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java @@ -44,16 +44,16 @@ import java.util.concurrent.Executor; public class NMSChunkGenerator extends ChunkGenerator { - private final @NotNull ChunkGenerator delegate; + private final @NotNull ChunkGenerator delegate; private final @NotNull TerraformWorld tw; private final @NotNull MapRenderWorldProviderBiome mapRendererBS; private final @NotNull TerraformWorldProviderBiome twBS; - - public NMSChunkGenerator(String worldName, long seed, - @NotNull ChunkGenerator delegate) { - super( + + public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) { + super( delegate.c(), // WorldChunkManager c() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldName, seed); this.delegate = delegate; @@ -62,61 +62,86 @@ public NMSChunkGenerator(String worldName, long seed, mapRendererBS = new MapRenderWorldProviderBiome(tw, delegate.c()); twBS = new TerraformWorldProviderBiome(tw, delegate.c()); } - + @Override // getBiomeSource public @NotNull WorldChunkManager c() { - return mapRendererBS; + return mapRendererBS; } - + public @NotNull TerraformWorld getTerraformWorld() { return tw; } @Override // createBiomes - public @NotNull CompletableFuture a(Executor executor, RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(Executor executor, + RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) + { + return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { + return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers + }), SystemUtils.f()); + } + + @Override // findNearestMapFeature + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) { - return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { - return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers - }), SystemUtils.f()); - } - - @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { - - int pX = blockposition.u(); // getX + + int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - - for(Holder holder:holderset) { - Structure feature = holder.a(); - // StructureGenerator structuregenerator = feature.; - TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); + + for (Holder holder : holderset) { + Structure feature = holder.a(); + // StructureGenerator structuregenerator = feature.; + TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); if (holder.a().getClass() == StrongholdStructure.class) { // stronghold int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); - } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { - if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { - // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { + // Buried Treasure + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -124,24 +149,38 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { - // POPULATES BIOMES. IMPORTANT - // (net.minecraft.world.level.biome.BiomeResolver,net.minecraft.world.level.biome.Climate$Sampler) + // POPULATES BIOMES. IMPORTANT + // (net.minecraft.world.level.biome.BiomeResolver,net.minecraft.world.level.biome.Climate$Sampler) // Use twBS as it is the biome provider that actually calculates biomes. // The other one only returns river/plains ichunkaccess.a(this.twBS, null); // This can be null as its passed into twBS // Call delegate applyCarvers to apply spigot ChunkGenerator; - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @Override // getSeaLevel @@ -150,87 +189,110 @@ public int e() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { + public void a(IRegistryCustom iregistrycustom, + ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { } @Override // getSpawnHeight public int a(LevelHeightAccessor levelheightaccessor) { return 64; - } + } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, - randomstate, structuremanager, - ichunkaccess); - } + public CompletableFuture a(Executor executor, + Blender blender, + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, randomstate, structuremanager, ichunkaccess); + } @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } - - @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) - { - delegate.a(gas, manager, ica); - } + + @Override // createReferences. Idk what this is + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) + { + delegate.a(gas, manager, ica); + } @Override protected Codec a() { return Codec.unit(null); } - @Override // getBaseColumn - public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); - } + @Override // getBaseColumn + public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + return this.delegate.a(i, j, levelheightaccessor, randomstate); + } // spawnOriginalMobs - public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { - this.delegate.a(regionlimitedworldaccess); - } - // getGenDepth - public int d() { - return this.delegate.d(); - } - - - // getMinY - @Override - public int f() { - return this.delegate.f(); - } - - @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); - } - - - @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; - } + public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { + this.delegate.a(regionlimitedworldaccess); + } + + // getGenDepth + public int d() { + return this.delegate.d(); + } + + + // getMinY + @Override + public int f() { + return this.delegate.f(); + } + + @Override // getFirstFreeHeight + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { + return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); + } + + + @Override // getFirstOccupiedHeight + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { + return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; + } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); - return 100; - // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); + return 100; + // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); } - + // private static boolean biomeDebug = false; - - @Override // addDebugScreenInfo - public void a(List list, RandomState randomstate, BlockPosition blockposition) { - - } - + + @Override // addDebugScreenInfo + public void a(List list, RandomState randomstate, BlockPosition blockposition) { + + } + } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSInjector.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSInjector.java index fc444006..b08666df 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSInjector.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSInjector.java @@ -30,15 +30,17 @@ import java.lang.reflect.Method; public class NMSInjector extends NMSInjectorAbstract { - - // private boolean heightInjectSuccess = true; - - @Override - public void startupTasks() { + + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; + + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } - + } + @Override public BlockDataFixerAbstract getBlockDataFixer() { return new BlockDataFixer(); @@ -48,7 +50,7 @@ public BlockDataFixerAbstract getBlockDataFixer() { public boolean attemptInject(@NotNull World world) { CraftWorld cw = (CraftWorld) world; WorldServer ws = cw.getHandle(); - + // Force world to correct height TerraformWorld.get(world).minY = -64; TerraformWorld.get(world).maxY = 320; @@ -56,30 +58,28 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkProvider, g is getChunkGenerator() ChunkGenerator delegate = ws.k().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); - + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); + // String worldname, // int seed, // WorldChunkManager worldchunkmanager, // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); - // Inject TerraformGenerator NMS chunk generator + // Inject TerraformGenerator NMS chunk generator PlayerChunkMap pcm = ws.k().a; // getChunkProvider().PlayerChunkMap try { - TerraformGeneratorPlugin.privateFieldHandler.injectField( - pcm, "t", bpg); // chunkGenerator - } catch (Throwable e) { + TerraformGeneratorPlugin.privateFieldHandler.injectField(pcm, "t", bpg); // chunkGenerator + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } - + return true; } @@ -89,7 +89,7 @@ public boolean attemptInject(@NotNull World world) { IChunkAccess ica = ((CraftChunk) chunk).getHandle(ChunkStatus.n); CraftWorld cw = (CraftWorld) chunk.getWorld(); WorldServer ws = cw.getHandle(); - + TerraformWorld tw = TerraformWorld.get(chunk.getWorld()); return new PopulatorDataICA(new PopulatorDataPostGen(chunk), tw, ws, ica, chunk.getX(), chunk.getZ()); } @@ -101,22 +101,28 @@ public boolean attemptInject(@NotNull World world) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.A()); // B is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { - getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); - getTileEntity.setAccessible(true); + if (getTileEntity == null) { + getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); + getTileEntity.setAccessible(true); } TileEntityBeehive teb = (TileEntityBeehive) getTileEntity.invoke(hive); @@ -125,19 +131,20 @@ public void storeBee(Beehive hive) { // TileEntityBeehive.storeBee teb.a(nbttagcompound, 0, false); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - @Override - public int getMinY() { - return -64; - } + @Override + public int getMinY() { + return -64; + } - @Override - public int getMaxY() { - return 320; - } + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/PopulatorDataICA.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/PopulatorDataICA.java index 48e2748f..f1f28fdf 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/PopulatorDataICA.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/PopulatorDataICA.java @@ -1,8 +1,25 @@ package org.terraform.v1_20_R2; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.EnumDirection; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.vehicle.EntityMinecartChest; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.structure.*; +import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; +import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -20,42 +37,26 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.EnumDirection; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; -import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Optional; import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -136,7 +139,7 @@ public int getChunkZ() { @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - parent.addEntity(rawX, rawY, rawZ, type); + parent.addEntity(rawX, rawY, rawZ, type); } @Override @@ -150,70 +153,77 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = ica.c_(pos); - if(te instanceof TileEntityLootable) - TileEntityLootable.a(ica, RandomSource.a(tw.getHashedRand(x, y, z).nextLong()), pos, LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - tw.getHashedRand(x, y, z).nextLong()); + if (te instanceof TileEntityLootable) { + TileEntityLootable.a(ica, + RandomSource.a(tw.getHashedRand(x, y, z).nextLong()), + pos, + LootTableTranslator.translationMap.get(table) + ); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + tw.getHashedRand(x, y, z).nextLong() + ); + } } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; // az is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().aU().d(Registries.az); - - Structure structureFeature = featureRegistry.a(structureKey); - - StructurePiece customBoundPiece = new OceanMonumentPieces - .h(RandomSource.a(), x0, z0, - EnumDirection.a); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{add(customBoundPiece);}}); - - StructureStart start = new StructureStart( - structureFeature, - new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); - - try { - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + IRegistry featureRegistry = MinecraftServer.getServer().aU().d(Registries.az); + + Structure structureFeature = featureRegistry.a(structureKey); + + StructurePiece customBoundPiece = new OceanMonumentPieces.h(RandomSource.a(), x0, z0, EnumDirection.a); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + add(customBoundPiece); + }}); + + StructureStart start = new StructureStart(structureFeature, + new ChunkCoordIntPair(chunkX, chunkZ), + 0, + container + ); + + try { + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + } + catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - ica.a(structureFeature, start); - ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong + ica.a(structureFeature, start); + ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(LootTableTranslator.translationMap.get(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/TerraformWorldProviderBiome.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/TerraformWorldProviderBiome.java index 54e20579..72e77bac 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/TerraformWorldProviderBiome.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/TerraformWorldProviderBiome.java @@ -19,11 +19,12 @@ import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; - - private final Set> biomeList; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -38,36 +39,40 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); + } + + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // Used for biome generation in NMSChunkGenerator. // Left shift x and z BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); Optional> holder = registry.b(rkey); - if(holder.isEmpty()) + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + } - if(holder.isPresent()) { + if (holder.isPresent()) { return holder.get(); - } else + } + else { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); + } } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/BlockDataFixer.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/BlockDataFixer.java index 0a87e0b5..480cf129 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/BlockDataFixer.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/BlockDataFixer.java @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/CustomBiomeHandler.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/CustomBiomeHandler.java index 884626b5..4eb3d1f7 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/CustomBiomeHandler.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/CustomBiomeHandler.java @@ -10,12 +10,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_20_R3.CraftServer; @@ -27,16 +23,11 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; +import java.util.*; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { @@ -46,131 +37,157 @@ public static IRegistry getBiomeRegistry() return MinecraftServer.getServer().aZ().d(Registries.at); } - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | + SecurityException | + IllegalArgumentException | + IllegalAccessException | + NoSuchMethodException | + InvocationTargetException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) throws + NoSuchFieldException, + SecurityException, + IllegalArgumentException, + IllegalAccessException, + NoSuchMethodException, + InvocationTargetException + { - ResourceKey newKey = ResourceKey.a(Registries.at, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); + ResourceKey newKey = ResourceKey.a( + Registries.at, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - // i is climateSettings + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); + + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // c is containsKey - if(registrywritable.c(newKey)) - { + if (registrywritable.c(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -190,9 +207,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder // registrywritable.f(biome); - // a is RegistryMaterials.register + // a is RegistryMaterials.register // Holder.c is Holder.Reference - Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); + Holder.c holder = registrywritable.a(newKey, biome, Lifecycle.stable()); // Holder.Reference.bindValue Method bindValue = Holder.c.class.getDeclaredMethod("b", Object.class); @@ -206,9 +223,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { @@ -216,17 +233,22 @@ public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry< List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/LootTableTranslator.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/LootTableTranslator.java index 5706be81..089986e0 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/LootTableTranslator.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/LootTableTranslator.java @@ -10,7 +10,7 @@ public class LootTableTranslator { // I am indeed formally trained to properly structure my code // I have however elected to completely ignore said training here - public static final HashMap translationMap = new HashMap<>(){{ + public static final HashMap translationMap = new HashMap<>() {{ put(TerraLootTable.EMPTY, LootTables.a); put(TerraLootTable.SPAWN_BONUS_CHEST, LootTables.b); put(TerraLootTable.END_CITY_TREASURE, LootTables.c); diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java index 32dbe549..5e565398 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java @@ -16,9 +16,13 @@ import java.util.stream.Stream; public class MapRenderWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; - private final Set> biomeList; + private final Holder river; + private final Holder plains; + public MapRenderWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -35,29 +39,24 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); - } + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); + } - private final Holder river; - private final Holder plains; - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // Used to be attempted for cave gen. That didn't work, so now, this is + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // Used to be attempted for cave gen. That didn't work, so now, this is // for optimising cartographers and buried treasure. // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x,z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? - river : plains; - } + return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java index 8208c249..50cbaac4 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java @@ -49,11 +49,11 @@ public class NMSChunkGenerator extends ChunkGenerator { private final @NotNull MapRenderWorldProviderBiome mapRendererBS; private final @NotNull TerraformWorldProviderBiome twBS; - public NMSChunkGenerator(String worldName, long seed, - @NotNull ChunkGenerator delegate) { + public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) { super( delegate.c(), // WorldChunkManager c() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldName, seed); this.delegate = delegate; @@ -74,7 +74,11 @@ public NMSChunkGenerator(String worldName, long seed, } @Override // createBiomes - public @NotNull CompletableFuture a(Executor executor, RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(Executor executor, + RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) { return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers @@ -82,13 +86,17 @@ public NMSChunkGenerator(String worldName, long seed, } @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) + { int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - for(Holder holder:holderset) { + for (Holder holder : holderset) { Structure feature = holder.a(); // StructureGenerator structuregenerator = feature.; TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); @@ -97,26 +105,43 @@ public Pair> a(WorldServer worldserver, @NotNul int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -124,14 +149,20 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { // POPULATES BIOMES. IMPORTANT @@ -141,7 +172,15 @@ public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, ichunkaccess.a(this.twBS, null); // This can be null as its passed into twBS // Call delegate applyCarvers to apply spigot ChunkGenerator; - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @Override // getSeaLevel @@ -150,7 +189,12 @@ public int e() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { + public void a(IRegistryCustom iregistrycustom, + ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { } @Override // getSpawnHeight @@ -159,22 +203,26 @@ public int a(LevelHeightAccessor levelheightaccessor) { } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, - randomstate, structuremanager, - ichunkaccess); + public CompletableFuture a(Executor executor, + Blender blender, + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, randomstate, structuremanager, ichunkaccess); } @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) { delegate.a(gas, manager, ica); } @@ -186,13 +234,14 @@ protected Codec a() { @Override // getBaseColumn public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); + return this.delegate.a(i, j, levelheightaccessor, randomstate); } // spawnOriginalMobs public void a(RegionLimitedWorldAccess regionlimitedworldaccess) { this.delegate.a(regionlimitedworldaccess); } + // getGenDepth public int d() { return this.delegate.d(); @@ -206,20 +255,33 @@ public int f() { } @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); } @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); return 100; // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSInjector.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSInjector.java index abfa0c28..a18d281b 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSInjector.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSInjector.java @@ -1,8 +1,13 @@ package org.terraform.v1_20_R3; + import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Beehive; @@ -21,23 +26,20 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class NMSInjector extends NMSInjectorAbstract { - // private boolean heightInjectSuccess = true; + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; - @Override - public void startupTasks() { + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } + } @Override public BlockDataFixerAbstract getBlockDataFixer() { @@ -56,7 +58,8 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkSource, g is getChunkGenerator() ChunkGenerator delegate = ws.l().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); // String worldname, // int seed, @@ -64,18 +67,15 @@ public boolean attemptInject(@NotNull World world) { // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); - // Inject TerraformGenerator NMS chunk generator + // Inject TerraformGenerator NMS chunk generator PlayerChunkMap pcm = ws.l().a; // getChunkProvider().PlayerChunkMap try { - TerraformGeneratorPlugin.privateFieldHandler.injectField( - pcm, "t", bpg); // chunkGenerator - } catch (Throwable e) { + TerraformGeneratorPlugin.privateFieldHandler.injectField(pcm, "t", bpg); // chunkGenerator + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } @@ -102,20 +102,26 @@ public boolean attemptInject(@NotNull World world) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.C()); // C is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } @@ -126,18 +132,20 @@ public void storeBee(Beehive hive) { // TileEntityBeehive.storeBee teb.a(nbttagcompound, 0, false); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java index 7878ef85..bb0b591d 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java @@ -5,11 +5,7 @@ import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.GeneratorAccessSeed; -import net.minecraft.world.level.block.entity.BrushableBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityBeehive; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import net.minecraft.world.level.block.entity.*; import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -36,79 +32,139 @@ import java.util.Optional; import java.util.Random; -public class PopulatorData extends PopulatorDataAbstract implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor { +public class PopulatorData extends PopulatorDataAbstract + implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor +{ + private static final HashMap> entityTypesDict = new HashMap<>(); + final GeneratorAccessSeed rlwa; + final IChunkAccess ica; private final int chunkX; private final int chunkZ; - private int radius = 1; private final NMSChunkGenerator gen; - final GeneratorAccessSeed rlwa; - final IChunkAccess ica; - - private static final HashMap> entityTypesDict = new HashMap<>(); - + private int radius = 1; + public PopulatorData(GeneratorAccessSeed rlwa, IChunkAccess ica, NMSChunkGenerator gen, int chunkX, int chunkZ) { this.rlwa = rlwa; this.chunkX = chunkX; this.chunkZ = chunkZ; this.gen = gen; this.ica = ica; - - if(entityTypesDict.isEmpty()) { - for(EntityType type:EntityType.values()) { - if(type == EntityType.ENDER_SIGNAL) continue; - if(type == EntityType.UNKNOWN) continue; - try { + + if (entityTypesDict.isEmpty()) { + for (EntityType type : EntityType.values()) { + if (type == EntityType.ENDER_SIGNAL) { + continue; + } + if (type == EntityType.UNKNOWN) { + continue; + } + try { // EntityTypes.byString - Optional> et = EntityTypes.a("minecraft:"+type.toString().toLowerCase(Locale.ENGLISH)); + Optional> et = EntityTypes.a("minecraft:" + type.toString() + .toLowerCase(Locale.ENGLISH)); et.ifPresent(entityTypes -> entityTypesDict.put(type, entityTypes)); - } catch (IllegalArgumentException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + } + catch (IllegalArgumentException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } } - + public void setRadius(int radius) { - this.radius = radius; + this.radius = radius; } public Material getType(int x, int y, int z) { - try { - // return rlwa.getType(x, y, z); - return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); - }catch(Exception e) { - Bukkit.getLogger().info("Error chunk: " + chunkX + "," + chunkZ + "--- Block Coords: " + 16*chunkX + "," + 16*chunkZ + " for coords " + x + "," + y + "," + z); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - return null; + try { + // return rlwa.getType(x, y, z); + return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); + } + catch (Exception e) { + Bukkit.getLogger() + .info("Error chunk: " + + chunkX + + "," + + chunkZ + + "--- Block Coords: " + + 16 * chunkX + + "," + + 16 * chunkZ + + " for coords " + + x + + "," + + y + + "," + + z); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + return null; } public BlockData getBlockData(int x, int y, int z) { // return rlwa.getBlockData(x,y,z); - return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); + return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, Bukkit.createBlockData(type)); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + Bukkit.createBlockData(type) + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), 0); - } + } } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, data); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { - rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + data + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { + rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); } } @@ -127,50 +183,67 @@ public int getChunkX() { public int getChunkZ() { return chunkZ; } - + @Override public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { - TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); - return; - } - - // Use this method for thread safety. - CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); - net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(),rawX,rawY,rawZ), - type.getEntityClass(), true); + if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { + TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); + return; + } + + // Use this method for thread safety. + CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); + net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(), + rawX, + rawY, + rawZ), type.getEntityClass(), true); // EntityInsentient.setPersistenceRequired() - if(e instanceof EntityInsentient) ((EntityInsentient) e).fF(); - rlwa.b(e); - // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); + if (e instanceof EntityInsentient) { + ((EntityInsentient) e).fF(); + } + rlwa.b(e); + // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); } @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); - + setType(rawX, rawY, rawZ, Material.SPAWNER); TileEntity tileentity = rlwa.c_(pos); if (tileentity instanceof TileEntityMobSpawner) { try { // Refer to WorldGenDungeons -// TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; -// -// tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); + // TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; + // + // tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); // Fetch from ENTITY_TYPE (Q)'s map - // q is ENTITY_TYPE - EntityTypes nmsEntity = entityTypesDict.get(type); - if(nmsEntity == null) TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + // q is ENTITY_TYPE + EntityTypes nmsEntity = entityTypesDict.get(type); + if (nmsEntity == null) { + TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + } ((TileEntityMobSpawner) tileentity).a(nmsEntity, new RandomSourceWrapper(new Random())); - } catch (IllegalArgumentException | SecurityException e) { + } + catch (IllegalArgumentException | SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - } else { - TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + "," + rawX + "," + rawY + "," + rawZ + ")"); + } + else { + TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + + "," + + rawX + + "," + + rawY + + "," + + rawZ + + ")"); } } @@ -180,42 +253,44 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = rlwa.c_(pos); - if(te instanceof TileEntityLootable) + if (te instanceof TileEntityLootable) { ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + gen.getTerraformWorld().getHashedRand(x, y, z).nextLong() + ); + } // TileEntityLootable.a(rlwa, RandomSource.a(gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()), pos, LootTableTranslator.translationMap.get(table)); } - @Override - public TerraformWorld getTerraformWorld() { - return gen.getTerraformWorld(); - } - - @Override - public int getBaseHeight(int rawX, int rawZ) { - // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) - return 100; - // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); - } - - @Override - public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { - BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); + @Override + public TerraformWorld getTerraformWorld() { + return gen.getTerraformWorld(); + } + + @Override + public int getBaseHeight(int rawX, int rawZ) { + // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) + return 100; + // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); + } + + @Override + public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { + BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); // TerraformGeneratorPlugin.logger.info(IRegistry.X.b(EntityTypes.h).toString()); setType(rawX, rawY, rawZ, Material.BEE_NEST); try { // TerraformGeneratorPlugin.logger.error("Failed to set beehive at (" + rawX + "," + rawY + "," + rawZ + ") " + BuiltInRegistries.h.b(entityTypesDict.get(EntityType.BEE))); TileEntityBeehive tileentity = (TileEntityBeehive) rlwa.c_(pos); - if(tileentity == null) - { // retry? - setType(rawX, rawY, rawZ, Material.BEE_NEST); - tileentity = (TileEntityBeehive) rlwa.c_(pos); + if (tileentity == null) { // retry? + setType(rawX, rawY, rawZ, Material.BEE_NEST); + tileentity = (TileEntityBeehive) rlwa.c_(pos); } NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -224,8 +299,9 @@ public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee tileentity.a(nbttagcompound, 0, false); - } catch (NullPointerException | IllegalArgumentException | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); } - } + catch (NullPointerException | IllegalArgumentException | SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorDataICA.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorDataICA.java index b8137900..93156af7 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorDataICA.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorDataICA.java @@ -1,8 +1,25 @@ package org.terraform.v1_20_R3; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.EnumDirection; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.vehicle.EntityMinecartChest; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.structure.*; +import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; +import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -20,42 +37,26 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.EnumDirection; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructurePiece; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; -import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Optional; import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -136,7 +139,7 @@ public int getChunkZ() { @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - parent.addEntity(rawX, rawY, rawZ, type); + parent.addEntity(rawX, rawY, rawZ, type); } @Override @@ -150,85 +153,88 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = ica.c_(pos); - if(te instanceof TileEntityLootable) - ((TileEntityLootable)te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - tw.getHashedRand(x, y, z).nextLong()); + if (te instanceof TileEntityLootable) { + ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + tw.getHashedRand(x, y, z).nextLong() + ); + } } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; // aD is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().aZ().d(Registries.aD); - - Structure structureFeature = featureRegistry.a(structureKey); - - StructurePiece customBoundPiece = new OceanMonumentPieces - .h(RandomSource.a(), x0, z0, - EnumDirection.a); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{add(customBoundPiece);}}); - - StructureStart start = new StructureStart( - structureFeature, - new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); - - try { - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + IRegistry featureRegistry = MinecraftServer.getServer().aZ().d(Registries.aD); + + Structure structureFeature = featureRegistry.a(structureKey); + + StructurePiece customBoundPiece = new OceanMonumentPieces.h(RandomSource.a(), x0, z0, EnumDirection.a); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + add(customBoundPiece); + }}); + + StructureStart start = new StructureStart(structureFeature, + new ChunkCoordIntPair(chunkX, chunkZ), + 0, + container + ); + + try { + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + } + catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); } - catch(NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - - - // ws.a() is getStructureManager - // a is setStartForStructure - /*setStartForStructure( - * SectionPosition sectionposition, - * Structure structure, - * StructureStart structurestart, - * StructureAccess structureaccess)**/ - // ws.a().a(SectionPosition.a(x0,y0,z0), structureFeature, start, ica); - - ica.a(structureFeature, start); -// ws.a().a( // setStartForFeature -// structureFeature, -// start); - + + + // ws.a() is getStructureManager + // a is setStartForStructure + /*setStartForStructure( + * SectionPosition sectionposition, + * Structure structure, + * StructureStart structurestart, + * StructureAccess structureaccess)**/ + // ws.a().a(SectionPosition.a(x0,y0,z0), structureFeature, start, ica); + + ica.a(structureFeature, start); + // ws.a().a( // setStartForFeature + // structureFeature, + // start); + // addReferenceForFeature - ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong + ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(LootTableTranslator.translationMap.get(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/TerraformWorldProviderBiome.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/TerraformWorldProviderBiome.java index 027ca601..e11aa4a8 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/TerraformWorldProviderBiome.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/TerraformWorldProviderBiome.java @@ -19,11 +19,12 @@ import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; - - private final Set> biomeList; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -38,36 +39,40 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } - @Override - protected Codec a() { - throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); - } - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + @Override + protected Codec a() { + throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); + } + + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // Used for biome generation in NMSChunkGenerator. // Left shift x and z BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); Optional> holder = registry.b(rkey); - if(holder.isEmpty()) + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + } - if(holder.isPresent()) { + if (holder.isPresent()) { return holder.get(); - } else + } + else { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); + } } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/BlockDataFixer.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/BlockDataFixer.java index a4bfb2b8..bac611d8 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/BlockDataFixer.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/BlockDataFixer.java @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/CustomBiomeHandler.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/CustomBiomeHandler.java index 32455768..fa638aef 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/CustomBiomeHandler.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/CustomBiomeHandler.java @@ -1,22 +1,14 @@ package org.terraform.v1_20_R4; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.core.IRegistryWritable; -import net.minecraft.core.RegistrationInfo; -import net.minecraft.core.RegistryMaterials; +import net.minecraft.core.*; import net.minecraft.core.registries.Registries; import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.ReloadableServerRegistries; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_20_R4.CraftServer; @@ -28,16 +20,11 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; +import java.util.*; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { @@ -47,56 +34,70 @@ public static IRegistry getBiomeRegistry() return MinecraftServer.getServer().bc().d(Registries.az); } - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | - NoSuchMethodException | InvocationTargetException e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (NoSuchFieldException | + SecurityException | + IllegalArgumentException | + IllegalAccessException | + NoSuchMethodException | + InvocationTargetException e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) throws + NoSuchFieldException, + SecurityException, + IllegalArgumentException, + IllegalAccessException, + NoSuchMethodException, + InvocationTargetException + { // be is reloadableRegistries() // a is get() @@ -106,80 +107,92 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, RegistrationInfo regInfo = (RegistrationInfo) defaultRegInfoField.get(null); // az is BIOME - ResourceKey newKey = ResourceKey.a(Registries.az, new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); - - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); - - // i is climateSettings + ResourceKey newKey = ResourceKey.a( + Registries.az, + new MinecraftKey("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); + + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); + + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); + + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // d is containsKey - if(registrywritable.d(newKey)) - { + if (registrywritable.d(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -199,9 +212,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder // registrywritable.f(biome); - // a is RegistryMaterials.register + // a is RegistryMaterials.register // Holder.c is Holder.Reference - Holder.c holder = registrywritable.a(newKey, biome, regInfo); + Holder.c holder = registrywritable.a(newKey, biome, regInfo); // Holder.Reference.bindValue Method bindValue = Holder.c.class.getDeclaredMethod("b", Object.class); @@ -217,9 +230,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { @@ -227,17 +240,22 @@ public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry< List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/LootTableTranslator.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/LootTableTranslator.java index a58066ee..6fe7fa42 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/LootTableTranslator.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/LootTableTranslator.java @@ -11,7 +11,7 @@ public class LootTableTranslator { // I am indeed formally trained to properly structure my code // I have however elected to completely ignore said training here - public static final HashMap> translationMap = new HashMap<>(){{ + public static final HashMap> translationMap = new HashMap<>() {{ put(TerraLootTable.EMPTY, LootTables.a); put(TerraLootTable.SPAWN_BONUS_CHEST, LootTables.b); put(TerraLootTable.END_CITY_TREASURE, LootTables.c); diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java index 9bb9e960..61de4a75 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java @@ -16,9 +16,13 @@ import java.util.stream.Stream; public class MapRenderWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; - private final Set> biomeList; + private final Holder river; + private final Holder plains; + public MapRenderWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -35,29 +39,24 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } @Override protected MapCodec a() { - throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); - } + throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); + } - private final Holder river; - private final Holder plains; - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // Used to be attempted for cave gen. That didn't work, so now, this is + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // Used to be attempted for cave gen. That didn't work, so now, this is // for optimising cartographers and buried treasure. // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x,z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? - river : plains; - } + return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java index 392dd1fd..f2ac3cf2 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java @@ -53,7 +53,8 @@ public class NMSChunkGenerator extends ChunkGenerator { public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) { super( delegate.d(), // WorldChunkManager d() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldName, seed); this.delegate = delegate; @@ -79,7 +80,11 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de } @Override // createBiomes - public @NotNull CompletableFuture a(Executor executor, RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(Executor executor, + RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) { return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers @@ -87,13 +92,17 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de } @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) + { int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - for(Holder holder:holderset) { + for (Holder holder : holderset) { Structure feature = holder.a(); // StructureGenerator structuregenerator = feature.; TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); @@ -102,26 +111,43 @@ public Pair> a(WorldServer worldserver, @NotNul int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -129,14 +155,20 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { delegate.a(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { // POPULATES BIOMES. IMPORTANT @@ -146,7 +178,15 @@ public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, ichunkaccess.a(this.twBS, null); // This can be null as its passed into twBS // Call delegate applyCarvers to apply spigot ChunkGenerator; - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @Override // getSeaLevel @@ -155,7 +195,12 @@ public int e() { } @Override // createStructures should be empty - public void a(IRegistryCustom iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { + public void a(IRegistryCustom iregistrycustom, + ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { } @Override // getSpawnHeight @@ -164,29 +209,33 @@ public int a(LevelHeightAccessor levelheightaccessor) { } @Override // fillFromNoise - public CompletableFuture a(Executor executor, Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(executor, blender, - randomstate, structuremanager, - ichunkaccess); + public CompletableFuture a(Executor executor, + Blender blender, + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(executor, blender, randomstate, structuremanager, ichunkaccess); } @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } @Override // createReferences. Idk what this is - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) { delegate.a(gas, manager, ica); } @Override // getBaseColumn public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); + return this.delegate.a(i, j, levelheightaccessor, randomstate); } // spawnOriginalMobs @@ -208,20 +257,33 @@ public int g() { } @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); } @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); return 100; // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSInjector.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSInjector.java index 560cb0b2..3738fe50 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSInjector.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSInjector.java @@ -1,6 +1,11 @@ package org.terraform.v1_20_R4; + +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.status.WorldGenContext; import org.bukkit.Chunk; @@ -20,11 +25,6 @@ import org.terraform.coregen.populatordata.PopulatorDataSpigotAPI; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; - -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; import org.terraform.utils.GenUtils; import java.lang.reflect.Field; @@ -33,13 +33,15 @@ public class NMSInjector extends NMSInjectorAbstract { - // private boolean heightInjectSuccess = true; + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; - @Override - public void startupTasks() { + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } + } @Override public @NotNull BlockDataFixerAbstract getBlockDataFixer() { @@ -58,7 +60,8 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkSource, g is getChunkGenerator() ChunkGenerator delegate = ws.l().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); // String worldname, // int seed, @@ -66,12 +69,9 @@ public boolean attemptInject(@NotNull World world) { // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); - // Inject TerraformGenerator NMS chunk generator into playerchunkmap AND worldgencontext + // Inject TerraformGenerator NMS chunk generator into playerchunkmap AND worldgencontext PlayerChunkMap pcm = ws.l().a; // getChunkProvider().PlayerChunkMap pcm.t = bpg; try { @@ -80,17 +80,16 @@ public boolean attemptInject(@NotNull World world) { wgc.setAccessible(true); WorldGenContext worldGenContext = (WorldGenContext) wgc.get(pcm); // b is chunkGenerator - wgc.set(pcm, new WorldGenContext( - worldGenContext.a(), - bpg, - worldGenContext.c(), - worldGenContext.d() - )); - } catch (Throwable e) { + wgc.set(pcm, new WorldGenContext(worldGenContext.a(), bpg, worldGenContext.c(), worldGenContext.d())); + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } - TerraformGeneratorPlugin.logger.info("Post injection: getChunkSource().getChunkGenerator() is of type " + ws.l().g().getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("Post injection: getChunkSource().getChunkGenerator() is of type " + ws.l() + .g() + .getClass() + .getSimpleName()); return true; } @@ -114,44 +113,52 @@ public boolean attemptInject(@NotNull World world) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.C()); // C is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } TileEntityBeehive teb = (TileEntityBeehive) getTileEntity.invoke(hive); -// -// NBTTagCompound nbttagcompound = new NBTTagCompound(); -// nbttagcompound.a("id", "minecraft:bee"); + // + // NBTTagCompound nbttagcompound = new NBTTagCompound(); + // nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee // TileEntityBeehive.Occupant.create(1) // Copied from world\level\levelgen\feature\treedecorators\WorldGenFeatureTreeBeehive.java teb.a(TileEntityBeehive.c.a(GenUtils.RANDOMIZER.nextInt(599))); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java index 64dcc649..81468c0e 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java @@ -4,11 +4,7 @@ import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.GeneratorAccessSeed; -import net.minecraft.world.level.block.entity.BrushableBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityBeehive; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import net.minecraft.world.level.block.entity.*; import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -36,78 +32,136 @@ import java.util.Optional; import java.util.Random; -public class PopulatorData extends PopulatorDataAbstract implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor { +public class PopulatorData extends PopulatorDataAbstract + implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor +{ + private static final HashMap> entityTypesDict = new HashMap<>(); + final GeneratorAccessSeed rlwa; + final IChunkAccess ica; private final int chunkX; private final int chunkZ; - private int radius = 1; private final NMSChunkGenerator gen; - final GeneratorAccessSeed rlwa; - final IChunkAccess ica; - - private static final HashMap> entityTypesDict = new HashMap<>(); - + private int radius = 1; + public PopulatorData(GeneratorAccessSeed rlwa, IChunkAccess ica, NMSChunkGenerator gen, int chunkX, int chunkZ) { this.rlwa = rlwa; this.chunkX = chunkX; this.chunkZ = chunkZ; this.gen = gen; this.ica = ica; - - if(entityTypesDict.isEmpty()) { - for(EntityType type:EntityType.values()) { - if(type == EntityType.UNKNOWN) continue; - try { + + if (entityTypesDict.isEmpty()) { + for (EntityType type : EntityType.values()) { + if (type == EntityType.UNKNOWN) { + continue; + } + try { // EntityTypes.byString - Optional> et = EntityTypes.a("minecraft:"+type.toString().toLowerCase(Locale.ENGLISH)); + Optional> et = EntityTypes.a("minecraft:" + type.toString() + .toLowerCase(Locale.ENGLISH)); et.ifPresent(entityTypes -> entityTypesDict.put(type, entityTypes)); - } catch (IllegalArgumentException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + } + catch (IllegalArgumentException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } } - + public void setRadius(int radius) { - this.radius = radius; + this.radius = radius; } public Material getType(int x, int y, int z) { - try { - // return rlwa.getType(x, y, z); - return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); - }catch(Exception e) { - Bukkit.getLogger().info("Error chunk: " + chunkX + "," + chunkZ + "--- Block Coords: " + 16*chunkX + "," + 16*chunkZ + " for coords " + x + "," + y + "," + z); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - return null; + try { + // return rlwa.getType(x, y, z); + return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); + } + catch (Exception e) { + Bukkit.getLogger() + .info("Error chunk: " + + chunkX + + "," + + chunkZ + + "--- Block Coords: " + + 16 * chunkX + + "," + + 16 * chunkZ + + " for coords " + + x + + "," + + y + + "," + + z); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + return null; } public BlockData getBlockData(int x, int y, int z) { // return rlwa.getBlockData(x,y,z); - return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); + return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, Bukkit.createBlockData(type)); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + Bukkit.createBlockData(type) + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), 0); - } + } } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, data); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { - rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + data + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { + rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); } } @@ -126,50 +180,67 @@ public int getChunkX() { public int getChunkZ() { return chunkZ; } - + @Override public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { - TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); - return; - } - - // Use this method for thread safety. - CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); - net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(),rawX,rawY,rawZ), - type.getEntityClass(), true); + if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { + TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); + return; + } + + // Use this method for thread safety. + CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); + net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(), + rawX, + rawY, + rawZ), type.getEntityClass(), true); // EntityInsentient.setPersistenceRequired() - if(e instanceof EntityInsentient) ((EntityInsentient) e).fF(); - rlwa.b(e); - // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); + if (e instanceof EntityInsentient) { + ((EntityInsentient) e).fF(); + } + rlwa.b(e); + // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); } @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); - + setType(rawX, rawY, rawZ, Material.SPAWNER); TileEntity tileentity = rlwa.c_(pos); if (tileentity instanceof TileEntityMobSpawner) { try { // Refer to WorldGenDungeons -// TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; -// -// tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); + // TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; + // + // tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); // Fetch from ENTITY_TYPE (Q)'s map - // q is ENTITY_TYPE - EntityTypes nmsEntity = entityTypesDict.get(type); - if(nmsEntity == null) TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + // q is ENTITY_TYPE + EntityTypes nmsEntity = entityTypesDict.get(type); + if (nmsEntity == null) { + TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + } ((TileEntityMobSpawner) tileentity).a(nmsEntity, new RandomSourceWrapper(new Random())); - } catch (IllegalArgumentException | SecurityException e) { + } + catch (IllegalArgumentException | SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - } else { - TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + "," + rawX + "," + rawY + "," + rawZ + ")"); + } + else { + TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + + "," + + rawX + + "," + + rawY + + "," + + rawZ + + ")"); } } @@ -179,51 +250,54 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = rlwa.c_(pos); - if(te instanceof TileEntityLootable) + if (te instanceof TileEntityLootable) { ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + gen.getTerraformWorld().getHashedRand(x, y, z).nextLong() + ); + } // TileEntityLootable.a(rlwa, RandomSource.a(gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()), pos, LootTableTranslator.translationMap.get(table)); } - @Override - public TerraformWorld getTerraformWorld() { - return gen.getTerraformWorld(); - } - - @Override - public int getBaseHeight(int rawX, int rawZ) { - // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) - return 100; - // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); - } - - @Override - public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { - BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); + @Override + public TerraformWorld getTerraformWorld() { + return gen.getTerraformWorld(); + } + + @Override + public int getBaseHeight(int rawX, int rawZ) { + // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) + return 100; + // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); + } + + @Override + public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { + BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); // TerraformGeneratorPlugin.logger.info(IRegistry.X.b(EntityTypes.h).toString()); setType(rawX, rawY, rawZ, Material.BEE_NEST); try { // TerraformGeneratorPlugin.logger.error("Failed to set beehive at (" + rawX + "," + rawY + "," + rawZ + ") " + BuiltInRegistries.h.b(entityTypesDict.get(EntityType.BEE))); TileEntityBeehive tileentity = (TileEntityBeehive) rlwa.c_(pos); - if(tileentity == null) - { // retry? - setType(rawX, rawY, rawZ, Material.BEE_NEST); - tileentity = (TileEntityBeehive) rlwa.c_(pos); + if (tileentity == null) { // retry? + setType(rawX, rawY, rawZ, Material.BEE_NEST); + tileentity = (TileEntityBeehive) rlwa.c_(pos); } -// -// NBTTagCompound nbttagcompound = new NBTTagCompound(); -// nbttagcompound.a("id", "minecraft:bee"); + // + // NBTTagCompound nbttagcompound = new NBTTagCompound(); + // nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee // TileEntityBeehive.Occupant.create(1) tileentity.a(TileEntityBeehive.c.a(GenUtils.RANDOMIZER.nextInt(599))); - } catch (NullPointerException | IllegalArgumentException | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); } - } + catch (NullPointerException | IllegalArgumentException | SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorDataICA.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorDataICA.java index da7e52eb..e5b1dbf0 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorDataICA.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorDataICA.java @@ -1,9 +1,23 @@ package org.terraform.v1_20_R4; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.vehicle.EntityMinecartChest; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.levelgen.structure.StructurePiece; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.structure.*; +import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -22,25 +36,6 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -48,14 +43,20 @@ import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public @NotNull Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -136,7 +139,7 @@ public int getChunkZ() { @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - parent.addEntity(rawX, rawY, rawZ, type); + parent.addEntity(rawX, rawY, rawZ, type); } @Override @@ -150,19 +153,22 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = ica.c_(pos); - if(te instanceof TileEntityLootable) - ((TileEntityLootable)te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - tw.getHashedRand(x, y, z).nextLong()); + if (te instanceof TileEntityLootable) { + ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + tw.getHashedRand(x, y, z).nextLong() + ); + } } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; @@ -170,9 +176,9 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 // bc is registryAccess // d is getOrThrow // aJ is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().bc().d(Registries.aJ); - - Structure structureFeature = featureRegistry.a(structureKey); + IRegistry featureRegistry = MinecraftServer.getServer().bc().d(Registries.aJ); + + Structure structureFeature = featureRegistry.a(structureKey); try { // Something's broken about EnumDirection's import. Might be a temporary thing. @@ -180,22 +186,26 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 Field enumDirectionA = enumDirectionClass.getField("a"); enumDirectionA.setAccessible(true); Class oceanMonumentPiecesHClass = OceanMonumentPieces.h.class; - StructurePiece customBoundPiece = (StructurePiece) oceanMonumentPiecesHClass - .getConstructor(RandomSource.class, int.class, int.class, enumDirectionClass) - .newInstance( - RandomSource.a(), x0, z0, enumDirectionA.get(null) - ); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{add(customBoundPiece);}}); - - StructureStart start = new StructureStart( - structureFeature, + StructurePiece customBoundPiece = (StructurePiece) oceanMonumentPiecesHClass.getConstructor( + RandomSource.class, + int.class, + int.class, + enumDirectionClass + ).newInstance(RandomSource.a(), x0, z0, enumDirectionA.get(null)); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + add(customBoundPiece); + }}); + + StructureStart start = new StructureStart(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); + 0, + container + ); - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); // ws.a() is getStructureManager // a is setStartForStructure @@ -207,35 +217,41 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 // ws.a().a(SectionPosition.a(x0,y0,z0), structureFeature, start, ica); ica.a(structureFeature, start); - // ws.a().a( // setStartForFeature - // structureFeature, - // start); + // ws.a().a( // setStartForFeature + // structureFeature, + // start); // addReferenceForFeature ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } - catch(NoSuchMethodException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + catch (NoSuchMethodException | + InstantiationException | + InvocationTargetException | + ClassNotFoundException | + NoSuchFieldException | + IllegalArgumentException | + IllegalAccessException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(LootTableTranslator.translationMap.get(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/TerraformWorldProviderBiome.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/TerraformWorldProviderBiome.java index b6a6c8af..c4e37e82 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/TerraformWorldProviderBiome.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/TerraformWorldProviderBiome.java @@ -19,11 +19,12 @@ import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; - - private final Set> biomeList; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -38,7 +39,7 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } @@ -48,26 +49,29 @@ protected MapCodec a() { throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); } - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // Used for biome generation in NMSChunkGenerator. // Left shift x and z BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); Optional> holder = registry.b(rkey); - if(holder.isEmpty()) + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + } - if(holder.isPresent()) { + if (holder.isPresent()) { return holder.get(); - } else + } + else { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); + } } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/BlockDataFixer.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/BlockDataFixer.java index a0455c56..188b1301 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/BlockDataFixer.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/BlockDataFixer.java @@ -1,8 +1,8 @@ package org.terraform.v1_21_R1; import org.bukkit.Tag; -import org.bukkit.block.data.BlockData; import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Wall; import org.bukkit.block.data.type.Wall.Height; import org.bukkit.util.Vector; @@ -14,49 +14,62 @@ public class BlockDataFixer extends BlockDataFixerAbstract { - @Override - public String updateSchematic(double schematicVersion, String schematic) { - return schematic; - } - - @Override - public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { - if (data == null && b != null) data = b.getBlockData(); - - if (!hasFlushed && data instanceof Wall) { - this.pushChanges(v); - return; - } - - if (data instanceof Wall && b != null) { - // 1.16 stuff. - correctSurroundingWallData(b); - } - } - // --------[1.16 stuff] public static void correctWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall data)) return; + if (!(target.getBlockData() instanceof Wall data)) { + return; + } for (BlockFace face : BlockUtils.directBlockFaces) { - if (target.getRelative(face).isSolid() && - !target.getRelative(face).getType().toString().contains("PRESSURE_PLATE")) { + if (target.getRelative(face).isSolid() && !target.getRelative(face) + .getType() + .toString() + .contains("PRESSURE_PLATE")) + { data.setHeight(face, Height.LOW); if (target.getRelative(BlockFace.UP).isSolid()) { data.setHeight(face, Height.TALL); } - } else data.setHeight(face, Height.NONE); + } + else { + data.setHeight(face, Height.NONE); + } } -// target.setBlockData(data); + // target.setBlockData(data); } public static void correctSurroundingWallData(@NotNull SimpleBlock target) { - if (!(target.getBlockData() instanceof Wall)) return; + if (!(target.getBlockData() instanceof Wall)) { + return; + } correctWallData(target); for (BlockFace face : BlockUtils.directBlockFaces) { - if (Tag.WALLS.isTagged(target.getRelative(face).getType())) + if (Tag.WALLS.isTagged(target.getRelative(face).getType())) { correctWallData(target.getRelative(face)); + } + } + } + + @Override + public String updateSchematic(double schematicVersion, String schematic) { + return schematic; + } + + @Override + public void correctFacing(Vector v, @Nullable SimpleBlock b, @Nullable BlockData data, BlockFace face) { + if (data == null && b != null) { + data = b.getBlockData(); + } + + if (!hasFlushed && data instanceof Wall) { + this.pushChanges(v); + return; + } + + if (data instanceof Wall && b != null) { + // 1.16 stuff. + correctSurroundingWallData(b); } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/CustomBiomeHandler.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/CustomBiomeHandler.java index 8ee4f2e9..bc1081e2 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/CustomBiomeHandler.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/CustomBiomeHandler.java @@ -10,12 +10,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.ReloadableServerRegistries; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.biome.BiomeFog; +import net.minecraft.world.level.biome.*; import net.minecraft.world.level.biome.BiomeFog.GrassColor; -import net.minecraft.world.level.biome.BiomeSettingsGeneration; -import net.minecraft.world.level.biome.BiomeSettingsMobs; -import net.minecraft.world.level.biome.Biomes; import org.bukkit.Bukkit; import org.bukkit.block.Biome; import org.bukkit.craftbukkit.v1_21_R1.CraftServer; @@ -26,16 +22,11 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.Set; +import java.util.*; public class CustomBiomeHandler { - - public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); + + public static final HashMap> terraformGenBiomeRegistry = new HashMap<>(); public static IRegistry getBiomeRegistry() { @@ -45,55 +36,59 @@ public static IRegistry getBiomeRegistry() return MinecraftServer.getServer().bc().d(Registries.aF); } - public static void init() { - CraftServer craftserver = (CraftServer)Bukkit.getServer(); - DedicatedServer dedicatedserver = craftserver.getServer(); - IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); - - // This thing isn't actually writable, so we have to forcefully UNFREEZE IT - // l is frozen - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, false); - TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } - - BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest - - for(CustomBiomeType type:CustomBiomeType.values()) { - if(type == CustomBiomeType.NONE) - continue; - - try { + public static void init() { + CraftServer craftserver = (CraftServer) Bukkit.getServer(); + DedicatedServer dedicatedserver = craftserver.getServer(); + IRegistryWritable registrywritable = (IRegistryWritable) getBiomeRegistry(); + + // This thing isn't actually writable, so we have to forcefully UNFREEZE IT + // l is frozen + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, false); + TerraformGeneratorPlugin.logger.info("Unfreezing biome registry..."); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } + + BiomeBase forestbiome = registrywritable.a(Biomes.i); // forest + + for (CustomBiomeType type : CustomBiomeType.values()) { + if (type == CustomBiomeType.NONE) { + continue; + } + + try { assert forestbiome != null; - registerCustomBiomeBase( - type, - dedicatedserver, - registrywritable, - forestbiome - ); - TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString().toLowerCase(Locale.ENGLISH)); - } catch (Throwable e) { - TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } - - try { - Field frozen = RegistryMaterials.class.getDeclaredField("l"); - frozen.setAccessible(true); - frozen.set(registrywritable, true); - TerraformGeneratorPlugin.logger.info("Freezing biome registry"); - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { - TerraformGeneratorPlugin.logger.stackTrace(e1); - } + registerCustomBiomeBase(type, dedicatedserver, registrywritable, forestbiome); + TerraformGeneratorPlugin.logger.info("Registered custom biome: " + type.toString() + .toLowerCase(Locale.ENGLISH)); + } + catch (Throwable e) { + TerraformGeneratorPlugin.logger.error("Failed to register custom biome: " + type.getKey()); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } + + try { + Field frozen = RegistryMaterials.class.getDeclaredField("l"); + frozen.setAccessible(true); + frozen.set(registrywritable, true); + TerraformGeneratorPlugin.logger.info("Freezing biome registry"); + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e1) { + TerraformGeneratorPlugin.logger.stackTrace(e1); + } } - private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, DedicatedServer dedicatedserver, @NotNull IRegistryWritable registrywritable, @NotNull BiomeBase forestbiome) throws Throwable { + private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, + DedicatedServer dedicatedserver, + @NotNull IRegistryWritable registrywritable, + @NotNull BiomeBase forestbiome) throws Throwable + { // be is reloadableRegistries() // a is get() @@ -103,80 +98,92 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, Object regInfo = defaultRegInfoField.get(null); // az is BIOME - ResourceKey newKey = ResourceKey.a(Registries.aF, MinecraftKey.a("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH))); - - // BiomeBase.a is BiomeBuilder - BiomeBase.a newBiomeBuilder = new BiomeBase.a(); - - // BiomeBase.b is ClimateSettings - // d is temperatureModifier - // This temperature modifier stuff is more cleanly handled below. -// Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); -// Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); -// temperatureModififierField.setAccessible(true); - - // i is climateSettings + ResourceKey newKey = ResourceKey.a( + Registries.aF, + MinecraftKey.a("terraformgenerator", biomeType.toString().toLowerCase(Locale.ENGLISH)) + ); + + // BiomeBase.a is BiomeBuilder + BiomeBase.a newBiomeBuilder = new BiomeBase.a(); + + // BiomeBase.b is ClimateSettings + // d is temperatureModifier + // This temperature modifier stuff is more cleanly handled below. + // Class climateSettingsClass = Class.forName("net.minecraft.world.level.biome.BiomeBase.b"); + // Field temperatureModififierField = climateSettingsClass.getDeclaredField("d"); + // temperatureModififierField.setAccessible(true); + + // i is climateSettings newBiomeBuilder.a(forestbiome.c()); // c is getPrecipitation - // k is mobSettings - Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); - biomeSettingMobsField.setAccessible(true); - BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); - newBiomeBuilder.a(biomeSettingMobs); + // k is mobSettings + Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); + biomeSettingMobsField.setAccessible(true); + BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(forestbiome); + newBiomeBuilder.a(biomeSettingMobs); - // j is generationSettings - Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); - biomeSettingGenField.setAccessible(true); - BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); - newBiomeBuilder.a(biomeSettingGen); + // j is generationSettings + Field biomeSettingGenField = BiomeBase.class.getDeclaredField("j"); + biomeSettingGenField.setAccessible(true); + BiomeSettingsGeneration biomeSettingGen = (BiomeSettingsGeneration) biomeSettingGenField.get(forestbiome); + newBiomeBuilder.a(biomeSettingGen); newBiomeBuilder.a(0.7F); // Temperature of biome - newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome - - // BiomeBase.TemperatureModifier.a will make your biome normal - // BiomeBase.TemperatureModifier.b will make your biome frozen - if(biomeType.isCold()) - newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); - else - newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); - - BiomeFog.a newFog = new BiomeFog.a(); - newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors - - // Set biome colours. If field is empty, default to forest color - - // fogcolor - newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e():Integer.parseInt(biomeType.getFogColor(),16)); - - // water color i is getWaterColor - newFog.b(biomeType.getWaterColor().isEmpty() ? forestbiome.i():Integer.parseInt(biomeType.getWaterColor(),16)); - - // water fog color j is getWaterFogColor - newFog.c(biomeType.getWaterFogColor().isEmpty() ? forestbiome.j():Integer.parseInt(biomeType.getWaterFogColor(),16)); - - // sky color - newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a():Integer.parseInt(biomeType.getSkyColor(),16)); - - - // Unnecessary values; can be removed safely if you don't want to change them - - // foliage color (leaves, fines and more) f is getFoliageColor - newFog.e(biomeType.getFoliageColor().isEmpty() ? forestbiome.f():Integer.parseInt(biomeType.getFoliageColor(),16)); - - // grass blocks color - newFog.f(biomeType.getGrassColor().isEmpty() ? Integer.parseInt("79C05A",16):Integer.parseInt(biomeType.getGrassColor(),16)); - - - newBiomeBuilder.a(newFog.a()); - - BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); - - // Inject into the data registry for biomes - // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); + newBiomeBuilder.b(biomeType.getRainFall()); // Downfall of biome + + // BiomeBase.TemperatureModifier.a will make your biome normal + // BiomeBase.TemperatureModifier.b will make your biome frozen + if (biomeType.isCold()) { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.b); + } + else { + newBiomeBuilder.a(BiomeBase.TemperatureModifier.a); + } + + BiomeFog.a newFog = new BiomeFog.a(); + newFog.a(GrassColor.a); // This doesn't affect the actual final grass color, just leave this line as it is or you will get errors + + // Set biome colours. If field is empty, default to forest color + + // fogcolor + newFog.a(biomeType.getFogColor().isEmpty() ? forestbiome.e() : Integer.parseInt(biomeType.getFogColor(), 16)); + + // water color i is getWaterColor + newFog.b(biomeType.getWaterColor().isEmpty() + ? forestbiome.i() + : Integer.parseInt(biomeType.getWaterColor(), 16)); + + // water fog color j is getWaterFogColor + newFog.c(biomeType.getWaterFogColor().isEmpty() + ? forestbiome.j() + : Integer.parseInt(biomeType.getWaterFogColor(), 16)); + + // sky color + newFog.d(biomeType.getSkyColor().isEmpty() ? forestbiome.a() : Integer.parseInt(biomeType.getSkyColor(), 16)); + + + // Unnecessary values; can be removed safely if you don't want to change them + + // foliage color (leaves, fines and more) f is getFoliageColor + newFog.e(biomeType.getFoliageColor().isEmpty() + ? forestbiome.f() + : Integer.parseInt(biomeType.getFoliageColor(), 16)); + + // grass blocks color + newFog.f(biomeType.getGrassColor().isEmpty() + ? Integer.parseInt("79C05A", 16) + : Integer.parseInt(biomeType.getGrassColor(), 16)); + + + newBiomeBuilder.a(newFog.a()); + + BiomeBase biome = newBiomeBuilder.a(); // biomebuilder.build(); + + // Inject into the data registry for biomes + // RegistryGeneration.a(RegistryGeneration.i, newKey, biome); // d is containsKey - if(registrywritable.d(newKey)) - { + if (registrywritable.d(newKey)) { TerraformGeneratorPlugin.logger.info(newKey + " was already registered. Was there a plugin/server reload?"); return; } @@ -196,13 +203,13 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // f is createIntrusiveHolder // registrywritable.f(biome); - // a is RegistryMaterials.register + // a is RegistryMaterials.register // Holder.c is Holder.Reference - Method register = registrywritable.getClass().getDeclaredMethod( - "a", + Method register = registrywritable.getClass().getDeclaredMethod("a", net.minecraft.resources.ResourceKey.class, Object.class, - Class.forName("net.minecraft.core.RegistrationInfo")); + Class.forName("net.minecraft.core.RegistrationInfo") + ); register.setAccessible(true); Holder.c holder = (Holder.c) register.invoke(registrywritable, newKey, biome, regInfo); @@ -220,9 +227,9 @@ private static void registerCustomBiomeBase(@NotNull CustomBiomeType biomeType, // instead of the whole unregistered intrusive holders stuff), // but it also involves reflection so I don't want to // change this out just yet. Consider for the next version. - terraformGenBiomeRegistry.put(biomeType, newKey); - - } + terraformGenBiomeRegistry.put(biomeType, newKey); + + } public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry registry) { @@ -230,17 +237,22 @@ public static Set> biomeListToBiomeBaseSet(@NotNull IRegistry< List> biomeBases = new ArrayList<>(); for (Biome biome : Biome.values()) { - if(biome == null || biome == Biome.CUSTOM) continue; + if (biome == null || biome == Biome.CUSTOM) { + continue; + } try { // Preconditions.checkArgument(biome != Biome.CUSTOM, "Cannot use the biome %s", biome); biomeBases.add(CraftBiome.bukkitToMinecraftHolder(biome)); - } catch(IllegalStateException e) { + } + catch (IllegalStateException e) { TerraformGeneratorPlugin.logger.info("Ignoring biome " + biome); } } - for(CustomBiomeType cbt:CustomBiomeType.values()) { - if(cbt == CustomBiomeType.NONE) continue; + for (CustomBiomeType cbt : CustomBiomeType.values()) { + if (cbt == CustomBiomeType.NONE) { + continue; + } ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt); // TerraformGeneratorPlugin.logger.info(cbt + " --- " + rkey); // Holder.c is Holder.Reference. It implements Holder. No idk why. diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/LootTableTranslator.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/LootTableTranslator.java index e16a6ece..0ae0ffe5 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/LootTableTranslator.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/LootTableTranslator.java @@ -11,7 +11,7 @@ public class LootTableTranslator { // I am indeed formally trained to properly structure my code // I have however elected to completely ignore said training here - public static final HashMap> translationMap = new HashMap<>(){{ + public static final HashMap> translationMap = new HashMap<>() {{ put(TerraLootTable.EMPTY, LootTables.a); put(TerraLootTable.SPAWN_BONUS_CHEST, LootTables.b); put(TerraLootTable.END_CITY_TREASURE, LootTables.c); diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java index 05b38f9b..dc73b094 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java @@ -16,9 +16,13 @@ import java.util.stream.Stream; public class MapRenderWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; - private final Set> biomeList; + private final Holder river; + private final Holder plains; + public MapRenderWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -35,29 +39,24 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } @Override protected MapCodec a() { - throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); - } + throw new UnsupportedOperationException("Cannot serialize MapRenderWorldProviderBiome"); + } - private final Holder river; - private final Holder plains; - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { - // Used to be attempted for cave gen. That didn't work, so now, this is + @Override + public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + // Used to be attempted for cave gen. That didn't work, so now, this is // for optimising cartographers and buried treasure. // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x,z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? - river : plains; - } + return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java index 1c04c2f1..9c3ecdae 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java @@ -3,21 +3,13 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.MapCodec; import net.minecraft.SystemUtils; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; -import net.minecraft.core.IRegistryCustom; -import net.minecraft.core.SectionPosition; +import net.minecraft.core.*; import net.minecraft.core.registries.Registries; import net.minecraft.resources.MinecraftKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.RegionLimitedWorldAccess; import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.BlockColumn; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.GeneratorAccessSeed; -import net.minecraft.world.level.LevelHeightAccessor; -import net.minecraft.world.level.StructureManager; +import net.minecraft.world.level.*; import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.biome.WorldChunkManager; import net.minecraft.world.level.chunk.ChunkGenerator; @@ -30,11 +22,7 @@ import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; -import net.minecraft.world.level.levelgen.structure.structures.BuriedTreasureStructure; -import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure; -import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentStructure; -import net.minecraft.world.level.levelgen.structure.structures.StrongholdStructure; -import net.minecraft.world.level.levelgen.structure.structures.WoodlandMansionStructure; +import net.minecraft.world.level.levelgen.structure.structures.*; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import org.jetbrains.annotations.NotNull; import org.terraform.coregen.bukkit.TerraformGenerator; @@ -42,11 +30,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; import org.terraform.main.config.TConfigOption; -import org.terraform.structure.SingleMegaChunkStructurePopulator; -import org.terraform.structure.StructureLocator; -import org.terraform.structure.StructurePopulator; -import org.terraform.structure.StructureRegistry; -import org.terraform.structure.VanillaStructurePopulator; +import org.terraform.structure.*; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; import org.terraform.structure.small.buriedtreasure.BuriedTreasurePopulator; @@ -65,10 +49,14 @@ public class NMSChunkGenerator extends ChunkGenerator { private final @NotNull TerraformWorldProviderBiome twBS; private final @NotNull Method tryGenerateStructure; private final ArrayList possibleStructureSets = new ArrayList<>(); - public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) throws NoSuchMethodException, SecurityException{ + + public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator delegate) + throws NoSuchMethodException, SecurityException + { super( delegate.d(), // WorldChunkManager d() is getBiomeSource() - delegate.d); // Idk what generationSettingsGetter is + delegate.d + ); // Idk what generationSettingsGetter is tw = TerraformWorld.get(worldName, seed); this.delegate = delegate; @@ -80,10 +68,8 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de // This is tryGenerateStructure // Register VanillaStructurePopulators to allow Minecraft to properly // handle them - for(StructurePopulator pop : StructureRegistry.getAllPopulators()) - { - if(pop instanceof VanillaStructurePopulator vsp) - { + for (StructurePopulator pop : StructureRegistry.getAllPopulators()) { + if (pop instanceof VanillaStructurePopulator vsp) { possibleStructureSets.add(MinecraftKey.a(vsp.structureRegistryKey)); // MinecraftKey.create } } @@ -96,7 +82,8 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de long.class, IChunkAccess.class, ChunkCoordIntPair.class, - SectionPosition.class); + SectionPosition.class + ); tryGenerateStructure.setAccessible(true); } @@ -116,7 +103,10 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de } @Override // createBiomes - public @NotNull CompletableFuture a(RandomState randomstate, Blender blender, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess) + public @NotNull CompletableFuture a(RandomState randomstate, + Blender blender, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess) { return CompletableFuture.supplyAsync(SystemUtils.a("init_biomes", () -> { return ichunkaccess; // Don't do any calculations here, biomes are set in applyCarvers @@ -124,13 +114,17 @@ public NMSChunkGenerator(String worldName, long seed, @NotNull ChunkGenerator de } @Override // findNearestMapFeature - public Pair> a(WorldServer worldserver, @NotNull HolderSet holderset, - @NotNull BlockPosition blockposition, int i, boolean flag) { + public Pair> a(WorldServer worldserver, + @NotNull HolderSet holderset, + @NotNull BlockPosition blockposition, + int i, + boolean flag) + { int pX = blockposition.u(); // getX int pZ = blockposition.w(); // getZ - for(Holder holder:holderset) { + for (Holder holder : holderset) { Structure feature = holder.a(); // StructureGenerator structuregenerator = feature.; TerraformGeneratorPlugin.logger.info("Vanilla locate for " + feature.getClass().getName() + " invoked."); @@ -139,34 +133,58 @@ public Pair> a(WorldServer worldserver, @NotNul int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) - { + else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MonumentPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new MansionPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MonumentPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a() instanceof JigsawStructure - && MinecraftServer.getServer().bc().d(Registries.aR).a(MinecraftKey.a("trial_chambers")) == holder.a() - ) { // Trial Chamber + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion - int[] coords = StructureLocator.locateSingleMegaChunkStructure(tw, pX, pZ, new TrialChamberPopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new MansionPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); - } else if (holder.a().getClass() == BuriedTreasureStructure.class) { + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a() instanceof JigsawStructure + && MinecraftServer.getServer().bc().d(Registries.aR).a(MinecraftKey.a("trial_chambers")) + == holder.a()) + { // Trial Chamber + + int[] coords = StructureLocator.locateSingleMegaChunkStructure( + tw, + pX, + pZ, + new TrialChamberPopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); + } + else if (holder.a().getClass() == BuriedTreasureStructure.class) { // Buried Treasure - int[] coords = StructureLocator.locateMultiMegaChunkStructure(tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt()); - if(coords == null) return null; - return new Pair<> - (new BlockPosition(coords[0], 50, coords[1]), holder); + int[] coords = StructureLocator.locateMultiMegaChunkStructure( + tw, + new MegaChunk(pX, 0, pZ), + new BuriedTreasurePopulator(), + TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + ); + if (coords == null) { + return null; + } + return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); } } } @@ -174,17 +192,23 @@ else if(!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) } @Override // applyBiomeDecoration - public void a(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { + public void a(GeneratorAccessSeed generatoraccessseed, + IChunkAccess ichunkaccess, + StructureManager structuremanager) + { delegate.a(generatoraccessseed, ichunkaccess, structuremanager); // This triggers structure gen. Needed for VanillaStructurePopulator - addVanillaDecorations(generatoraccessseed,ichunkaccess, structuremanager); + addVanillaDecorations(generatoraccessseed, ichunkaccess, structuremanager); } @Override // applyCarvers - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, - RandomState randomstate, BiomeManager biomemanager, - StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + long seed, + RandomState randomstate, + BiomeManager biomemanager, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { // POPULATES BIOMES. IMPORTANT @@ -194,7 +218,15 @@ public void a(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, ichunkaccess.a(this.twBS, null); // This can be null as its passed into twBS // Call delegate applyCarvers to apply spigot ChunkGenerator; - delegate.a(regionlimitedworldaccess, seed, randomstate, biomemanager,structuremanager,ichunkaccess,worldgenstage_features); + delegate.a( + regionlimitedworldaccess, + seed, + randomstate, + biomemanager, + structuremanager, + ichunkaccess, + worldgenstage_features + ); } @Override // getSeaLevel @@ -208,7 +240,12 @@ public int e() { * checks cut out and replaced with TFG code. */ @Override - public void a(IRegistryCustom iregistrycustom, @NotNull ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, @NotNull IChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) { + public void a(IRegistryCustom iregistrycustom, + @NotNull ChunkGeneratorStructureState chunkgeneratorstructurestate, + StructureManager structuremanager, + @NotNull IChunkAccess ichunkaccess, + StructureTemplateManager structuretemplatemanager) + { ChunkCoordIntPair chunkcoordintpair = ichunkaccess.f(); // getPos SectionPosition sectionposition = SectionPosition.a(ichunkaccess); // bottomOf RandomState randomstate = chunkgeneratorstructurestate.c(); // randomState @@ -216,41 +253,58 @@ public void a(IRegistryCustom iregistrycustom, @NotNull ChunkGeneratorStructureS SingleMegaChunkStructurePopulator[] spops = StructureRegistry.getLargeStructureForMegaChunk(tw, mc); int[] centerCoords = mc.getCenterBiomeSectionChunkCoords(); - for(SingleMegaChunkStructurePopulator pop:spops) - { - if(!(pop instanceof VanillaStructurePopulator vpop)) continue; + for (SingleMegaChunkStructurePopulator pop : spops) { + if (!(pop instanceof VanillaStructurePopulator vpop)) { + continue; + } // possibleStructureSets - possibleStructureSets - .stream().filter((resourceLoc)->{ - return vpop.structureRegistryKey.equals(resourceLoc.a()); // MinecraftKey.getPath() - }) - .map((resourceLoc)-> MinecraftServer.getServer().bc().d(Registries.aT).a(resourceLoc)) - .forEach((structureSet) -> { - StructurePlacement structureplacement = structureSet.b(); // placement() - List list = structureSet.a(); // structures() - - // This will be true depending on the structure manager - if (centerCoords[0] == chunkcoordintpair.e - && centerCoords[1] == chunkcoordintpair.f) { - - // d() -> getLevelSeed() - try{ - Object retVal = tryGenerateStructure.invoke(this, list.getFirst(), structuremanager, iregistrycustom, randomstate, - structuretemplatemanager, chunkgeneratorstructurestate.d(), - ichunkaccess, chunkcoordintpair, sectionposition); - TerraformGeneratorPlugin.logger.info(chunkcoordintpair.e + "," + chunkcoordintpair.f + " will spawn a vanilla structure, with tryGenerateStructure == " + retVal); - } - catch(Throwable t) - { - TerraformGeneratorPlugin.logger.info(chunkcoordintpair.e + "," + chunkcoordintpair.f + " Failed to generate a vanilla structure"); - TerraformGeneratorPlugin.logger.stackTrace(t); - } - } - }); + possibleStructureSets.stream() + .filter((resourceLoc) -> { + return vpop.structureRegistryKey.equals(resourceLoc.a()); // MinecraftKey.getPath() + }) + .map((resourceLoc) -> MinecraftServer.getServer().bc().d(Registries.aT).a(resourceLoc)) + .forEach((structureSet) -> { + StructurePlacement structureplacement = structureSet.b(); // placement() + List list = structureSet.a(); // structures() + + // This will be true depending on the structure manager + if (centerCoords[0] == chunkcoordintpair.e + && centerCoords[1] == chunkcoordintpair.f) + { + + // d() -> getLevelSeed() + try { + Object retVal = tryGenerateStructure.invoke(this, + list.getFirst(), + structuremanager, + iregistrycustom, + randomstate, + structuretemplatemanager, + chunkgeneratorstructurestate.d(), + ichunkaccess, + chunkcoordintpair, + sectionposition + ); + TerraformGeneratorPlugin.logger.info(chunkcoordintpair.e + + "," + + chunkcoordintpair.f + + " will spawn a vanilla structure, with tryGenerateStructure == " + + retVal); + } + catch (Throwable t) { + TerraformGeneratorPlugin.logger.info(chunkcoordintpair.e + + "," + + chunkcoordintpair.f + + " Failed to generate a vanilla structure"); + TerraformGeneratorPlugin.logger.stackTrace(t); + } + } + }); } } + @Override // createReferences. Structure related - public void a(GeneratorAccessSeed gas,StructureManager manager,IChunkAccess ica) + public void a(GeneratorAccessSeed gas, StructureManager manager, IChunkAccess ica) { delegate.a(gas, manager, ica); } @@ -262,15 +316,18 @@ public int a(LevelHeightAccessor levelheightaccessor) { @Override // fillFromNoise public CompletableFuture a(Blender blender, - RandomState randomstate, StructureManager structuremanager, - IChunkAccess ichunkaccess) { - return delegate.a(blender, - randomstate, structuremanager, - ichunkaccess); + RandomState randomstate, + StructureManager structuremanager, + IChunkAccess ichunkaccess) + { + return delegate.a(blender, randomstate, structuremanager, ichunkaccess); } @Override // buildSurface. Used to be buildBase - public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, IChunkAccess ichunkaccess) + public void a(RegionLimitedWorldAccess regionlimitedworldaccess, + StructureManager structuremanager, + RandomState randomstate, + IChunkAccess ichunkaccess) { delegate.a(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess); } @@ -278,7 +335,7 @@ public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManage @Override // getBaseColumn public BlockColumn a(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { - return this.delegate.a(i,j,levelheightaccessor,randomstate); + return this.delegate.a(i, j, levelheightaccessor, randomstate); } // spawnOriginalMobs @@ -300,20 +357,33 @@ public int g() { } @Override // getFirstFreeHeight - public int b(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int b(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate); } @Override // getFirstOccupiedHeight - public int c(int i, int j, HeightMap.Type heightmap_type, - LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int c(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { return this.a(i, j, heightmap_type, levelheightaccessor, randomstate) - 1; } @Override // getBaseHeight - public int a(int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) { + public int a(int i, + int j, + HeightMap.Type heightmap_type, + LevelHeightAccessor levelheightaccessor, + RandomState randomstate) + { // return delegate.a(x, z, var2, var3); return 100; // return org.terraform.coregen.HeightMap.getBlockHeight(tw, x, z); diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSInjector.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSInjector.java index 10d12ff0..34de1f74 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSInjector.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSInjector.java @@ -1,11 +1,15 @@ package org.terraform.v1_21_R1; +import net.minecraft.server.level.PlayerChunkMap; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.block.entity.TileEntityBeehive; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.status.ChunkStatus; +import net.minecraft.world.level.chunk.status.WorldGenContext; import org.bukkit.Chunk; import org.bukkit.World; -import net.minecraft.world.level.chunk.status.WorldGenContext; import org.bukkit.block.Beehive; import org.bukkit.craftbukkit.v1_21_R1.CraftChunk; import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; @@ -21,11 +25,6 @@ import org.terraform.coregen.populatordata.PopulatorDataSpigotAPI; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; - -import net.minecraft.server.level.PlayerChunkMap; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.chunk.IChunkAccess; import org.terraform.utils.GenUtils; import java.lang.reflect.Field; @@ -34,13 +33,15 @@ public class NMSInjector extends NMSInjectorAbstract { - // private boolean heightInjectSuccess = true; + // private boolean heightInjectSuccess = true; + + private static @Nullable Method getTileEntity = null; - @Override - public void startupTasks() { + @Override + public void startupTasks() { // Inject new biomes CustomBiomeHandler.init(); - } + } @Override public @NotNull BlockDataFixerAbstract getBlockDataFixer() { @@ -60,7 +61,8 @@ public boolean attemptInject(@NotNull World world) { // k is getChunkSource, g is getChunkGenerator() ChunkGenerator delegate = ws.l().g(); - TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass().getSimpleName()); + TerraformGeneratorPlugin.logger.info("NMSChunkGenerator Delegate is of type " + delegate.getClass() + .getSimpleName()); // String worldname, // int seed, @@ -68,10 +70,7 @@ public boolean attemptInject(@NotNull World world) { // WorldChunkManager worldchunkmanager1, // StructureSettings structuresettings, // long i - NMSChunkGenerator bpg = new NMSChunkGenerator( - world.getName(), - (int) world.getSeed(), - delegate); + NMSChunkGenerator bpg = new NMSChunkGenerator(world.getName(), (int) world.getSeed(), delegate); // Inject TerraformGenerator NMS chunk generator into playerchunkmap AND worldgencontext PlayerChunkMap pcm = ws.l().a; // getChunkProvider().PlayerChunkMap @@ -81,15 +80,18 @@ public boolean attemptInject(@NotNull World world) { wgc.setAccessible(true); WorldGenContext worldGenContext = (WorldGenContext) wgc.get(pcm); // b is chunkGenerator - wgc.set(pcm, new WorldGenContext( - worldGenContext.a(), - bpg, - worldGenContext.c(), - worldGenContext.d(), - worldGenContext.e() - )); - TerraformGeneratorPlugin.logger.info("Post injection: getChunkSource().getChunkGenerator() is of type " + ws.l().g().getClass().getSimpleName()); - } catch (Throwable e) { + wgc.set(pcm, + new WorldGenContext(worldGenContext.a(), + bpg, + worldGenContext.c(), + worldGenContext.d(), + worldGenContext.e() + ) + ); + TerraformGeneratorPlugin.logger.info("Post injection: getChunkSource().getChunkGenerator() is of type " + + ws.l().g().getClass().getSimpleName()); + } + catch (Throwable e) { TerraformGeneratorPlugin.logger.stackTrace(e); return false; } @@ -116,44 +118,52 @@ public PopulatorDataICAAbstract getICAData(PopulatorDataAbstract data) { GeneratorAccessSeed gas = ((CraftLimitedRegion) pdata.lr).getHandle(); WorldServer ws = gas.getMinecraftWorld(); TerraformWorld tw = TerraformWorld.get(ws.getWorld().getName(), ws.C()); // C is getSeed() - return new PopulatorDataICA(data, tw, ws, gas.a(data.getChunkX(),data.getChunkZ()), data.getChunkX(), data.getChunkZ()); + return new PopulatorDataICA( + data, + tw, + ws, + gas.a(data.getChunkX(), data.getChunkZ()), + data.getChunkX(), + data.getChunkZ() + ); } - if(data instanceof PopulatorDataPostGen gdata) + if (data instanceof PopulatorDataPostGen gdata) { return getICAData(gdata.getChunk()); + } return null; } - private static @Nullable Method getTileEntity = null; @Override public void storeBee(Beehive hive) { try { - if(getTileEntity == null) - { + if (getTileEntity == null) { getTileEntity = CraftBlockEntityState.class.getDeclaredMethod("getTileEntity"); getTileEntity.setAccessible(true); } TileEntityBeehive teb = (TileEntityBeehive) getTileEntity.invoke(hive); -// -// NBTTagCompound nbttagcompound = new NBTTagCompound(); -// nbttagcompound.a("id", "minecraft:bee"); + // + // NBTTagCompound nbttagcompound = new NBTTagCompound(); + // nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee // TileEntityBeehive.Occupant.create(1) // Copied from world\level\levelgen\feature\treedecorators\WorldGenFeatureTreeBeehive.java teb.a(TileEntityBeehive.c.a(GenUtils.RANDOMIZER.nextInt(599))); - } catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - @Override - public int getMinY() { - return -64; - } - - @Override - public int getMaxY() { - return 320; - } + + @Override + public int getMinY() { + return -64; + } + + @Override + public int getMaxY() { + return 320; + } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java index 8bcfbe8d..2a1fb4f2 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java @@ -4,11 +4,7 @@ import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.GeneratorAccessSeed; -import net.minecraft.world.level.block.entity.BrushableBlockEntity; -import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.block.entity.TileEntityBeehive; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.entity.TileEntityMobSpawner; +import net.minecraft.world.level.block.entity.*; import net.minecraft.world.level.chunk.IChunkAccess; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -36,78 +32,136 @@ import java.util.Optional; import java.util.Random; -public class PopulatorData extends PopulatorDataAbstract implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor { +public class PopulatorData extends PopulatorDataAbstract + implements IPopulatorDataBaseHeightAccess, IPopulatorDataBeehiveEditor +{ + private static final HashMap> entityTypesDict = new HashMap<>(); + final GeneratorAccessSeed rlwa; + final IChunkAccess ica; private final int chunkX; private final int chunkZ; - private int radius = 1; private final NMSChunkGenerator gen; - final GeneratorAccessSeed rlwa; - final IChunkAccess ica; - - private static final HashMap> entityTypesDict = new HashMap<>(); - + private int radius = 1; + public PopulatorData(GeneratorAccessSeed rlwa, IChunkAccess ica, NMSChunkGenerator gen, int chunkX, int chunkZ) { this.rlwa = rlwa; this.chunkX = chunkX; this.chunkZ = chunkZ; this.gen = gen; this.ica = ica; - - if(entityTypesDict.isEmpty()) { - for(EntityType type:EntityType.values()) { - if(type == EntityType.UNKNOWN) continue; - try { + + if (entityTypesDict.isEmpty()) { + for (EntityType type : EntityType.values()) { + if (type == EntityType.UNKNOWN) { + continue; + } + try { // EntityTypes.byString - Optional> et = EntityTypes.a("minecraft:"+type.toString().toLowerCase(Locale.ENGLISH)); + Optional> et = EntityTypes.a("minecraft:" + type.toString() + .toLowerCase(Locale.ENGLISH)); et.ifPresent(entityTypes -> entityTypesDict.put(type, entityTypes)); - } catch (IllegalArgumentException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - } - } + } + catch (IllegalArgumentException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } } - + public void setRadius(int radius) { - this.radius = radius; + this.radius = radius; } public Material getType(int x, int y, int z) { - try { - // return rlwa.getType(x, y, z); - return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); - }catch(Exception e) { - Bukkit.getLogger().info("Error chunk: " + chunkX + "," + chunkZ + "--- Block Coords: " + 16*chunkX + "," + 16*chunkZ + " for coords " + x + "," + y + "," + z); - TerraformGeneratorPlugin.logger.stackTrace(e); - } - return null; + try { + // return rlwa.getType(x, y, z); + return CraftMagicNumbers.getMaterial(rlwa.a_(new BlockPosition(x, y, z)).b()); + } + catch (Exception e) { + Bukkit.getLogger() + .info("Error chunk: " + + chunkX + + "," + + chunkZ + + "--- Block Coords: " + + 16 * chunkX + + "," + + 16 * chunkZ + + " for coords " + + x + + "," + + y + + "," + + z); + TerraformGeneratorPlugin.logger.stackTrace(e); + } + return null; } public BlockData getBlockData(int x, int y, int z) { // return rlwa.getBlockData(x,y,z); - return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); + return CraftBlockData.fromData(rlwa.a_(new BlockPosition(x, y, z))); } @Override public void setType(int x, int y, int z, @NotNull Material type) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, Bukkit.createBlockData(type)); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + Bukkit.createBlockData(type) + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), 0); - } + } } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { - if(radius > 0) - NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), x, y, z, data); - else - TerraformGeneratorPlugin.logger.stackTrace(new Exception("Tried to call adjacent chunk with populator radius 0: (" + x + "," + y + "," + z + ") for chunk (" + chunkX + "," + chunkZ + ")")); - } else { - rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); + if (Math.abs((x >> 4) - chunkX) > radius || Math.abs((z >> 4) - chunkZ) > radius) { + if (radius > 0) { + NativeGeneratorPatcherPopulator.pushChange(rlwa.getMinecraftWorld().getWorld().getName(), + x, + y, + z, + data + ); + } + else { + TerraformGeneratorPlugin.logger.stackTrace(new Exception( + "Tried to call adjacent chunk with populator radius 0: (" + + x + + "," + + y + + "," + + z + + ") for chunk (" + + chunkX + + "," + + chunkZ + + ")")); + } + } + else { + rlwa.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), 0); } } @@ -126,50 +180,67 @@ public int getChunkX() { public int getChunkZ() { return chunkZ; } - + @Override public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { - TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); - return; - } - - // Use this method for thread safety. - CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); - net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(),rawX,rawY,rawZ), - type.getEntityClass(), true); + if (Math.abs((rawX >> 4) - chunkX) > 1 || Math.abs((rawZ >> 4) - chunkZ) > 1) { + TerraformGeneratorPlugin.logger.info("Failed to spawn " + type + " as it was out of bounds."); + return; + } + + // Use this method for thread safety. + CraftLimitedRegion clr = new CraftLimitedRegion(rlwa, ica.f()); + net.minecraft.world.entity.Entity e = clr.createEntity(new Location(gen.getTerraformWorld().getWorld(), + rawX, + rawY, + rawZ), type.getEntityClass(), true); // EntityInsentient.setPersistenceRequired() - if(e instanceof EntityInsentient) ((EntityInsentient) e).fF(); - rlwa.b(e); - // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); + if (e instanceof EntityInsentient) { + ((EntityInsentient) e).fF(); + } + rlwa.b(e); + // TerraformGeneratorPlugin.logger.info("Spawned " + e.getType() + " at " + rawX + " " + rawY + " " + rawZ); } @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if ( !TConfigOption.areAnimalsEnabled() ) return; + if (!TConfigOption.areAnimalsEnabled()) { + return; + } BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); - + setType(rawX, rawY, rawZ, Material.SPAWNER); TileEntity tileentity = rlwa.c_(pos); if (tileentity instanceof TileEntityMobSpawner) { try { // Refer to WorldGenDungeons -// TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; -// -// tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); + // TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity; + // + // tileentitymobspawner.setEntityId(this.randomEntityId(randomsource), randomsource); // Fetch from ENTITY_TYPE (Q)'s map - // q is ENTITY_TYPE - EntityTypes nmsEntity = entityTypesDict.get(type); - if(nmsEntity == null) TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + // q is ENTITY_TYPE + EntityTypes nmsEntity = entityTypesDict.get(type); + if (nmsEntity == null) { + TerraformGeneratorPlugin.logger.error(type + " was not present in the entityTypesDict."); + } ((TileEntityMobSpawner) tileentity).a(nmsEntity, new RandomSourceWrapper(new Random())); - } catch (IllegalArgumentException | SecurityException e) { + } + catch (IllegalArgumentException | SecurityException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } - } else { - TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + "," + rawX + "," + rawY + "," + rawZ + ")"); + } + else { + TerraformGeneratorPlugin.logger.error("Failed to fetch mob spawner entity at (" + + "," + + rawX + + "," + + rawY + + "," + + rawZ + + ")"); } } @@ -179,51 +250,54 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = rlwa.c_(pos); - if(te instanceof TileEntityLootable) + if (te instanceof TileEntityLootable) { ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + gen.getTerraformWorld().getHashedRand(x, y, z).nextLong() + ); + } // TileEntityLootable.a(rlwa, RandomSource.a(gen.getTerraformWorld().getHashedRand(x, y, z).nextLong()), pos, LootTableTranslator.translationMap.get(table)); } - @Override - public TerraformWorld getTerraformWorld() { - return gen.getTerraformWorld(); - } - - @Override - public int getBaseHeight(int rawX, int rawZ) { - // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) - return 100; - // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); - } - - @Override - public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { - BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); + @Override + public TerraformWorld getTerraformWorld() { + return gen.getTerraformWorld(); + } + + @Override + public int getBaseHeight(int rawX, int rawZ) { + // (int i, int j, HeightMap.Type heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) + return 100; + // return gen.a(rawX, rawZ, HeightMap.Type.a, this.rlwa); + } + + @Override + public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { + BlockPosition pos = new BlockPosition(rawX, rawY, rawZ); // TerraformGeneratorPlugin.logger.info(IRegistry.X.b(EntityTypes.h).toString()); setType(rawX, rawY, rawZ, Material.BEE_NEST); try { // TerraformGeneratorPlugin.logger.error("Failed to set beehive at (" + rawX + "," + rawY + "," + rawZ + ") " + BuiltInRegistries.h.b(entityTypesDict.get(EntityType.BEE))); TileEntityBeehive tileentity = (TileEntityBeehive) rlwa.c_(pos); - if(tileentity == null) - { // retry? - setType(rawX, rawY, rawZ, Material.BEE_NEST); - tileentity = (TileEntityBeehive) rlwa.c_(pos); + if (tileentity == null) { // retry? + setType(rawX, rawY, rawZ, Material.BEE_NEST); + tileentity = (TileEntityBeehive) rlwa.c_(pos); } -// -// NBTTagCompound nbttagcompound = new NBTTagCompound(); -// nbttagcompound.a("id", "minecraft:bee"); + // + // NBTTagCompound nbttagcompound = new NBTTagCompound(); + // nbttagcompound.a("id", "minecraft:bee"); // TileEntityBeehive.storeBee // TileEntityBeehive.Occupant.create(1) tileentity.a(TileEntityBeehive.c.a(GenUtils.RANDOMIZER.nextInt(599))); - } catch (NullPointerException | IllegalArgumentException | SecurityException e) { - TerraformGeneratorPlugin.logger.stackTrace(e); } - } + catch (NullPointerException | IllegalArgumentException | SecurityException e) { + TerraformGeneratorPlugin.logger.stackTrace(e); + } + } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorDataICA.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorDataICA.java index 0a6d3628..6bb39907 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorDataICA.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorDataICA.java @@ -1,9 +1,23 @@ package org.terraform.v1_21_R1; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.vehicle.EntityMinecartChest; +import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.TileEntity; -import net.minecraft.world.level.levelgen.structure.StructurePiece; +import net.minecraft.world.level.block.entity.TileEntityLootable; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.levelgen.structure.*; +import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentPieces; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -22,25 +36,6 @@ import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import net.minecraft.core.BlockPosition; -import net.minecraft.core.Holder; -import net.minecraft.core.IRegistry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.WorldServer; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.level.ChunkCoordIntPair; -import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.block.entity.TileEntityLootable; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.level.chunk.IChunkAccess; -import net.minecraft.world.level.levelgen.structure.BuiltinStructures; -import net.minecraft.world.level.levelgen.structure.Structure; -import net.minecraft.world.level.levelgen.structure.StructureBoundingBox; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -48,14 +43,20 @@ import java.util.Random; public class PopulatorDataICA extends PopulatorDataICABiomeWriterAbstract { - private final PopulatorDataAbstract parent; + private final PopulatorDataAbstract parent; private final IChunkAccess ica; private final int chunkX; private final int chunkZ; private final WorldServer ws; private final TerraformWorld tw; - public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldServer ws, IChunkAccess ica, int chunkX, int chunkZ) { + public PopulatorDataICA(PopulatorDataAbstract parent, + TerraformWorld tw, + WorldServer ws, + IChunkAccess ica, + int chunkX, + int chunkZ) + { this.ica = ica; this.parent = parent; this.chunkX = chunkX; @@ -63,68 +64,70 @@ public PopulatorDataICA(PopulatorDataAbstract parent, TerraformWorld tw, WorldSe this.ws = ws; this.tw = tw; } - + public @NotNull Material getType(int x, int y, int z) { - // return parent.getType(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getType(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd).getMaterial(); } public BlockData getBlockData(int x, int y, int z) { - // return parent.getBlockData(x, y, z); - IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState + // return parent.getBlockData(x, y, z); + IBlockData ibd = ica.a_(new BlockPosition(x, y, z)); // getState return CraftBlockData.fromData(ibd); } - @Override - public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { - IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); + @Override + public void setBiome(int rawX, int rawY, int rawZ, CustomBiomeType cbt, Biome fallback) { + IRegistry biomeRegistry = CustomBiomeHandler.getBiomeRegistry(); Holder targetBiome; - if(cbt == CustomBiomeType.NONE) { - - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); - Optional> optHolder = biomeRegistry.b(rkey); // getHolder - if(optHolder.isEmpty()) { - TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); - targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); - } - else - targetBiome = optHolder.get(); - } - - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); - } - - @Override - public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { - // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); - ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); - } + if (cbt == CustomBiomeType.NONE) { + + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(cbt);// ResourceKey.a(IRegistry.aP, new MinecraftKey(cbt.getKey())); + Optional> optHolder = biomeRegistry.b(rkey); // getHolder + if (optHolder.isEmpty()) { + TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + targetBiome = CraftBiome.bukkitToMinecraftHolder(fallback); + } + else { + targetBiome = optHolder.get(); + } + } + + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, targetBiome); + } + + @Override + public void setBiome(int rawX, int rawY, int rawZ, Biome biome) { + // TerraformGeneratorPlugin.logger.info("Set " + rawX + "," + rawY + "," + rawZ + " to " + biome); + ica.setBiome(rawX >> 2, rawY >> 2, rawZ >> 2, CraftBiome.bukkitToMinecraftHolder(biome)); + } @Override public void setType(int x, int y, int z, @NotNull Material type) { - // parent.setType(x, y, z, type); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // parent.setType(x, y, z, type); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); - // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); + // ica.setType(new BlockPosition(x, y, z), ((CraftBlockData) Bukkit.createBlockData(type)).getState(), false); } @Override public void setBlockData(int x, int y, int z, @NotNull BlockData data) { - // parent.setBlockData(x, y, z, data); - ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); + // parent.setBlockData(x, y, z, data); + ica.a(new BlockPosition(x, y, z), ((CraftBlockData) data).getState(), false); } public Biome getBiome(int rawX, int rawZ) { - return parent.getBiome(rawX, rawZ); + return parent.getBiome(rawX, rawZ); // return tw.getBiomeBank(rawX, rawZ).getHandler().getBiome();// BiomeBank.calculateBiome(tw,tw.getTemperature(rawX, rawZ), y).getHandler().getBiome();// Biome.valueOf(ica // .getBiome(rawX, rawY, rawZ).l().replace("biome.minecraft.", "").toUpperCase(Locale.ENGLISH)); } - @Override + @Override public int getChunkX() { return chunkX; } @@ -136,7 +139,7 @@ public int getChunkZ() { @Override public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { - parent.addEntity(rawX, rawY, rawZ, type); + parent.addEntity(rawX, rawY, rawZ, type); } @Override @@ -150,19 +153,22 @@ public void lootTableChest(int x, int y, int z, TerraLootTable table) { // getBlockEntity TileEntity te = ica.c_(pos); - if(te instanceof TileEntityLootable) - ((TileEntityLootable)te).a(LootTableTranslator.translationMap.get(table)); - else if(te instanceof BrushableBlockEntity) - // BrushableBlockEntity.setLootTable - ((BrushableBlockEntity) te).a( - LootTableTranslator.translationMap.get(table), - tw.getHashedRand(x, y, z).nextLong()); + if (te instanceof TileEntityLootable) { + ((TileEntityLootable) te).a(LootTableTranslator.translationMap.get(table)); + } + else if (te instanceof BrushableBlockEntity) + // BrushableBlockEntity.setLootTable + { + ((BrushableBlockEntity) te).a(LootTableTranslator.translationMap.get(table), + tw.getHashedRand(x, y, z).nextLong() + ); + } } @SuppressWarnings("deprecation") - @Override + @Override public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0, int z0, int x1, int y1, int z1) { - ResourceKey structureKey = switch(type) { + ResourceKey structureKey = switch (type) { case GUARDIAN -> BuiltinStructures.l; // Ocean Monument case PILLAGER -> BuiltinStructures.a; // Pillager Outpost }; @@ -170,9 +176,9 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 // bc is registryAccess // d is getOrThrow // aR is STRUCTURE - IRegistry featureRegistry = MinecraftServer.getServer().bc().d(Registries.aR); - - Structure structureFeature = featureRegistry.a(structureKey); + IRegistry featureRegistry = MinecraftServer.getServer().bc().d(Registries.aR); + + Structure structureFeature = featureRegistry.a(structureKey); try { // Something's broken about EnumDirection's import. Might be a temporary thing. @@ -180,22 +186,26 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 Field enumDirectionA = enumDirectionClass.getField("a"); enumDirectionA.setAccessible(true); Class oceanMonumentPiecesHClass = OceanMonumentPieces.h.class; - StructurePiece customBoundPiece = (StructurePiece) oceanMonumentPiecesHClass - .getConstructor(RandomSource.class, int.class, int.class, enumDirectionClass) - .newInstance( - RandomSource.a(), x0, z0, enumDirectionA.get(null) - ); - - PiecesContainer container = new PiecesContainer(new ArrayList<>() {{add(customBoundPiece);}}); - - StructureStart start = new StructureStart( - structureFeature, + StructurePiece customBoundPiece = (StructurePiece) oceanMonumentPiecesHClass.getConstructor( + RandomSource.class, + int.class, + int.class, + enumDirectionClass + ).newInstance(RandomSource.a(), x0, z0, enumDirectionA.get(null)); + + PiecesContainer container = new PiecesContainer(new ArrayList<>() {{ + add(customBoundPiece); + }}); + + StructureStart start = new StructureStart(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ), - 0, container); + 0, + container + ); - Field i = StructureStart.class.getDeclaredField("h"); // boundingBox - i.setAccessible(true); - i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); + Field i = StructureStart.class.getDeclaredField("h"); // boundingBox + i.setAccessible(true); + i.set(start, new StructureBoundingBox(x0, y0, z0, x1, y1, z1)); // ws.a() is getStructureManager // a is setStartForStructure @@ -207,35 +217,41 @@ public void registerNaturalSpawns(@NotNull NaturalSpawnType type, int x0, int y0 // ws.a().a(SectionPosition.a(x0,y0,z0), structureFeature, start, ica); ica.a(structureFeature, start); - // ws.a().a( // setStartForFeature - // structureFeature, - // start); + // ws.a().a( // setStartForFeature + // structureFeature, + // start); // addReferenceForFeature ica.a(structureFeature, new ChunkCoordIntPair(chunkX, chunkZ).a()); // a is toLong } - catch(NoSuchMethodException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { + catch (NoSuchMethodException | + InstantiationException | + InvocationTargetException | + ClassNotFoundException | + NoSuchFieldException | + IllegalArgumentException | + IllegalAccessException e) { TerraformGeneratorPlugin.logger.stackTrace(e); } } @SuppressWarnings("deprecation") - @Override + @Override public void spawnMinecartWithChest(int x, int y, int z, TerraLootTable table, @NotNull Random random) { - EntityMinecartChest entityminecartchest = new EntityMinecartChest( - ws.getMinecraftWorld(), + EntityMinecartChest entityminecartchest = new EntityMinecartChest(ws.getMinecraftWorld(), (float) x + 0.5F, (float) y + 0.5F, - (float) z + 0.5F); + (float) z + 0.5F + ); entityminecartchest.a(LootTableTranslator.translationMap.get(table), random.nextLong()); ws.addFreshEntity(entityminecartchest, SpawnReason.CHUNK_GEN); } - @Override - public TerraformWorld getTerraformWorld() { - return tw; - } + @Override + public TerraformWorld getTerraformWorld() { + return tw; + } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/TerraformWorldProviderBiome.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/TerraformWorldProviderBiome.java index f0786e9f..d1d12286 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/TerraformWorldProviderBiome.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/TerraformWorldProviderBiome.java @@ -19,11 +19,12 @@ import java.util.stream.Stream; public class TerraformWorldProviderBiome extends WorldChunkManager { + @SuppressWarnings("unused") + private static final boolean debug = false; private final TerraformWorld tw; private final IRegistry registry; - - private final Set> biomeList; + public TerraformWorldProviderBiome(TerraformWorld tw, WorldChunkManager delegate) { // super(biomeListToBiomeBaseList(CustomBiomeHandler.getBiomeRegistry())); this.biomeList = CustomBiomeHandler.biomeListToBiomeBaseSet(CustomBiomeHandler.getBiomeRegistry()); @@ -38,7 +39,7 @@ public Stream> b() } @Override // c is getPossibleBiomes - public Set> c() + public Set> c() { return this.biomeList; } @@ -48,26 +49,29 @@ protected MapCodec a() { throw new UnsupportedOperationException("Cannot serialize TerraformWorldProviderBiome"); } - @SuppressWarnings("unused") - private static final boolean debug = false; - @Override - public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { + @Override + public @Nullable Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // Used for biome generation in NMSChunkGenerator. // Left shift x and z BiomeBank bank = tw.getBiomeBank(x << 2, z << 2); - if(bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { + if (bank.getHandler().getCustomBiome() == CustomBiomeType.NONE) { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); - } else { - ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler().getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); + } + else { + ResourceKey rkey = CustomBiomeHandler.terraformGenBiomeRegistry.get(bank.getHandler() + .getCustomBiome()); // ResourceKey.a(IRegistry.aP, new MinecraftKey(bank.getHandler().getCustomBiome().getKey())); Optional> holder = registry.b(rkey); - if(holder.isEmpty()) + if (holder.isEmpty()) { TerraformGeneratorPlugin.logger.error("Custom biome was not found in the vanilla registry!"); + } - if(holder.isPresent()) { + if (holder.isPresent()) { return holder.get(); - } else + } + else { return CraftBiome.bukkitToMinecraftHolder(bank.getHandler().getBiome()); + } } } From 955d3c9bfa773fd2dcb999a5ae2b25a6a92809c7 Mon Sep 17 00:00:00 2001 From: Steven Van Ingelgem Date: Mon, 19 Aug 2024 10:20:00 +0200 Subject: [PATCH 2/4] Use direct types instead of getters (#135) * Get rid of all the `get*` methods for the configuration in favor of direct support of the actual types. * remove last zeroes from floats/doubles. * Few changes for inaccurate float<->double conversions. * Use a File instead of a String --- build.gradle.kts | 1 + buildProj/build.gradle.kts | 1 + common/build.gradle.kts | 1 + .../java/org/terraform/biome/BiomeBank.java | 152 +-- .../org/terraform/biome/BiomeClimate.java | 49 +- .../org/terraform/biome/BiomeSection.java | 10 +- .../biome/beach/MushroomBeachHandler.java | 6 +- .../org/terraform/biome/beach/OasisBeach.java | 8 +- .../cavepopulators/CaveClusterRegistry.java | 30 +- .../LushClusterCavePopulator.java | 6 +- .../biome/flat/ArchedCliffsHandler.java | 4 +- .../terraform/biome/flat/BadlandsHandler.java | 14 +- .../biome/flat/BambooForestHandler.java | 6 +- .../biome/flat/CherryGroveHandler.java | 4 +- .../biome/flat/DarkForestHandler.java | 8 +- .../terraform/biome/flat/DesertHandler.java | 6 +- .../biome/flat/ElevatedPlainsHandler.java | 4 +- .../biome/flat/ErodedPlainsHandler.java | 4 +- .../terraform/biome/flat/ForestHandler.java | 4 +- .../terraform/biome/flat/GorgeHandler.java | 4 +- .../terraform/biome/flat/JungleHandler.java | 10 +- .../terraform/biome/flat/MangroveHandler.java | 4 +- .../terraform/biome/flat/MuddyBogHandler.java | 4 +- .../terraform/biome/flat/PlainsHandler.java | 4 +- .../terraform/biome/flat/SavannaHandler.java | 6 +- .../biome/flat/ScarletForestHandler.java | 4 +- .../biome/flat/SnowyTaigaHandler.java | 4 +- .../biome/flat/SnowyWastelandHandler.java | 4 +- .../terraform/biome/flat/TaigaHandler.java | 6 +- .../mountainous/AbstractMountainHandler.java | 8 +- .../mountainous/BirchMountainsHandler.java | 8 +- .../biome/mountainous/DesertHillsHandler.java | 6 +- .../mountainous/ForestedMountainsHandler.java | 4 +- .../mountainous/PaintedHillsHandler.java | 4 +- .../mountainous/RockyMountainsHandler.java | 4 +- .../mountainous/ShatteredSavannaHandler.java | 14 +- .../biome/river/BogRiverHandler.java | 4 +- .../biome/river/CherryGroveRiverHandler.java | 4 +- .../biome/river/DarkForestRiverHandler.java | 6 +- .../biome/river/FrozenRiverHandler.java | 4 +- .../biome/river/JungleRiverHandler.java | 4 +- .../terraform/biome/river/RiverHandler.java | 4 +- .../river/ScarletForestRiverHandler.java | 4 +- .../org/terraform/cave/NoiseCaveRegistry.java | 6 +- .../org/terraform/command/MansionCommand.java | 6 +- .../java/org/terraform/coregen/HeightMap.java | 8 +- .../terraform/coregen/TerraformPopulator.java | 193 ++-- .../NativeGeneratorPatcherPopulator.java | 4 +- .../bukkit/PhysicsUpdaterPopulator.java | 4 +- .../bukkit/TerraformAnimalPopulator.java | 146 +-- .../coregen/bukkit/TerraformGenerator.java | 8 +- .../bukkit/TerraformStructurePopulator.java | 10 +- .../populatordata/PopulatorDataPostGen.java | 4 +- .../populatordata/PopulatorDataSpigotAPI.java | 4 +- .../java/org/terraform/data/MegaChunk.java | 4 +- .../org/terraform/data/SimpleLocation.java | 6 +- .../org/terraform/data/TerraformWorld.java | 10 +- .../org/terraform/main/LanguageManager.java | 25 +- .../main/java/org/terraform/main/TLogger.java | 6 +- .../main/TerraformCommandManager.java | 4 +- .../main/TerraformGeneratorPlugin.java | 44 +- .../terraform/main/config/ConfigLoader.java | 116 --- .../org/terraform/main/config/TConfig.java | 954 ++++++++++++++++++ .../terraform/main/config/TConfigOption.java | 625 ------------ .../populators/AmethystGeodePopulator.java | 4 +- .../terraform/populators/AnimalPopulator.java | 8 +- .../terraform/populators/OrePopulator.java | 4 +- .../terraform/small_items/PlantBuilder.java | 8 +- .../StructureBufferDistanceHandler.java | 4 +- .../terraform/structure/StructureLocator.java | 8 +- .../structure/StructureRegistry.java | 8 +- .../ancientcity/AncientCityPopulator.java | 10 +- .../CatacombsCasketRoomPopulator.java | 8 +- .../catacombs/CatacombsPathPopulator.java | 6 +- .../catacombs/CatacombsPopulator.java | 18 +- .../CatacombsSkeletonDungeonPopulator.java | 4 +- .../catacombs/CatacombsStandardPopulator.java | 6 +- .../structure/caves/LargeCavePopulator.java | 6 +- .../caves/LargeLushCavePopulator.java | 4 +- .../mineshaft/BadlandsMinePopulator.java | 10 +- .../mineshaft/MineshaftPathPopulator.java | 8 +- .../mineshaft/MineshaftPopulator.java | 10 +- .../mineshaft/SmeltingHallPopulator.java | 8 +- .../structure/monument/MonumentPopulator.java | 6 +- .../pillager/mansion/MansionPopulator.java | 16 +- .../mansion/MansionRoomSchematicParser.java | 6 +- .../mansion/MansionStandardRoomPiece.java | 4 +- .../pillager/outpost/OutpostPopulator.java | 6 +- .../structure/pyramid/Antechamber.java | 4 +- .../pyramid/ElderGuardianChamber.java | 4 +- .../structure/pyramid/PyramidPopulator.java | 12 +- .../terraform/structure/room/CarvedRoom.java | 6 +- .../structure/room/RoomLayoutGenerator.java | 6 +- .../structure/room/carver/CaveRoomCarver.java | 6 +- .../structure/small/DesertWellPopulator.java | 12 +- .../small/GiantPumpkinPopulator.java | 8 +- .../structure/small/WitchHutPopulator.java | 12 +- .../BuriedTreasurePopulator.java | 8 +- .../small/dungeon/SmallDungeonPopulator.java | 18 +- .../structure/small/igloo/IglooPopulator.java | 10 +- .../ruinedportal/RuinedPortalPopulator.java | 14 +- .../small/shipwreck/ShipwreckPopulator.java | 8 +- .../stronghold/StrongholdPopulator.java | 12 +- .../trailruins/TrailRuinsPopulator.java | 8 +- .../trialchamber/TrialChamberPopulator.java | 6 +- .../structure/village/VillagePopulator.java | 10 +- .../PlainsVillageAbstractRoomPopulator.java | 8 +- .../PlainsVillageAnimalPenPopulator.java | 8 +- .../PlainsVillageCropFarmPopulator.java | 6 +- .../plains/PlainsVillagePathPopulator.java | 4 +- .../plains/PlainsVillagePondPopulator.java | 10 +- .../plains/PlainsVillageWellPopulator.java | 4 +- .../PlainsVillageTempleJigsawBuilder.java | 4 +- .../PlainsVillageTempleLoungePiece.java | 6 +- .../villagehouse/VillageHousePopulator.java | 36 +- .../farmhouse/FarmhousePopulator.java | 8 +- .../warmoceanruins/WarmOceanAltarRoom.java | 4 +- .../warmoceanruins/WarmOceanDomeHutRoom.java | 2 +- .../warmoceanruins/WarmOceanLargeArcRoom.java | 24 +- .../WarmOceanRuinsPopulator.java | 8 +- .../org/terraform/tree/FractalLeaves.java | 4 +- .../terraform/tree/FractalTreeBuilder.java | 34 +- .../java/org/terraform/tree/FractalTypes.java | 18 +- .../org/terraform/tree/MushroomBuilder.java | 6 +- .../terraform/tree/NewFractalTreeBuilder.java | 14 +- .../org/terraform/tree/SaplingOverrider.java | 8 +- .../main/java/org/terraform/tree/TreeDB.java | 12 +- .../tree/VanillaMushroomBuilder.java | 4 +- .../java/org/terraform/utils/BlockUtils.java | 32 +- .../org/terraform/utils/CoralGenerator.java | 6 +- .../java/org/terraform/utils/MazeSpawner.java | 2 +- .../terraform/utils/StalactiteBuilder.java | 4 +- .../TerraformGeneratorMetricsHandler.java | 8 +- .../watchdog/TfgWatchdogSuppressant.java | 4 +- common/src/main/resources/plugin.yml | 1 + implementation/v1_18_R2/build.gradle.kts | 1 + .../terraform/v1_18_R2/NMSChunkGenerator.java | 10 +- .../org/terraform/v1_18_R2/PopulatorData.java | 4 +- implementation/v1_19_R3/build.gradle.kts | 1 + .../terraform/v1_19_R3/NMSChunkGenerator.java | 10 +- .../org/terraform/v1_19_R3/PopulatorData.java | 4 +- implementation/v1_20_R1/build.gradle.kts | 1 + .../v1_20_R1/MapRenderWorldProviderBiome.java | 4 +- .../terraform/v1_20_R1/NMSChunkGenerator.java | 10 +- implementation/v1_20_R2/build.gradle.kts | 1 + .../v1_20_R2/MapRenderWorldProviderBiome.java | 4 +- .../terraform/v1_20_R2/NMSChunkGenerator.java | 10 +- implementation/v1_20_R3/build.gradle.kts | 1 + .../v1_20_R3/MapRenderWorldProviderBiome.java | 4 +- .../terraform/v1_20_R3/NMSChunkGenerator.java | 10 +- .../org/terraform/v1_20_R3/PopulatorData.java | 4 +- implementation/v1_20_R4/build.gradle.kts | 1 + .../v1_20_R4/MapRenderWorldProviderBiome.java | 4 +- .../terraform/v1_20_R4/NMSChunkGenerator.java | 10 +- .../org/terraform/v1_20_R4/PopulatorData.java | 4 +- implementation/v1_21_R1/build.gradle.kts | 1 + .../v1_21_R1/MapRenderWorldProviderBiome.java | 4 +- .../terraform/v1_21_R1/NMSChunkGenerator.java | 12 +- .../org/terraform/v1_21_R1/PopulatorData.java | 4 +- 159 files changed, 1809 insertions(+), 1576 deletions(-) delete mode 100644 common/src/main/java/org/terraform/main/config/ConfigLoader.java create mode 100644 common/src/main/java/org/terraform/main/config/TConfig.java delete mode 100644 common/src/main/java/org/terraform/main/config/TConfigOption.java diff --git a/build.gradle.kts b/build.gradle.kts index 8c216340..d41d1cd9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,7 @@ subprojects { maven("https://repo.codemc.io/repository/nms/") // maven("https://libraries.minecraft.net/minecraft-server") maven("https://papermc.io/repo/repository/maven-public/") + maven("https://jitpack.io") } // Handle this inside each implementation as different minecraft versions support a different max jvm version // java { diff --git a/buildProj/build.gradle.kts b/buildProj/build.gradle.kts index e409f0a0..6c9b989a 100644 --- a/buildProj/build.gradle.kts +++ b/buildProj/build.gradle.kts @@ -17,6 +17,7 @@ dependencies { implementation(project(":implementation:v1_20_R3")) implementation(project(":implementation:v1_20_R4")) implementation(project(":implementation:v1_21_R1")) + implementation("com.github.AvarionMC:yaml:1.1.1") } tasks.shadowJar { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 3638dc18..eba656d7 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -4,6 +4,7 @@ dependencies { compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18-R0.1-SNAPSHOT") // compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.4-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } // Set this to the lowest compat in implementation diff --git a/common/src/main/java/org/terraform/biome/BiomeBank.java b/common/src/main/java/org/terraform/biome/BiomeBank.java index d3e9f071..a67d404b 100644 --- a/common/src/main/java/org/terraform/biome/BiomeBank.java +++ b/common/src/main/java/org/terraform/biome/BiomeBank.java @@ -18,7 +18,7 @@ import org.terraform.data.TWSimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; import org.terraform.utils.noise.NoiseCacheHandler; @@ -35,46 +35,46 @@ public enum BiomeBank { new SnowyMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.SNOWY, - TConfigOption.BIOME_SNOWY_MOUNTAINS_WEIGHT.getInt(), + TConfig.c.BIOME_SNOWY_MOUNTAINS_WEIGHT, new FrozenCavePopulator() ), BIRCH_MOUNTAINS(new BirchMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.COLD, - TConfigOption.BIOME_BIRCH_MOUNTAINS_WEIGHT.getInt() + TConfig.c.BIOME_BIRCH_MOUNTAINS_WEIGHT ), ROCKY_MOUNTAINS(new RockyMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.TRANSITION, - TConfigOption.BIOME_ROCKY_MOUNTAINS_WEIGHT.getInt() + TConfig.c.BIOME_ROCKY_MOUNTAINS_WEIGHT ), FORESTED_MOUNTAINS(new ForestedMountainsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), + TConfig.c.BIOME_FORESTED_MOUNTAINS_WEIGHT, new ForestedMountainsCavePopulator() ), SHATTERED_SAVANNA(new ShatteredSavannaHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt() + TConfig.c.BIOME_SHATTERED_SAVANNA_WEIGHT ), PAINTED_HILLS(new PaintedHillsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_PAINTED_HILLS_WEIGHT.getInt() + TConfig.c.BIOME_PAINTED_HILLS_WEIGHT ), BADLANDS_CANYON(new BadlandsCanyonHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt() + TConfig.c.BIOME_BADLANDS_MOUNTAINS_WEIGHT ), // For now, disabled by default. DESERT_MOUNTAINS( new DesertHillsHandler(), BiomeType.MOUNTAINOUS, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_DESERT_MOUNTAINS_WEIGHT.getInt() + TConfig.c.BIOME_DESERT_MOUNTAINS_WEIGHT ), // HIGH MOUNTAINOUS @@ -82,36 +82,36 @@ public enum BiomeBank { new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.SNOWY, - TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + TConfig.c.BIOME_JAGGED_PEAKS_WEIGHT, new FrozenCavePopulator() ), COLD_JAGGED_PEAKS(new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.COLD, - TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + TConfig.c.BIOME_JAGGED_PEAKS_WEIGHT, new FrozenCavePopulator() ), TRANSITION_JAGGED_PEAKS(new JaggedPeaksHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.TRANSITION, - TConfigOption.BIOME_JAGGED_PEAKS_WEIGHT.getInt(), + TConfig.c.BIOME_JAGGED_PEAKS_WEIGHT, new FrozenCavePopulator() ), FORESTED_PEAKS(new ForestedMountainsHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_FORESTED_MOUNTAINS_WEIGHT.getInt(), + TConfig.c.BIOME_FORESTED_MOUNTAINS_WEIGHT, new ForestedMountainsCavePopulator() ), SHATTERED_SAVANNA_PEAK(new ShatteredSavannaHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_SHATTERED_SAVANNA_WEIGHT.getInt() + TConfig.c.BIOME_SHATTERED_SAVANNA_WEIGHT ), BADLANDS_CANYON_PEAK(new BadlandsCanyonHandler(), BiomeType.HIGH_MOUNTAINOUS, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_BADLANDS_MOUNTAINS_WEIGHT.getInt() + TConfig.c.BIOME_BADLANDS_MOUNTAINS_WEIGHT ), // OCEANIC @@ -119,43 +119,43 @@ public enum BiomeBank { new OceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.TRANSITION, - TConfigOption.BIOME_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_OCEAN_WEIGHT ), BLACK_OCEAN(new BlackOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.TRANSITION, - TConfigOption.BIOME_BLACK_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_BLACK_OCEAN_WEIGHT ), COLD_OCEAN(new ColdOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.COLD, - TConfigOption.BIOME_COLD_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_COLD_OCEAN_WEIGHT ), FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.SNOWY, - TConfigOption.BIOME_FROZEN_OCEAN_WEIGHT.getInt(), + TConfig.c.BIOME_FROZEN_OCEAN_WEIGHT, new FrozenCavePopulator() ), WARM_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_WARM_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_WARM_OCEAN_WEIGHT ), HUMID_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_HUMID_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_HUMID_OCEAN_WEIGHT ), DRY_OCEAN(new WarmOceansHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_DRY_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DRY_OCEAN_WEIGHT ), CORAL_REEF_OCEAN(new CoralReefOceanHandler(BiomeType.OCEANIC), BiomeType.OCEANIC, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_CORALREEF_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_CORALREEF_OCEAN_WEIGHT ), // RIVERS (Don't include in selectBiome) @@ -184,143 +184,143 @@ public enum BiomeBank { new OceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, - TConfigOption.BIOME_DEEP_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_OCEAN_WEIGHT ), DEEP_COLD_OCEAN(new ColdOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.COLD, - TConfigOption.BIOME_DEEP_COLD_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_COLD_OCEAN_WEIGHT ), DEEP_BLACK_OCEAN(new BlackOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, - TConfigOption.BIOME_DEEP_BLACK_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_BLACK_OCEAN_WEIGHT ), DEEP_FROZEN_OCEAN(new FrozenOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.SNOWY, - TConfigOption.BIOME_DEEP_FROZEN_OCEAN_WEIGHT.getInt(), + TConfig.c.BIOME_DEEP_FROZEN_OCEAN_WEIGHT, new FrozenCavePopulator() ), DEEP_WARM_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_DEEP_WARM_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_WARM_OCEAN_WEIGHT ), DEEP_HUMID_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_DEEP_HUMID_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_HUMID_OCEAN_WEIGHT ), DEEP_DRY_OCEAN(new WarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_DEEP_DRY_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_DRY_OCEAN_WEIGHT ), DEEP_LUKEWARM_OCEAN(new LukewarmOceansHandler(BiomeType.DEEP_OCEANIC), BiomeType.DEEP_OCEANIC, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT.getInt() + TConfig.c.BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT ), MUSHROOM_ISLANDS(new MushroomIslandHandler(), BiomeType.DEEP_OCEANIC, BiomeClimate.TRANSITION, - TConfigOption.BIOME_MUSHROOM_ISLAND_WEIGHT.getInt() + TConfig.c.BIOME_MUSHROOM_ISLAND_WEIGHT ), // FLAT - PLAINS(new PlainsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_PLAINS_WEIGHT.getInt()), + PLAINS(new PlainsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfig.c.BIOME_PLAINS_WEIGHT), ELEVATED_PLAINS(new ElevatedPlainsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, - TConfigOption.BIOME_ELEVATED_PLAINS_WEIGHT.getInt() + TConfig.c.BIOME_ELEVATED_PLAINS_WEIGHT ), - GORGE(new GorgeHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfigOption.BIOME_GORGE_WEIGHT.getInt()), + GORGE(new GorgeHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, TConfig.c.BIOME_GORGE_WEIGHT), PETRIFIED_CLIFFS(new PetrifiedCliffsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, - TConfigOption.BIOME_PETRIFIEDCLIFFS_WEIGHT.getInt() + TConfig.c.BIOME_PETRIFIEDCLIFFS_WEIGHT ), ARCHED_CLIFFS(new ArchedCliffsHandler(), BiomeType.FLAT, BiomeClimate.TRANSITION, - TConfigOption.BIOME_ARCHED_CLIFFS_WEIGHT.getInt() + TConfig.c.BIOME_ARCHED_CLIFFS_WEIGHT ), SAVANNA(new SavannaHandler(), BiomeType.FLAT, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_SAVANNA_WEIGHT.getInt() + TConfig.c.BIOME_SAVANNA_WEIGHT ), MUDDY_BOG(new MuddyBogHandler(), BiomeType.FLAT, BiomeClimate.DRY_VEGETATION, - TConfigOption.BIOME_MUDDYBOG_WEIGHT.getInt() + TConfig.c.BIOME_MUDDYBOG_WEIGHT ), FOREST(new ForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_FOREST_WEIGHT.getInt() + TConfig.c.BIOME_FOREST_WEIGHT ), JUNGLE(new JungleHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_JUNGLE_WEIGHT.getInt() + TConfig.c.BIOME_JUNGLE_WEIGHT ), BAMBOO_FOREST(new BambooForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_BAMBOO_FOREST_WEIGHT.getInt() + TConfig.c.BIOME_BAMBOO_FOREST_WEIGHT ), - DESERT(new DesertHandler(), BiomeType.FLAT, BiomeClimate.HOT_BARREN, TConfigOption.BIOME_DESERT_WEIGHT.getInt()), + DESERT(new DesertHandler(), BiomeType.FLAT, BiomeClimate.HOT_BARREN, TConfig.c.BIOME_DESERT_WEIGHT), BADLANDS(new BadlandsHandler(), BiomeType.FLAT, BiomeClimate.HOT_BARREN, - TConfigOption.BIOME_BADLANDS_WEIGHT.getInt() + TConfig.c.BIOME_BADLANDS_WEIGHT ), ERODED_PLAINS(new ErodedPlainsHandler(), BiomeType.FLAT, BiomeClimate.COLD, - TConfigOption.BIOME_ERODED_PLAINS_WEIGHT.getInt() + TConfig.c.BIOME_ERODED_PLAINS_WEIGHT ), SCARLET_FOREST(new ScarletForestHandler(), BiomeType.FLAT, BiomeClimate.COLD, - TConfigOption.BIOME_SCARLETFOREST_WEIGHT.getInt() + TConfig.c.BIOME_SCARLETFOREST_WEIGHT ), CHERRY_GROVE(new CherryGroveHandler(), BiomeType.FLAT, BiomeClimate.COLD, - TConfigOption.BIOME_CHERRYGROVE_WEIGHT.getInt() + TConfig.c.BIOME_CHERRYGROVE_WEIGHT ), - TAIGA(new TaigaHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfigOption.BIOME_TAIGA_WEIGHT.getInt()), + TAIGA(new TaigaHandler(), BiomeType.FLAT, BiomeClimate.COLD, TConfig.c.BIOME_TAIGA_WEIGHT), SNOWY_TAIGA(new SnowyTaigaHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, - TConfigOption.BIOME_SNOWY_TAIGA_WEIGHT.getInt(), + TConfig.c.BIOME_SNOWY_TAIGA_WEIGHT, new FrozenCavePopulator() ), SNOWY_WASTELAND(new SnowyWastelandHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, - TConfigOption.BIOME_SNOWY_WASTELAND_WEIGHT.getInt(), + TConfig.c.BIOME_SNOWY_WASTELAND_WEIGHT, new FrozenCavePopulator() ), ICE_SPIKES(new IceSpikesHandler(), BiomeType.FLAT, BiomeClimate.SNOWY, - TConfigOption.BIOME_ICE_SPIKES_WEIGHT.getInt(), + TConfig.c.BIOME_ICE_SPIKES_WEIGHT, new FrozenCavePopulator() ), DARK_FOREST(new DarkForestHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_DARK_FOREST_WEIGHT.getInt() + TConfig.c.BIOME_DARK_FOREST_WEIGHT ), - SWAMP(new SwampHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfigOption.BIOME_SWAMP_WEIGHT.getInt()), + SWAMP(new SwampHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, TConfig.c.BIOME_SWAMP_WEIGHT), MANGROVE(new MangroveHandler(), BiomeType.FLAT, BiomeClimate.HUMID_VEGETATION, - TConfigOption.BIOME_MANGROVE_WEIGHT.getInt() + TConfig.c.BIOME_MANGROVE_WEIGHT ), // BEACHES (Don't include in selectBiome) @@ -606,36 +606,36 @@ else if (height >= TerraformGenerator.seaLevel && height <= TerraformGenerator.s public static void initSinglesConfig() { try { - singleLand = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_TERRESTRIAL_TYPE.getString() - .toUpperCase(Locale.ENGLISH)); + singleLand = BiomeBank.valueOf(TConfig.c.BIOME_SINGLE_TERRESTRIAL_TYPE + .toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { singleLand = null; } try { - singleOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_OCEAN_TYPE.getString() - .toUpperCase(Locale.ENGLISH)); + singleOcean = BiomeBank.valueOf(TConfig.c.BIOME_SINGLE_OCEAN_TYPE + .toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { singleOcean = null; } try { - singleDeepOcean = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_DEEPOCEAN_TYPE.getString() - .toUpperCase(Locale.ENGLISH)); + singleDeepOcean = BiomeBank.valueOf(TConfig.c.BIOME_SINGLE_DEEPOCEAN_TYPE + .toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { singleDeepOcean = null; } try { - singleMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_MOUNTAIN_TYPE.getString() - .toUpperCase(Locale.ENGLISH)); + singleMountain = BiomeBank.valueOf(TConfig.c.BIOME_SINGLE_MOUNTAIN_TYPE + .toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { singleMountain = null; } try { - singleHighMountain = BiomeBank.valueOf(TConfigOption.BIOME_SINGLE_HIGHMOUNTAIN_TYPE.getString() - .toUpperCase(Locale.ENGLISH)); + singleHighMountain = BiomeBank.valueOf(TConfig.c.BIOME_SINGLE_HIGHMOUNTAIN_TYPE + .toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { singleHighMountain = null; @@ -672,12 +672,12 @@ public static boolean isBiomeEnabled(@NotNull BiomeBank bank) { BiomeClimate climate = BiomeClimate.selectClimate(temperature, moisture); double oceanicNoise = section.getOceanLevel(); - if (oceanicNoise < 0 || TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat() < 0) { + if (oceanicNoise < 0 || TConfig.c.BIOME_OCEANIC_THRESHOLD < 0) { oceanicNoise = Math.abs(oceanicNoise); - if (oceanicNoise >= TConfigOption.BIOME_DEEP_OCEANIC_THRESHOLD.getFloat()) { + if (oceanicNoise >= TConfig.c.BIOME_DEEP_OCEANIC_THRESHOLD) { targetType = BiomeType.DEEP_OCEANIC; } - else if (oceanicNoise >= TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat()) { + else if (oceanicNoise >= TConfig.c.BIOME_OCEANIC_THRESHOLD) { targetType = BiomeType.OCEANIC; } } @@ -685,10 +685,10 @@ else if (oceanicNoise >= TConfigOption.BIOME_OCEANIC_THRESHOLD.getFloat()) { // If it isn't an ocean, mountains may be plausible. double mountainousNoise = section.getMountainLevel(); if (mountainousNoise > 0) { - if (mountainousNoise >= TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat()) { + if (mountainousNoise >= TConfig.c.BIOME_HIGH_MOUNTAINOUS_THRESHOLD) { targetType = BiomeType.HIGH_MOUNTAINOUS; } - else if (mountainousNoise >= TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat()) { + else if (mountainousNoise >= TConfig.c.BIOME_MOUNTAINOUS_THRESHOLD) { targetType = BiomeType.MOUNTAINOUS; } } @@ -753,7 +753,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_BEACH.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_BEACH); } case DEEP_OCEANIC -> { TerraformGeneratorPlugin.logger.info("Defaulted for deep oceanic: " @@ -764,7 +764,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_DEEPOCEANIC.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_DEEPOCEANIC); } case FLAT -> { TerraformGeneratorPlugin.logger.info("Defaulted for flat: " @@ -775,7 +775,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_FLAT.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_FLAT); } case MOUNTAINOUS -> { TerraformGeneratorPlugin.logger.info("Defaulted for mountainous: " @@ -786,7 +786,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_MOUNTAINOUS.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_MOUNTAINOUS); } case OCEANIC -> { TerraformGeneratorPlugin.logger.info("Defaulted for ocean: " @@ -797,7 +797,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_OCEANIC.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_OCEANIC); } case RIVER -> { TerraformGeneratorPlugin.logger.info("Defaulted for river: " @@ -808,7 +808,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_RIVER.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_RIVER); } case HIGH_MOUNTAINOUS -> { TerraformGeneratorPlugin.logger.info("Defaulted for high mountainous: " @@ -819,7 +819,7 @@ else if (biome.getType() == BiomeType.DEEP_OCEANIC + climate + ":" + targetType); - yield BiomeBank.valueOf(TConfigOption.BIOME_DEFAULT_HIGHMOUNTAINOUS.getString()); + yield BiomeBank.valueOf(TConfig.c.BIOME_DEFAULT_HIGHMOUNTAINOUS); } }; } diff --git a/common/src/main/java/org/terraform/biome/BiomeClimate.java b/common/src/main/java/org/terraform/biome/BiomeClimate.java index f39faa43..3553e043 100644 --- a/common/src/main/java/org/terraform/biome/BiomeClimate.java +++ b/common/src/main/java/org/terraform/biome/BiomeClimate.java @@ -1,49 +1,58 @@ package org.terraform.biome; import org.jetbrains.annotations.NotNull; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.Range; public enum BiomeClimate { // Tree-Dense areas - HUMID_VEGETATION(Range.between(TConfigOption.CLIMATE_HUMIDVEGETATION_MINTEMP.getDouble(), - TConfigOption.CLIMATE_HUMIDVEGETATION_MAXTEMP.getDouble() - ), Range.between(TConfigOption.CLIMATE_HUMIDVEGETATION_MINMOIST.getDouble(), - TConfigOption.CLIMATE_HUMIDVEGETATION_MAXMOIST.getDouble() + HUMID_VEGETATION(Range.between( + TConfig.c.CLIMATE_HUMIDVEGETATION_MINTEMP, + TConfig.c.CLIMATE_HUMIDVEGETATION_MAXTEMP + ), Range.between( + TConfig.c.CLIMATE_HUMIDVEGETATION_MINMOIST, + TConfig.c.CLIMATE_HUMIDVEGETATION_MAXMOIST ), 2), // Savannas - DRY_VEGETATION(Range.between(TConfigOption.CLIMATE_DRYVEGETATION_MINTEMP.getDouble(), - TConfigOption.CLIMATE_DRYVEGETATION_MAXTEMP.getDouble() - ), Range.between(TConfigOption.CLIMATE_DRYVEGETATION_MINMOIST.getDouble(), - TConfigOption.CLIMATE_DRYVEGETATION_MAXMOIST.getDouble() + DRY_VEGETATION(Range.between( + TConfig.c.CLIMATE_DRYVEGETATION_MINTEMP, + TConfig.c.CLIMATE_DRYVEGETATION_MAXTEMP + ), Range.between( + TConfig.c.CLIMATE_DRYVEGETATION_MINMOIST, + TConfig.c.CLIMATE_DRYVEGETATION_MAXMOIST ), 1), // Deserts - HOT_BARREN(Range.between(TConfigOption.CLIMATE_HOTBARREN_MINTEMP.getDouble(), - TConfigOption.CLIMATE_HOTBARREN_MAXTEMP.getDouble() + HOT_BARREN(Range.between( + TConfig.c.CLIMATE_HOTBARREN_MINTEMP, + TConfig.c.CLIMATE_HOTBARREN_MAXTEMP ), - Range.between(TConfigOption.CLIMATE_HOTBARREN_MINMOIST.getDouble(), - TConfigOption.CLIMATE_HOTBARREN_MAXMOIST.getDouble() + Range.between( + TConfig.c.CLIMATE_HOTBARREN_MINMOIST, + TConfig.c.CLIMATE_HOTBARREN_MAXMOIST ), 2 ), // Cold biomes - taigas, maybe eroded plains - COLD(Range.between(TConfigOption.CLIMATE_COLD_MINTEMP.getDouble(), TConfigOption.CLIMATE_COLD_MAXTEMP.getDouble()), - Range.between(TConfigOption.CLIMATE_COLD_MINMOIST.getDouble(), - TConfigOption.CLIMATE_COLD_MAXMOIST.getDouble() + COLD(Range.between(TConfig.c.CLIMATE_COLD_MINTEMP, TConfig.c.CLIMATE_COLD_MAXTEMP), + Range.between( + TConfig.c.CLIMATE_COLD_MINMOIST, + TConfig.c.CLIMATE_COLD_MAXMOIST ), 1 ), // Any snowy biomes. - SNOWY(Range.between(TConfigOption.CLIMATE_SNOWY_MINTEMP.getDouble(), - TConfigOption.CLIMATE_SNOWY_MAXTEMP.getDouble() + SNOWY(Range.between( + TConfig.c.CLIMATE_SNOWY_MINTEMP, + TConfig.c.CLIMATE_SNOWY_MAXTEMP ), - Range.between(TConfigOption.CLIMATE_SNOWY_MINMOIST.getDouble(), - TConfigOption.CLIMATE_SNOWY_MAXMOIST.getDouble() + Range.between( + TConfig.c.CLIMATE_SNOWY_MINMOIST, + TConfig.c.CLIMATE_SNOWY_MAXMOIST ), 2 ), diff --git a/common/src/main/java/org/terraform/biome/BiomeSection.java b/common/src/main/java/org/terraform/biome/BiomeSection.java index de0f97da..3dcff881 100644 --- a/common/src/main/java/org/terraform/biome/BiomeSection.java +++ b/common/src/main/java/org/terraform/biome/BiomeSection.java @@ -5,7 +5,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; @@ -17,7 +17,7 @@ public class BiomeSection { // A BiomeSection is 128 blocks wide (Default of bitshift 7). - public static final int bitshifts = TConfigOption.BIOME_SECTION_BITSHIFTS.getInt(); + public static final int bitshifts = TConfig.c.BIOME_SECTION_BITSHIFTS; public static final int sectionWidth = (int) (1 << bitshifts); public static final int minSize = sectionWidth; public static final int dominanceThreshold = (int) (0.35 * sectionWidth); @@ -119,7 +119,7 @@ protected BiomeSection(TerraformWorld tw, int x, int z, boolean useSectionCoords public static @NotNull BiomeSection getMostDominantSection(@NotNull TerraformWorld tw, int x, int z) { - double dither = TConfigOption.BIOME_DITHER.getDouble(); + double dither = TConfig.c.BIOME_DITHER; Random locationBasedRandom = new Random(Objects.hash(tw.getSeed(), x, z)); SimpleLocation target = new SimpleLocation(x, 0, z); BiomeSection homeSection = BiomeBank.getBiomeSectionFromBlockCoords(tw, x, z); @@ -169,8 +169,8 @@ protected void doCalculations() { } private @Nullable BiomeBank parseBiomeBank() { - temperature = 3.0f * 2.5f * tw.getTemperatureOctave().GetNoise(this.x, this.z); - moisture = 3.0f * 2.5f * tw.getMoistureOctave().GetNoise(this.x, this.z); + temperature = 3f * 2.5f * tw.getTemperatureOctave().GetNoise(this.x, this.z); + moisture = 3f * 2.5f * tw.getMoistureOctave().GetNoise(this.x, this.z); return BiomeBank.selectBiome( this, diff --git a/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java b/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java index 77676cf4..eeeb387e 100644 --- a/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java +++ b/common/src/main/java/org/terraform/biome/beach/MushroomBeachHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.tree.MushroomBuilder; @@ -79,7 +79,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, data.getChunkX(), data.getChunkZ(), 15, - 0.30f + 0.3f ); // Giant mushrooms @@ -98,7 +98,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, }; if (HeightMap.getTrueHeightGradient(data, sLoc.getX(), sLoc.getZ(), 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + <= TConfig.c.MISC_TREES_GRADIENT_LIMIT) { new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); } diff --git a/common/src/main/java/org/terraform/biome/beach/OasisBeach.java b/common/src/main/java/org/terraform/biome/beach/OasisBeach.java index 548e3404..391e897f 100644 --- a/common/src/main/java/org/terraform/biome/beach/OasisBeach.java +++ b/common/src/main/java/org/terraform/biome/beach/OasisBeach.java @@ -7,7 +7,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.TreeDB; import org.terraform.utils.GenUtils; @@ -20,8 +20,8 @@ * This class contains functions for oases, it's not a biome handler. */ public class OasisBeach { - public static final double oasisThreshold = (2 - TConfigOption.BIOME_OASIS_COMMONNESS.getDouble()) * 0.31; - private static final float oasisFrequency = TConfigOption.BIOME_OASIS_FREQUENCY.getFloat(); + public static final double oasisThreshold = (2 - TConfig.c.BIOME_OASIS_COMMONNESS) * 0.31; + private static final float oasisFrequency = TConfig.c.BIOME_OASIS_FREQUENCY; public static float getOasisNoise(TerraformWorld world, int x, int z) { FastNoise lushRiversNoise = NoiseCacheHandler.getNoise(world, @@ -127,7 +127,7 @@ public static void createBush(@NotNull Random random, Material stem, double density) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java b/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java index 52012053..605d800c 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/CaveClusterRegistry.java @@ -1,21 +1,21 @@ package org.terraform.biome.cavepopulators; import org.jetbrains.annotations.NotNull; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.Random; public enum CaveClusterRegistry { LUSH(9527213, - TConfigOption.BIOME_CAVE_LUSHCLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXPERTUB.getFloat() + TConfig.c.BIOME_CAVE_LUSHCLUSTER_SEPARATION, + (float)TConfig.c.BIOME_CAVE_LUSHCLUSTER_MAXPERTUB ), DRIPSTONE(5902907, - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB.getFloat() + TConfig.c.BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION, + (float)TConfig.c.BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB ), CRYSTALLINE(4427781, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB.getFloat() + TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION, + (float)TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB ), FLUID(79183628, 40, 0.2f), ; @@ -32,20 +32,20 @@ public enum CaveClusterRegistry { public @NotNull AbstractCaveClusterPopulator getPopulator(@NotNull Random random) { return switch (this) { case LUSH -> new LushClusterCavePopulator(GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_LUSHCLUSTER_MAXSIZE.getInt() + TConfig.c.BIOME_CAVE_LUSHCLUSTER_MINSIZE, + TConfig.c.BIOME_CAVE_LUSHCLUSTER_MAXSIZE ), false); case DRIPSTONE -> new DripstoneClusterCavePopulator(GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE.getInt() + TConfig.c.BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE, + TConfig.c.BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE )); case CRYSTALLINE -> new CrystallineClusterCavePopulator(GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt() + TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE, + TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE )); case FLUID -> new CaveFluidClusterPopulator(GenUtils.randInt(random, - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE.getInt(), - TConfigOption.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE.getInt() + TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE, + TConfig.c.BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE )); }; diff --git a/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java b/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java index fa275536..745ff3c9 100644 --- a/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java +++ b/common/src/main/java/org/terraform/biome/cavepopulators/LushClusterCavePopulator.java @@ -9,7 +9,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.TreeDB; import org.terraform.utils.BlockUtils; @@ -128,7 +128,7 @@ public void oneUnit(@NotNull TerraformWorld tw, } } else if (Version.isAtLeast(17) && GenUtils.chance(random, 1, 7)) { // Dripleaves - if (TConfigOption.arePlantsEnabled()) { + if (TConfig.arePlantsEnabled()) { if (random.nextBoolean()) { new DirectionalBuilder(Material.BIG_DRIPLEAF).setFacing(BlockUtils.getDirectBlockFace(random)) .apply(floor.getUp()); @@ -178,7 +178,7 @@ else if (GenUtils.chance(random, 1, 7)) if (BlockUtils.isStoneLike(rel.getType())) { rel.setType(Material.MOSS_BLOCK); - if (TConfigOption.arePlantsEnabled() && BlockUtils.isAir(target.getType()) && GenUtils.chance( + if (TConfig.arePlantsEnabled() && BlockUtils.isAir(target.getType()) && GenUtils.chance( random, 1, 5 diff --git a/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java b/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java index a51ec890..19e96558 100644 --- a/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ArchedCliffsHandler.java @@ -16,7 +16,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -119,7 +119,7 @@ public void populateSmallItems(TerraformWorld world, // If an underside was valid, you can check the upper area for // decorating overhangs for (BlockFace face : BlockUtils.directBlockFaces) { - if (TConfigOption.arePlantsEnabled() && target.getRelative(face).getType() == Material.AIR) { + if (TConfig.arePlantsEnabled() && target.getRelative(face).getType() == Material.AIR) { if (GenUtils.chance(random, 1, 5)) // TODO:PlantBuilder { diff --git a/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java b/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java index 1b364d9d..71348a2f 100644 --- a/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/BadlandsHandler.java @@ -15,7 +15,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -27,11 +27,11 @@ import java.util.Random; public class BadlandsHandler extends BiomeHandler { - static final int sandRadius = TConfigOption.BIOME_BADLANDS_PLATEAU_SAND_RADIUS.getInt(); - static final int plateauHeight = TConfigOption.BIOME_BADLANDS_PLATEAU_HEIGHT.getInt(); - static final float plateauFrequency = TConfigOption.BIOME_BADLANDS_PLATEAU_FREQUENCY.getFloat(); - static final double plateauThreshold = TConfigOption.BIOME_BADLANDS_PLATEAU_THRESHOLD.getDouble(); - static final double plateauCommonness = TConfigOption.BIOME_BADLANDS_PLATEAU_COMMONNESS.getDouble(); + static final int sandRadius = TConfig.c.BIOME_BADLANDS_PLATEAU_SAND_RADIUS; + static final int plateauHeight = TConfig.c.BIOME_BADLANDS_PLATEAU_HEIGHT; + static final float plateauFrequency = TConfig.c.BIOME_BADLANDS_PLATEAU_FREQUENCY; + static final double plateauThreshold = TConfig.c.BIOME_BADLANDS_PLATEAU_THRESHOLD; + static final double plateauCommonness = TConfig.c.BIOME_BADLANDS_PLATEAU_COMMONNESS; static private BiomeBlender riversBlender; static private BiomeBlender plateauBlender; @@ -324,7 +324,7 @@ else if ((int) graduated * plateauHeight == y + 2) { } void spawnDeadTree(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java b/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java index 210e2f0f..25eeb0c8 100644 --- a/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/BambooForestHandler.java @@ -10,7 +10,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -105,7 +105,7 @@ public void populateLargeItems(TerraformWorld tw, @NotNull Random random, @NotNu if (data.getType(x, y, z) == Material.GRASS_BLOCK || data.getType(x, y, z) == Material.PODZOL) { // Small grass poffs - if (TConfigOption.arePlantsEnabled() && GenUtils.chance(random, 1, 50)) { + if (TConfig.arePlantsEnabled() && GenUtils.chance(random, 1, 50)) { BlockUtils.replaceSphere(random.nextInt(424444), 2, 3, @@ -117,7 +117,7 @@ public void populateLargeItems(TerraformWorld tw, @NotNull Random random, @NotNu } // Bamboo - if (TConfigOption.arePlantsEnabled() + if (TConfig.arePlantsEnabled() && GenUtils.chance(random, 1, 3) && BlockUtils.isDirtLike(data.getType(x, y, z))) { diff --git a/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java b/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java index 141fd129..b0531d47 100644 --- a/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/CherryGroveHandler.java @@ -11,7 +11,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -65,7 +65,7 @@ public void populateSmallItems(TerraformWorld world, if (GenUtils.chance(random, 2, 10)) { // Grass if (GenUtils.chance(random, 8, 10)) { // Pink petals. No longer generate tall grass. - if (Version.isAtLeast(20) && TConfigOption.arePlantsEnabled() && GenUtils.chance(random, 6, 10)) { + if (Version.isAtLeast(20) && TConfig.arePlantsEnabled() && GenUtils.chance(random, 6, 10)) { data.setBlockData( rawX, surfaceY + 1, diff --git a/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java b/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java index 4da9c7f0..f54f4e41 100644 --- a/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/DarkForestHandler.java @@ -11,7 +11,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.tree.MushroomBuilder; @@ -93,7 +93,7 @@ public void populateSmallItems(TerraformWorld tw, int rawZ, @NotNull PopulatorDataAbstract data) { - boolean spawnHeads = TConfigOption.BIOME_DARK_FOREST_SPAWN_HEADS.getBoolean() && GenUtils.chance( + boolean spawnHeads = TConfig.c.BIOME_DARK_FOREST_SPAWN_HEADS && GenUtils.chance( random, 1, 100 @@ -120,7 +120,7 @@ public void populateSmallItems(TerraformWorld tw, } } - if (spawnHeads && TConfigOption.areDecorationsEnabled() && GenUtils.chance(random, 1, 50)) { + if (spawnHeads && TConfig.areDecorationsEnabled() && GenUtils.chance(random, 1, 50)) { if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { Rotatable skull = (Rotatable) Bukkit.createBlockData(Material.PLAYER_HEAD); skull.setRotation(BlockUtils.getXZPlaneBlockFace(random)); @@ -157,7 +157,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, }; new MushroomBuilder(type).build(tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); } - else if (TConfigOption.TREES_DARK_FOREST_BIG_ENABLED.getBoolean()) { + else if (TConfig.c.TREES_DARK_FOREST_BIG_ENABLED) { FractalTypes.Tree.DARK_OAK_BIG_TOP.build(tw, new SimpleBlock(data, sLoc)); } } diff --git a/common/src/main/java/org/terraform/biome/flat/DesertHandler.java b/common/src/main/java/org/terraform/biome/flat/DesertHandler.java index 072c849e..7ad5e370 100644 --- a/common/src/main/java/org/terraform/biome/flat/DesertHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/DesertHandler.java @@ -13,7 +13,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -117,7 +117,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, } public void spawnRibCage(@NotNull Random random, @NotNull SimpleBlock target) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } @@ -131,7 +131,7 @@ public void spawnRibCage(@NotNull Random random, @NotNull SimpleBlock target) { interval += 1; } - float ribSizeMultiplier = 1.0f; + float ribSizeMultiplier = 1f; for (int segmentIndex = 0; segmentIndex < spineLength; segmentIndex++) { Wall seg = new Wall(target.getRelative(direction, segmentIndex), direction); diff --git a/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java index 237fc18c..81ccdd8d 100644 --- a/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ElevatedPlainsHandler.java @@ -13,7 +13,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalLeaves; import org.terraform.tree.FractalTreeBuilder; @@ -74,7 +74,7 @@ public void populateSmallItems(TerraformWorld world, @NotNull PopulatorDataAbstract data) { boolean gradient = HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble(); + <= TConfig.c.MISC_TREES_GRADIENT_LIMIT; if (gradient) { data.setType(rawX, surfaceY, rawZ, Material.GRASS_BLOCK); if (random.nextBoolean()) { diff --git a/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java index e0037d2c..cb48a860 100644 --- a/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ErodedPlainsHandler.java @@ -11,7 +11,7 @@ import org.terraform.coregen.HeightMap; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.NoiseCacheHandler; @@ -21,7 +21,7 @@ public class ErodedPlainsHandler extends BiomeHandler { static final BiomeHandler plainsHandler = BiomeBank.PLAINS.getHandler(); - static final boolean slabs = TConfigOption.MISC_USE_SLABS_TO_SMOOTH.getBoolean(); + static final boolean slabs = TConfig.c.MISC_USE_SLABS_TO_SMOOTH; static BiomeBlender biomeBlender; private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { diff --git a/common/src/main/java/org/terraform/biome/flat/ForestHandler.java b/common/src/main/java/org/terraform/biome/flat/ForestHandler.java index 78f91b9b..4e629e9e 100644 --- a/common/src/main/java/org/terraform/biome/flat/ForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ForestHandler.java @@ -8,7 +8,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; @@ -130,7 +130,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { // Most forest chunks have a big tree - if (TConfigOption.TREES_FOREST_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 6, 10)) { + if (TConfig.c.TREES_FOREST_BIG_ENABLED && GenUtils.chance(random, 6, 10)) { int treeX = GenUtils.randInt(random, 2, 12) + data.getChunkX() * 16; int treeZ = GenUtils.randInt(random, 2, 12) + data.getChunkZ() * 16; if (data.getBiome(treeX, treeZ) == getBiome()) { diff --git a/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java b/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java index 0477c418..7d2d2d0b 100644 --- a/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/GorgeHandler.java @@ -15,7 +15,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; @@ -26,7 +26,7 @@ public class GorgeHandler extends BiomeHandler { static final BiomeHandler plainsHandler = BiomeBank.PLAINS.getHandler(); - static final boolean slabs = TConfigOption.MISC_USE_SLABS_TO_SMOOTH.getBoolean(); + static final boolean slabs = TConfig.c.MISC_USE_SLABS_TO_SMOOTH; static BiomeBlender biomeBlender; private static @NotNull BiomeBlender getBiomeBlender(TerraformWorld tw) { diff --git a/common/src/main/java/org/terraform/biome/flat/JungleHandler.java b/common/src/main/java/org/terraform/biome/flat/JungleHandler.java index 030050d4..1bdadb78 100644 --- a/common/src/main/java/org/terraform/biome/flat/JungleHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/JungleHandler.java @@ -13,7 +13,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.schematic.TerraSchematic; import org.terraform.small_items.PlantBuilder; @@ -38,7 +38,7 @@ public static void createBush(@NotNull PopulatorDataAbstract data, int oriY, int oriZ) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -156,7 +156,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - if (TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) { + if (TConfig.c.TREES_JUNGLE_BIG_ENABLED) { for (SimpleLocation sLoc : bigTrees) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); @@ -185,7 +185,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, sLoc.getY(), sLoc.getZ()))) { - if (GenUtils.chance(random, 1000 - TConfigOption.BIOME_JUNGLE_STATUE_CHANCE.getInt(), 1000)) { + if (GenUtils.chance(random, 1000 - TConfig.c.BIOME_JUNGLE_STATUE_CHANCE, 1000)) { TreeDB.spawnSmallJungleTree(false, tw, data, sLoc.getX(), sLoc.getY(), sLoc.getZ()); } else { @@ -243,7 +243,7 @@ private void spawnStatue(@NotNull Random random, @NotNull PopulatorDataAbstract data, @NotNull SimpleLocation sLoc) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java b/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java index bbfddda0..70aae7c3 100644 --- a/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/MangroveHandler.java @@ -12,7 +12,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.tree.TreeDB; @@ -134,7 +134,7 @@ public void populateSmallItems(TerraformWorld tw, CoralGenerator.generateKelpGrowth(data, rawX, surfaceY + 1, rawZ); } - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } if (GenUtils.chance(random, 5, 1000)) { diff --git a/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java b/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java index 03e41dcd..912cd6a6 100644 --- a/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/MuddyBogHandler.java @@ -12,7 +12,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.tree.MushroomBuilder; @@ -85,7 +85,7 @@ else if (GenUtils.chance(random, 1, 85)) { else if (GenUtils.chance(random, 1, 85)) { PlantBuilder.TALL_GRASS.build(data, rawX, surfaceY + 1, rawZ); } - else if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(random, 1, 300)) {// Dripstone Cluster + else if (TConfig.areDecorationsEnabled() && GenUtils.chance(random, 1, 300)) {// Dripstone Cluster BlockUtils.replaceCircularPatch(random.nextInt(9999), 2.5f, block, Material.DRIPSTONE_BLOCK); if (GenUtils.chance(random, 1, 7)) { BlockUtils.upLPointedDripstone(GenUtils.randInt(random, 2, 4), block.getUp()); diff --git a/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java b/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java index a0ba205a..4c3e73e9 100644 --- a/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/PlainsHandler.java @@ -8,7 +8,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -141,7 +141,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, } else { // Poffs sLoc.setY(highestY); - if (TConfigOption.arePlantsEnabled() + if (TConfig.arePlantsEnabled() && data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) { diff --git a/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java b/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java index abfd25c7..907911c0 100644 --- a/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SavannaHandler.java @@ -8,7 +8,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -111,7 +111,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, // large trees SimpleLocation[] trees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 112, 0.6f); - if (TConfigOption.TREES_SAVANNA_BIG_ENABLED.getBoolean()) { + if (TConfig.c.TREES_SAVANNA_BIG_ENABLED) { for (SimpleLocation sLoc : trees) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); @@ -150,7 +150,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, } // Grass Poffs - if (TConfigOption.arePlantsEnabled()) { + if (TConfig.arePlantsEnabled()) { SimpleLocation[] poffs = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 31); for (SimpleLocation sLoc : poffs) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); diff --git a/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java b/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java index 03c49352..b5ab9e72 100644 --- a/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/ScarletForestHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -89,7 +89,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, Random random, @NotNu if (tw.getBiomeBank(sLoc.getX(), sLoc.getZ()) == BiomeBank.SCARLET_FOREST && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ()))) { - if (TConfigOption.TREES_SCARLET_BIG_ENABLED.getBoolean()) { + if (TConfig.c.TREES_SCARLET_BIG_ENABLED) { new FractalTreeBuilder(FractalTypes.Tree.SCARLET_BIG).build(tw, data, sLoc.getX(), diff --git a/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java b/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java index 18d8663a..6f46e849 100644 --- a/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SnowyTaigaHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; @@ -129,7 +129,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees - if (TConfigOption.TREES_TAIGA_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { + if (TConfig.c.TREES_TAIGA_BIG_ENABLED && GenUtils.chance(random, 1, 20)) { FractalTypes.Tree.TAIGA_BIG.build( tw, new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()), diff --git a/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java b/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java index 3d4d00d4..2f8ba914 100644 --- a/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/SnowyWastelandHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; @@ -87,7 +87,7 @@ public void populateLargeItems(@NotNull TerraformWorld world, continue; } - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { BlockUtils.spawnPillar(random, data, sLoc.getX(), sLoc.getY(), sLoc.getZ(), Material.SPRUCE_LOG, 6, 8); } diff --git a/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java b/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java index 85e1b837..fd0b6b4d 100644 --- a/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java +++ b/common/src/main/java/org/terraform/biome/flat/TaigaHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTypes; import org.terraform.utils.BlockUtils; @@ -109,7 +109,7 @@ public void populateSmallItems(TerraformWorld tw, if (BlockUtils.isDirtLike(data.getType(rawX, surfaceY, rawZ))) { // Generate sweet berry bushes - if (TConfigOption.arePlantsEnabled() + if (TConfig.arePlantsEnabled() && sweetBerriesNoise.GetNoise(rawX, rawZ) > 0.3 && sweetBerriesNoise.GetNoise(rawX, rawZ) * random.nextFloat() > 0.35) { @@ -158,7 +158,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees - if (TConfigOption.TREES_TAIGA_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { + if (TConfig.c.TREES_TAIGA_BIG_ENABLED && GenUtils.chance(random, 1, 20)) { if (FractalTypes.Tree.TAIGA_BIG.build(tw, new SimpleBlock(data, sLoc.getX(), sLoc.getY(), sLoc.getZ()) )) diff --git a/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java b/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java index 8a63096f..15c63b41 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/AbstractMountainHandler.java @@ -6,7 +6,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.Random; @@ -22,8 +22,8 @@ protected double getPeakMultiplier(@NotNull BiomeSection section, @NotNull Rando // boolean surroundedByMountains = true; - float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); - // float hmt = TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD.getFloat(); + float mt = TConfig.c.BIOME_MOUNTAINOUS_THRESHOLD; + // float hmt = TConfigOption.BIOME_HIGH_MOUNTAINOUS_THRESHOLD; // Check direct faces, not diagonals for (int[] rel : new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}) { @@ -75,7 +75,7 @@ public double calculateHeight(@NotNull TerraformWorld tw, int x, int z) { double minMultiplier = 1; BiomeSubSection subSect = sect.getSubSection(x, z); - float mt = TConfigOption.BIOME_MOUNTAINOUS_THRESHOLD.getFloat(); + float mt = TConfig.c.BIOME_MOUNTAINOUS_THRESHOLD; switch (subSect) { case NEGATIVE_X: if (sect.getRelative(-1, 0).getOceanLevel() >= mt) { diff --git a/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java index f0dfe46f..dec36dc8 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/BirchMountainsHandler.java @@ -12,7 +12,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -79,11 +79,11 @@ public void populateSmallItems(TerraformWorld tw, */ private void setRock(@NotNull SimpleBlock target) { if (HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) - > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + > TConfig.c.MISC_TREES_GRADIENT_LIMIT) { Material rock = Material.ANDESITE; if (HeightMap.getTrueHeightGradient(target.getPopData(), target.getX(), target.getZ(), 3) - > TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble() * 2) + > TConfig.c.MISC_TREES_GRADIENT_LIMIT * 2) { rock = Material.DIORITE; } @@ -106,7 +106,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); // Rarely spawn huge taiga trees - if (TConfigOption.TREES_BIRCH_BIG_ENABLED.getBoolean() && GenUtils.chance(random, 1, 20)) { + if (TConfig.c.TREES_BIRCH_BIG_ENABLED && GenUtils.chance(random, 1, 20)) { new FractalTreeBuilder(FractalTypes.Tree.BIRCH_BIG).build( tw, data, diff --git a/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java index 713c87e3..341a2b16 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/DesertHillsHandler.java @@ -7,7 +7,7 @@ import org.terraform.coregen.HeightMap; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; @@ -72,14 +72,14 @@ public void populateSmallItems(TerraformWorld world, for (int y = surfaceY; y > HeightMap.CORE.getHeight(world, rawX, rawZ); y--) { if (duneNoise.GetNoise(rawX, y, rawZ) > 0) { if (data.getType(rawX, y, rawZ) == Material.SAND || data.getType(rawX, y, rawZ) == Material.RED_SAND) { - if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER.getBoolean()) { + if (TConfig.c.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER) { data.setType(rawX, y, rawZ, Material.YELLOW_CONCRETE_POWDER); } } else if (data.getType(rawX, y, rawZ) == Material.SANDSTONE || data.getType(rawX, y, rawZ) == Material.RED_SANDSTONE) { - if (TConfigOption.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE.getBoolean()) { + if (TConfig.c.BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE) { data.setType(rawX, y, rawZ, Material.YELLOW_CONCRETE); } } diff --git a/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java index 70f6ba8c..ce064d5f 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/ForestedMountainsHandler.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -158,7 +158,7 @@ public void populateLargeItems(@NotNull TerraformWorld tw, SimpleLocation[] bigTrees = GenUtils.randomObjectPositions(tw, data.getChunkX(), data.getChunkZ(), 20); - if (TConfigOption.TREES_JUNGLE_BIG_ENABLED.getBoolean()) { + if (TConfig.c.TREES_JUNGLE_BIG_ENABLED) { for (SimpleLocation sLoc : bigTrees) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); diff --git a/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java index 4fdd4b8a..c4a5e1e2 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/PaintedHillsHandler.java @@ -12,7 +12,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -80,7 +80,7 @@ public void populateSmallItems(TerraformWorld tw, if (HeightMap.getTrueHeightGradient(data, rawX, rawZ, 3) - < TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()) + < TConfig.c.MISC_TREES_GRADIENT_LIMIT) { data.setType(rawX, surfaceY, rawZ, Material.GRASS_BLOCK); diff --git a/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java b/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java index 39d2e01e..8f806089 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/RockyMountainsHandler.java @@ -43,14 +43,14 @@ private static void dirtStack(@NotNull PopulatorDataAbstract data, @NotNull Rand } public static void placeWaterFall(@NotNull TerraformWorld tw, int seed, @NotNull SimpleBlock base) { - float radius = 4.0f; + float radius = 4f; FastNoise noise = new FastNoise(seed); noise.SetNoiseType(NoiseType.Simplex); noise.SetFrequency(0.09f); for (float x = -radius; x <= radius; x++) { - for (float y = -radius / 2.0f; y <= radius / 2.0f; y++) { + for (float y = -radius / 2f; y <= radius / 2f; y++) { for (float z = -radius; z <= radius; z++) { SimpleBlock rel = base.getRelative(Math.round(x), Math.round(y), Math.round(z)); diff --git a/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java b/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java index 1ef6918b..cdaabff9 100644 --- a/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java +++ b/common/src/main/java/org/terraform/biome/mountainous/ShatteredSavannaHandler.java @@ -14,7 +14,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -107,7 +107,7 @@ public void transformTerrain(@NotNull ChunkCache cache, int rawZ = chunkZ * 16 + z; double crevice = Math.abs(creviceNoise.GetNoise(rawX, rawZ)); // peakHeight *= getBiomeBlender(tw).getEdgeFactor(BiomeBank.SHATTERED_SAVANNA, rawX, rawZ); - if (crevice < 0.40f) { + if (crevice < 0.4f) { return; } @@ -120,7 +120,7 @@ public void transformTerrain(@NotNull ChunkCache cache, // Make the pillars connect around baseHeight+0.5*(peakHeight-baseHeight) // by multiplying a factor that approaches lower values there double scale = (1f - 0.4 * Math.abs(yScaleNoise.GetNoise(y, 0))); - if (crevice * scale < 0.40f) { + if (crevice * scale < 0.4f) { updateHeight = false; continue; } @@ -195,10 +195,10 @@ public void populateLargeItems(@NotNull TerraformWorld tw, for (SimpleLocation sLoc : poffs) { int treeY = GenUtils.getHighestGround(data, sLoc.getX(), sLoc.getZ()); sLoc.setY(treeY); - if (TConfigOption.arePlantsEnabled() - && data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() - && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) - && !data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()).isSolid()) + if (TConfig.arePlantsEnabled() + && data.getBiome(sLoc.getX(), sLoc.getZ()) == getBiome() + && BlockUtils.isDirtLike(data.getType(sLoc.getX(), sLoc.getY(), sLoc.getZ())) + && !data.getType(sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()).isSolid()) { SimpleBlock base = new SimpleBlock(data, sLoc.getX(), sLoc.getY() + 1, sLoc.getZ()); int rX = GenUtils.randInt(random, 2, 4); diff --git a/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java b/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java index c8a5659a..35e9869a 100644 --- a/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/BogRiverHandler.java @@ -13,7 +13,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; @@ -130,7 +130,7 @@ public void populateSmallItems(@NotNull TerraformWorld tw, RiverHandler.riverVegetation(tw, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java b/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java index 5b3e8dee..51852bea 100644 --- a/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/CherryGroveRiverHandler.java @@ -8,7 +8,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -64,7 +64,7 @@ public void populateSmallItems(@NotNull TerraformWorld world, RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java b/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java index 6e6d252e..c45ff9f0 100644 --- a/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/DarkForestRiverHandler.java @@ -9,7 +9,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.tree.FractalTypes; import org.terraform.tree.TreeDB; import org.terraform.utils.BlockUtils; @@ -71,14 +71,14 @@ else if (surfaceY >= TerraformGenerator.seaLevel - 4) { RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } if (GenUtils.chance(random, 1, 1000)) { BlockUtils.replaceCircularPatch( random.nextInt(9999), - 2.0f, + 2f, new SimpleBlock(data, rawX, surfaceY, rawZ), Material.MAGMA_BLOCK ); diff --git a/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java b/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java index 44754bda..5ec662ac 100644 --- a/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/FrozenRiverHandler.java @@ -7,7 +7,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -73,7 +73,7 @@ else if (surfaceY >= TerraformGenerator.seaLevel - 4) { RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java b/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java index 9aaca11b..926e87cb 100644 --- a/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/JungleRiverHandler.java @@ -7,7 +7,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -112,7 +112,7 @@ else if (surfaceY >= TerraformGenerator.seaLevel - 4) { RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/biome/river/RiverHandler.java b/common/src/main/java/org/terraform/biome/river/RiverHandler.java index 2e042aef..82caa004 100644 --- a/common/src/main/java/org/terraform/biome/river/RiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/RiverHandler.java @@ -7,7 +7,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -111,7 +111,7 @@ else if (surfaceY >= TerraformGenerator.seaLevel - 4) { riverVegetation(world, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java b/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java index ffb74e2d..d7d05b7d 100644 --- a/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java +++ b/common/src/main/java/org/terraform/biome/river/ScarletForestRiverHandler.java @@ -8,7 +8,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -76,7 +76,7 @@ else if (surfaceY >= TerraformGenerator.seaLevel - 4) { RiverHandler.riverVegetation(world, random, data, rawX, surfaceY, rawZ); // Generate clay - if (GenUtils.chance(random, TConfigOption.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND.getInt(), 1000)) { + if (GenUtils.chance(random, TConfig.c.BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND, 1000)) { BlockUtils.generateClayDeposit(rawX, surfaceY, rawZ, data, random); } } diff --git a/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java b/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java index e8537e20..d001abfb 100644 --- a/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java +++ b/common/src/main/java/org/terraform/cave/NoiseCaveRegistry.java @@ -4,7 +4,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.noise.FastNoise; public class NoiseCaveRegistry { @@ -23,7 +23,7 @@ public NoiseCaveRegistry(TerraformWorld tw) { } public boolean canNoiseCarve(int x, int y, int z, double height) { - if (!TConfigOption.areCavesEnabled()) { + if (!TConfig.areCavesEnabled()) { return false; } @@ -39,7 +39,7 @@ public boolean canNoiseCarve(int x, int y, int z, double height) { } public boolean canGenerateCarve(int x, int y, int z, double height) { - if (!TConfigOption.areCavesEnabled()) { + if (!TConfig.areCavesEnabled()) { return false; } diff --git a/common/src/main/java/org/terraform/command/MansionCommand.java b/common/src/main/java/org/terraform/command/MansionCommand.java index 0fcaabcb..a5f3a0b0 100644 --- a/common/src/main/java/org/terraform/command/MansionCommand.java +++ b/common/src/main/java/org/terraform/command/MansionCommand.java @@ -6,7 +6,7 @@ import org.terraform.command.contants.TerraCommand; import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.pillager.mansion.MansionJigsawBuilder; import java.util.Random; @@ -43,8 +43,8 @@ public void execute(CommandSender sender, Stack args) { int y = p.getLocation().getBlockY(); int z = p.getLocation().getBlockZ(); MansionJigsawBuilder builder = new MansionJigsawBuilder( - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), + TConfig.c.STRUCTURES_MANSION_SIZE, + TConfig.c.STRUCTURES_MANSION_SIZE, data, x, y, diff --git a/common/src/main/java/org/terraform/coregen/HeightMap.java b/common/src/main/java/org/terraform/coregen/HeightMap.java index 7f8f1823..b8f63444 100644 --- a/common/src/main/java/org/terraform/coregen/HeightMap.java +++ b/common/src/main/java/org/terraform/coregen/HeightMap.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; @@ -23,7 +23,7 @@ public double getHeight(TerraformWorld tw, int x, int z) { FastNoise noise = NoiseCacheHandler.getNoise(tw, NoiseCacheEntry.HEIGHTMAP_RIVER, world -> { FastNoise n = new FastNoise((int) world.getSeed()); n.SetNoiseType(NoiseType.PerlinFractal); - n.SetFrequency(TConfigOption.HEIGHT_MAP_RIVER_FREQUENCY.getFloat()); + n.SetFrequency(TConfig.c.HEIGHT_MAP_RIVER_FREQUENCY); n.SetFractalOctaves(5); return n; }); @@ -36,7 +36,7 @@ public double getHeight(TerraformWorld tw, int x, int z) { FastNoise n = new FastNoise((int) world.getSeed()); n.SetNoiseType(NoiseType.SimplexFractal); n.SetFractalOctaves(2); // Poor detail after blurs. Rely on Attrition for detail - n.SetFrequency(TConfigOption.HEIGHT_MAP_CORE_FREQUENCY.getFloat()); + n.SetFrequency(TConfig.c.HEIGHT_MAP_CORE_FREQUENCY); return n; }); @@ -69,7 +69,7 @@ public double getHeight(TerraformWorld tw, int x, int z) { }; public static final int defaultSeaLevel = 62; - public static final float heightAmplifier = TConfigOption.HEIGHT_MAP_LAND_HEIGHT_AMPLIFIER.getFloat(); + public static final float heightAmplifier = TConfig.c.HEIGHT_MAP_LAND_HEIGHT_AMPLIFIER; private static final int upscaleSize = 3; public static int spawnFlatRadiusSquared = -324534; diff --git a/common/src/main/java/org/terraform/coregen/TerraformPopulator.java b/common/src/main/java/org/terraform/coregen/TerraformPopulator.java index ad27ab0f..6cb9411b 100644 --- a/common/src/main/java/org/terraform/coregen/TerraformPopulator.java +++ b/common/src/main/java/org/terraform/coregen/TerraformPopulator.java @@ -9,7 +9,7 @@ import org.terraform.coregen.populatordata.PopulatorDataSpigotAPI; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.populators.AmethystGeodePopulator; import org.terraform.populators.OrePopulator; import org.terraform.structure.MultiMegaChunkStructurePopulator; @@ -25,70 +25,70 @@ public class TerraformPopulator extends BlockPopulator { private static final OrePopulator[] ORE_POPS = { // Ores new OrePopulator(Material.DEEPSLATE, - TConfigOption.ORE_DEEPSLATE_CHANCE.getInt(), - TConfigOption.ORE_DEEPSLATE_VEINSIZE.getInt(), - TConfigOption.ORE_DEEPSLATE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_DEEPSLATE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DEEPSLATE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DEEPSLATE_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_DEEPSLATE_CHANCE, + TConfig.c.ORE_DEEPSLATE_VEINSIZE, + TConfig.c.ORE_DEEPSLATE_MAXVEINNUMBER, + TConfig.c.ORE_DEEPSLATE_MINSPAWNHEIGHT, + TConfig.c.ORE_DEEPSLATE_COMMONSPAWNHEIGHT, + TConfig.c.ORE_DEEPSLATE_MAXSPAWNHEIGHT, true ),// deepslate new OrePopulator(Material.TUFF, - TConfigOption.ORE_TUFF_CHANCE.getInt(), - TConfigOption.ORE_TUFF_VEINSIZE.getInt(), - TConfigOption.ORE_TUFF_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_TUFF_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_TUFF_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_TUFF_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_TUFF_CHANCE, + TConfig.c.ORE_TUFF_VEINSIZE, + TConfig.c.ORE_TUFF_MAXVEINNUMBER, + TConfig.c.ORE_TUFF_MINSPAWNHEIGHT, + TConfig.c.ORE_TUFF_COMMONSPAWNHEIGHT, + TConfig.c.ORE_TUFF_MAXSPAWNHEIGHT, true ),// tuff new OrePopulator(Material.COPPER_ORE, - TConfigOption.ORE_COPPER_CHANCE.getInt(), - TConfigOption.ORE_COPPER_VEINSIZE.getInt(), - TConfigOption.ORE_COPPER_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_COPPER_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COPPER_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COPPER_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_COPPER_CHANCE, + TConfig.c.ORE_COPPER_VEINSIZE, + TConfig.c.ORE_COPPER_MAXVEINNUMBER, + TConfig.c.ORE_COPPER_MINSPAWNHEIGHT, + TConfig.c.ORE_COPPER_COMMONSPAWNHEIGHT, + TConfig.c.ORE_COPPER_MAXSPAWNHEIGHT, false ),// Space for copper new OrePopulator(Material.COAL_ORE, - TConfigOption.ORE_COAL_CHANCE.getInt(), - TConfigOption.ORE_COAL_VEINSIZE.getInt(), - TConfigOption.ORE_COAL_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_COAL_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COAL_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_COAL_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_COAL_CHANCE, + TConfig.c.ORE_COAL_VEINSIZE, + TConfig.c.ORE_COAL_MAXVEINNUMBER, + TConfig.c.ORE_COAL_MINSPAWNHEIGHT, + TConfig.c.ORE_COAL_COMMONSPAWNHEIGHT, + TConfig.c.ORE_COAL_MAXSPAWNHEIGHT, false ), new OrePopulator(Material.IRON_ORE, - TConfigOption.ORE_IRON_CHANCE.getInt(), - TConfigOption.ORE_IRON_VEINSIZE.getInt(), - TConfigOption.ORE_IRON_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_IRON_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_IRON_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_IRON_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_IRON_CHANCE, + TConfig.c.ORE_IRON_VEINSIZE, + TConfig.c.ORE_IRON_MAXVEINNUMBER, + TConfig.c.ORE_IRON_MINSPAWNHEIGHT, + TConfig.c.ORE_IRON_COMMONSPAWNHEIGHT, + TConfig.c.ORE_IRON_MAXSPAWNHEIGHT, false ), new OrePopulator(Material.GOLD_ORE, - TConfigOption.ORE_GOLD_CHANCE.getInt(), - TConfigOption.ORE_GOLD_VEINSIZE.getInt(), - TConfigOption.ORE_GOLD_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GOLD_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GOLD_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GOLD_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_GOLD_CHANCE, + TConfig.c.ORE_GOLD_VEINSIZE, + TConfig.c.ORE_GOLD_MAXVEINNUMBER, + TConfig.c.ORE_GOLD_MINSPAWNHEIGHT, + TConfig.c.ORE_GOLD_COMMONSPAWNHEIGHT, + TConfig.c.ORE_GOLD_MAXSPAWNHEIGHT, false ), // BADLANDS SPAWNRATE new OrePopulator(Material.GOLD_ORE, - TConfigOption.ORE_BADLANDSGOLD_CHANCE.getInt(), - TConfigOption.ORE_BADLANDSGOLD_VEINSIZE.getInt(), - TConfigOption.ORE_BADLANDSGOLD_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_BADLANDSGOLD_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_BADLANDSGOLD_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_BADLANDSGOLD_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_BADLANDSGOLD_CHANCE, + TConfig.c.ORE_BADLANDSGOLD_VEINSIZE, + TConfig.c.ORE_BADLANDSGOLD_MAXVEINNUMBER, + TConfig.c.ORE_BADLANDSGOLD_MINSPAWNHEIGHT, + TConfig.c.ORE_BADLANDSGOLD_COMMONSPAWNHEIGHT, + TConfig.c.ORE_BADLANDSGOLD_MAXSPAWNHEIGHT, false, BiomeBank.BADLANDS, BiomeBank.BADLANDS_CANYON, @@ -98,24 +98,24 @@ public class TerraformPopulator extends BlockPopulator { ), new OrePopulator(Material.DIAMOND_ORE, - TConfigOption.ORE_DIAMOND_CHANCE.getInt(), - TConfigOption.ORE_DIAMOND_VEINSIZE.getInt(), - TConfigOption.ORE_DIAMOND_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_DIAMOND_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIAMOND_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIAMOND_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_DIAMOND_CHANCE, + TConfig.c.ORE_DIAMOND_VEINSIZE, + TConfig.c.ORE_DIAMOND_MAXVEINNUMBER, + TConfig.c.ORE_DIAMOND_MINSPAWNHEIGHT, + TConfig.c.ORE_DIAMOND_COMMONSPAWNHEIGHT, + TConfig.c.ORE_DIAMOND_MAXSPAWNHEIGHT, false ), // Emeralds only spawn in mountainous biomes (except deserts) new OrePopulator(Material.EMERALD_ORE, - TConfigOption.ORE_EMERALD_CHANCE.getInt(), - TConfigOption.ORE_EMERALD_VEINSIZE.getInt(), - TConfigOption.ORE_EMERALD_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_EMERALD_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_EMERALD_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_EMERALD_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_EMERALD_CHANCE, + TConfig.c.ORE_EMERALD_VEINSIZE, + TConfig.c.ORE_EMERALD_MAXVEINNUMBER, + TConfig.c.ORE_EMERALD_MINSPAWNHEIGHT, + TConfig.c.ORE_EMERALD_COMMONSPAWNHEIGHT, + TConfig.c.ORE_EMERALD_MAXSPAWNHEIGHT, false, BiomeBank.BIRCH_MOUNTAINS, BiomeBank.ROCKY_MOUNTAINS, @@ -128,72 +128,73 @@ public class TerraformPopulator extends BlockPopulator { new OrePopulator(Material.LAPIS_ORE, - TConfigOption.ORE_LAPIS_CHANCE.getInt(), - TConfigOption.ORE_LAPIS_VEINSIZE.getInt(), - TConfigOption.ORE_LAPIS_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_LAPIS_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_LAPIS_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_LAPIS_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_LAPIS_CHANCE, + TConfig.c.ORE_LAPIS_VEINSIZE, + TConfig.c.ORE_LAPIS_MAXVEINNUMBER, + TConfig.c.ORE_LAPIS_MINSPAWNHEIGHT, + TConfig.c.ORE_LAPIS_COMMONSPAWNHEIGHT, + TConfig.c.ORE_LAPIS_MAXSPAWNHEIGHT, false ), new OrePopulator(Material.REDSTONE_ORE, - TConfigOption.ORE_REDSTONE_CHANCE.getInt(), - TConfigOption.ORE_REDSTONE_VEINSIZE.getInt(), - TConfigOption.ORE_REDSTONE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_REDSTONE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_REDSTONE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_REDSTONE_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_REDSTONE_CHANCE, + TConfig.c.ORE_REDSTONE_VEINSIZE, + TConfig.c.ORE_REDSTONE_MAXVEINNUMBER, + TConfig.c.ORE_REDSTONE_MINSPAWNHEIGHT, + TConfig.c.ORE_REDSTONE_COMMONSPAWNHEIGHT, + TConfig.c.ORE_REDSTONE_MAXSPAWNHEIGHT, false ), // Non-ores new OrePopulator(Material.GRAVEL, - TConfigOption.ORE_GRAVEL_CHANCE.getInt(), - TConfigOption.ORE_GRAVEL_VEINSIZE.getInt(), - TConfigOption.ORE_GRAVEL_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GRAVEL_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRAVEL_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRAVEL_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_GRAVEL_CHANCE, + TConfig.c.ORE_GRAVEL_VEINSIZE, + TConfig.c.ORE_GRAVEL_MAXVEINNUMBER, + TConfig.c.ORE_GRAVEL_MINSPAWNHEIGHT, + TConfig.c.ORE_GRAVEL_COMMONSPAWNHEIGHT, + TConfig.c.ORE_GRAVEL_MAXSPAWNHEIGHT, true ), new OrePopulator(Material.ANDESITE, - TConfigOption.ORE_ANDESITE_CHANCE.getInt(), - TConfigOption.ORE_ANDESITE_VEINSIZE.getInt(), - TConfigOption.ORE_ANDESITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_ANDESITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_ANDESITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_ANDESITE_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_ANDESITE_CHANCE, + TConfig.c.ORE_ANDESITE_VEINSIZE, + TConfig.c.ORE_ANDESITE_MAXVEINNUMBER, + TConfig.c.ORE_ANDESITE_MINSPAWNHEIGHT, + TConfig.c.ORE_ANDESITE_COMMONSPAWNHEIGHT, + TConfig.c.ORE_ANDESITE_MAXSPAWNHEIGHT, true ), new OrePopulator(Material.DIORITE, - TConfigOption.ORE_DIORITE_CHANCE.getInt(), - TConfigOption.ORE_DIORITE_VEINSIZE.getInt(), - TConfigOption.ORE_DIORITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_DIORITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIORITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_DIORITE_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_DIORITE_CHANCE, + TConfig.c.ORE_DIORITE_VEINSIZE, + TConfig.c.ORE_DIORITE_MAXVEINNUMBER, + TConfig.c.ORE_DIORITE_MINSPAWNHEIGHT, + TConfig.c.ORE_DIORITE_COMMONSPAWNHEIGHT, + TConfig.c.ORE_DIORITE_MAXSPAWNHEIGHT, true ), new OrePopulator(Material.GRANITE, - TConfigOption.ORE_GRANITE_CHANCE.getInt(), - TConfigOption.ORE_GRANITE_VEINSIZE.getInt(), - TConfigOption.ORE_GRANITE_MAXVEINNUMBER.getInt(), - TConfigOption.ORE_GRANITE_MINSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRANITE_COMMONSPAWNHEIGHT.getInt(), - TConfigOption.ORE_GRANITE_MAXSPAWNHEIGHT.getInt(), + TConfig.c.ORE_GRANITE_CHANCE, + TConfig.c.ORE_GRANITE_VEINSIZE, + TConfig.c.ORE_GRANITE_MAXVEINNUMBER, + TConfig.c.ORE_GRANITE_MINSPAWNHEIGHT, + TConfig.c.ORE_GRANITE_COMMONSPAWNHEIGHT, + TConfig.c.ORE_GRANITE_MAXSPAWNHEIGHT, true ) }; - private final AmethystGeodePopulator amethystGeodePopulator = new AmethystGeodePopulator(TConfigOption.ORE_AMETHYST_GEODE_SIZE.getInt(), - TConfigOption.ORE_AMETHYST_CHANCE.getDouble(), - TConfigOption.ORE_AMETHYST_MIN_DEPTH.getInt(), - TConfigOption.ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE.getInt() + private final AmethystGeodePopulator amethystGeodePopulator = new AmethystGeodePopulator( + TConfig.c.ORE_AMETHYST_GEODE_SIZE, + TConfig.c.ORE_AMETHYST_CHANCE, + TConfig.c.ORE_AMETHYST_MIN_DEPTH, + TConfig.c.ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE ); private final MasterCavePopulatorDistributor caveDistributor = new MasterCavePopulatorDistributor(); @@ -256,7 +257,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // Multi-megachunk structures for (MultiMegaChunkStructurePopulator spop : StructureRegistry.smallStructureRegistry) { - if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, data.getChunkX(), data.getChunkZ())) { + if (TConfig.areStructuresEnabled() && spop.canSpawn(tw, data.getChunkX(), data.getChunkZ())) { TerraformGeneratorPlugin.logger.info("Generating " + spop.getClass().getName() + " at chunk: " diff --git a/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java index 0d93924c..d8ce5f3b 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/NativeGeneratorPatcherPopulator.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.data.SimpleChunkLocation; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.ArrayList; import java.util.Collection; @@ -34,7 +34,7 @@ public NativeGeneratorPatcherPopulator() { public static void pushChange(String world, int x, int y, int z, BlockData data) { - if (!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { + if (!flushIsQueued && cache.size() > TConfig.c.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY) { flushIsQueued = true; new BukkitRunnable() { @Override diff --git a/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java index 77e2528e..f4ebb6b9 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/PhysicsUpdaterPopulator.java @@ -15,7 +15,7 @@ import org.terraform.data.SimpleChunkLocation; import org.terraform.data.SimpleLocation; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.ArrayList; import java.util.Collection; @@ -37,7 +37,7 @@ public PhysicsUpdaterPopulator() { public static void pushChange(String world, @NotNull SimpleLocation loc) { - if (!flushIsQueued && cache.size() > TConfigOption.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY.getInt()) { + if (!flushIsQueued && cache.size() > TConfig.c.DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY) { flushIsQueued = true; new BukkitRunnable() { @Override diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java index 4866abbc..75a98de2 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformAnimalPopulator.java @@ -8,7 +8,7 @@ import org.terraform.biome.BiomeBank; import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.populators.AnimalPopulator; import org.terraform.utils.version.OneTwentyFiveBlockHandler; import org.terraform.utils.version.Version; @@ -22,9 +22,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { null, // Slot for armadillo new AnimalPopulator(EntityType.PIG, - TConfigOption.ANIMALS_PIG_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_PIG_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PIG_CHANCE.getInt(), + TConfig.c.ANIMALS_PIG_MINHERDSIZE, + TConfig.c.ANIMALS_PIG_MAXHERDSIZE, + TConfig.c.ANIMALS_PIG_CHANCE, false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, @@ -50,9 +50,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.COW, - TConfigOption.ANIMALS_COW_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_COW_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_COW_CHANCE.getInt(), + TConfig.c.ANIMALS_COW_MINHERDSIZE, + TConfig.c.ANIMALS_COW_MAXHERDSIZE, + TConfig.c.ANIMALS_COW_CHANCE, false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, @@ -78,9 +78,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.SHEEP, - TConfigOption.ANIMALS_SHEEP_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_SHEEP_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SHEEP_CHANCE.getInt(), + TConfig.c.ANIMALS_SHEEP_MINHERDSIZE, + TConfig.c.ANIMALS_SHEEP_MAXHERDSIZE, + TConfig.c.ANIMALS_SHEEP_CHANCE, false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, @@ -106,9 +106,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.CHICKEN, - TConfigOption.ANIMALS_CHICKEN_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_CHICKEN_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_CHICKEN_CHANCE.getInt(), + TConfig.c.ANIMALS_CHICKEN_MINHERDSIZE, + TConfig.c.ANIMALS_CHICKEN_MAXHERDSIZE, + TConfig.c.ANIMALS_CHICKEN_CHANCE, false, BiomeBank.BLACK_OCEAN, BiomeBank.MUSHROOM_ISLANDS, @@ -134,27 +134,27 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.HORSE, - TConfigOption.ANIMALS_HORSE_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_HORSE_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_HORSE_CHANCE.getInt(), + TConfig.c.ANIMALS_HORSE_MINHERDSIZE, + TConfig.c.ANIMALS_HORSE_MAXHERDSIZE, + TConfig.c.ANIMALS_HORSE_CHANCE, true, BiomeBank.PLAINS, BiomeBank.SAVANNA ), new AnimalPopulator(EntityType.DONKEY, - TConfigOption.ANIMALS_DONKEY_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_DONKEY_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_DONKEY_CHANCE.getInt(), + TConfig.c.ANIMALS_DONKEY_MINHERDSIZE, + TConfig.c.ANIMALS_DONKEY_MAXHERDSIZE, + TConfig.c.ANIMALS_DONKEY_CHANCE, true, BiomeBank.PLAINS, BiomeBank.SAVANNA ), new AnimalPopulator(EntityType.RABBIT, - TConfigOption.ANIMALS_RABBIT_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_RABBIT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_RABBIT_CHANCE.getInt(), + TConfig.c.ANIMALS_RABBIT_MINHERDSIZE, + TConfig.c.ANIMALS_RABBIT_MAXHERDSIZE, + TConfig.c.ANIMALS_RABBIT_CHANCE, true, BiomeBank.DESERT, BiomeBank.FOREST, @@ -165,9 +165,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.POLAR_BEAR, - TConfigOption.ANIMALS_POLAR_BEAR_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_POLAR_BEAR_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_POLAR_BEAR_CHANCE.getInt(), + TConfig.c.ANIMALS_POLAR_BEAR_MINHERDSIZE, + TConfig.c.ANIMALS_POLAR_BEAR_MAXHERDSIZE, + TConfig.c.ANIMALS_POLAR_BEAR_CHANCE, true, BiomeBank.ICE_SPIKES, BiomeBank.SNOWY_TAIGA, @@ -176,52 +176,52 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.PANDA, - TConfigOption.ANIMALS_PANDA_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_PANDA_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PANDA_CHANCE.getInt(), + TConfig.c.ANIMALS_PANDA_MINHERDSIZE, + TConfig.c.ANIMALS_PANDA_MAXHERDSIZE, + TConfig.c.ANIMALS_PANDA_CHANCE, true, BiomeBank.BAMBOO_FOREST ), new AnimalPopulator(EntityType.FOX, - TConfigOption.ANIMALS_FOX_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_FOX_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_FOX_CHANCE.getInt(), + TConfig.c.ANIMALS_FOX_MINHERDSIZE, + TConfig.c.ANIMALS_FOX_MAXHERDSIZE, + TConfig.c.ANIMALS_FOX_CHANCE, true, BiomeBank.TAIGA, BiomeBank.SNOWY_TAIGA ), new AnimalPopulator(EntityType.LLAMA, - TConfigOption.ANIMALS_LLAMA_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_LLAMA_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_LLAMA_CHANCE.getInt(), + TConfig.c.ANIMALS_LLAMA_MINHERDSIZE, + TConfig.c.ANIMALS_LLAMA_MAXHERDSIZE, + TConfig.c.ANIMALS_LLAMA_CHANCE, true, BiomeBank.SAVANNA, BiomeBank.ROCKY_MOUNTAINS ), new AnimalPopulator(EntityType.PARROT, - TConfigOption.ANIMALS_PARROT_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_PARROT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PARROT_CHANCE.getInt(), + TConfig.c.ANIMALS_PARROT_MINHERDSIZE, + TConfig.c.ANIMALS_PARROT_MAXHERDSIZE, + TConfig.c.ANIMALS_PARROT_CHANCE, true, BiomeBank.JUNGLE ), new AnimalPopulator(EntityType.OCELOT, - TConfigOption.ANIMALS_OCELOT_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_OCELOT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_OCELOT_CHANCE.getInt(), + TConfig.c.ANIMALS_OCELOT_MINHERDSIZE, + TConfig.c.ANIMALS_OCELOT_MAXHERDSIZE, + TConfig.c.ANIMALS_OCELOT_CHANCE, true, BiomeBank.JUNGLE, BiomeBank.BAMBOO_FOREST ), new AnimalPopulator(EntityType.WOLF, - TConfigOption.ANIMALS_WOLF_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_WOLF_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_WOLF_CHANCE.getInt(), + TConfig.c.ANIMALS_WOLF_MINHERDSIZE, + TConfig.c.ANIMALS_WOLF_MAXHERDSIZE, + TConfig.c.ANIMALS_WOLF_CHANCE, true, BiomeBank.FOREST, BiomeBank.TAIGA, @@ -230,17 +230,17 @@ public class TerraformAnimalPopulator extends BlockPopulator { ), new AnimalPopulator(EntityType.TURTLE, - TConfigOption.ANIMALS_TURTLE_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_TURTLE_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_TURTLE_CHANCE.getInt(), + TConfig.c.ANIMALS_TURTLE_MINHERDSIZE, + TConfig.c.ANIMALS_TURTLE_MAXHERDSIZE, + TConfig.c.ANIMALS_TURTLE_CHANCE, true, BiomeBank.SANDY_BEACH ), new AnimalPopulator(EntityType.DOLPHIN, - TConfigOption.ANIMALS_DOLPHIN_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_DOLPHIN_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_DOLPHIN_CHANCE.getInt(), + TConfig.c.ANIMALS_DOLPHIN_MINHERDSIZE, + TConfig.c.ANIMALS_DOLPHIN_MAXHERDSIZE, + TConfig.c.ANIMALS_DOLPHIN_CHANCE, true, BiomeBank.OCEAN, BiomeBank.DEEP_OCEAN, @@ -252,9 +252,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.COD, - TConfigOption.ANIMALS_COD_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_COD_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_COD_CHANCE.getInt(), + TConfig.c.ANIMALS_COD_MINHERDSIZE, + TConfig.c.ANIMALS_COD_MAXHERDSIZE, + TConfig.c.ANIMALS_COD_CHANCE, true, BiomeBank.OCEAN, BiomeBank.DEEP_OCEAN, @@ -266,9 +266,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.SQUID, - TConfigOption.ANIMALS_SQUID_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_SQUID_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SQUID_CHANCE.getInt(), + TConfig.c.ANIMALS_SQUID_MINHERDSIZE, + TConfig.c.ANIMALS_SQUID_MAXHERDSIZE, + TConfig.c.ANIMALS_SQUID_CHANCE, true, BiomeBank.FROZEN_OCEAN, BiomeBank.DEEP_FROZEN_OCEAN, @@ -289,9 +289,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.SALMON, - TConfigOption.ANIMALS_SALMON_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_SALMON_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_SALMON_CHANCE.getInt(), + TConfig.c.ANIMALS_SALMON_MINHERDSIZE, + TConfig.c.ANIMALS_SALMON_MAXHERDSIZE, + TConfig.c.ANIMALS_SALMON_CHANCE, true, BiomeBank.COLD_OCEAN, BiomeBank.DEEP_COLD_OCEAN, @@ -302,9 +302,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.PUFFERFISH, - TConfigOption.ANIMALS_PUFFERFISH_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_PUFFERFISH_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_PUFFERFISH_CHANCE.getInt(), + TConfig.c.ANIMALS_PUFFERFISH_MINHERDSIZE, + TConfig.c.ANIMALS_PUFFERFISH_MAXHERDSIZE, + TConfig.c.ANIMALS_PUFFERFISH_CHANCE, true, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, @@ -314,9 +314,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.TROPICAL_FISH, - TConfigOption.ANIMALS_TROPICALFISH_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_TROPICALFISH_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_TROPICALFISH_CHANCE.getInt(), + TConfig.c.ANIMALS_TROPICALFISH_MINHERDSIZE, + TConfig.c.ANIMALS_TROPICALFISH_MAXHERDSIZE, + TConfig.c.ANIMALS_TROPICALFISH_CHANCE, true, BiomeBank.DEEP_LUKEWARM_OCEAN, BiomeBank.CORAL_REEF_OCEAN, @@ -325,9 +325,9 @@ public class TerraformAnimalPopulator extends BlockPopulator { ).setAquatic(true), new AnimalPopulator(EntityType.MUSHROOM_COW, - TConfigOption.ANIMALS_MOOSHROOM_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_MOOSHROOM_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_MOOSHROOM_CHANCE.getInt(), + TConfig.c.ANIMALS_MOOSHROOM_MINHERDSIZE, + TConfig.c.ANIMALS_MOOSHROOM_MAXHERDSIZE, + TConfig.c.ANIMALS_MOOSHROOM_CHANCE, true, BiomeBank.MUSHROOM_BEACH, BiomeBank.MUSHROOM_ISLANDS @@ -339,9 +339,9 @@ public TerraformAnimalPopulator(TerraformWorld tw) { this.tw = tw; if (Version.isAtLeast(17)) { ANIMAL_POPULATORS[0] = new AnimalPopulator(EntityType.valueOf("GOAT"), - TConfigOption.ANIMALS_GOAT_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_GOAT_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_GOAT_CHANCE.getInt(), + TConfig.c.ANIMALS_GOAT_MINHERDSIZE, + TConfig.c.ANIMALS_GOAT_MAXHERDSIZE, + TConfig.c.ANIMALS_GOAT_CHANCE, true, BiomeBank.ROCKY_MOUNTAINS, BiomeBank.SNOWY_MOUNTAINS @@ -349,9 +349,9 @@ public TerraformAnimalPopulator(TerraformWorld tw) { } if (Version.isAtLeast(20.5)) { ANIMAL_POPULATORS[1] = new AnimalPopulator(OneTwentyFiveBlockHandler.ARMADILLO, - TConfigOption.ANIMALS_ARMADILLO_MINHERDSIZE.getInt(), - TConfigOption.ANIMALS_ARMADILLO_MAXHERDSIZE.getInt(), - TConfigOption.ANIMALS_ARMADILLO_CHANCE.getInt(), + TConfig.c.ANIMALS_ARMADILLO_MINHERDSIZE, + TConfig.c.ANIMALS_ARMADILLO_MAXHERDSIZE, + TConfig.c.ANIMALS_ARMADILLO_CHANCE, true, BiomeBank.SAVANNA, BiomeBank.SHATTERED_SAVANNA, diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java index 931db7c6..0e63ffa6 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformGenerator.java @@ -17,7 +17,7 @@ import org.terraform.data.SimpleChunkLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.ArrayList; @@ -33,7 +33,7 @@ public class TerraformGenerator extends ChunkGenerator { public static int seaLevel = 62; public static void updateSeaLevelFromConfig() { - seaLevel = TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt(); + seaLevel = TConfig.c.HEIGHT_MAP_SEA_LEVEL; } /** @@ -202,8 +202,8 @@ else if (y <= 2) { chunkData.setBlock(x, TerraformGeneratorPlugin.injector.getMinY(), z, Material.BEDROCK); // Up till y = minY+HEIGHT_MAP_BEDROCK_HEIGHT - for (int i = 1; i < TConfigOption.HEIGHT_MAP_BEDROCK_HEIGHT.getInt(); i++) { - if (GenUtils.chance(dontCareRandom, TConfigOption.HEIGHT_MAP_BEDROCK_DENSITY.getInt(), 100)) { + for (int i = 1; i < TConfig.c.HEIGHT_MAP_BEDROCK_HEIGHT; i++) { + if (GenUtils.chance(dontCareRandom, TConfig.c.HEIGHT_MAP_BEDROCK_DENSITY, 100)) { chunkData.setBlock(x, TerraformGeneratorPlugin.injector.getMinY() + i, z, Material.BEDROCK); } else { diff --git a/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java b/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java index ca04f1ad..0932911a 100644 --- a/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java +++ b/common/src/main/java/org/terraform/coregen/bukkit/TerraformStructurePopulator.java @@ -21,7 +21,7 @@ import org.terraform.data.Wall; import org.terraform.event.TerraformStructureSpawnEvent; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.JigsawState; import org.terraform.structure.JigsawStructurePopulator; import org.terraform.structure.SingleMegaChunkStructurePopulator; @@ -139,7 +139,7 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun // Use IChunkAccess to place blocks instead. Known to cause lighting problems. // Since people keep turning this on for fun, then reporting bugs, I'm removing it. - // if (TConfigOption.DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT.getBoolean()) + // if (TConfigOption.DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT) // data = new PopulatorDataRecursiveICA(chunk); // Spawn large structures @@ -147,7 +147,7 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // Special Case - if (!TConfigOption.areStructuresEnabled() && new StrongholdPopulator().canSpawn( + if (!TConfig.areStructuresEnabled() && new StrongholdPopulator().canSpawn( tw, data.getChunkX(), data.getChunkZ(), @@ -178,7 +178,7 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun if (spop instanceof StrongholdPopulator) { continue; } - if (TConfigOption.areStructuresEnabled() && spop.canSpawn( + if (TConfig.areStructuresEnabled() && spop.canSpawn( tw, data.getChunkX(), data.getChunkZ(), @@ -219,7 +219,7 @@ public void populate(@NotNull World world, @NotNull Random random, @NotNull Chun continue; } // TerraformGeneratorPlugin.logger.info("[v] MC(" + mc.getX() + "," + mc.getZ() + ") - Checking " + spop.getClass().getName()); - if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { + if (TConfig.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { return spop; } } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java index d99bad0d..8327bd67 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataPostGen.java @@ -17,7 +17,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Random; @@ -133,7 +133,7 @@ public void addEntity(int x, int y, int z, @NotNull EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java index cb0105c6..6f4ee74d 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java @@ -18,7 +18,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Random; @@ -96,7 +96,7 @@ public int getChunkZ() { @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/data/MegaChunk.java b/common/src/main/java/org/terraform/data/MegaChunk.java index 3b2ae545..fb49b045 100644 --- a/common/src/main/java/org/terraform/data/MegaChunk.java +++ b/common/src/main/java/org/terraform/data/MegaChunk.java @@ -3,14 +3,14 @@ import org.jetbrains.annotations.NotNull; import org.terraform.biome.BiomeBank; import org.terraform.biome.BiomeSection; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.Random; public class MegaChunk { public static final int megaChunkBlockWidth = BiomeSection.sectionWidth - * TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt(); + * TConfig.c.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS; private int x, z; public MegaChunk(@NotNull SimpleChunkLocation sLoc) { diff --git a/common/src/main/java/org/terraform/data/SimpleLocation.java b/common/src/main/java/org/terraform/data/SimpleLocation.java index 359f9c9e..ef707634 100644 --- a/common/src/main/java/org/terraform/data/SimpleLocation.java +++ b/common/src/main/java/org/terraform/data/SimpleLocation.java @@ -61,10 +61,10 @@ public float twoDAngleTo(@NotNull SimpleLocation o) { // Handle absolute cases first if (o.x == x && o.z == z) { - return 0.0f; + return 0f; } else if (o.x == x && o.z > z) { - return 0.0f; + return 0f; } else if (o.x == x) { return (float) Math.PI; @@ -100,7 +100,7 @@ public float twoDAngleWrapTo(@NotNull SimpleLocation o) { // Handle absolute cases first if (o.x == x && o.z == z) { - return 0.0f; + return 0f; } else if (o.x == x && o.z > z) { return 0; diff --git a/common/src/main/java/org/terraform/data/TerraformWorld.java b/common/src/main/java/org/terraform/data/TerraformWorld.java index 8462d396..84c30697 100644 --- a/common/src/main/java/org/terraform/data/TerraformWorld.java +++ b/common/src/main/java/org/terraform/data/TerraformWorld.java @@ -11,7 +11,7 @@ import org.terraform.coregen.bukkit.TerraformBukkitBlockPopulator; import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.noise.FastNoise; import org.terraform.utils.noise.FastNoise.NoiseType; import org.terraform.utils.noise.NoiseCacheHandler; @@ -69,7 +69,7 @@ private TerraformWorld(@NotNull World world) { return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_TEMPERATURE, tw -> { FastNoise n = new FastNoise((int) (tw.getSeed() * 2)); n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_TEMPERATURE_FREQUENCY.getFloat()); // Default 0.03f + n.SetFrequency(TConfig.c.BIOME_TEMPERATURE_FREQUENCY); // Default 0.03f return n; }); } @@ -78,7 +78,7 @@ private TerraformWorld(@NotNull World world) { return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_MOISTURE, tw -> { FastNoise n = new FastNoise((int) (tw.getSeed() / 4)); n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_MOISTURE_FREQUENCY.getFloat()); // Default 0.03f + n.SetFrequency(TConfig.c.BIOME_MOISTURE_FREQUENCY); // Default 0.03f return n; }); } @@ -87,7 +87,7 @@ private TerraformWorld(@NotNull World world) { return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_OCEANIC, tw -> { FastNoise n = new FastNoise((int) tw.getSeed() * 12); n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_OCEANIC_FREQUENCY.getFloat()); + n.SetFrequency(TConfig.c.BIOME_OCEANIC_FREQUENCY); return n; }); } @@ -96,7 +96,7 @@ private TerraformWorld(@NotNull World world) { return NoiseCacheHandler.getNoise(this, NoiseCacheEntry.TW_MOUNTAINOUS, tw -> { FastNoise n = new FastNoise((int) tw.getSeed() * 73); n.SetNoiseType(NoiseType.Simplex); - n.SetFrequency(TConfigOption.BIOME_MOUNTAINOUS_FREQUENCY.getFloat()); + n.SetFrequency((float)TConfig.c.BIOME_MOUNTAINOUS_FREQUENCY); return n; }); } diff --git a/common/src/main/java/org/terraform/main/LanguageManager.java b/common/src/main/java/org/terraform/main/LanguageManager.java index abfd39c9..ae78c49a 100644 --- a/common/src/main/java/org/terraform/main/LanguageManager.java +++ b/common/src/main/java/org/terraform/main/LanguageManager.java @@ -5,6 +5,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.terraform.main.config.TConfig; import java.io.File; import java.io.IOException; @@ -16,8 +17,8 @@ public class LanguageManager { private final @NotNull HashMap cache = new HashMap<>(); private FileConfiguration langFile; - public LanguageManager(@NotNull TerraformGeneratorPlugin plugin) { - this.file = new File(plugin.getDataFolder(), plugin.getConfigLoader().getString("lang")); + public LanguageManager(@NotNull TerraformGeneratorPlugin plugin, @NotNull TConfig config) { + this.file = new File(plugin.getDataFolder(), config.LANGUAGE_FILE); reloadLangFile(); loadDefaults(); } @@ -38,21 +39,17 @@ public String fetchLang(@NotNull String langKey, @Nullable String def) { if (cache.containsKey(langKey)) { return cache.get(langKey); } - if (langFile.isSet(langKey)) { - String value = ChatColor.translateAlternateColorCodes('&', langFile.getString(langKey)); - cache.put(langKey, value); - return value; - } - else if (def != null) { - langFile.set(langKey, def); + + String value = langFile.getString(langKey); + if (value == null) { + value = def == null ? langKey : def; // if no default is given, the default becomes the `langKey` + langFile.set(langKey, value); saveLangFile(); } - cache.put(langKey, ChatColor.translateAlternateColorCodes('&', def)); - return ChatColor.translateAlternateColorCodes('&', def); - } - public FileConfiguration getLangFile() { - return langFile; + value = ChatColor.translateAlternateColorCodes('&', value); + cache.put(langKey, value); + return value; } public void saveLangFile() { diff --git a/common/src/main/java/org/terraform/main/TLogger.java b/common/src/main/java/org/terraform/main/TLogger.java index 90f1bd4e..2863af44 100644 --- a/common/src/main/java/org/terraform/main/TLogger.java +++ b/common/src/main/java/org/terraform/main/TLogger.java @@ -3,7 +3,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.io.File; import java.io.IOException; @@ -17,7 +17,7 @@ public class TLogger { private static boolean suppressConsoleLogs = false; public TLogger() { - suppressConsoleLogs = TConfigOption.DEVSTUFF_SUPPRESS_CONSOLE_LOGS.getBoolean(); + suppressConsoleLogs = TConfig.c.DEVSTUFF_SUPPRESS_CONSOLE_LOGS; if (suppressConsoleLogs) { Handler consoleHandler; Handler fileHandler; @@ -103,7 +103,7 @@ public void info(@NotNull String message) { } public void debug(@NotNull String message) { - if (TConfigOption.DEVSTUFF_DEBUG_MODE.getBoolean()) { + if (TConfig.c.DEVSTUFF_DEBUG_MODE) { if (suppressConsoleLogs) { LOGGER.log(Level.INFO, "[v] " + message); } diff --git a/common/src/main/java/org/terraform/main/TerraformCommandManager.java b/common/src/main/java/org/terraform/main/TerraformCommandManager.java index e9abe3d8..aa4652c5 100644 --- a/common/src/main/java/org/terraform/main/TerraformCommandManager.java +++ b/common/src/main/java/org/terraform/main/TerraformCommandManager.java @@ -11,7 +11,7 @@ import org.terraform.command.contants.InvalidArgumentException; import org.terraform.command.contants.TerraCommand; import org.terraform.command.contants.TerraCommandArgument; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.ArrayList; import java.util.List; @@ -33,7 +33,7 @@ public TerraformCommandManager(@NotNull TerraformGeneratorPlugin plugin, String } registerCommand(new HelpCommand(plugin, this, "help", "h", "?")); - if (TConfigOption.DEVSTUFF_EXTENDED_COMMANDS.getBoolean()) { + if (TConfig.c.DEVSTUFF_EXTENDED_COMMANDS) { this.registerCommand(new PreviewCommand(plugin, "preview")); this.registerCommand(new TimingsCommand(plugin, "timings", "lag")); this.registerCommand(new CoconutCommand(plugin, "coconut")); diff --git a/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java b/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java index 10e8b528..0e0116c4 100644 --- a/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java +++ b/common/src/main/java/org/terraform/main/TerraformGeneratorPlugin.java @@ -17,8 +17,7 @@ import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleChunkLocation; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.ConfigLoader; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.reflection.Post14PrivateFieldHandler; import org.terraform.reflection.Pre14PrivateFieldHandler; import org.terraform.reflection.PrivateFieldHandler; @@ -31,6 +30,8 @@ import org.terraform.utils.version.Version; import org.terraform.watchdog.TfgWatchdogSuppressant; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.EnumSet; @@ -58,7 +59,6 @@ public class TerraformGeneratorPlugin extends JavaPlugin implements Listener { privateFieldHandler = handler; } - private ConfigLoader config; private LanguageManager lang; public static TerraformGeneratorPlugin get() { @@ -71,12 +71,21 @@ public void onEnable() { GenUtils.initGenUtils(); BlockUtils.initBlockUtils(); instance = this; - config = new ConfigLoader(this); - lang = new LanguageManager(this); - TConfigOption.loadValues(config); + + try { + TConfig.init(new File(getDataFolder(), "config.yml")); + } + catch (IOException e) { + getLogger().severe("Failed to load config.yml: " + e.getMessage()); + getPluginLoader().disablePlugin(this); + return; + } + + logger = new TLogger(); + lang = new LanguageManager(this, TConfig.c); // Initiate the height map flat radius value - HeightMap.spawnFlatRadiusSquared = TConfigOption.HEIGHT_MAP_SPAWN_FLAT_RADIUS.getInt(); + HeightMap.spawnFlatRadiusSquared = TConfig.c.HEIGHT_MAP_SPAWN_FLAT_RADIUS; if (HeightMap.spawnFlatRadiusSquared > 0) { HeightMap.spawnFlatRadiusSquared *= HeightMap.spawnFlatRadiusSquared; } @@ -85,12 +94,12 @@ public void onEnable() { // Initialize chunk cache based on config size TerraformGenerator.CHUNK_CACHE = CacheBuilder.newBuilder() - .maximumSize(TConfigOption.DEVSTUFF_CHUNKCACHE_SIZE.getInt()) + .maximumSize(TConfig.c.DEVSTUFF_CHUNKCACHE_SIZE) .build(new ChunkCacheLoader()); // Initialize biome query cache based on config size GenUtils.biomeQueryCache = CacheBuilder.newBuilder() - .maximumSize(TConfigOption.DEVSTUFF_CHUNKBIOMES_SIZE.getInt()) + .maximumSize(TConfig.c.DEVSTUFF_CHUNKBIOMES_SIZE) .build(new CacheLoader<>() { @Override public @NotNull EnumSet load(@NotNull ChunkCache key) { @@ -110,7 +119,6 @@ public void onEnable() { }); LangOpt.init(this); - logger = new TLogger(); watchdogSuppressant = new TfgWatchdogSuppressant(); new TerraformGeneratorMetricsHandler(this); // bStats @@ -122,8 +130,8 @@ public void onEnable() { logger.stdout("Detected version: " + version + ", number: " + Version.DOUBLE); try { injector = Version.SupportedVersion.getInjector(); - if (injector == null) { - throw new ClassNotFoundException(); + if (injector != null) { + injector.startupTasks(); } } catch (ClassNotFoundException e) { @@ -140,9 +148,7 @@ public void onEnable() { logger.stdout("&cSomething went wrong initiating the injector!"); } - injector.startupTasks(); - - if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_ENABLED.getBoolean()) { + if (TConfig.c.MISC_SAPLING_CUSTOM_TREES_ENABLED) { Bukkit.getPluginManager().registerEvents(new SaplingOverrider(), this); } @@ -167,7 +173,7 @@ public void onWorldLoad(@NotNull WorldLoadEvent event) { if (event.getWorld().getGenerator() instanceof TerraformGenerator) { logger.stdout(event.getWorld().getName() + " loaded."); if (!TerraformGenerator.preWorldInitGen.isEmpty()) { - if (!TConfigOption.DEVSTUFF_ATTEMPT_FIXING_PREMATURE.getBoolean()) { + if (!TConfig.c.DEVSTUFF_ATTEMPT_FIXING_PREMATURE) { logger.stdout("&cIgnoring " + TerraformGenerator.preWorldInitGen.size() + " pre-maturely generated chunks." @@ -200,7 +206,7 @@ public void onWorldInit(@NotNull WorldInitEvent event) { if (event.getWorld().getGenerator() instanceof TerraformGenerator) { logger.stdout("Detected world: " + event.getWorld().getName() + ", commencing injection... "); TerraformWorld tw = TerraformWorld.forceOverrideSeed(event.getWorld()); - if (injector.attemptInject(event.getWorld())) { + if (injector != null && injector.attemptInject(event.getWorld())) { INJECTED_WORLDS.add(event.getWorld().getName()); tw.minY = injector.getMinY(); tw.maxY = injector.getMaxY(); @@ -219,10 +225,6 @@ public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String return new TerraformGenerator(); } - public ConfigLoader getConfigLoader() { - return config; - } - public LanguageManager getLang() { // TODO Auto-generated method stub return lang; diff --git a/common/src/main/java/org/terraform/main/config/ConfigLoader.java b/common/src/main/java/org/terraform/main/config/ConfigLoader.java deleted file mode 100644 index edffc805..00000000 --- a/common/src/main/java/org/terraform/main/config/ConfigLoader.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.terraform.main.config; - -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import org.terraform.main.TerraformGeneratorPlugin; - -import java.io.File; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class ConfigLoader { - - private static final int configVersion = 4; - private final @NotNull HashMap configOptions = new HashMap<>(); - private final TerraformGeneratorPlugin plugin; - - public ConfigLoader(@NotNull TerraformGeneratorPlugin plugin) { - this.plugin = plugin; - plugin.getConfig().options().copyDefaults(false); - plugin.saveConfig(); - configOptions.put("lang", "eng.yml"); - configOptions.put("config-version", configVersion); - } - - public void load() { - - // If config version is older, overwrite the whole config. - boolean overwrite = false; - if (!plugin.getConfig().isSet("config-version")) { - overwrite = true; - } - else if (plugin.getConfig().getInt("config-version") < configVersion) { - overwrite = true; - } - - // Make backup of old config before overwriting - if (overwrite) { - try { - if (new File("./plugins/TerraformGenerator/config.yml").exists()) { - Bukkit.getLogger() - .info("New config version detected. Overwriting old config. A backup will be made"); - Files.copy( - new File("./plugins/TerraformGenerator/config.yml").toPath(), - new File("./plugins/TerraformGenerator/config.yml-" - + System.currentTimeMillis() - + ".bak").toPath() - ); - } - } - catch (Exception e) { - TerraformGeneratorPlugin.logger.stackTrace(e); - Bukkit.getLogger().info("Failed to backup old config before overwrite."); - } - } - - for (String key : new ArrayList<>(configOptions.keySet())) { - if (!overwrite && plugin.getConfig().isSet(key)) { - configOptions.put(key, plugin.getConfig().get(key)); - } - else { - plugin.getConfig().set(key, configOptions.get(key)); - plugin.saveConfig(); - } - } - } - - public void reload() { - plugin.reloadConfig(); - load(); - } - - /** - * Registers a new config option - * - * @param key the key of the new option - * @param defaultValue the default value of the new option - */ - public void reg(String key, Object defaultValue) { - this.configOptions.put(key, defaultValue); - } - - public void save() { - for (String key : configOptions.keySet()) { - plugin.getConfig().set(key, configOptions.get(key)); - plugin.saveConfig(); - } - } - - public String getString(String key) { - return (String) configOptions.get(key); - } - - public Object get(String key) { - return configOptions.get(key); - } - - public boolean getBoolean(String key) { - return (Boolean) configOptions.get(key); - } - - public int getInt(String key) { - return (Integer) configOptions.get(key); - } - - public double getDouble(String key) { - return (Double) configOptions.get(key); - } - - @SuppressWarnings("unchecked") - public List getStringList(String key) { - return (List) configOptions.get(key); - } - -} \ No newline at end of file diff --git a/common/src/main/java/org/terraform/main/config/TConfig.java b/common/src/main/java/org/terraform/main/config/TConfig.java new file mode 100644 index 00000000..9361aaaa --- /dev/null +++ b/common/src/main/java/org/terraform/main/config/TConfig.java @@ -0,0 +1,954 @@ +package org.terraform.main.config; + +import org.avarion.yaml.YamlComment; +import org.avarion.yaml.YamlFileInterface; +import org.avarion.yaml.YamlKey; + +import java.io.File; +import java.io.IOException; + +public class TConfig extends YamlFileInterface { + public static TConfig c; + public static void init(final File f) throws IOException { + if (c == null) { + c = new TConfig().load(f); + c.save(f); // updates the configuration file to the newest format + } + } + + // -=[HEIGHTMAP]=- + @YamlKey("heightmap.core-frequency") + public float HEIGHT_MAP_CORE_FREQUENCY = 0.003f; + @YamlKey("heightmap.river-frequency") + public float HEIGHT_MAP_RIVER_FREQUENCY = 0.005f; + @YamlKey("heightmap.land-height-amplifier") + public float HEIGHT_MAP_LAND_HEIGHT_AMPLIFIER = 1f; + @YamlKey("heightmap.sea-level") + public int HEIGHT_MAP_SEA_LEVEL = 62; + @YamlKey("heightmap.bedrock-height") + public int HEIGHT_MAP_BEDROCK_HEIGHT = 5; + @YamlKey("heightmap.bedrock-density") + public int HEIGHT_MAP_BEDROCK_DENSITY = 70; + @YamlKey("heightmap.spawn-flat-radius") + public int HEIGHT_MAP_SPAWN_FLAT_RADIUS = -1; + + // -=[CLIMATES]=- + @YamlKey("climate.humid-vegetation.minimum-temperature") + public double CLIMATE_HUMIDVEGETATION_MINTEMP = -0.35d; + @YamlKey("climate.humid-vegetation.maximum-temperature") + public double CLIMATE_HUMIDVEGETATION_MAXTEMP = 4d; + @YamlKey("climate.humid-vegetation.minimum-moisture") + public double CLIMATE_HUMIDVEGETATION_MINMOIST = 0d; + @YamlKey("climate.humid-vegetation.maximum-moisture") + public double CLIMATE_HUMIDVEGETATION_MAXMOIST = 4d; + + @YamlKey("climate.dry-vegetation.minimum-temperature") + public double CLIMATE_DRYVEGETATION_MINTEMP = -0.35d; + @YamlKey("climate.dry-vegetation.maximum-temperature") + public double CLIMATE_DRYVEGETATION_MAXTEMP = 4d; + @YamlKey("climate.dry-vegetation.minimum-moisture") + public double CLIMATE_DRYVEGETATION_MINMOIST = -4d; + @YamlKey("climate.dry-vegetation.maximum-moisture") + public double CLIMATE_DRYVEGETATION_MAXMOIST = 0d; + + @YamlKey("climate.hot-barren.minimum-temperature") + public double CLIMATE_HOTBARREN_MINTEMP = 1d; + @YamlKey("climate.hot-barren.maximum-temperature") + public double CLIMATE_HOTBARREN_MAXTEMP = 4d; + @YamlKey("climate.hot-barren.minimum-moisture") + public double CLIMATE_HOTBARREN_MINMOIST = -4d; + @YamlKey("climate.hot-barren.maximum-moisture") + public double CLIMATE_HOTBARREN_MAXMOIST = -1d; + + @YamlKey("climate.cold.minimum-temperature") + public double CLIMATE_COLD_MINTEMP = -4d; + @YamlKey("climate.cold.maximum-temperature") + public double CLIMATE_COLD_MAXTEMP = -0.5d; + @YamlKey("climate.cold.minimum-moisture") + public double CLIMATE_COLD_MINMOIST = -4d; + @YamlKey("climate.cold.maximum-moisture") + public double CLIMATE_COLD_MAXMOIST = 4d; + + @YamlKey("climate.snowy.minimum-temperature") + public double CLIMATE_SNOWY_MINTEMP = -4d; + @YamlKey("climate.snowy.maximum-temperature") + public double CLIMATE_SNOWY_MAXTEMP = -2.7d; + @YamlKey("climate.snowy.minimum-moisture") + public double CLIMATE_SNOWY_MINMOIST = -4d; + @YamlKey("climate.snowy.maximum-moisture") + public double CLIMATE_SNOWY_MAXMOIST = 4d; + + // -=[BIOMES]=- + // Biome globals + @YamlKey("biome.temperature-frequency") + public float BIOME_TEMPERATURE_FREQUENCY = 0.03f; + @YamlKey("biome.moisture-frequency") + public float BIOME_MOISTURE_FREQUENCY = 0.03f; + @YamlKey("biome.mountainous-threshold") + public float BIOME_MOUNTAINOUS_THRESHOLD = 18.5f; + @YamlKey("biome.highmountains-threshold") + public float BIOME_HIGH_MOUNTAINOUS_THRESHOLD = 27.5f; + @YamlKey("biome.mountainous-frequency") + public double BIOME_MOUNTAINOUS_FREQUENCY = 0.3d; + @YamlKey("biome.oceanic-frequency") + public float BIOME_OCEANIC_FREQUENCY = 0.11f; + @YamlKey("biome.oceanic-threshold") + public float BIOME_OCEANIC_THRESHOLD = 22f; + @YamlKey("biome.cave.crystalline-cluster.separation") + public int BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION = 86; + @YamlKey("biome.cave.crystalline-cluster.separation-maxpertub") + public double BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB = 0.37f; + @YamlKey("biome.cave.crystalline-cluster.minsize") + public int BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE = 7; + @YamlKey("biome.cave.crystalline-cluster.maxsize") + public int BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE = 11; + @YamlKey("biome.cave.dripstone-cluster.separation") + public int BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION = 64; + @YamlKey("biome.cave.dripstone-cluster.separation-maxpertub") + public double BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB = 0.35d; + @YamlKey("biome.cave.dripstone-cluster.minsize") + public int BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE = 5; + @YamlKey("biome.cave.dripstone-cluster.maxsize") + public int BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE = 11; + @YamlKey("biome.cave.lush-cluster.separation") + public int BIOME_CAVE_LUSHCLUSTER_SEPARATION = 64; + @YamlKey("biome.cave.lush-cluster.separation-maxpertub") + public double BIOME_CAVE_LUSHCLUSTER_MAXPERTUB = 0.35d; + @YamlKey("biome.cave.lush-cluster.minsize") + public int BIOME_CAVE_LUSHCLUSTER_MINSIZE = 10; + @YamlKey("biome.cave.lush-cluster.maxsize") + public int BIOME_CAVE_LUSHCLUSTER_MAXSIZE = 15; + @YamlKey("biome.deep-oceanic-threshold") + public float BIOME_DEEP_OCEANIC_THRESHOLD = 27f; + @YamlKey("biome.dithering") + public double BIOME_DITHER = 0.04d; + @YamlKey("biome.biomesection-bitshifts") + public int BIOME_SECTION_BITSHIFTS = 7; + @YamlKey("biome.clay-deposit-radius") + public float BIOME_CLAY_DEPOSIT_SIZE = 3f; + @YamlKey("biome.clay-deposit-chance-out-of-thousand") + public int BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND = 3; + @YamlKey("biome.single.land") + public String BIOME_SINGLE_TERRESTRIAL_TYPE = "disabled"; + @YamlKey("biome.single.ocean") + public String BIOME_SINGLE_OCEAN_TYPE = "disabled"; + @YamlKey("biome.single.deepocean") + public String BIOME_SINGLE_DEEPOCEAN_TYPE = "disabled"; + @YamlKey("biome.single.mountain") + public String BIOME_SINGLE_MOUNTAIN_TYPE = "disabled"; + @YamlKey("biome.single.highmountain") + public String BIOME_SINGLE_HIGHMOUNTAIN_TYPE = "disabled"; + // BIOME_SINGLE_RIVER_TYPE("biome.single.river", "disabled"), + // BIOME_SINGLE_BEACH_TYPE("biome.single.beach", "disabled"), + @YamlKey("biome.defaults.flat") + public String BIOME_DEFAULT_FLAT = "PLAINS"; + @YamlKey("biome.defaults.oceanic") + public String BIOME_DEFAULT_OCEANIC = "OCEAN"; + @YamlKey("biome.defaults.deepoceanic") + public String BIOME_DEFAULT_DEEPOCEANIC = "DEEP_OCEAN"; + @YamlKey("biome.defaults.mountainous") + public String BIOME_DEFAULT_MOUNTAINOUS = "ROCKY_MOUNTAINS"; + @YamlKey("biome.defaults.highmountainous") + public String BIOME_DEFAULT_HIGHMOUNTAINOUS = "JAGGED_PEAKS"; + @YamlKey("biome.defaults.river") + public String BIOME_DEFAULT_RIVER = "RIVER"; + @YamlKey("biome.defaults.beach") + public String BIOME_DEFAULT_BEACH = "SANDY_BEACH"; + + // Biome specific + @YamlKey("biome.rockymountains.weight") + public int BIOME_ROCKY_MOUNTAINS_WEIGHT = 1; + @YamlKey("biome.forestedmountains.weight") + public int BIOME_FORESTED_MOUNTAINS_WEIGHT = 1; + @YamlKey("biome.badlandsmountains.weight") + public int BIOME_BADLANDS_MOUNTAINS_WEIGHT = 1; + @YamlKey("biome.snowymountains.weight") + public int BIOME_SNOWY_MOUNTAINS_WEIGHT = 1; + @YamlKey("biome.birchmountains.weight") + public int BIOME_BIRCH_MOUNTAINS_WEIGHT = 1; + @YamlKey("biome.paintedhills.weight") + public int BIOME_PAINTED_HILLS_WEIGHT = 1; + @YamlKey("biome.shatteredsavanna.weight") + public int BIOME_SHATTERED_SAVANNA_WEIGHT = 4; + @YamlKey("biome.desertmountains.weight") + public int BIOME_DESERT_MOUNTAINS_WEIGHT = 0; + @YamlKey("biome.desertmountains.place-yellow-concrete") + public boolean BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE = true; + @YamlKey("biome.desertmountains.place-yellow-concrete-powder") + public boolean BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER = true; + @YamlKey("biome.jaggedpeaks.weight") + public int BIOME_JAGGED_PEAKS_WEIGHT = 1; + @YamlKey("biome.ocean.weight") + public int BIOME_OCEAN_WEIGHT = 6; + @YamlKey("biome.blackocean.weight") + public int BIOME_BLACK_OCEAN_WEIGHT = 1; + @YamlKey("biome.coldocean.weight") + public int BIOME_COLD_OCEAN_WEIGHT = 6; + @YamlKey("biome.frozenocean.weight") + public int BIOME_FROZEN_OCEAN_WEIGHT = 6; + @YamlKey("biome.warmocean.weight") + public int BIOME_WARM_OCEAN_WEIGHT = 6; + @YamlKey("biome.humidocean.weight") + public int BIOME_HUMID_OCEAN_WEIGHT = 6; + @YamlKey("biome.dryocean.weight") + public int BIOME_DRY_OCEAN_WEIGHT = 6; + @YamlKey("biome.coralreefocean.weight") + public int BIOME_CORALREEF_OCEAN_WEIGHT = 5; + @YamlKey("biome.deepocean.weight") + public int BIOME_DEEP_OCEAN_WEIGHT = 7; + @YamlKey("biome.deepcoldocean.weight") + public int BIOME_DEEP_COLD_OCEAN_WEIGHT = 7; + @YamlKey("biome.deepblackocean.weight") + public int BIOME_DEEP_BLACK_OCEAN_WEIGHT = 0; + @YamlKey("biome.deepfrozenocean.weight") + public int BIOME_DEEP_FROZEN_OCEAN_WEIGHT = 7; + @YamlKey("biome.deepwarmocean.weight") + public int BIOME_DEEP_WARM_OCEAN_WEIGHT = 7; + @YamlKey("biome.deephumidocean.weight") + public int BIOME_DEEP_HUMID_OCEAN_WEIGHT = 7; + @YamlKey("biome.deepdryocean.weight") + public int BIOME_DEEP_DRY_OCEAN_WEIGHT = 7; + @YamlKey("biome.deeplukewarmocean.weight") + public int BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT = 7; + @YamlKey("biome.mushroomisland.weight") + public int BIOME_MUSHROOM_ISLAND_WEIGHT = 1; + @YamlKey("biome.plains.weight") + public int BIOME_PLAINS_WEIGHT = 10; + @YamlKey("biome.elevatedplains.weight") + public int BIOME_ELEVATED_PLAINS_WEIGHT = 8; + @YamlKey("biome.petrifiedcliffs.weight") + public int BIOME_PETRIFIEDCLIFFS_WEIGHT = 6; + @YamlKey("biome.archedcliffs.weight") + public int BIOME_ARCHED_CLIFFS_WEIGHT = 6; + @YamlKey("biome.gorge.weight") + public int BIOME_GORGE_WEIGHT = 6; + @YamlKey("biome.erodedplains.weight") + public int BIOME_ERODED_PLAINS_WEIGHT = 6; + @YamlKey("biome.savanna.weight") + public int BIOME_SAVANNA_WEIGHT = 6; + @YamlKey("biome.muddybog.weight") + public int BIOME_MUDDYBOG_WEIGHT = 2; + @YamlKey("biome.forest.weight") + public int BIOME_FOREST_WEIGHT = 8; + @YamlKey("biome.desert.weight") + public int BIOME_DESERT_WEIGHT = 6; + @YamlKey("biome.jungle.weight") + public int BIOME_JUNGLE_WEIGHT = 5; + @YamlKey("biome.jungle.statue-chance-out-of-1000") + public int BIOME_JUNGLE_STATUE_CHANCE = 4; + @YamlKey("biome.bambooforest.weight") + public int BIOME_BAMBOO_FOREST_WEIGHT = 2; + @YamlKey("biome.badlands.weight") + public int BIOME_BADLANDS_WEIGHT = 1; + @YamlKey("biome.badlands.plateaus.height") + public int BIOME_BADLANDS_PLATEAU_HEIGHT = 15; + @YamlKey("biome.badlands.plateaus.sand-radius") + public int BIOME_BADLANDS_PLATEAU_SAND_RADIUS = 7; + @YamlKey("biome.badlands.plateaus.threshold") + public double BIOME_BADLANDS_PLATEAU_THRESHOLD = 0.23d; + @YamlKey("biome.badlands.plateaus.frequency") + public float BIOME_BADLANDS_PLATEAU_FREQUENCY = 0.01f; + @YamlKey("biome.badlands.plateaus.commonness") + public double BIOME_BADLANDS_PLATEAU_COMMONNESS = 0.18d; + @YamlKey("biome.taiga.weight") + public int BIOME_TAIGA_WEIGHT = 6; + @YamlKey("biome.cherrygrove.weight") + public int BIOME_CHERRYGROVE_WEIGHT = 3; + @YamlKey("biome.scarletforest.weight") + public int BIOME_SCARLETFOREST_WEIGHT = 3; + @YamlKey("biome.snowytaiga.weight") + public int BIOME_SNOWY_TAIGA_WEIGHT = 6; + @YamlKey("biome.snowywasteland.weight") + public int BIOME_SNOWY_WASTELAND_WEIGHT = 4; + @YamlKey("biome.icespikes.weight") + public int BIOME_ICE_SPIKES_WEIGHT = 2; + @YamlKey("biome.darkforest.weight") + public int BIOME_DARK_FOREST_WEIGHT = 5; + @YamlKey("biome.darkforest.spawn-heads") + public boolean BIOME_DARK_FOREST_SPAWN_HEADS = true; + @YamlKey("biome.swamp.weight") + public int BIOME_SWAMP_WEIGHT = 5; + @YamlKey("biome.mangrove.weight") + public int BIOME_MANGROVE_WEIGHT = 5; + @YamlKey("biome.oasis.commonness") + public double BIOME_OASIS_COMMONNESS = 1d; + @YamlKey("biome.oasis.frequency") + public float BIOME_OASIS_FREQUENCY = 0.012f; + + + // -=[TREES]=- + @YamlKey("trees.big-jungle-trees.enabled") + public boolean TREES_JUNGLE_BIG_ENABLED = true; + @YamlKey("trees.big-taiga-trees.enabled") + public boolean TREES_TAIGA_BIG_ENABLED = true; + @YamlKey("trees.big-forest-trees.enabled") + public boolean TREES_FOREST_BIG_ENABLED = true; + @YamlKey("trees.big-savanna-trees.enabled") + public boolean TREES_SAVANNA_BIG_ENABLED = true; + @YamlKey("trees.big-birch-trees.enabled") + public boolean TREES_BIRCH_BIG_ENABLED = true; + @YamlKey("trees.big-scarlet-trees.enabled") + public boolean TREES_SCARLET_BIG_ENABLED = true; + @YamlKey("trees.big-snowy-taiga-trees.enabled") + public boolean TREES_SNOWY_TAIGA_BIG_ENABLED = true; + @YamlKey("trees.big-dark-forest-trees.enabled") + public boolean TREES_DARK_FOREST_BIG_ENABLED = true; + + // -=[MISC]=- + // MISC_SMOOTH_DESIGN("misc.smooth-design",false), + @YamlKey("misc.custom-small-trees-from-saplings.enabled") + public boolean MISC_SAPLING_CUSTOM_TREES_ENABLED = true; + @YamlKey("misc.custom-small-trees-from-saplings.big-jungle-tree") + public boolean MISC_SAPLING_CUSTOM_TREES_BIGTREES = true; + @YamlKey("misc.trees.only-use-logs-no-wood") + public boolean MISC_TREES_FORCE_LOGS = false; + @YamlKey("misc.trees.ground-gradient-limit") + public double MISC_TREES_GRADIENT_LIMIT = 1.3d; + @YamlKey("misc.use-slabs-to-smooth-terrain") + public boolean MISC_USE_SLABS_TO_SMOOTH = true; + + // -=[DEVSTUFF]=- + @YamlKey("dev-stuff.suppress-watchdog") + public boolean DEVSTUFF_SUPPRESS_WATCHDOG = true; + @YamlKey("dev-stuff.chunk-cache-size") + public int DEVSTUFF_CHUNKCACHE_SIZE = 6000; + @YamlKey("dev-stuff.biomecache-size") + public int DEVSTUFF_CHUNKBIOMES_SIZE = 3000; + // DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT("dev-stuff.experimental-structure-placement", false), + @YamlKey("dev-stuff.debug-mode") + public boolean DEVSTUFF_DEBUG_MODE = false; + @YamlKey("dev-stuff.force-only-vanilla-mushrooms") + public boolean DEVSTUFF_VANILLA_MUSHROOMS = false; + @YamlKey("dev-stuff.patcher-cache-max-size") + public int DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY = 100; + @YamlKey("dev-stuff.extended-commands") + public boolean DEVSTUFF_EXTENDED_COMMANDS = false; + @YamlKey("dev-stuff.suppress-terraform-console-logs") + public boolean DEVSTUFF_SUPPRESS_CONSOLE_LOGS = true; + @YamlKey("dev-stuff.attempt-fixing-premature-generations") + public boolean DEVSTUFF_ATTEMPT_FIXING_PREMATURE = true; + @YamlKey("dev-stuff.vanilla-structure-locate-timeoutmillis") + public int DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS = 5000; + @YamlKey("dev-stuff.vanilla-disable-locate") + public boolean DEVSTUFF_VANILLA_LOCATE_DISABLE = false; + + // -=[CAVES]=- + @YamlKey("caves.allow-flooded-caves") + public boolean CAVES_ALLOW_FLOODED_CAVES = false; + // CAVES_ALLOW_FLOODED_RAVINES("caves.allow-flooded-ravines",true), + + // -=[STRUCTURES]=- + @YamlKey("structures.technical.megachunk.numbiomesections") + public int STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS = 4; + @YamlKey("structures.technical.megachunk.max-structures-per-megachunk") + public int STRUCTURES_MEGACHUNK_MAXSTRUCTURES = 3; + @YamlKey("structures.mansion.enabled") + public boolean STRUCTURES_MANSION_ENABLED = true; + @YamlKey("structures.mansion.size") + public int STRUCTURES_MANSION_SIZE = 80; + @YamlKey("structures.mansion.min-distance-blocks") + public int STRUCTURES_MANSION_MINDISTANCE = 5000; + @YamlKey("structures.mansion.pillager-spawn-aggression") + public int STRUCTURES_MANSION_SPAWNAGGRESSION = 1; + @YamlKey("structures.mansion.spawnratio") + public double STRUCTURES_MANSION_SPAWNRATIO = 0.3d; + @YamlKey("structures.mansion.chunk-exclusion-zone") + public int STRUCTURES_MANSION_CHUNK_EXCLUSION_ZONE = 4; + @YamlKey("structures.stronghold.enabled") + public boolean STRUCTURES_STRONGHOLD_ENABLED = true; + @YamlKey("structures.stronghold.failsafe-y") + public int STRUCTURES_STRONGHOLD_FAILSAFE_Y = -16; + @YamlKey("structures.stronghold.min-y") + public int STRUCTURES_STRONGHOLD_MIN_Y = 0; + @YamlKey("structures.stronghold.max-y") + public int STRUCTURES_STRONGHOLD_MAX_Y = 25; + @YamlKey("structures.monument.enabled") + public boolean STRUCTURES_MONUMENT_ENABLED = true; + @YamlKey("structures.monument.spawn-ratio") + public double STRUCTURES_MONUMENT_SPAWNRATIO = 0.3d; + @YamlKey("structures.pyramid.enabled") + public boolean STRUCTURES_PYRAMID_ENABLED = true; + @YamlKey("structures.pyramid.spawn-ratio") + public double STRUCTURES_PYRAMID_SPAWNRATIO = 0.3d; + @YamlKey("structures.pyramid.spawn-elder-guardian") + public boolean STRUCTURES_PYRAMID_SPAWN_ELDER_GUARDIAN = true; + @YamlKey("structures.pyramid.suspicious-sand-per-antechamber") + public int STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER = 4; + @YamlKey("structures.villagehouse.spawnratio") + public double STRUCTURES_VILLAGEHOUSE_SPAWNRATIO = 0.8d; + @YamlKey("structures.mountainhouse.enabled") + public boolean STRUCTURES_MOUNTAINHOUSE_ENABLED = true; + @YamlKey("structures.farmhouse.enabled") + public boolean STRUCTURES_FARMHOUSE_ENABLED = true; + @YamlKey("structures.animalfarm.enabled") + public boolean STRUCTURES_ANIMALFARM_ENABLED = true; + @YamlKey("structures.trailruins.spawnratio") + public double STRUCTURES_TRAILRUINS_SPAWNRATIO = 0.5d; + @YamlKey("structures.trailruins.enabled") + public boolean STRUCTURES_TRAILRUINS_ENABLED = true; + @YamlKey("structures.trialchamber.spawnratio") + public double STRUCTURES_TRIALCHAMBER_SPAWNRATIO = 0.3d; + @YamlKey("structures.trialchamber.enabled") + public boolean STRUCTURES_TRIALCHAMBER_ENABLED = true; + @YamlKey("structures.warmoceanruins.spawnratio") + public double STRUCTURES_WARMOCEANRUINS_SPAWNRATIO = 1d; + @YamlKey("structures.warmoceanruins.enabled") + public boolean STRUCTURES_WARMOCEANRUINS_ENABLED = true; + @YamlKey("structures.village.spawnratio") + public double STRUCTURES_VILLAGE_SPAWNRATIO = 1d; + @YamlKey("structures.plainsvillage.enabled") + public boolean STRUCTURES_PLAINSVILLAGE_ENABLED = true; + @YamlKey("structures.plainsvillage.height-tolerance") + public int STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE = 10; + @YamlKey("structures.village.chunk-exclusion-zone") + public int STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE = 4; + @YamlKey("structures.swamphut.enabled") + public boolean STRUCTURES_SWAMPHUT_ENABLED = true; + @YamlKey("structures.swamphut.spawnratio") + public double STRUCTURES_SWAMPHUT_SPAWNRATIO = 0.4d; + @YamlKey("structures.swamphut.count-per-megachunk") + public int STRUCTURES_SWAMPHUT_COUNT_PER_MEGACHUNK = 1; + @YamlKey("structures.desertwell.enabled") + public boolean STRUCTURES_DESERTWELL_ENABLED = true; + @YamlKey("structures.desertwell.spawnratio") + public double STRUCTURES_DESERTWELL_SPAWNRATIO = 0.3d; + @YamlKey("structures.desertwell.count-per-megachunk") + public int STRUCTURES_DESERTWELL_COUNT_PER_MEGACHUNK = 2; + @YamlKey("structures.small-dungeon.spawnratio") + public double STRUCTURES_DUNGEONS_SPAWNRATIO = 0.4d; + @YamlKey("structures.small-dungeon.count-per-megachunk") + public int STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK = 3; + @YamlKey("structures.underground-dungeon.enabled") + public boolean STRUCTURES_UNDERGROUNDDUNGEON_ENABLED = true; + @YamlKey("structures.drowned-dungeon.enabled") + public boolean STRUCTURES_DROWNEDDUNGEON_ENABLED = true; + @YamlKey("structures.drowned-dungeon.min-chunk-y") + public int STRUCTURES_DROWNEDDUNGEON_MIN_DEPTH = 52; + @YamlKey("structures.drowned-dungeon.chance-out-of-1000") + public int STRUCTURES_DROWNEDDUNGEON_CHANCE = 200; + @YamlKey("structures.shipwreck.spawnratio") + public double STRUCTURES_SHIPWRECK_SPAWNRATIO = 0.6d; + @YamlKey("structures.shipwreck.enabled") + public boolean STRUCTURES_SHIPWRECK_ENABLED = true; + @YamlKey("structures.shipwreck.count-per-megachunk") + public int STRUCTURES_SHIPWRECK_COUNT_PER_MEGACHUNK = 2; + @YamlKey("structures.ruinedportal.spawnratio") + public double STRUCTURES_RUINEDPORTAL_SPAWNRATIO = 0.4d; + @YamlKey("structures.ruinedportal.enabled") + public boolean STRUCTURES_RUINEDPORTAL_ENABLED = true; + @YamlKey("structures.ruinedportal.count-per-megachunk") + public int STRUCTURES_RUINEDPORTAL_COUNT_PER_MEGACHUNK = 1; + @YamlKey("structures.igloo.spawnratio") + public double STRUCTURES_IGLOO_SPAWNRATIO = 0.8d; + @YamlKey("structures.igloo.enabled") + public boolean STRUCTURES_IGLOO_ENABLED = true; + @YamlKey("structures.igloo.count-per-megachunk") + public int STRUCTURES_IGLOO_COUNT_PER_MEGACHUNK = 1; + @YamlKey("structures.buriedtreasure.spawnratio") + public double STRUCTURES_BURIEDTREASURE_SPAWNRATIO = 0.3d; + @YamlKey("structures.buriedtreasure.enabled") + public boolean STRUCTURES_BURIEDTREASURE_ENABLED = true; + @YamlKey("structures.buriedtreasure.count-per-megachunk") + public int STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK = 2; + @YamlKey("structures.mineshaft.enabled") + public boolean STRUCTURES_MINESHAFT_ENABLED = true; + @YamlKey("structures.mineshaft.spawnratio") + public double STRUCTURES_MINESHAFT_SPAWNRATIO = 0.8d; + @YamlKey("structures.mineshaft.min-y") + public int STRUCTURES_MINESHAFT_MIN_Y = -10; + @YamlKey("structures.mineshaft.max-y") + public int STRUCTURES_MINESHAFT_MAX_Y = 30; + @YamlKey("structures.catacombs.enabled") + public boolean STRUCTURES_CATACOMBS_ENABLED = true; + @YamlKey("structures.catacombs.spawnratio") + public double STRUCTURES_CATACOMBS_SPAWNRATIO = 0.6d; + @YamlKey("structures.catacombs.sizerollchance") + public double STRUCTURES_CATACOMBS_SIZEROLLCHANCE = 0.40d; + @YamlKey("structures.catacombs.max-levels") + public int STRUCTURES_CATACOMBS_MAX_LEVELS = 5; + @YamlKey("structures.catacombs.min-y") + public int STRUCTURES_CATACOMBS_MIN_Y = 0; + @YamlKey("structures.catacombs.max-y") + public int STRUCTURES_CATACOMBS_MAX_Y = 30; + @YamlKey("structures.ancientcity.enabled") + public boolean STRUCTURES_ANCIENTCITY_ENABLED = true; + @YamlKey("structures.ancientcity.spawnratio") + public double STRUCTURES_ANCIENTCITY_SPAWNRATIO = 0.5d; + @YamlKey("structures.ancientcity.min-y") + public int STRUCTURES_ANCIENTCITY_MIN_Y = -20; + @YamlKey("structures.ancientcity.max-y") + public int STRUCTURES_ANCIENTCITY_MAX_Y = -10; + @YamlKey("structures.largecave.enabled") + public boolean STRUCTURES_LARGECAVE_ENABLED = true; + @YamlKey("structures.largecave.spawnratio") + public double STRUCTURES_LARGECAVE_SPAWNRATIO = 0.8d; + @YamlKey("structures.badlands-mine.enabled") + public boolean STRUCTURES_BADLANDS_MINE_ENABLED = true; + @YamlKey("structures.badlands-mine.distance-between-mines") + public int STRUCTURES_BADLANDS_MINE_DISTANCE = 8; + @YamlKey("structures.badlands-mine.depth") + public int STRUCTURES_BADLANDS_MINE_DEPTH = 25; + @YamlKey("structures.outpost.enabled") + public boolean STRUCTURES_OUTPOST_ENABLED = true; + @YamlKey("structures.outpost.spawnratio") + public double STRUCTURES_OUTPOST_SPAWNRATIO = 0.8d; + + // -=[ANIMALS]=- + // BEES + @YamlKey("animals.bee.hive-frequency") + public double ANIMALS_BEE_HIVEFREQUENCY = 0.02d; + // PIG + @YamlKey("animals.pig.min-herd-size") + public int ANIMALS_PIG_MINHERDSIZE = 3; + @YamlKey("animals.pig.max-herd-size") + public int ANIMALS_PIG_MAXHERDSIZE = 4; + @YamlKey("animals.pig.chance") + public int ANIMALS_PIG_CHANCE = 2; + // COW + @YamlKey("animals.cow.min-herd-size") + public int ANIMALS_COW_MINHERDSIZE = 4; + @YamlKey("animals.cow.max-herd-size") + public int ANIMALS_COW_MAXHERDSIZE = 12; + @YamlKey("animals.cow.chance") + public int ANIMALS_COW_CHANCE = 2; + // MOOSHROOM + @YamlKey("animals.mooshroom.min-herd-size") + public int ANIMALS_MOOSHROOM_MINHERDSIZE = 2; + @YamlKey("animals.mooshroom.max-herd-size") + public int ANIMALS_MOOSHROOM_MAXHERDSIZE = 6; + @YamlKey("animals.mooshroom.chance") + public int ANIMALS_MOOSHROOM_CHANCE = 10; + // SHEEP + @YamlKey("animals.sheep.min-herd-size") + public int ANIMALS_SHEEP_MINHERDSIZE = 2; + @YamlKey("animals.sheep.max-herd-size") + public int ANIMALS_SHEEP_MAXHERDSIZE = 8; + @YamlKey("animals.sheep.chance") + public int ANIMALS_SHEEP_CHANCE = 2; + // CHICKEN + @YamlKey("animals.chicken.min-herd-size") + public int ANIMALS_CHICKEN_MINHERDSIZE = 1; + @YamlKey("animals.chicken.max-herd-size") + public int ANIMALS_CHICKEN_MAXHERDSIZE = 3; + @YamlKey("animals.chicken.chance") + public int ANIMALS_CHICKEN_CHANCE = 2; + // ARMADILLO + @YamlKey("animals.armadillo.min-herd-size") + public int ANIMALS_ARMADILLO_MINHERDSIZE = 1; + @YamlKey("animals.armadillo.max-herd-size") + public int ANIMALS_ARMADILLO_MAXHERDSIZE = 3; + @YamlKey("animals.armadillo.chance") + public int ANIMALS_ARMADILLO_CHANCE = 2; + // HORSE + @YamlKey("animals.horse.min-herd-size") + public int ANIMALS_HORSE_MINHERDSIZE = 2; + @YamlKey("animals.horse.max-herd-size") + public int ANIMALS_HORSE_MAXHERDSIZE = 6; + @YamlKey("animals.horse.chance") + public int ANIMALS_HORSE_CHANCE = 1; + // DONKEY + @YamlKey("animals.donkey.min-herd-size") + public int ANIMALS_DONKEY_MINHERDSIZE = 2; + @YamlKey("animals.donkey.max-herd-size") + public int ANIMALS_DONKEY_MAXHERDSIZE = 6; + @YamlKey("animals.donkey.chance") + public int ANIMALS_DONKEY_CHANCE = 1; + // GOAT + @YamlKey("animals.goat.min-herd-size") + public int ANIMALS_GOAT_MINHERDSIZE = 3; + @YamlKey("animals.goat.max-herd-size") + public int ANIMALS_GOAT_MAXHERDSIZE = 4; + @YamlKey("animals.goat.chance") + public int ANIMALS_GOAT_CHANCE = 1; + // RABBIT + @YamlKey("animals.rabbit.min-herd-size") + public int ANIMALS_RABBIT_MINHERDSIZE = 2; + @YamlKey("animals.rabbit.max-herd-size") + public int ANIMALS_RABBIT_MAXHERDSIZE = 3; + @YamlKey("animals.rabbit.chance") + public int ANIMALS_RABBIT_CHANCE = 1; + // POLAR_BEAR + @YamlKey("animals.polarbear.min-herd-size") + public int ANIMALS_POLAR_BEAR_MINHERDSIZE = 2; + @YamlKey("animals.polarbear.max-herd-size") + public int ANIMALS_POLAR_BEAR_MAXHERDSIZE = 3; + @YamlKey("animals.polarbear.chance") + public int ANIMALS_POLAR_BEAR_CHANCE = 1; + // PANDA + @YamlKey("animals.panda.min-herd-size") + public int ANIMALS_PANDA_MINHERDSIZE = 2; + @YamlKey("animals.panda.max-herd-size") + public int ANIMALS_PANDA_MAXHERDSIZE = 3; + @YamlKey("animals.panda.chance") + public int ANIMALS_PANDA_CHANCE = 1; + // FOX + @YamlKey("animals.fox.min-herd-size") + public int ANIMALS_FOX_MINHERDSIZE = 1; + @YamlKey("animals.fox.max-herd-size") + public int ANIMALS_FOX_MAXHERDSIZE = 2; + @YamlKey("animals.fox.chance") + public int ANIMALS_FOX_CHANCE = 1; + // LLAMMA + @YamlKey("animals.llama.min-herd-size") + public int ANIMALS_LLAMA_MINHERDSIZE = 4; + @YamlKey("animals.llama.max-herd-size") + public int ANIMALS_LLAMA_MAXHERDSIZE = 6; + @YamlKey("animals.llama.chance") + public int ANIMALS_LLAMA_CHANCE = 2; + // PARROT + @YamlKey("animals.parrot.min-herd-size") + public int ANIMALS_PARROT_MINHERDSIZE = 1; + @YamlKey("animals.parrot.max-herd-size") + public int ANIMALS_PARROT_MAXHERDSIZE = 2; + @YamlKey("animals.parrot.chance") + public int ANIMALS_PARROT_CHANCE = 2; + // OCELOT + @YamlKey("animals.ocelot.min-herd-size") + public int ANIMALS_OCELOT_MINHERDSIZE = 1; + @YamlKey("animals.ocelot.max-herd-size") + public int ANIMALS_OCELOT_MAXHERDSIZE = 3; + @YamlKey("animals.ocelot.chance") + public int ANIMALS_OCELOT_CHANCE = 1; + // WOLF + @YamlKey("animals.wolf.min-herd-size") + public int ANIMALS_WOLF_MINHERDSIZE = 1; + @YamlKey("animals.wolf.max-herd-size") + public int ANIMALS_WOLF_MAXHERDSIZE = 4; + @YamlKey("animals.wolf.chance") + public int ANIMALS_WOLF_CHANCE = 2; + // TURTLE + @YamlKey("animals.turtle.min-herd-size") + public int ANIMALS_TURTLE_MINHERDSIZE = 2; + @YamlKey("animals.turtle.max-herd-size") + public int ANIMALS_TURTLE_MAXHERDSIZE = 5; + @YamlKey("animals.turtle.chance") + public int ANIMALS_TURTLE_CHANCE = 1; + // DOLPHIN + @YamlKey("animals.dolphin.min-herd-size") + public int ANIMALS_DOLPHIN_MINHERDSIZE = 1; + @YamlKey("animals.dolphin.max-herd-size") + public int ANIMALS_DOLPHIN_MAXHERDSIZE = 3; + @YamlKey("animals.dolphin.chance") + public int ANIMALS_DOLPHIN_CHANCE = 1; + // COD + @YamlKey("animals.cod.min-herd-size") + public int ANIMALS_COD_MINHERDSIZE = 3; + @YamlKey("animals.cod.max-herd-size") + public int ANIMALS_COD_MAXHERDSIZE = 6; + @YamlKey("animals.cod.chance") + public int ANIMALS_COD_CHANCE = 2; + // SQUID + @YamlKey("animals.squid.min-herd-size") + public int ANIMALS_SQUID_MINHERDSIZE = 1; + @YamlKey("animals.squid.max-herd-size") + public int ANIMALS_SQUID_MAXHERDSIZE = 4; + @YamlKey("animals.squid.chance") + public int ANIMALS_SQUID_CHANCE = 2; + // SALMON + @YamlKey("animals.salmon.min-herd-size") + public int ANIMALS_SALMON_MINHERDSIZE = 4; + @YamlKey("animals.salmon.max-herd-size") + public int ANIMALS_SALMON_MAXHERDSIZE = 4; + @YamlKey("animals.salmon.chance") + public int ANIMALS_SALMON_CHANCE = 2; + // PUFFERFISH + @YamlKey("animals.pufferfish.min-herd-size") + public int ANIMALS_PUFFERFISH_MINHERDSIZE = 1; + @YamlKey("animals.pufferfish.max-herd-size") + public int ANIMALS_PUFFERFISH_MAXHERDSIZE = 3; + @YamlKey("animals.pufferfish.chance") + public int ANIMALS_PUFFERFISH_CHANCE = 1; + // TROPICALFISH + @YamlKey("animals.tropical-fish.min-herd-size") + public int ANIMALS_TROPICALFISH_MINHERDSIZE = 4; + @YamlKey("animals.tropical-fish.max-herd-size") + public int ANIMALS_TROPICALFISH_MAXHERDSIZE = 8; + @YamlKey("animals.tropical-fish.chance") + public int ANIMALS_TROPICALFISH_CHANCE = 2; + + // -=[ORES]=- + // AMETHYST + @YamlKey("ore.amethyst.chance-per-chunk") + public double ORE_AMETHYST_CHANCE = 0.05d; + @YamlKey("ore.amethyst.geode-size") + public int ORE_AMETHYST_GEODE_SIZE = 7; + @YamlKey("ore.amethyst.min-depth") + public int ORE_AMETHYST_MIN_DEPTH = 70; + @YamlKey("ore.amethyst.min-depth-below-surface") + public int ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE = 15; + + // COAL + @YamlKey("ore.coal.chance-per-chunk") + public int ORE_COAL_CHANCE = 50; + @YamlKey("ore.coal.max-vein-size") + public int ORE_COAL_VEINSIZE = 25; + @YamlKey("ore.coal.max-vein-count") + public int ORE_COAL_MAXVEINNUMBER = 115; + @YamlKey("ore.coal.common-spawn-height") + public int ORE_COAL_COMMONSPAWNHEIGHT = 96; + @YamlKey("ore.coal.max-spawn-height") + public int ORE_COAL_MAXSPAWNHEIGHT = 256; + @YamlKey("ore.coal.min-spawn-height") + public int ORE_COAL_MINSPAWNHEIGHT = 5; + + // IRON + @YamlKey("ore.iron.chance-per-chunk") + public int ORE_IRON_CHANCE = 50; + @YamlKey("ore.iron.max-vein-size") + public int ORE_IRON_VEINSIZE = 10; + @YamlKey("ore.iron.max-vein-count") + public int ORE_IRON_MAXVEINNUMBER = 73; + @YamlKey("ore.iron.common-spawn-height") + public int ORE_IRON_COMMONSPAWNHEIGHT = 16; + @YamlKey("ore.iron.max-spawn-height") + public int ORE_IRON_MAXSPAWNHEIGHT = 256; + @YamlKey("ore.iron.min-spawn-height") + public int ORE_IRON_MINSPAWNHEIGHT = -64; + + // GOLD + @YamlKey("ore.gold.chance-per-chunk") + public int ORE_GOLD_CHANCE = 40; + @YamlKey("ore.gold.max-vein-size") + public int ORE_GOLD_VEINSIZE = 10; + @YamlKey("ore.gold.max-vein-count") + public int ORE_GOLD_MAXVEINNUMBER = 15; + @YamlKey("ore.gold.common-spawn-height") + public int ORE_GOLD_COMMONSPAWNHEIGHT = -16; + @YamlKey("ore.gold.max-spawn-height") + public int ORE_GOLD_MAXSPAWNHEIGHT = 32; + @YamlKey("ore.gold.min-spawn-height") + public int ORE_GOLD_MINSPAWNHEIGHT = -64; + + // GOLD + @YamlKey("ore.badlandsgold.chance-per-chunk") + public int ORE_BADLANDSGOLD_CHANCE = 40; + @YamlKey("ore.badlandsgold.max-vein-size") + public int ORE_BADLANDSGOLD_VEINSIZE = 10; + @YamlKey("ore.badlandsgold.max-vein-count") + public int ORE_BADLANDSGOLD_MAXVEINNUMBER = 15; + @YamlKey("ore.badlandsgold.common-spawn-height") + public int ORE_BADLANDSGOLD_COMMONSPAWNHEIGHT = 32; + @YamlKey("ore.badlandsgold.max-spawn-height") + public int ORE_BADLANDSGOLD_MAXSPAWNHEIGHT = 256; + @YamlKey("ore.badlandsgold.min-spawn-height") + public int ORE_BADLANDSGOLD_MINSPAWNHEIGHT = -64; + + // DIAMOND + @YamlKey("ore.diamond.chance-per-chunk") + public int ORE_DIAMOND_CHANCE = 30; + @YamlKey("ore.diamond.max-vein-size") + public int ORE_DIAMOND_VEINSIZE = 7; + @YamlKey("ore.diamond.max-vein-count") + public int ORE_DIAMOND_MAXVEINNUMBER = 16; + @YamlKey("ore.diamond.common-spawn-height") + public int ORE_DIAMOND_COMMONSPAWNHEIGHT = -64; + @YamlKey("ore.diamond.max-spawn-height") + public int ORE_DIAMOND_MAXSPAWNHEIGHT = 16; + @YamlKey("ore.diamond.min-spawn-height") + public int ORE_DIAMOND_MINSPAWNHEIGHT = -64; + + // EMERALD + @YamlKey("ore.emerald.chance-per-chunk") + public int ORE_EMERALD_CHANCE = 30; + @YamlKey("ore.emerald.max-vein-size") + public int ORE_EMERALD_VEINSIZE = 7; + @YamlKey("ore.emerald.max-vein-count") + public int ORE_EMERALD_MAXVEINNUMBER = 3; + @YamlKey("ore.emerald.common-spawn-height") + public int ORE_EMERALD_COMMONSPAWNHEIGHT = 12; + @YamlKey("ore.emerald.max-spawn-height") + public int ORE_EMERALD_MAXSPAWNHEIGHT = 256; + @YamlKey("ore.emerald.min-spawn-height") + public int ORE_EMERALD_MINSPAWNHEIGHT = -16; + + // LAPIS + @YamlKey("ore.lapis.chance-per-chunk") + public int ORE_LAPIS_CHANCE = 30; + @YamlKey("ore.lapis.max-vein-size") + public int ORE_LAPIS_VEINSIZE = 6; + @YamlKey("ore.lapis.max-vein-count") + public int ORE_LAPIS_MAXVEINNUMBER = 40; + @YamlKey("ore.lapis.common-spawn-height") + public int ORE_LAPIS_COMMONSPAWNHEIGHT = 0; + @YamlKey("ore.lapis.max-spawn-height") + public int ORE_LAPIS_MAXSPAWNHEIGHT = 64; + @YamlKey("ore.lapis.min-spawn-height") + public int ORE_LAPIS_MINSPAWNHEIGHT = -64; + + // REDSTONE + @YamlKey("ore.redstone.chance-per-chunk") + public int ORE_REDSTONE_CHANCE = 40; + @YamlKey("ore.redstone.max-vein-size") + public int ORE_REDSTONE_VEINSIZE = 10; + @YamlKey("ore.redstone.max-vein-count") + public int ORE_REDSTONE_MAXVEINNUMBER = 15; + @YamlKey("ore.redstone.common-spawn-height") + public int ORE_REDSTONE_COMMONSPAWNHEIGHT = -32; + @YamlKey("ore.redstone.max-spawn-height") + public int ORE_REDSTONE_MAXSPAWNHEIGHT = 16; + @YamlKey("ore.redstone.min-spawn-height") + public int ORE_REDSTONE_MINSPAWNHEIGHT = -64; + + // COPPER + @YamlKey("ore.copper.chance-per-chunk") + public int ORE_COPPER_CHANCE = 40; + @YamlKey("ore.copper.max-vein-size") + public int ORE_COPPER_VEINSIZE = 10; + @YamlKey("ore.copper.max-vein-count") + public int ORE_COPPER_MAXVEINNUMBER = 45; + @YamlKey("ore.copper.common-spawn-height") + public int ORE_COPPER_COMMONSPAWNHEIGHT = 48; + @YamlKey("ore.copper.max-spawn-height") + public int ORE_COPPER_MAXSPAWNHEIGHT = 104; + @YamlKey("ore.copper.min-spawn-height") + public int ORE_COPPER_MINSPAWNHEIGHT = -16; + + // GRAVEL + @YamlKey("ore.gravel.chance-per-chunk") + public int ORE_GRAVEL_CHANCE = 75; + @YamlKey("ore.gravel.max-vein-size") + public int ORE_GRAVEL_VEINSIZE = 45; + @YamlKey("ore.gravel.max-vein-count") + public int ORE_GRAVEL_MAXVEINNUMBER = 100; + @YamlKey("ore.gravel.common-spawn-height") + public int ORE_GRAVEL_COMMONSPAWNHEIGHT = 255; + @YamlKey("ore.gravel.max-spawn-height") + public int ORE_GRAVEL_MAXSPAWNHEIGHT = 300; + @YamlKey("ore.gravel.min-spawn-height") + public int ORE_GRAVEL_MINSPAWNHEIGHT = -64; + + // ANDESITE + @YamlKey("ore.andesite.chance-per-chunk") + public int ORE_ANDESITE_CHANCE = 80; + @YamlKey("ore.andesite.max-vein-size") + public int ORE_ANDESITE_VEINSIZE = 45; + @YamlKey("ore.andesite.max-vein-count") + public int ORE_ANDESITE_MAXVEINNUMBER = 110; + @YamlKey("ore.andesite.common-spawn-height") + public int ORE_ANDESITE_COMMONSPAWNHEIGHT = 255; + @YamlKey("ore.andesite.max-spawn-height") + public int ORE_ANDESITE_MAXSPAWNHEIGHT = 300; + @YamlKey("ore.andesite.min-spawn-height") + public int ORE_ANDESITE_MINSPAWNHEIGHT = -64; + + // DIORITE + @YamlKey("ore.diorite.chance-per-chunk") + public int ORE_DIORITE_CHANCE = 80; + @YamlKey("ore.diorite.max-vein-size") + public int ORE_DIORITE_VEINSIZE = 45; + @YamlKey("ore.diorite.max-vein-count") + public int ORE_DIORITE_MAXVEINNUMBER = 110; + @YamlKey("ore.diorite.common-spawn-height") + public int ORE_DIORITE_COMMONSPAWNHEIGHT = 255; + @YamlKey("ore.diorite.max-spawn-height") + public int ORE_DIORITE_MAXSPAWNHEIGHT = 300; + @YamlKey("ore.diorite.min-spawn-height") + public int ORE_DIORITE_MINSPAWNHEIGHT = -64; + + // GRANITE + @YamlKey("ore.granite.chance-per-chunk") + public int ORE_GRANITE_CHANCE = 80; + @YamlKey("ore.granite.max-vein-size") + public int ORE_GRANITE_VEINSIZE = 45; + @YamlKey("ore.granite.max-vein-count") + public int ORE_GRANITE_MAXVEINNUMBER = 110; + @YamlKey("ore.granite.common-spawn-height") + public int ORE_GRANITE_COMMONSPAWNHEIGHT = 255; + @YamlKey("ore.granite.max-spawn-height") + public int ORE_GRANITE_MAXSPAWNHEIGHT = 300; + @YamlKey("ore.granite.min-spawn-height") + public int ORE_GRANITE_MINSPAWNHEIGHT = -64; + + // TUFF + @YamlKey("ore.tuff.chance-per-chunk") + public int ORE_TUFF_CHANCE = 40; + @YamlKey("ore.tuff.max-vein-size") + public int ORE_TUFF_VEINSIZE = 30; + @YamlKey("ore.tuff.max-vein-count") + public int ORE_TUFF_MAXVEINNUMBER = 50; + @YamlKey("ore.tuff.common-spawn-height") + public int ORE_TUFF_COMMONSPAWNHEIGHT = -64; + @YamlKey("ore.tuff.max-spawn-height") + public int ORE_TUFF_MAXSPAWNHEIGHT = 10; + @YamlKey("ore.tuff.min-spawn-height") + public int ORE_TUFF_MINSPAWNHEIGHT = -63; + + // DEEPSLATE + @YamlKey("ore.deepslate.chance-per-chunk") + public int ORE_DEEPSLATE_CHANCE = 80; + @YamlKey("ore.deepslate.max-vein-size") + public int ORE_DEEPSLATE_VEINSIZE = 45; + @YamlKey("ore.deepslate.max-vein-count") + public int ORE_DEEPSLATE_MAXVEINNUMBER = 50; + @YamlKey("ore.deepslate.common-spawn-height") + public int ORE_DEEPSLATE_COMMONSPAWNHEIGHT = 5; + @YamlKey("ore.deepslate.max-spawn-height") + public int ORE_DEEPSLATE_MAXSPAWNHEIGHT = 15; + @YamlKey("ore.deepslate.min-spawn-height") + public int ORE_DEEPSLATE_MINSPAWNHEIGHT = 0; + + @YamlComment("Turn this off to remove any cave carveouts") + @YamlKey("feature_toggle.caves") + public boolean FEATURE_CAVES_ENABLED = true; + @YamlComment("No animals anymore (or spawners). Ensure to `.setGameRule(GameRule.DO_MOB_SPAWNING, false)` to make sure none actually spawn afterwards.") + @YamlKey("feature_toggle.animals") + public boolean FEATURE_ANIMALS_ENABLED = true; + @YamlComment("Toggle (precious) ores") + @YamlKey("feature_toggle.ores") + public boolean FEATURE_ORES_ENABLED = true; + @YamlComment("'Trees' means the big trees") + @YamlKey("feature_toggle.trees") + public boolean FEATURE_TREES_ENABLED = true; + @YamlComment("'Tall' means those tree-like mushrooms. The smaller ones are governed by the plants-toggle.") + @YamlKey("feature_toggle.tall_mushrooms") + public boolean FEATURE_TALL_MUSHROOMS_ENABLED = true; + @YamlComment("'Plants' mean everything but the big trees") + @YamlKey("feature_toggle.plants") + public boolean FEATURE_PLANTS_ENABLED = true; + @YamlComment("Toggle this for no more villages, ruined portals, ...") + @YamlKey("feature_toggle.structures") + public boolean FEATURE_STRUCTURES_ENABLED = true; + @YamlComment("Small lanterns, barrels, chests, ...") + @YamlKey("feature_toggle.decorations") + public boolean FEATURE_DECORATIONS_ENABLED = true; + + // Extras + @YamlComment("What language file should be used?") + @YamlKey("lang") + public String LANGUAGE_FILE = "eng.yml"; + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areCavesEnabled() { + return c.FEATURE_CAVES_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areTreesEnabled() { + return c.FEATURE_TREES_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areTallMushroomsEnabled() { + return c.FEATURE_TALL_MUSHROOMS_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean arePlantsEnabled() { + return c.FEATURE_PLANTS_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areStructuresEnabled() { + return c.FEATURE_STRUCTURES_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areAnimalsEnabled() { + return c.FEATURE_ANIMALS_ENABLED; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean areDecorationsEnabled() { + return c.FEATURE_DECORATIONS_ENABLED; + } +} diff --git a/common/src/main/java/org/terraform/main/config/TConfigOption.java b/common/src/main/java/org/terraform/main/config/TConfigOption.java deleted file mode 100644 index 1eb2e701..00000000 --- a/common/src/main/java/org/terraform/main/config/TConfigOption.java +++ /dev/null @@ -1,625 +0,0 @@ -package org.terraform.main.config; - -import org.bukkit.ChatColor; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.function.Function; - -public enum TConfigOption { - // -=[HEIGHTMAP]=- - HEIGHT_MAP_CORE_FREQUENCY("heightmap.core-frequency", 0.003f), - HEIGHT_MAP_RIVER_FREQUENCY("heightmap.river-frequency", 0.005f), - HEIGHT_MAP_LAND_HEIGHT_AMPLIFIER("heightmap.land-height-amplifier", 1f), - HEIGHT_MAP_SEA_LEVEL("heightmap.sea-level", 62), - HEIGHT_MAP_BEDROCK_HEIGHT("heightmap.bedrock-height", 5), - HEIGHT_MAP_BEDROCK_DENSITY("heightmap.bedrock-density", 70), - HEIGHT_MAP_SPAWN_FLAT_RADIUS("heightmap.spawn-flat-radius", -1), - - // -=[CLIMATES]=- - CLIMATE_HUMIDVEGETATION_MINTEMP("climate.humid-vegetation.minimum-temperature", -0.35d), - CLIMATE_HUMIDVEGETATION_MAXTEMP("climate.humid-vegetation.maximum-temperature", 4.0d), - CLIMATE_HUMIDVEGETATION_MINMOIST("climate.humid-vegetation.minimum-moisture", 0d), - CLIMATE_HUMIDVEGETATION_MAXMOIST("climate.humid-vegetation.maximum-moisture", 4.0d), - - CLIMATE_DRYVEGETATION_MINTEMP("climate.dry-vegetation.minimum-temperature", -0.35d), - CLIMATE_DRYVEGETATION_MAXTEMP("climate.dry-vegetation.maximum-temperature", 4.0d), - CLIMATE_DRYVEGETATION_MINMOIST("climate.dry-vegetation.minimum-moisture", -4.0d), - CLIMATE_DRYVEGETATION_MAXMOIST("climate.dry-vegetation.maximum-moisture", 0d), - - CLIMATE_HOTBARREN_MINTEMP("climate.hot-barren.minimum-temperature", 1d), - CLIMATE_HOTBARREN_MAXTEMP("climate.hot-barren.maximum-temperature", 4.0d), - CLIMATE_HOTBARREN_MINMOIST("climate.hot-barren.minimum-moisture", -4.0d), - CLIMATE_HOTBARREN_MAXMOIST("climate.hot-barren.maximum-moisture", -1.0d), - - CLIMATE_COLD_MINTEMP("climate.cold.minimum-temperature", -4.0d), - CLIMATE_COLD_MAXTEMP("climate.cold.maximum-temperature", -0.5d), - CLIMATE_COLD_MINMOIST("climate.cold.minimum-moisture", -4.0d), - CLIMATE_COLD_MAXMOIST("climate.cold.maximum-moisture", 4.0d), - - CLIMATE_SNOWY_MINTEMP("climate.snowy.minimum-temperature", -4.0d), - CLIMATE_SNOWY_MAXTEMP("climate.snowy.maximum-temperature", -2.7d), - CLIMATE_SNOWY_MINMOIST("climate.snowy.minimum-moisture", -4.0d), - CLIMATE_SNOWY_MAXMOIST("climate.snowy.maximum-moisture", 4.0d), - - // -=[BIOMES]=- - // Biome globals - BIOME_TEMPERATURE_FREQUENCY("biome.temperature-frequency", 0.03f), - BIOME_MOISTURE_FREQUENCY("biome.moisture-frequency", 0.03f), - BIOME_MOUNTAINOUS_THRESHOLD("biome.mountainous-threshold", 18.5f), - BIOME_HIGH_MOUNTAINOUS_THRESHOLD("biome.highmountains-threshold", 27.5f), - BIOME_MOUNTAINOUS_FREQUENCY("biome.mountainous-frequency", 0.30f), - BIOME_OCEANIC_FREQUENCY("biome.oceanic-frequency", 0.11f), - BIOME_OCEANIC_THRESHOLD("biome.oceanic-threshold", 22f), - BIOME_CAVE_CRYSTALLINECLUSTER_SEPARATION("biome.cave.crystalline-cluster.separation", 86), - BIOME_CAVE_CRYSTALLINECLUSTER_MAXPERTUB("biome.cave.crystalline-cluster.separation-maxpertub", 0.37), - BIOME_CAVE_CRYSTALLINECLUSTER_MINSIZE("biome.cave.crystalline-cluster.minsize", 7), - BIOME_CAVE_CRYSTALLINECLUSTER_MAXSIZE("biome.cave.crystalline-cluster.maxsize", 11), - BIOME_CAVE_DRIPSTONECLUSTER_SEPARATION("biome.cave.dripstone-cluster.separation", 64), - BIOME_CAVE_DRIPSTONECLUSTER_MAXPERTUB("biome.cave.dripstone-cluster.separation-maxpertub", 0.35), - BIOME_CAVE_DRIPSTONECLUSTER_MINSIZE("biome.cave.dripstone-cluster.minsize", 5), - BIOME_CAVE_DRIPSTONECLUSTER_MAXSIZE("biome.cave.dripstone-cluster.maxsize", 11), - BIOME_CAVE_LUSHCLUSTER_SEPARATION("biome.cave.lush-cluster.separation", 64), - BIOME_CAVE_LUSHCLUSTER_MAXPERTUB("biome.cave.lush-cluster.separation-maxpertub", 0.35), - BIOME_CAVE_LUSHCLUSTER_MINSIZE("biome.cave.lush-cluster.minsize", 10), - BIOME_CAVE_LUSHCLUSTER_MAXSIZE("biome.cave.lush-cluster.maxsize", 15), - BIOME_DEEP_OCEANIC_THRESHOLD("biome.deep-oceanic-threshold", 27f), - BIOME_DITHER("biome.dithering", 0.04d), - BIOME_SECTION_BITSHIFTS("biome.biomesection-bitshifts", 7), - BIOME_CLAY_DEPOSIT_SIZE("biome.clay-deposit-radius", 3f), - BIOME_CLAY_DEPOSIT_CHANCE_OUT_OF_THOUSAND("biome.clay-deposit-chance-out-of-thousand", 3), - BIOME_SINGLE_TERRESTRIAL_TYPE("biome.single.land", "disabled"), - BIOME_SINGLE_OCEAN_TYPE("biome.single.ocean", "disabled"), - BIOME_SINGLE_DEEPOCEAN_TYPE("biome.single.deepocean", "disabled"), - BIOME_SINGLE_MOUNTAIN_TYPE("biome.single.mountain", "disabled"), - BIOME_SINGLE_HIGHMOUNTAIN_TYPE("biome.single.highmountain", "disabled"), - // BIOME_SINGLE_RIVER_TYPE("biome.single.river", "disabled"), - // BIOME_SINGLE_BEACH_TYPE("biome.single.beach", "disabled"), - BIOME_DEFAULT_FLAT("biome.defaults.flat", "PLAINS"), - BIOME_DEFAULT_OCEANIC("biome.defaults.oceanic", "OCEAN"), - BIOME_DEFAULT_DEEPOCEANIC("biome.defaults.deepoceanic", "DEEP_OCEAN"), - BIOME_DEFAULT_MOUNTAINOUS("biome.defaults.mountainous", "ROCKY_MOUNTAINS"), - BIOME_DEFAULT_HIGHMOUNTAINOUS("biome.defaults.highmountainous", "JAGGED_PEAKS"), - BIOME_DEFAULT_RIVER("biome.defaults.river", "RIVER"), - BIOME_DEFAULT_BEACH("biome.defaults.beach", "SANDY_BEACH"), - - // Biome specific - BIOME_ROCKY_MOUNTAINS_WEIGHT("biome.rockymountains.weight", 1), - BIOME_FORESTED_MOUNTAINS_WEIGHT("biome.forestedmountains.weight", 1), - BIOME_BADLANDS_MOUNTAINS_WEIGHT("biome.badlandsmountains.weight", 1), - BIOME_SNOWY_MOUNTAINS_WEIGHT("biome.snowymountains.weight", 1), - BIOME_BIRCH_MOUNTAINS_WEIGHT("biome.birchmountains.weight", 1), - BIOME_PAINTED_HILLS_WEIGHT("biome.paintedhills.weight", 1), - BIOME_SHATTERED_SAVANNA_WEIGHT("biome.shatteredsavanna.weight", 4), - BIOME_DESERT_MOUNTAINS_WEIGHT("biome.desertmountains.weight", 0), - BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE("biome.desertmountains.place-yellow-concrete", true), - BIOME_DESERT_MOUNTAINS_YELLOW_CONCRETE_POWDER("biome.desertmountains.place-yellow-concrete-powder", true), - BIOME_JAGGED_PEAKS_WEIGHT("biome.jaggedpeaks.weight", 1), - BIOME_OCEAN_WEIGHT("biome.ocean.weight", 6), - BIOME_BLACK_OCEAN_WEIGHT("biome.blackocean.weight", 1), - BIOME_COLD_OCEAN_WEIGHT("biome.coldocean.weight", 6), - BIOME_FROZEN_OCEAN_WEIGHT("biome.frozenocean.weight", 6), - BIOME_WARM_OCEAN_WEIGHT("biome.warmocean.weight", 6), - BIOME_HUMID_OCEAN_WEIGHT("biome.humidocean.weight", 6), - BIOME_DRY_OCEAN_WEIGHT("biome.dryocean.weight", 6), - BIOME_CORALREEF_OCEAN_WEIGHT("biome.coralreefocean.weight", 5), - BIOME_DEEP_OCEAN_WEIGHT("biome.deepocean.weight", 7), - BIOME_DEEP_COLD_OCEAN_WEIGHT("biome.deepcoldocean.weight", 7), - BIOME_DEEP_BLACK_OCEAN_WEIGHT("biome.deepblackocean.weight", 0), - BIOME_DEEP_FROZEN_OCEAN_WEIGHT("biome.deepfrozenocean.weight", 7), - BIOME_DEEP_WARM_OCEAN_WEIGHT("biome.deepwarmocean.weight", 7), - BIOME_DEEP_HUMID_OCEAN_WEIGHT("biome.deephumidocean.weight", 7), - BIOME_DEEP_DRY_OCEAN_WEIGHT("biome.deepdryocean.weight", 7), - BIOME_DEEP_LUKEWARM_OCEAN_WEIGHT("biome.deeplukewarmocean.weight", 7), - BIOME_MUSHROOM_ISLAND_WEIGHT("biome.mushroomisland.weight", 1), - BIOME_PLAINS_WEIGHT("biome.plains.weight", 10), - BIOME_ELEVATED_PLAINS_WEIGHT("biome.elevatedplains.weight", 8), - BIOME_PETRIFIEDCLIFFS_WEIGHT("biome.petrifiedcliffs.weight", 6), - BIOME_ARCHED_CLIFFS_WEIGHT("biome.archedcliffs.weight", 6), - BIOME_GORGE_WEIGHT("biome.gorge.weight", 6), - BIOME_ERODED_PLAINS_WEIGHT("biome.erodedplains.weight", 6), - BIOME_SAVANNA_WEIGHT("biome.savanna.weight", 6), - BIOME_MUDDYBOG_WEIGHT("biome.muddybog.weight", 2), - BIOME_FOREST_WEIGHT("biome.forest.weight", 8), - BIOME_DESERT_WEIGHT("biome.desert.weight", 6), - BIOME_JUNGLE_WEIGHT("biome.jungle.weight", 5), - BIOME_JUNGLE_STATUE_CHANCE("biome.jungle.statue-chance-out-of-1000", 4), - BIOME_BAMBOO_FOREST_WEIGHT("biome.bambooforest.weight", 2), - BIOME_BADLANDS_WEIGHT("biome.badlands.weight", 1), - BIOME_BADLANDS_PLATEAU_HEIGHT("biome.badlands.plateaus.height", 15), - BIOME_BADLANDS_PLATEAU_SAND_RADIUS("biome.badlands.plateaus.sand-radius", 7), - BIOME_BADLANDS_PLATEAU_THRESHOLD("biome.badlands.plateaus.threshold", 0.23), - BIOME_BADLANDS_PLATEAU_FREQUENCY("biome.badlands.plateaus.frequency", 0.01), - BIOME_BADLANDS_PLATEAU_COMMONNESS("biome.badlands.plateaus.commonness", 0.18), - BIOME_TAIGA_WEIGHT("biome.taiga.weight", 6), - BIOME_CHERRYGROVE_WEIGHT("biome.cherrygrove.weight", 3), - BIOME_SCARLETFOREST_WEIGHT("biome.scarletforest.weight", 3), - BIOME_SNOWY_TAIGA_WEIGHT("biome.snowytaiga.weight", 6), - BIOME_SNOWY_WASTELAND_WEIGHT("biome.snowywasteland.weight", 4), - BIOME_ICE_SPIKES_WEIGHT("biome.icespikes.weight", 2), - BIOME_DARK_FOREST_WEIGHT("biome.darkforest.weight", 5), - BIOME_DARK_FOREST_SPAWN_HEADS("biome.darkforest.spawn-heads", true), - BIOME_SWAMP_WEIGHT("biome.swamp.weight", 5), - BIOME_MANGROVE_WEIGHT("biome.mangrove.weight", 5), - BIOME_OASIS_COMMONNESS("biome.oasis.commonness", 1.0), - BIOME_OASIS_FREQUENCY("biome.oasis.frequency", 0.012f), - - - // -=[TREES]=- - TREES_JUNGLE_BIG_ENABLED("trees.big-jungle-trees.enabled", true), - TREES_TAIGA_BIG_ENABLED("trees.big-taiga-trees.enabled", true), - TREES_FOREST_BIG_ENABLED("trees.big-forest-trees.enabled", true), - TREES_SAVANNA_BIG_ENABLED("trees.big-savanna-trees.enabled", true), - TREES_BIRCH_BIG_ENABLED("trees.big-birch-trees.enabled", true), - TREES_SCARLET_BIG_ENABLED("trees.big-scarlet-trees.enabled", true), - TREES_SNOWY_TAIGA_BIG_ENABLED("trees.big-snowy-taiga-trees.enabled", true), - TREES_DARK_FOREST_BIG_ENABLED("trees.big-dark-forest-trees.enabled", true), - - // -=[MISC]=- - // MISC_SMOOTH_DESIGN("misc.smooth-design",false), - MISC_SAPLING_CUSTOM_TREES_ENABLED("misc.custom-small-trees-from-saplings.enabled", true), - MISC_SAPLING_CUSTOM_TREES_BIGTREES("misc.custom-small-trees-from-saplings.big-jungle-tree", true), - MISC_TREES_FORCE_LOGS("misc.trees.only-use-logs-no-wood", false), - MISC_TREES_GRADIENT_LIMIT("misc.trees.ground-gradient-limit", 1.3d), - MISC_USE_SLABS_TO_SMOOTH("misc.use-slabs-to-smooth-terrain", true), - - // -=[DEVSTUFF]=- - DEVSTUFF_SUPPRESS_WATCHDOG("dev-stuff.suppress-watchdog", true), - DEVSTUFF_CHUNKCACHE_SIZE("dev-stuff.chunk-cache-size", 6000), - DEVSTUFF_CHUNKBIOMES_SIZE("dev-stuff.biomecache-size", 3000), - // DEVSTUFF_EXPERIMENTAL_STRUCTURE_PLACEMENT("dev-stuff.experimental-structure-placement", false), - DEVSTUFF_DEBUG_MODE("dev-stuff.debug-mode", false), - DEVSTUFF_VANILLA_MUSHROOMS("dev-stuff.force-only-vanilla-mushrooms", false), - DEVSTUFF_FLUSH_PATCHER_CACHE_FREQUENCY("dev-stuff.patcher-cache-max-size", 100), - DEVSTUFF_EXTENDED_COMMANDS("dev-stuff.extended-commands", false), - DEVSTUFF_SUPPRESS_CONSOLE_LOGS("dev-stuff.suppress-terraform-console-logs", true), - DEVSTUFF_ATTEMPT_FIXING_PREMATURE("dev-stuff.attempt-fixing-premature-generations", true), - DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS("dev-stuff.vanilla-structure-locate-timeoutmillis", 5000), - DEVSTUFF_VANILLA_LOCATE_DISABLE("dev-stuff.vanilla-disable-locate", false), - - // -=[CAVES]=- - CAVES_ALLOW_FLOODED_CAVES("caves.allow-flooded-caves", false), - // CAVES_ALLOW_FLOODED_RAVINES("caves.allow-flooded-ravines",true), - - // -=[STRUCTURES]=- - STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS("structures.technical.megachunk.numbiomesections", 4), - STRUCTURES_MEGACHUNK_MAXSTRUCTURES("structures.technical.megachunk.max-structures-per-megachunk", 3), - STRUCTURES_MANSION_ENABLED("structures.mansion.enabled", true), - STRUCTURES_MANSION_SIZE("structures.mansion.size", 80), - STRUCTURES_MANSION_MINDISTANCE("structures.mansion.min-distance-blocks", 5000), - STRUCTURES_MANSION_SPAWNAGGRESSION("structures.mansion.pillager-spawn-aggression", 1), - STRUCTURES_MANSION_SPAWNRATIO("structures.mansion.spawnratio", 0.3), - STRUCTURES_MANSION_CHUNK_EXCLUSION_ZONE("structures.mansion.chunk-exclusion-zone", 4), - STRUCTURES_STRONGHOLD_ENABLED("structures.stronghold.enabled", true), - STRUCTURES_STRONGHOLD_FAILSAFE_Y("structures.stronghold.failsafe-y", -16), - STRUCTURES_STRONGHOLD_MIN_Y("structures.stronghold.min-y", 0), - STRUCTURES_STRONGHOLD_MAX_Y("structures.stronghold.max-y", 25), - STRUCTURES_MONUMENT_ENABLED("structures.monument.enabled", true), - STRUCTURES_MONUMENT_SPAWNRATIO("structures.monument.spawn-ratio", 0.3), - STRUCTURES_PYRAMID_ENABLED("structures.pyramid.enabled", true), - STRUCTURES_PYRAMID_SPAWNRATIO("structures.pyramid.spawn-ratio", 0.3), - STRUCTURES_PYRAMID_SPAWN_ELDER_GUARDIAN("structures.pyramid.spawn-elder-guardian", true), - STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER("structures.pyramid.suspicious-sand-per-antechamber", 4), - STRUCTURES_VILLAGEHOUSE_SPAWNRATIO("structures.villagehouse.spawnratio", 0.8), - STRUCTURES_MOUNTAINHOUSE_ENABLED("structures.mountainhouse.enabled", true), - STRUCTURES_FARMHOUSE_ENABLED("structures.farmhouse.enabled", true), - STRUCTURES_ANIMALFARM_ENABLED("structures.animalfarm.enabled", true), - STRUCTURES_TRAILRUINS_SPAWNRATIO("structures.trailruins.spawnratio", 0.5), - STRUCTURES_TRAILRUINS_ENABLED("structures.trailruins.enabled", true), - STRUCTURES_TRIALCHAMBER_SPAWNRATIO("structures.trialchamber.spawnratio", 0.3), - STRUCTURES_TRIALCHAMBER_ENABLED("structures.trialchamber.enabled", true), - STRUCTURES_WARMOCEANRUINS_SPAWNRATIO("structures.warmoceanruins.spawnratio", 1.0), - STRUCTURES_WARMOCEANRUINS_ENABLED("structures.warmoceanruins.enabled", true), - STRUCTURES_VILLAGE_SPAWNRATIO("structures.village.spawnratio", 1.0), - STRUCTURES_PLAINSVILLAGE_ENABLED("structures.plainsvillage.enabled", true), - STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE("structures.plainsvillage.height-tolerance", 10), - STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE("structures.village.chunk-exclusion-zone", 4), - STRUCTURES_SWAMPHUT_ENABLED("structures.swamphut.enabled", true), - STRUCTURES_SWAMPHUT_SPAWNRATIO("structures.swamphut.spawnratio", 0.4), - STRUCTURES_SWAMPHUT_COUNT_PER_MEGACHUNK("structures.swamphut.count-per-megachunk", 1), - STRUCTURES_DESERTWELL_ENABLED("structures.desertwell.enabled", true), - STRUCTURES_DESERTWELL_SPAWNRATIO("structures.desertwell.spawnratio", 0.3), - STRUCTURES_DESERTWELL_COUNT_PER_MEGACHUNK("structures.desertwell.count-per-megachunk", 2), - STRUCTURES_DUNGEONS_SPAWNRATIO("structures.small-dungeon.spawnratio", 0.4), - STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK("structures.small-dungeon.count-per-megachunk", 3), - STRUCTURES_UNDERGROUNDDUNGEON_ENABLED("structures.underground-dungeon.enabled", true), - STRUCTURES_DROWNEDDUNGEON_ENABLED("structures.drowned-dungeon.enabled", true), - STRUCTURES_DROWNEDDUNGEON_MIN_DEPTH("structures.drowned-dungeon.min-chunk-y", 52), - STRUCTURES_DROWNEDDUNGEON_CHANCE("structures.drowned-dungeon.chance-out-of-1000", 200), - STRUCTURES_SHIPWRECK_SPAWNRATIO("structures.shipwreck.spawnratio", 0.6), - STRUCTURES_SHIPWRECK_ENABLED("structures.shipwreck.enabled", true), - STRUCTURES_SHIPWRECK_COUNT_PER_MEGACHUNK("structures.shipwreck.count-per-megachunk", 2), - STRUCTURES_RUINEDPORTAL_SPAWNRATIO("structures.ruinedportal.spawnratio", 0.4), - STRUCTURES_RUINEDPORTAL_ENABLED("structures.ruinedportal.enabled", true), - STRUCTURES_RUINEDPORTAL_COUNT_PER_MEGACHUNK("structures.ruinedportal.count-per-megachunk", 1), - STRUCTURES_IGLOO_SPAWNRATIO("structures.igloo.spawnratio", 0.8), - STRUCTURES_IGLOO_ENABLED("structures.igloo.enabled", true), - STRUCTURES_IGLOO_COUNT_PER_MEGACHUNK("structures.igloo.count-per-megachunk", 1), - STRUCTURES_BURIEDTREASURE_SPAWNRATIO("structures.buriedtreasure.spawnratio", 0.3), - STRUCTURES_BURIEDTREASURE_ENABLED("structures.buriedtreasure.enabled", true), - STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK("structures.buriedtreasure.count-per-megachunk", 2), - STRUCTURES_MINESHAFT_ENABLED("structures.mineshaft.enabled", true), - STRUCTURES_MINESHAFT_SPAWNRATIO("structures.mineshaft.spawnratio", 0.8), - STRUCTURES_MINESHAFT_MIN_Y("structures.mineshaft.min-y", -10), - STRUCTURES_MINESHAFT_MAX_Y("structures.mineshaft.max-y", 30), - STRUCTURES_CATACOMBS_ENABLED("structures.catacombs.enabled", true), - STRUCTURES_CATACOMBS_SPAWNRATIO("structures.catacombs.spawnratio", 0.6), - STRUCTURES_CATACOMBS_SIZEROLLCHANCE("structures.catacombs.sizerollchance", 0.40), - STRUCTURES_CATACOMBS_MAX_LEVELS("structures.catacombs.max-levels", 5), - STRUCTURES_CATACOMBS_MIN_Y("structures.catacombs.min-y", 0), - STRUCTURES_CATACOMBS_MAX_Y("structures.catacombs.max-y", 30), - STRUCTURES_ANCIENTCITY_ENABLED("structures.ancientcity.enabled", true), - STRUCTURES_ANCIENTCITY_SPAWNRATIO("structures.ancientcity.spawnratio", 0.5), - STRUCTURES_ANCIENTCITY_MIN_Y("structures.ancientcity.min-y", -20), - STRUCTURES_ANCIENTCITY_MAX_Y("structures.ancientcity.max-y", -10), - STRUCTURES_LARGECAVE_ENABLED("structures.largecave.enabled", true), - STRUCTURES_LARGECAVE_SPAWNRATIO("structures.largecave.spawnratio", 0.8), - STRUCTURES_BADLANDS_MINE_ENABLED("structures.badlands-mine.enabled", true), - STRUCTURES_BADLANDS_MINE_DISTANCE("structures.badlands-mine.distance-between-mines", 8), - STRUCTURES_BADLANDS_MINE_DEPTH("structures.badlands-mine.depth", 25), - STRUCTURES_OUTPOST_ENABLED("structures.outpost.enabled", true), - STRUCTURES_OUTPOST_SPAWNRATIO("structures.outpost.spawnratio", 0.8), - - // -=[ANIMALS]=- - // BEES - ANIMALS_BEE_HIVEFREQUENCY("animals.bee.hive-frequency", 0.02), - // PIG - ANIMALS_PIG_MINHERDSIZE("animals.pig.min-herd-size", 3), - ANIMALS_PIG_MAXHERDSIZE("animals.pig.max-herd-size", 4), - ANIMALS_PIG_CHANCE("animals.pig.chance", 2), - // COW - ANIMALS_COW_MINHERDSIZE("animals.cow.min-herd-size", 4), - ANIMALS_COW_MAXHERDSIZE("animals.cow.max-herd-size", 12), - ANIMALS_COW_CHANCE("animals.cow.chance", 2), - // MOOSHROOM - ANIMALS_MOOSHROOM_MINHERDSIZE("animals.mooshroom.min-herd-size", 2), - ANIMALS_MOOSHROOM_MAXHERDSIZE("animals.mooshroom.max-herd-size", 6), - ANIMALS_MOOSHROOM_CHANCE("animals.mooshroom.chance", 10), - // SHEEP - ANIMALS_SHEEP_MINHERDSIZE("animals.sheep.min-herd-size", 2), - ANIMALS_SHEEP_MAXHERDSIZE("animals.sheep.max-herd-size", 8), - ANIMALS_SHEEP_CHANCE("animals.sheep.chance", 2), - // CHICKEN - ANIMALS_CHICKEN_MINHERDSIZE("animals.chicken.min-herd-size", 1), - ANIMALS_CHICKEN_MAXHERDSIZE("animals.chicken.max-herd-size", 3), - ANIMALS_CHICKEN_CHANCE("animals.chicken.chance", 2), - // ARMADILLO - ANIMALS_ARMADILLO_MINHERDSIZE("animals.armadillo.min-herd-size", 1), - ANIMALS_ARMADILLO_MAXHERDSIZE("animals.armadillo.max-herd-size", 3), - ANIMALS_ARMADILLO_CHANCE("animals.armadillo.chance", 2), - // HORSE - ANIMALS_HORSE_MINHERDSIZE("animals.horse.min-herd-size", 2), - ANIMALS_HORSE_MAXHERDSIZE("animals.horse.max-herd-size", 6), - ANIMALS_HORSE_CHANCE("animals.horse.chance", 1), - // DONKEY - ANIMALS_DONKEY_MINHERDSIZE("animals.donkey.min-herd-size", 2), - ANIMALS_DONKEY_MAXHERDSIZE("animals.donkey.max-herd-size", 6), - ANIMALS_DONKEY_CHANCE("animals.donkey.chance", 1), - // GOAT - ANIMALS_GOAT_MINHERDSIZE("animals.goat.min-herd-size", 3), - ANIMALS_GOAT_MAXHERDSIZE("animals.goat.max-herd-size", 4), - ANIMALS_GOAT_CHANCE("animals.goat.chance", 1), - // RABBIT - ANIMALS_RABBIT_MINHERDSIZE("animals.rabbit.min-herd-size", 2), - ANIMALS_RABBIT_MAXHERDSIZE("animals.rabbit.max-herd-size", 3), - ANIMALS_RABBIT_CHANCE("animals.rabbit.chance", 1), - // POLAR_BEAR - ANIMALS_POLAR_BEAR_MINHERDSIZE("animals.polarbear.min-herd-size", 2), - ANIMALS_POLAR_BEAR_MAXHERDSIZE("animals.polarbear.max-herd-size", 3), - ANIMALS_POLAR_BEAR_CHANCE("animals.polarbear.chance", 1), - // PANDA - ANIMALS_PANDA_MINHERDSIZE("animals.panda.min-herd-size", 2), - ANIMALS_PANDA_MAXHERDSIZE("animals.panda.max-herd-size", 3), - ANIMALS_PANDA_CHANCE("animals.panda.chance", 1), - // FOX - ANIMALS_FOX_MINHERDSIZE("animals.fox.min-herd-size", 1), - ANIMALS_FOX_MAXHERDSIZE("animals.fox.max-herd-size", 2), - ANIMALS_FOX_CHANCE("animals.fox.chance", 1), - // LLAMMA - ANIMALS_LLAMA_MINHERDSIZE("animals.llama.min-herd-size", 4), - ANIMALS_LLAMA_MAXHERDSIZE("animals.llama.max-herd-size", 6), - ANIMALS_LLAMA_CHANCE("animals.llama.chance", 2), - // PARROT - ANIMALS_PARROT_MINHERDSIZE("animals.parrot.min-herd-size", 1), - ANIMALS_PARROT_MAXHERDSIZE("animals.parrot.max-herd-size", 2), - ANIMALS_PARROT_CHANCE("animals.parrot.chance", 2), - // OCELOT - ANIMALS_OCELOT_MINHERDSIZE("animals.ocelot.min-herd-size", 1), - ANIMALS_OCELOT_MAXHERDSIZE("animals.ocelot.max-herd-size", 3), - ANIMALS_OCELOT_CHANCE("animals.ocelot.chance", 1), - // WOLF - ANIMALS_WOLF_MINHERDSIZE("animals.wolf.min-herd-size", 1), - ANIMALS_WOLF_MAXHERDSIZE("animals.wolf.max-herd-size", 4), - ANIMALS_WOLF_CHANCE("animals.wolf.chance", 2), - // TURTLE - ANIMALS_TURTLE_MINHERDSIZE("animals.turtle.min-herd-size", 2), - ANIMALS_TURTLE_MAXHERDSIZE("animals.turtle.max-herd-size", 5), - ANIMALS_TURTLE_CHANCE("animals.turtle.chance", 1), - // DOLPHIN - ANIMALS_DOLPHIN_MINHERDSIZE("animals.dolphin.min-herd-size", 1), - ANIMALS_DOLPHIN_MAXHERDSIZE("animals.dolphin.max-herd-size", 3), - ANIMALS_DOLPHIN_CHANCE("animals.dolphin.chance", 1), - // COD - ANIMALS_COD_MINHERDSIZE("animals.cod.min-herd-size", 3), - ANIMALS_COD_MAXHERDSIZE("animals.cod.max-herd-size", 6), - ANIMALS_COD_CHANCE("animals.cod.chance", 2), - // SQUID - ANIMALS_SQUID_MINHERDSIZE("animals.squid.min-herd-size", 1), - ANIMALS_SQUID_MAXHERDSIZE("animals.squid.max-herd-size", 4), - ANIMALS_SQUID_CHANCE("animals.squid.chance", 2), - // SALMON - ANIMALS_SALMON_MINHERDSIZE("animals.salmon.min-herd-size", 4), - ANIMALS_SALMON_MAXHERDSIZE("animals.salmon.max-herd-size", 4), - ANIMALS_SALMON_CHANCE("animals.salmon.chance", 2), - // PUFFERFISH - ANIMALS_PUFFERFISH_MINHERDSIZE("animals.pufferfish.min-herd-size", 1), - ANIMALS_PUFFERFISH_MAXHERDSIZE("animals.pufferfish.max-herd-size", 3), - ANIMALS_PUFFERFISH_CHANCE("animals.pufferfish.chance", 1), - // TROPICALFISH - ANIMALS_TROPICALFISH_MINHERDSIZE("animals.tropical-fish.min-herd-size", 4), - ANIMALS_TROPICALFISH_MAXHERDSIZE("animals.tropical-fish.max-herd-size", 8), - ANIMALS_TROPICALFISH_CHANCE("animals.tropical-fish.chance", 2), - - // -=[ORES]=- - // AMETHYST - ORE_AMETHYST_CHANCE("ore.amethyst.chance-per-chunk", 0.05), - ORE_AMETHYST_GEODE_SIZE("ore.amethyst.geode-size", 7), - ORE_AMETHYST_MIN_DEPTH("ore.amethyst.min-depth", 70), - ORE_AMETHYST_MIN_DEPTH_BELOW_SURFACE("ore.amethyst.min-depth-below-surface", 15), - - // COAL - ORE_COAL_CHANCE("ore.coal.chance-per-chunk", 50), - ORE_COAL_VEINSIZE("ore.coal.max-vein-size", 25), - ORE_COAL_MAXVEINNUMBER("ore.coal.max-vein-count", 115), - ORE_COAL_COMMONSPAWNHEIGHT("ore.coal.common-spawn-height", 96), - ORE_COAL_MAXSPAWNHEIGHT("ore.coal.max-spawn-height", 256), - ORE_COAL_MINSPAWNHEIGHT("ore.coal.min-spawn-height", 5), - - // IRON - ORE_IRON_CHANCE("ore.iron.chance-per-chunk", 50), - ORE_IRON_VEINSIZE("ore.iron.max-vein-size", 10), - ORE_IRON_MAXVEINNUMBER("ore.iron.max-vein-count", 73), - ORE_IRON_COMMONSPAWNHEIGHT("ore.iron.common-spawn-height", 16), - ORE_IRON_MAXSPAWNHEIGHT("ore.iron.max-spawn-height", 256), - ORE_IRON_MINSPAWNHEIGHT("ore.iron.min-spawn-height", -64), - - // GOLD - ORE_GOLD_CHANCE("ore.gold.chance-per-chunk", 40), - ORE_GOLD_VEINSIZE("ore.gold.max-vein-size", 10), - ORE_GOLD_MAXVEINNUMBER("ore.gold.max-vein-count", 15), - ORE_GOLD_COMMONSPAWNHEIGHT("ore.gold.common-spawn-height", -16), - ORE_GOLD_MAXSPAWNHEIGHT("ore.gold.max-spawn-height", 32), - ORE_GOLD_MINSPAWNHEIGHT("ore.gold.min-spawn-height", -64), - - // GOLD - ORE_BADLANDSGOLD_CHANCE("ore.badlandsgold.chance-per-chunk", 40), - ORE_BADLANDSGOLD_VEINSIZE("ore.badlandsgold.max-vein-size", 10), - ORE_BADLANDSGOLD_MAXVEINNUMBER("ore.badlandsgold.max-vein-count", 15), - ORE_BADLANDSGOLD_COMMONSPAWNHEIGHT("ore.badlandsgold.common-spawn-height", 32), - ORE_BADLANDSGOLD_MAXSPAWNHEIGHT("ore.badlandsgold.max-spawn-height", 256), - ORE_BADLANDSGOLD_MINSPAWNHEIGHT("ore.badlandsgold.min-spawn-height", -64), - - // DIAMOND - ORE_DIAMOND_CHANCE("ore.diamond.chance-per-chunk", 30), - ORE_DIAMOND_VEINSIZE("ore.diamond.max-vein-size", 7), - ORE_DIAMOND_MAXVEINNUMBER("ore.diamond.max-vein-count", 16), - ORE_DIAMOND_COMMONSPAWNHEIGHT("ore.diamond.common-spawn-height", -64), - ORE_DIAMOND_MAXSPAWNHEIGHT("ore.diamond.max-spawn-height", 16), - ORE_DIAMOND_MINSPAWNHEIGHT("ore.diamond.min-spawn-height", -64), - - // EMERALD - ORE_EMERALD_CHANCE("ore.emerald.chance-per-chunk", 30), - ORE_EMERALD_VEINSIZE("ore.emerald.max-vein-size", 7), - ORE_EMERALD_MAXVEINNUMBER("ore.emerald.max-vein-count", 3), - ORE_EMERALD_COMMONSPAWNHEIGHT("ore.emerald.common-spawn-height", 12), - ORE_EMERALD_MAXSPAWNHEIGHT("ore.emerald.max-spawn-height", 256), - ORE_EMERALD_MINSPAWNHEIGHT("ore.emerald.min-spawn-height", -16), - - // LAPIS - ORE_LAPIS_CHANCE("ore.lapis.chance-per-chunk", 30), - ORE_LAPIS_VEINSIZE("ore.lapis.max-vein-size", 6), - ORE_LAPIS_MAXVEINNUMBER("ore.lapis.max-vein-count", 40), - ORE_LAPIS_COMMONSPAWNHEIGHT("ore.lapis.common-spawn-height", 0), - ORE_LAPIS_MAXSPAWNHEIGHT("ore.lapis.max-spawn-height", 64), - ORE_LAPIS_MINSPAWNHEIGHT("ore.lapis.min-spawn-height", -64), - - // REDSTONE - ORE_REDSTONE_CHANCE("ore.redstone.chance-per-chunk", 40), - ORE_REDSTONE_VEINSIZE("ore.redstone.max-vein-size", 10), - ORE_REDSTONE_MAXVEINNUMBER("ore.redstone.max-vein-count", 15), - ORE_REDSTONE_COMMONSPAWNHEIGHT("ore.redstone.common-spawn-height", -32), - ORE_REDSTONE_MAXSPAWNHEIGHT("ore.redstone.max-spawn-height", 16), - ORE_REDSTONE_MINSPAWNHEIGHT("ore.redstone.min-spawn-height", -64), - - // COPPER - ORE_COPPER_CHANCE("ore.copper.chance-per-chunk", 40), - ORE_COPPER_VEINSIZE("ore.copper.max-vein-size", 10), - ORE_COPPER_MAXVEINNUMBER("ore.copper.max-vein-count", 45), - ORE_COPPER_COMMONSPAWNHEIGHT("ore.copper.common-spawn-height", 48), - ORE_COPPER_MAXSPAWNHEIGHT("ore.copper.max-spawn-height", 104), - ORE_COPPER_MINSPAWNHEIGHT("ore.copper.min-spawn-height", -16), - - // GRAVEL - ORE_GRAVEL_CHANCE("ore.gravel.chance-per-chunk", 75), - ORE_GRAVEL_VEINSIZE("ore.gravel.max-vein-size", 45), - ORE_GRAVEL_MAXVEINNUMBER("ore.gravel.max-vein-count", 100), - ORE_GRAVEL_COMMONSPAWNHEIGHT("ore.gravel.common-spawn-height", 255), - ORE_GRAVEL_MAXSPAWNHEIGHT("ore.gravel.max-spawn-height", 300), - ORE_GRAVEL_MINSPAWNHEIGHT("ore.gravel.min-spawn-height", -64), - - // ANDESITE - ORE_ANDESITE_CHANCE("ore.andesite.chance-per-chunk", 80), - ORE_ANDESITE_VEINSIZE("ore.andesite.max-vein-size", 45), - ORE_ANDESITE_MAXVEINNUMBER("ore.andesite.max-vein-count", 110), - ORE_ANDESITE_COMMONSPAWNHEIGHT("ore.andesite.common-spawn-height", 255), - ORE_ANDESITE_MAXSPAWNHEIGHT("ore.andesite.max-spawn-height", 300), - ORE_ANDESITE_MINSPAWNHEIGHT("ore.andesite.min-spawn-height", -64), - - // DIORITE - ORE_DIORITE_CHANCE("ore.diorite.chance-per-chunk", 80), - ORE_DIORITE_VEINSIZE("ore.diorite.max-vein-size", 45), - ORE_DIORITE_MAXVEINNUMBER("ore.diorite.max-vein-count", 110), - ORE_DIORITE_COMMONSPAWNHEIGHT("ore.diorite.common-spawn-height", 255), - ORE_DIORITE_MAXSPAWNHEIGHT("ore.diorite.max-spawn-height", 300), - ORE_DIORITE_MINSPAWNHEIGHT("ore.diorite.min-spawn-height", -64), - - // GRANITE - ORE_GRANITE_CHANCE("ore.granite.chance-per-chunk", 80), - ORE_GRANITE_VEINSIZE("ore.granite.max-vein-size", 45), - ORE_GRANITE_MAXVEINNUMBER("ore.granite.max-vein-count", 110), - ORE_GRANITE_COMMONSPAWNHEIGHT("ore.granite.common-spawn-height", 255), - ORE_GRANITE_MAXSPAWNHEIGHT("ore.granite.max-spawn-height", 300), - ORE_GRANITE_MINSPAWNHEIGHT("ore.granite.min-spawn-height", -64), - - // TUFF - ORE_TUFF_CHANCE("ore.tuff.chance-per-chunk", 40), - ORE_TUFF_VEINSIZE("ore.tuff.max-vein-size", 30), - ORE_TUFF_MAXVEINNUMBER("ore.tuff.max-vein-count", 50), - ORE_TUFF_COMMONSPAWNHEIGHT("ore.tuff.common-spawn-height", -64), - ORE_TUFF_MAXSPAWNHEIGHT("ore.tuff.max-spawn-height", 10), - ORE_TUFF_MINSPAWNHEIGHT("ore.tuff.min-spawn-height", -63), - - // DEEPSLATE - ORE_DEEPSLATE_CHANCE("ore.deepslate.chance-per-chunk", 80), - ORE_DEEPSLATE_VEINSIZE("ore.deepslate.max-vein-size", 45), - ORE_DEEPSLATE_MAXVEINNUMBER("ore.deepslate.max-vein-count", 50), - ORE_DEEPSLATE_COMMONSPAWNHEIGHT("ore.deepslate.common-spawn-height", 5), - ORE_DEEPSLATE_MAXSPAWNHEIGHT("ore.deepslate.max-spawn-height", 15), - ORE_DEEPSLATE_MINSPAWNHEIGHT("ore.deepslate.min-spawn-height", 0), - - FEATURE_CAVES_ENABLED("feature_toggle.caves", true), - FEATURE_ANIMALS_ENABLED("feature_toggle.animals", true), - FEATURE_ORES_ENABLED("feature_toggle.ores", true), - FEATURE_TREES_ENABLED("feature_toggle.trees", true), - FEATURE_TALL_MUSHROOMS_ENABLED("feature_toggle.tall_mushrooms", true), - FEATURE_PLANTS_ENABLED("feature_toggle.plants", true), - FEATURE_STRUCTURES_ENABLED("feature_toggle.structures", true), - FEATURE_DECORATIONS_ENABLED("feature_toggle.decorations", true), - - ; - private final String path; - private final Function map; - private Object value; - - TConfigOption(String path, Object defaultValue) { - this.path = path; - this.value = defaultValue; - this.map = o -> o; - } - - TConfigOption(String path, Object defaultValue, Function map) { - this.path = path; - this.value = defaultValue; - this.map = map; - } - - public static void loadValues(@NotNull ConfigLoader conf) { - for (TConfigOption option : TConfigOption.values()) { - conf.reg(option.path, option.map.apply(option.value)); - } - conf.load(); - for (TConfigOption option : TConfigOption.values()) { - option.value = option.map.apply(conf.get(option.path)); - } - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areCavesEnabled() { - return TConfigOption.FEATURE_CAVES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areTreesEnabled() { - return TConfigOption.FEATURE_TREES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areTallMushroomsEnabled() { - return TConfigOption.FEATURE_TALL_MUSHROOMS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean arePlantsEnabled() { - return TConfigOption.FEATURE_PLANTS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areStructuresEnabled() { - return TConfigOption.FEATURE_STRUCTURES_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areAnimalsEnabled() { - return TConfigOption.FEATURE_ANIMALS_ENABLED.getBoolean(); - } - - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean areDecorationsEnabled() { - return TConfigOption.FEATURE_DECORATIONS_ENABLED.getBoolean(); - } - - public @NotNull String getString() { - return ChatColor.translateAlternateColorCodes('&', (String) value); - } - - public @NotNull String parse(String @NotNull ... placeholders) { - String parsed = this.getString(); - - String placeholder = ""; - - for (int i = 0; i < placeholders.length; i++) { - if (i % 2 == 0) { - placeholder = placeholders[i]; - } - else { - parsed = parsed.replaceAll(placeholder, placeholders[i]); - } - } - return parsed; - } - - public int getInt() { - if (value instanceof Number) { - return ((Number) value).intValue(); - } - return (int) value; - } - - public boolean getBoolean() { - return (Boolean) value; - } - - public double getDouble() { - if (value instanceof Number) { - return ((Number) value).doubleValue(); - } - return (double) value; - } - - public float getFloat() { - if (value instanceof Number) { - return ((Number) value).floatValue(); - } - return (float) value; - } - - @SuppressWarnings("unchecked") - public List getStringList() { - return (List) value; - } - - public String @NotNull [] getStringArray() { - String[] arr = new String[getStringList().size()]; - int i = 0; - for (String item : getStringList()) { - arr[i] = item; - i++; - } - return arr; - } - - public T get(@NotNull Class clazz) { - return clazz.cast(value); - } - -} diff --git a/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java b/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java index 82d41c46..81e67797 100644 --- a/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java +++ b/common/src/main/java/org/terraform/populators/AmethystGeodePopulator.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.DirectionalBuilder; @@ -26,7 +26,7 @@ public class AmethystGeodePopulator { public AmethystGeodePopulator(int geodeRadius, double frequency, int minDepth, int minDepthBelowSurface) { this.geodeRadius = geodeRadius; - this.frequency = TConfigOption.FEATURE_ORES_ENABLED.getBoolean() ? frequency : 0; + this.frequency = TConfig.c.FEATURE_ORES_ENABLED ? frequency : 0; this.minDepth = minDepth; this.minDepthBelowSurface = minDepthBelowSurface; } diff --git a/common/src/main/java/org/terraform/populators/AnimalPopulator.java b/common/src/main/java/org/terraform/populators/AnimalPopulator.java index 26d9e247..0b974371 100644 --- a/common/src/main/java/org/terraform/populators/AnimalPopulator.java +++ b/common/src/main/java/org/terraform/populators/AnimalPopulator.java @@ -7,7 +7,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.Random; @@ -46,11 +46,11 @@ public AnimalPopulator(EntityType animalType, // Instead, each query will just call getBiome per block. This sounds more // intensive, but it relies on the getBiome cache system to be faster. public boolean canSpawn(@NotNull Random rand) { - return TConfigOption.areAnimalsEnabled() && !GenUtils.chance(rand, 100 - chance, 100); + return TConfig.areAnimalsEnabled() && !GenUtils.chance(rand, 100 - chance, 100); } private boolean canSpawnInBiome(BiomeBank b) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return false; } @@ -74,7 +74,7 @@ private boolean canSpawnInBiome(BiomeBank b) { } public void populate(@NotNull TerraformWorld world, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/populators/OrePopulator.java b/common/src/main/java/org/terraform/populators/OrePopulator.java index 28e2f114..5aba3889 100644 --- a/common/src/main/java/org/terraform/populators/OrePopulator.java +++ b/common/src/main/java/org/terraform/populators/OrePopulator.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; @@ -69,7 +69,7 @@ public OrePopulator(Material type, this.baseChance = baseChance; this.maxOreSize = maxOreSize; this.minOreSize = maxOreSize / 2; - this.maxNumberOfVeins = TConfigOption.FEATURE_ORES_ENABLED.getBoolean() ? maxNumberOfVeins : 0; + this.maxNumberOfVeins = TConfig.c.FEATURE_ORES_ENABLED ? maxNumberOfVeins : 0; this.minRange = minRange; this.peakSpawnChanceHeight = peakSpawnChanceHeight; this.maxSpawnHeight = maxSpawnHeight; diff --git a/common/src/main/java/org/terraform/small_items/PlantBuilder.java b/common/src/main/java/org/terraform/small_items/PlantBuilder.java index 2319f57e..8ce0474a 100644 --- a/common/src/main/java/org/terraform/small_items/PlantBuilder.java +++ b/common/src/main/java/org/terraform/small_items/PlantBuilder.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -108,7 +108,7 @@ public static void build(@NotNull PopulatorDataAbstract data, } public void build(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -128,7 +128,7 @@ public void build(@NotNull Random rand, int minHeight, int maxHeight) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -140,7 +140,7 @@ public void build(@NotNull SimpleBlock block) { } public void build(@NotNull SimpleBlock block, @NotNull Random rand, int minHeight, int maxHeight) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java b/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java index 552ce5d9..d84ab39e 100644 --- a/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java +++ b/common/src/main/java/org/terraform/structure/StructureBufferDistanceHandler.java @@ -5,7 +5,7 @@ import org.terraform.coregen.HeightMap; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; public class StructureBufferDistanceHandler { @@ -40,7 +40,7 @@ public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, i // Grab the center chunk, where the structure will spawn int[] chunkCoords = mc.getCenterBiomeSectionChunkCoords(); - if (TConfigOption.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { + if (TConfig.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) { // If the structure will spawn, calculate distance to it. int dist = (int) (Math.pow(chunkCoords[0] - chunkX, 2) + Math.pow(chunkCoords[1] - chunkZ, 2)); if (Math.sqrt(dist) <= chunkBufferRadius) { diff --git a/common/src/main/java/org/terraform/structure/StructureLocator.java b/common/src/main/java/org/terraform/structure/StructureLocator.java index 1ad3bb4c..2ebc8101 100644 --- a/common/src/main/java/org/terraform/structure/StructureLocator.java +++ b/common/src/main/java/org/terraform/structure/StructureLocator.java @@ -11,7 +11,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; public class StructureLocator { @@ -62,7 +62,7 @@ public static int[] locateMultiMegaChunkStructure(TerraformWorld tw, continue; } - if (TConfigOption.areStructuresEnabled() && populator.canSpawn( + if (TConfig.areStructuresEnabled() && populator.canSpawn( tw, coords[0] >> 4, coords[1] >> 4 @@ -156,7 +156,7 @@ public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // Right bitshift of 4 is conversion from block coords to chunk coords. - if (TConfigOption.areStructuresEnabled() && populator.canSpawn( + if (TConfig.areStructuresEnabled() && populator.canSpawn( tw, coords[0] >> 4, coords[1] >> 4, @@ -170,7 +170,7 @@ public static int[] locateSingleMegaChunkStructure(@NotNull TerraformWorld tw, if (availablePops == null) { continue; } - if (TConfigOption.areStructuresEnabled() && availablePops.canSpawn( + if (TConfig.areStructuresEnabled() && availablePops.canSpawn( tw, coords[0] >> 4, coords[1] >> 4, diff --git a/common/src/main/java/org/terraform/structure/StructureRegistry.java b/common/src/main/java/org/terraform/structure/StructureRegistry.java index 7aaa05df..37d837b7 100644 --- a/common/src/main/java/org/terraform/structure/StructureRegistry.java +++ b/common/src/main/java/org/terraform/structure/StructureRegistry.java @@ -5,7 +5,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.ancientcity.AncientCityPopulator; import org.terraform.structure.catacombs.CatacombsPopulator; import org.terraform.structure.caves.LargeCavePopulator; @@ -116,7 +116,7 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( } Random structRand = tw.getHashedRand(9, mc.getX(), mc.getZ()); - int maxStructures = 3; // GenUtils.randInt(structRand, 1, TConfigOption.STRUCTURES_MEGACHUNK_MAXSTRUCTURES.getInt()); + int maxStructures = 3; // GenUtils.randInt(structRand, 1, TConfigOption.STRUCTURES_MEGACHUNK_MAXSTRUCTURES); SingleMegaChunkStructurePopulator[] pops = new SingleMegaChunkStructurePopulator[maxStructures]; int size = 0; @@ -135,7 +135,7 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( continue; } - if (TConfigOption.areStructuresEnabled() && pop.canSpawn( + if (TConfig.areStructuresEnabled() && pop.canSpawn( tw, coords[0] >> 4, coords[1] >> 4, @@ -157,7 +157,7 @@ public static SingleMegaChunkStructurePopulator[] getLargeStructureForMegaChunk( if (largeStructureRegistry.containsKey(type)) { for (SingleMegaChunkStructurePopulator pop : largeStructureRegistry.get(type)) { int[] coords = mc.getCenterBiomeSectionBlockCoords(); - if (TConfigOption.areStructuresEnabled() && pop.canSpawn(tw, + if (TConfig.areStructuresEnabled() && pop.canSpawn(tw, coords[0] >> 4, coords[1] >> 4, mc.getCenterBiomeSection(tw).getBiomeBank() diff --git a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java index 7bcdc7f3..e488457b 100644 --- a/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java +++ b/common/src/main/java/org/terraform/structure/ancientcity/AncientCityPopulator.java @@ -13,7 +13,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomLayout; @@ -54,7 +54,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 123122), - (int) (TConfigOption.STRUCTURES_ANCIENTCITY_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_ANCIENTCITY_SPAWNRATIO * 10000), 10000 ); } @@ -70,9 +70,9 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int x = coords[0]; int z = coords[1]; // int height = HeightMap.getBlockHeight(tw, x, z); - int minY = TConfigOption.STRUCTURES_ANCIENTCITY_MIN_Y.getInt(); + int minY = TConfig.c.STRUCTURES_ANCIENTCITY_MIN_Y; // if(!Version.isAtLeast(18) && minY < 0) minY = 8; - int y = GenUtils.randInt(minY, TConfigOption.STRUCTURES_ANCIENTCITY_MAX_Y.getInt()); + int y = GenUtils.randInt(minY, TConfig.c.STRUCTURES_ANCIENTCITY_MAX_Y); spawnAncientCity(tw, tw.getHashedRand(x, y, z, 23412222), data, x, y + 1, z); @@ -211,7 +211,7 @@ else if (rel.getType() == Material.WATER) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_ANCIENTCITY_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_ANCIENTCITY_ENABLED; } // Underground structures don't need a decorative buffer diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java index fd46a370..5f2fd828 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsCasketRoomPopulator.java @@ -10,7 +10,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.BlockUtils; import org.terraform.utils.blockdata.ChestBuilder; @@ -62,7 +62,7 @@ private void spawnCasket(@NotNull Wall target, @NotNull Random rand) { switch (rand.nextInt(3)) { case 0: // Chest inside the casket. - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getLeft(target.getDirection())) .setLootTable(TerraLootTable.SIMPLE_DUNGEON) .apply(target) @@ -71,7 +71,7 @@ private void spawnCasket(@NotNull Wall target, @NotNull Random rand) { break; case 1: // Skull and redstone - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { new RotatableBuilder(Material.SKELETON_SKULL).setRotation(BlockUtils.getXZPlaneBlockFace(rand)) .apply(target); target.getFront().setType(Material.REDSTONE_WIRE); @@ -79,7 +79,7 @@ private void spawnCasket(@NotNull Wall target, @NotNull Random rand) { break; default: // spiders - if (TConfigOption.areAnimalsEnabled()) { + if (TConfig.areAnimalsEnabled()) { target.addEntity(EntityType.CAVE_SPIDER); target.getFront().addEntity(EntityType.CAVE_SPIDER); } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java index 64648e1d..c05f756b 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPathPopulator.java @@ -7,7 +7,7 @@ import org.terraform.coregen.TerraLootTable; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.PathPopulatorAbstract; import org.terraform.structure.room.PathPopulatorData; import org.terraform.utils.BlockUtils; @@ -123,7 +123,7 @@ else if (core.getDirection().getModZ() != 0) { if (i == 1) { if (GenUtils.chance(rand, 1, 60)) { // Chests - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { new ChestBuilder(Material.CHEST).setFacing(dir.getOppositeFace()) .setLootTable(TerraLootTable.SIMPLE_DUNGEON) .apply(rel.getRelative(dir.getOppositeFace())); @@ -146,7 +146,7 @@ else if (GenUtils.chance(rand, 1, 20)) { } else if (rel.getRelative(dir.getOppositeFace()).getUp().isSolid() && GenUtils.chance(rand, 1, 10)) { // Cobwebs - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { rel.getRelative(dir.getOppositeFace()).setType(Material.COBWEB); } } diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java index 21ad8005..eb0db809 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsPopulator.java @@ -9,7 +9,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomLayout; @@ -54,7 +54,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not // Do height and space checks int height = HeightMap.getBlockHeight(tw, coords[0], coords[1]); - if (height < TConfigOption.STRUCTURES_CATACOMBS_MAX_Y.getInt() + 15) { + if (height < TConfig.c.STRUCTURES_CATACOMBS_MAX_Y + 15) { // Way too little space. Abort generation. return false; } @@ -64,7 +64,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 17261), - (int) (TConfigOption.STRUCTURES_CATACOMBS_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_CATACOMBS_SPAWNRATIO * 10000), 10000 ); } @@ -80,11 +80,11 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract int x = coords[0]; int z = coords[1]; int height = HeightMap.getBlockHeight(tw, x, z); - int minY = TConfigOption.STRUCTURES_CATACOMBS_MIN_Y.getInt(); + int minY = TConfig.c.STRUCTURES_CATACOMBS_MIN_Y; if (!Version.isAtLeast(18) && minY < 0) { minY = 8; } - int y = GenUtils.randInt(minY, TConfigOption.STRUCTURES_CATACOMBS_MAX_Y.getInt()); + int y = GenUtils.randInt(minY, TConfig.c.STRUCTURES_CATACOMBS_MAX_Y); spawnCatacombs(tw, tw.getHashedRand(x, y, z, 1928374), data, x, y + 1, z, height - y > 25); @@ -115,10 +115,10 @@ private boolean canGoDeeper(@NotNull TerraformWorld tw, int y, @NotNull Random r TerraformGeneratorPlugin.logger.info("TW MinY: " + tw.minY + ", Rolling chance: " - + ((int) (TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble() + + ((int) (TConfig.c.STRUCTURES_CATACOMBS_SIZEROLLCHANCE * 10000d))); return y > tw.minY + 10 && GenUtils.chance(random, - (int) (TConfigOption.STRUCTURES_CATACOMBS_SIZEROLLCHANCE.getDouble() * 10000d), + (int) (TConfig.c.STRUCTURES_CATACOMBS_SIZEROLLCHANCE * 10000d), 10000 ); } @@ -171,7 +171,7 @@ public void spawnCatacombs(@NotNull TerraformWorld tw, int catacombLevels = 1; RoomLayoutGenerator previousGen; while (canGoDeeper) { - if (catacombLevels >= TConfigOption.STRUCTURES_CATACOMBS_MAX_LEVELS.getInt()) { + if (catacombLevels >= TConfig.c.STRUCTURES_CATACOMBS_MAX_LEVELS) { break; } y -= 15; @@ -244,7 +244,7 @@ else if (room.getPop() instanceof CatacombsDripstoneCavern) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_CATACOMBS_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_CATACOMBS_ENABLED; } // Underground structures don't need a decorative buffer diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java index 99b6c76a..544473a5 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsSkeletonDungeonPopulator.java @@ -10,7 +10,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.ChestBuilder; @@ -38,7 +38,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room break; } for (int i = 0; i < entry.getValue(); i++) { - if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(rand, 1, 40)) { + if (TConfig.areDecorationsEnabled() && GenUtils.chance(rand, 1, 40)) { new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) .setLootTable(TerraLootTable.SIMPLE_DUNGEON) .apply(w); diff --git a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java index 9d303c76..70d1e643 100644 --- a/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java +++ b/common/src/main/java/org/terraform/structure/catacombs/CatacombsStandardPopulator.java @@ -11,7 +11,7 @@ import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomPopulatorAbstract; import org.terraform.utils.BlockUtils; @@ -81,7 +81,7 @@ else if (!data.getType(x, y, z).isSolid()) { ); // Cobwebs - if (TConfigOption.areDecorationsEnabled() && rand.nextInt(10) == 0) { + if (TConfig.areDecorationsEnabled() && rand.nextInt(10) == 0) { ceiling.getDown(extend + 1) .getRelative(BlockUtils.getDirectBlockFace(rand)) .lsetType(Material.COBWEB); @@ -147,7 +147,7 @@ else if (!data.getType(x, y, z).isSolid()) { // the chains interfere with lPillar by being solid. // Child classes are responsible for calling this. protected void spawnHangingChains(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java index 47f9ca16..adc9d254 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeCavePopulator.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleLocation; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.JigsawState; import org.terraform.structure.JigsawStructurePopulator; import org.terraform.structure.room.RoomLayout; @@ -155,7 +155,7 @@ public class LargeCavePopulator extends JigsawStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12345), - (int) (TConfigOption.STRUCTURES_LARGECAVE_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_LARGECAVE_SPAWNRATIO * 10000), 10000 ); } @@ -179,7 +179,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not @Override public boolean isEnabled() { - return TConfigOption.areCavesEnabled() && TConfigOption.STRUCTURES_LARGECAVE_ENABLED.getBoolean(); + return TConfig.areCavesEnabled() && TConfig.c.STRUCTURES_LARGECAVE_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java b/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java index 3293d4b5..55405f06 100644 --- a/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java +++ b/common/src/main/java/org/terraform/structure/caves/LargeLushCavePopulator.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -67,7 +67,7 @@ protected void populateFloor(@NotNull SimpleBlock floor, int waterLevel) { } // sea pickle - if (TConfigOption.arePlantsEnabled() && BlockUtils.isWet(floor.getUp()) && GenUtils.chance(rand, 7, 100)) { + if (TConfig.arePlantsEnabled() && BlockUtils.isWet(floor.getUp()) && GenUtils.chance(rand, 7, 100)) { SeaPickle sp = (SeaPickle) Bukkit.createBlockData(Material.SEA_PICKLE); sp.setPickles(GenUtils.randInt(3, 4)); floor.getUp().setBlockData(sp); diff --git a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java index 497e7e83..2ad871c7 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/BadlandsMinePopulator.java @@ -17,7 +17,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.JigsawState; import org.terraform.structure.JigsawStructurePopulator; @@ -32,7 +32,7 @@ import java.util.Random; public class BadlandsMinePopulator extends JigsawStructurePopulator { - static final int shaftDepth = TConfigOption.STRUCTURES_BADLANDS_MINE_DEPTH.getInt(); + static final int shaftDepth = TConfig.c.STRUCTURES_BADLANDS_MINE_DEPTH; @Override public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, BiomeBank biome) { @@ -59,7 +59,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, Biom private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_MINESHAFT_SPAWNRATIO * 10000), 10000 ); } @@ -71,9 +71,9 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && BiomeBank.isBiomeEnabled(BiomeBank.BADLANDS_CANYON) - && TConfigOption.STRUCTURES_BADLANDS_MINE_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_BADLANDS_MINE_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java index 551086e5..674a2b65 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPathPopulator.java @@ -19,7 +19,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.structure.room.PathPopulatorAbstract; import org.terraform.structure.room.PathPopulatorData; @@ -139,7 +139,7 @@ else if (GenUtils.chance(1, 10)) { // Mushroom } // Rails - if (TConfigOption.areDecorationsEnabled() && core.isSolid() && rand.nextBoolean()) { + if (TConfig.areDecorationsEnabled() && core.isSolid() && rand.nextBoolean()) { Rail rail = (Rail) Bukkit.createBlockData(Material.RAIL); switch (core.getDirection()) { case NORTH, SOUTH -> rail.setShape(Shape.NORTH_SOUTH); @@ -227,7 +227,7 @@ else if (GenUtils.chance(1, 10)) { // Mushroom } else if (GenUtils.chance(rand, 1, 6)) { // Cobweb - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { ceil.setType(Material.COBWEB); } } @@ -288,7 +288,7 @@ else if (GenUtils.chance(1, 15)) { // Mushroom } public boolean setMineshaftSupport(@Nullable Wall left, @Nullable Wall right, @Nullable Wall ceil) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return true; } diff --git a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java index 13f7f5f3..6cc0bccd 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/MineshaftPopulator.java @@ -8,7 +8,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.JigsawState; import org.terraform.structure.JigsawStructurePopulator; import org.terraform.structure.room.CubeRoom; @@ -50,7 +50,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_MINESHAFT_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_MINESHAFT_SPAWNRATIO * 10000), 10000 ); } @@ -73,8 +73,8 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk int y; if (!badlandsMineshaft) { y = GenUtils.randInt( - TConfigOption.STRUCTURES_MINESHAFT_MIN_Y.getInt(), - TConfigOption.STRUCTURES_MINESHAFT_MAX_Y.getInt() + TConfig.c.STRUCTURES_MINESHAFT_MIN_Y, + TConfig.c.STRUCTURES_MINESHAFT_MAX_Y ); if (y < TerraformGeneratorPlugin.injector.getMinY()) { y = TerraformGeneratorPlugin.injector.getMinY() + 15; @@ -200,7 +200,7 @@ private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunk @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_MINESHAFT_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_MINESHAFT_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java b/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java index 80c1ca58..58e30b81 100644 --- a/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java +++ b/common/src/main/java/org/terraform/structure/mineshaft/SmeltingHallPopulator.java @@ -10,7 +10,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomPopulatorAbstract; import org.terraform.utils.GenUtils; @@ -48,7 +48,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room Material.CAVE_AIR )); // Small chance to set a lantern - if (TConfigOption.areDecorationsEnabled() && GenUtils.chance(rand, 1, 150)) { + if (TConfig.areDecorationsEnabled() && GenUtils.chance(rand, 1, 150)) { b.getUp().setType(Material.COBBLESTONE); b.getUp(2).setType(Material.LANTERN); } @@ -62,7 +62,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int z = corner[1]; Wall w = new Wall(new SimpleBlock(data, x, room.getY() + 1, z), BlockFace.NORTH); if (w.findCeiling(50) != null) { - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { w.LPillar(50, rand, Material.IRON_BARS); } } @@ -81,7 +81,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room int l = walls.getValue(); for (int i = 0; i < l; i++) { // Non-rail areas - if (TConfigOption.areDecorationsEnabled() && w.getType() == Material.CAVE_AIR) { + if (TConfig.areDecorationsEnabled() && w.getType() == Material.CAVE_AIR) { if (type == 1) { // Furnaces Furnace furnace = (Furnace) Bukkit.createBlockData(Material.FURNACE); furnace.setFacing(w.getDirection()); diff --git a/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java b/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java index 98236090..5086c622 100644 --- a/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java +++ b/common/src/main/java/org/terraform/structure/monument/MonumentPopulator.java @@ -18,7 +18,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.RoomLayout; import org.terraform.structure.room.RoomLayoutGenerator; @@ -172,7 +172,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 92992), - (int) (TConfigOption.STRUCTURES_MONUMENT_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_MONUMENT_SPAWNRATIO * 10000), 10000 ); } @@ -400,6 +400,6 @@ public int getChunkBufferDistance() { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_MONUMENT_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_MONUMENT_ENABLED; } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionPopulator.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionPopulator.java index 27fafe1f..328521ec 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionPopulator.java @@ -8,7 +8,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.utils.GenUtils; @@ -22,7 +22,7 @@ public class MansionPopulator extends SingleMegaChunkStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance( tw.getHashedRand(chunkX, chunkZ, 99572), - (int) (TConfigOption.STRUCTURES_MANSION_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_MANSION_SPAWNRATIO * 10000), 10000 ); } @@ -35,7 +35,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, Biom // Enforce minimum distance if (Math.pow(chunkX * 16, 2) + Math.pow(chunkZ * 16, 2) - < Math.pow(TConfigOption.STRUCTURES_MANSION_MINDISTANCE.getInt(), 2)) + < Math.pow(TConfig.c.STRUCTURES_MANSION_MINDISTANCE, 2)) { return false; } @@ -65,8 +65,8 @@ public void populate(TerraformWorld tw, @NotNull PopulatorDataAbstract data) { MansionJigsawBuilder builder = new MansionJigsawBuilder( - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), - TConfigOption.STRUCTURES_MANSION_SIZE.getInt(), + TConfig.c.STRUCTURES_MANSION_SIZE, + TConfig.c.STRUCTURES_MANSION_SIZE, data, coords[0], y, @@ -79,13 +79,13 @@ public void populate(TerraformWorld tw, @NotNull PopulatorDataAbstract data) { @Override public int getChunkBufferDistance() { - return TConfigOption.STRUCTURES_MANSION_CHUNK_EXCLUSION_ZONE.getInt(); + return TConfig.c.STRUCTURES_MANSION_CHUNK_EXCLUSION_ZONE; } @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && BiomeBank.isBiomeEnabled(BiomeBank.DARK_FOREST) - && TConfigOption.STRUCTURES_MANSION_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_MANSION_ENABLED; } } diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java index 42e6bb9e..21f013eb 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionRoomSchematicParser.java @@ -6,7 +6,7 @@ import org.terraform.coregen.TerraLootTable; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -25,8 +25,8 @@ public MansionRoomSchematicParser(Random rand, PopulatorDataAbstract pop) { @Override public void applyData(@NotNull SimpleBlock block, @NotNull BlockData data) { - if (TConfigOption.areDecorationsEnabled() && (data.getMaterial() == Material.CHEST - || data.getMaterial() == Material.BARREL)) + if (TConfig.areDecorationsEnabled() && (data.getMaterial() == Material.CHEST + || data.getMaterial() == Material.BARREL)) { if (GenUtils.chance(rand, 2, 5)) { block.setType(Material.AIR); diff --git a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java index fd258df6..f0cf08d6 100644 --- a/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java +++ b/common/src/main/java/org/terraform/structure/pillager/mansion/MansionStandardRoomPiece.java @@ -11,7 +11,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.SimpleLocation; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.jigsaw.JigsawStructurePiece; import org.terraform.structure.room.jigsaw.JigsawType; import org.terraform.utils.BlockUtils; @@ -237,7 +237,7 @@ public void spawnGuards(@NotNull Random rand, @NotNull PopulatorDataAbstract dat target.addEntity(type); spawnedGuards++; if (!this.roomPopulator.getSize().equals(new MansionRoomSize(1, 1))) { - for (int i = 0; i < TConfigOption.STRUCTURES_MANSION_SPAWNAGGRESSION.getInt(); i++) { + for (int i = 0; i < TConfig.c.STRUCTURES_MANSION_SPAWNAGGRESSION; i++) { if (rand.nextBoolean()) { target.addEntity(EntityType.VINDICATOR); spawnedGuards++; diff --git a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java index 25bff9c8..9f8fcff2 100644 --- a/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java +++ b/common/src/main/java/org/terraform/structure/pillager/outpost/OutpostPopulator.java @@ -14,7 +14,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; @@ -278,14 +278,14 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 92992), - (int) (TConfigOption.STRUCTURES_OUTPOST_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_OUTPOST_SPAWNRATIO * 10000), 10000 ); } @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_OUTPOST_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_OUTPOST_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java b/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java index 29208ac9..5be91003 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/Antechamber.java @@ -10,7 +10,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomPopulatorAbstract; import org.terraform.utils.BlockUtils; @@ -73,7 +73,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // If at 1.20, spawn suspicious sand in the floor if (Version.isAtLeast(20)) { - for (int i = 0; i < TConfigOption.STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER.getInt(); i++) { + for (int i = 0; i < TConfig.c.STRUCTURES_PYRAMID_SUSPICIOUS_SAND_COUNT_PER_ANTECHAMBER; i++) { SimpleBlock target = center.getRelative(GenUtils.getSign(rand) * GenUtils.randInt(rand, 1, room.getWidthX() / 2 - 1 diff --git a/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java b/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java index 00866ee3..137be2d2 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java +++ b/common/src/main/java/org/terraform/structure/pyramid/ElderGuardianChamber.java @@ -13,7 +13,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.room.CubeRoom; @@ -68,7 +68,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room } // Elder Guardian cage - if (TConfigOption.STRUCTURES_PYRAMID_SPAWN_ELDER_GUARDIAN.getBoolean()) { + if (TConfig.c.STRUCTURES_PYRAMID_SPAWN_ELDER_GUARDIAN) { SimpleBlock cageCenter = center.getUp(11); placeElderGuardianCage(cageCenter); } diff --git a/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java b/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java index 7464fd72..fc144231 100644 --- a/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java +++ b/common/src/main/java/org/terraform/structure/pyramid/PyramidPopulator.java @@ -14,7 +14,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomLayout; @@ -47,7 +47,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, Biom private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 163456), - (int) (TConfigOption.STRUCTURES_PYRAMID_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_PYRAMID_SPAWNRATIO * 10000), 10000 ); } @@ -351,8 +351,8 @@ public void spawnSandBase(TerraformWorld tw, @NotNull PopulatorDataAbstract data // Depress downwards int dist = Math.max(XdistanceFromCenter, ZdistanceFromCenter); - // Bukkit.getLogger().info(height + ":" + (height-raiseDone+((raiseDone)*((50.0f-dist)/5.0f)))); - float comp = original + ((raiseDone) * ((((float) squareRadius - 5) - dist) / 5.0f)) + Math.abs( + // Bukkit.getLogger().info(height + ":" + (height-raiseDone+((raiseDone)*((5f-dist)/5f)))); + float comp = original + ((raiseDone) * ((((float) squareRadius - 5) - dist) / 5f)) + Math.abs( vertNoise.GetNoise(nx, nz) * 30); if (comp < original) { comp = original; @@ -492,9 +492,9 @@ else if (height == elevation + 16) { @Override public boolean isEnabled() { // TODO Auto-generated method stub - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && BiomeBank.isBiomeEnabled(BiomeBank.DESERT) - && TConfigOption.STRUCTURES_PYRAMID_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_PYRAMID_ENABLED; } diff --git a/common/src/main/java/org/terraform/structure/room/CarvedRoom.java b/common/src/main/java/org/terraform/structure/room/CarvedRoom.java index ef941782..7031bad5 100644 --- a/common/src/main/java/org/terraform/structure/room/CarvedRoom.java +++ b/common/src/main/java/org/terraform/structure/room/CarvedRoom.java @@ -10,9 +10,9 @@ public class CarvedRoom extends CubeRoom { - private float xMultiplier = 1.0f; - private float yMultiplier = 1.0f; - private float zMultiplier = 1.0f; + private float xMultiplier = 1f; + private float yMultiplier = 1f; + private float zMultiplier = 1f; private float frequency = 0.09f; public CarvedRoom(int widthX, int widthZ, int height, int x, int y, int z) { diff --git a/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java b/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java index 43ca3659..b356717a 100644 --- a/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java +++ b/common/src/main/java/org/terraform/structure/room/RoomLayoutGenerator.java @@ -61,9 +61,9 @@ public class RoomLayoutGenerator { private int range; private Random rand; private boolean carveRooms = false; - private float xCarveMul = 1.0f; - private float yCarveMul = 1.0f; - private float zCarveMul = 1.0f; + private float xCarveMul = 1f; + private float yCarveMul = 1f; + private float zCarveMul = 1f; private boolean pyramidish = false; private MazeSpawner mazePathGenerator; private int tile = -1; diff --git a/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java b/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java index ec5aa979..64e1271a 100644 --- a/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java +++ b/common/src/main/java/org/terraform/structure/room/carver/CaveRoomCarver.java @@ -9,9 +9,9 @@ public class CaveRoomCarver extends RoomCarver { - private float xMultiplier = 1.0f; - private float yMultiplier = 1.0f; - private float zMultiplier = 1.0f; + private float xMultiplier = 1f; + private float yMultiplier = 1f; + private float zMultiplier = 1f; private float frequency = 0.09f; private float largeRoomFrequency = 0.03f; diff --git a/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java b/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java index fa33f016..27321512 100644 --- a/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/DesertWellPopulator.java @@ -15,7 +15,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.MultiMegaChunkStructurePopulator; @@ -117,7 +117,7 @@ public void spawnDesertWell(TerraformWorld tw, private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 8291374), - (int) (TConfigOption.STRUCTURES_DESERTWELL_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_DESERTWELL_SPAWNRATIO * 10000), 10000 ); } @@ -149,7 +149,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_DESERTWELL_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_DESERTWELL_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227 * (1 + i))); @@ -179,9 +179,9 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_DESERTWELL_ENABLED.getBoolean() && ( - TConfigOption.BIOME_DESERT_WEIGHT.getInt() > 0 - || TConfigOption.BIOME_BADLANDS_WEIGHT.getInt() > 0); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_DESERTWELL_ENABLED && ( + TConfig.c.BIOME_DESERT_WEIGHT > 0 + || TConfig.c.BIOME_BADLANDS_WEIGHT > 0); } @Override diff --git a/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java b/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java index c6220c2f..f6beedfd 100644 --- a/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/GiantPumpkinPopulator.java @@ -5,7 +5,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.tree.FractalTreeBuilder; import org.terraform.tree.FractalTypes; @@ -16,11 +16,11 @@ public class GiantPumpkinPopulator { public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } - if (!TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_SWAMPHUT_ENABLED) { return; } int x = data.getChunkX() * 16 + random.nextInt(16); @@ -59,7 +59,7 @@ public void spawnGiantPumpkin(@NotNull TerraformWorld tw, } // Spawn big bushes - if (TConfigOption.arePlantsEnabled()) { + if (TConfig.arePlantsEnabled()) { for (int i = 0; i < GenUtils.randInt(random, 4, 6); i++) { int nx = x + GenUtils.getSign(random) * GenUtils.randInt(4, 6); int nz = z + GenUtils.getSign(random) * GenUtils.randInt(4, 6); diff --git a/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java b/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java index 93d3edcd..1b9f7e3a 100644 --- a/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/WitchHutPopulator.java @@ -16,7 +16,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.MultiMegaChunkStructurePopulator; @@ -93,7 +93,7 @@ public void spawnSwampHut(TerraformWorld tw, private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 8242112), - (int) (TConfigOption.STRUCTURES_SWAMPHUT_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_SWAMPHUT_SPAWNRATIO * 10000), 10000 ); } @@ -122,7 +122,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_SWAMPHUT_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_SWAMPHUT_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 819227 * (1 + i))); @@ -152,9 +152,9 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_SWAMPHUT_ENABLED.getBoolean() && ( - TConfigOption.BIOME_SWAMP_WEIGHT.getInt() > 0 - || TConfigOption.BIOME_MANGROVE_WEIGHT.getInt() > 0); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_SWAMPHUT_ENABLED && ( + TConfig.c.BIOME_SWAMP_WEIGHT > 0 + || TConfig.c.BIOME_MANGROVE_WEIGHT > 0); } @Override diff --git a/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java b/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java index f485efa0..dd7d1b11 100644 --- a/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java +++ b/common/src/main/java/org/terraform/structure/small/buriedtreasure/BuriedTreasurePopulator.java @@ -9,7 +9,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.MultiMegaChunkStructurePopulator; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -47,7 +47,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_BURIEDTREASURE_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 87464 * (1 + i))); @@ -78,7 +78,7 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance( tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_BURIEDTREASURE_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_BURIEDTREASURE_SPAWNRATIO * 10000), 10000 ); } @@ -113,7 +113,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_BURIEDTREASURE_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_BURIEDTREASURE_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java b/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java index 9b19643f..c39a8fb7 100644 --- a/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/dungeon/SmallDungeonPopulator.java @@ -5,7 +5,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.MultiMegaChunkStructurePopulator; import org.terraform.utils.GenUtils; @@ -25,21 +25,21 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract } } - if (totalHeight / 256 <= TConfigOption.STRUCTURES_DROWNEDDUNGEON_MIN_DEPTH.getInt() + if (totalHeight / 256 <= TConfig.c.STRUCTURES_DROWNEDDUNGEON_MIN_DEPTH && GenUtils.chance( tw.getHashedRand(1223, data.getChunkX(), data.getChunkZ()), - TConfigOption.STRUCTURES_DROWNEDDUNGEON_CHANCE.getInt(), + TConfig.c.STRUCTURES_DROWNEDDUNGEON_CHANCE, 1000 )) { // Only spawn these in full oceans - if (!TConfigOption.STRUCTURES_DROWNEDDUNGEON_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_DROWNEDDUNGEON_ENABLED) { return; } new DrownedDungeonPopulator().populate(tw, data); } else { - if (!TConfigOption.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED) { return; } new UndergroundDungeonPopulator().populate(tw, data); @@ -48,7 +48,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12222), - (int) (TConfigOption.STRUCTURES_DUNGEONS_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_DUNGEONS_SPAWNRATIO * 10000), 10000 ); } @@ -72,7 +72,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { // Each mega chunk has config option dungeons @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_DUNGEONS_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 1317324 * (1 + i))); @@ -107,7 +107,7 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && (TConfigOption.STRUCTURES_DROWNEDDUNGEON_ENABLED.getBoolean() - || TConfigOption.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED.getBoolean()); + return TConfig.areStructuresEnabled() && (TConfig.c.STRUCTURES_DROWNEDDUNGEON_ENABLED + || TConfig.c.STRUCTURES_UNDERGROUNDDUNGEON_ENABLED); } } diff --git a/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java b/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java index 3818037c..173b129c 100644 --- a/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/igloo/IglooPopulator.java @@ -17,7 +17,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.MultiMegaChunkStructurePopulator; import org.terraform.utils.*; import org.terraform.utils.SphereBuilder.SphereType; @@ -63,7 +63,7 @@ public void spawnIgloo(TerraformWorld tw, .setRX(size * 1.5f) .setRY(0.5f) .setRZ(size * 1.5f) - .setMinRadius(1.0f) + .setMinRadius(1f) .setSingleBlockY(true) .build(); @@ -369,7 +369,7 @@ private void spawnSpire(@NotNull SimpleBlock block) { @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_IGLOO_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_IGLOO_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCenterChunkBlockCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 992722 * (1 + i))); @@ -399,7 +399,7 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 976123), - (int) (TConfigOption.STRUCTURES_IGLOO_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_IGLOO_SPAWNRATIO * 10000), 10000 ); } @@ -438,7 +438,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_IGLOO_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_IGLOO_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java b/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java index 0cd31b6b..8bc86a43 100644 --- a/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/ruinedportal/RuinedPortalPopulator.java @@ -11,7 +11,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.MultiMegaChunkStructurePopulator; import org.terraform.utils.BlockUtils; import org.terraform.utils.CylinderBuilder; @@ -219,7 +219,7 @@ public void spawnRuinedPortal(TerraformWorld tw, double fissureNoise = (3 - 100 * Math.abs(noise.GetNoise(relx + core.getX(), relz + core.getZ()))); if (fissureNoise > 0) { SimpleBlock target = core.getRelative(relx, 0, relz).getGround(); - fissureNoise = (1.0 - Math.min(1.0f, target.distance(core) / (horRadius * 3))) * fissureNoise; + fissureNoise = (1.0 - Math.min(1f, target.distance(core) / (horRadius * 3))) * fissureNoise; lavaLocs.put(target, (int) Math.round(fissureNoise)); if (lowestY > target.getY()) { lowestY = target.getY(); @@ -255,7 +255,7 @@ public void spawnRuinedPortal(TerraformWorld tw, rightCorner.getLeft(i).setType(getFluid(rightCorner.getLeft(i))); BlockUtils.dropDownBlock(rightCorner.getLeft(i).getUp(), getFluid(rightCorner.getLeft(i).getUp())); } - if (overgrown && TConfigOption.arePlantsEnabled() && leftCorner.getRight().isSolid()) { + if (overgrown && TConfig.arePlantsEnabled() && leftCorner.getRight().isSolid()) { leftCorner.getRight() .getRear() .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); @@ -274,7 +274,7 @@ public void spawnRuinedPortal(TerraformWorld tw, leftCorner.getRight(i).setType(getFluid(leftCorner.getRight(i))); BlockUtils.dropDownBlock(leftCorner.getRight(i).getUp(), getFluid(leftCorner.getRight(i).getUp())); } - if (overgrown && TConfigOption.arePlantsEnabled() && rightCorner.getLeft().isSolid()) { + if (overgrown && TConfig.arePlantsEnabled() && rightCorner.getLeft().isSolid()) { rightCorner.getLeft() .getRear() .downLPillar(random, GenUtils.randInt(vertHeight / 2, vertHeight - 1), Material.OAK_LEAVES); @@ -331,7 +331,7 @@ public void spawnRuinedPortal(TerraformWorld tw, @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_RUINEDPORTAL_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_RUINEDPORTAL_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 4363463 * (1 + i))); @@ -361,7 +361,7 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 976123), - (int) (TConfigOption.STRUCTURES_RUINEDPORTAL_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_RUINEDPORTAL_SPAWNRATIO * 10000), 10000 ); } @@ -388,7 +388,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_RUINEDPORTAL_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_RUINEDPORTAL_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java index 2f83afa1..eb54237b 100644 --- a/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java +++ b/common/src/main/java/org/terraform/structure/small/shipwreck/ShipwreckPopulator.java @@ -9,7 +9,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.MultiMegaChunkStructurePopulator; import org.terraform.utils.BlockUtils; @@ -131,7 +131,7 @@ public void spawnShipwreck(@NotNull TerraformWorld tw, @Override public int[][] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChunk mc) { - int num = TConfigOption.STRUCTURES_SHIPWRECK_COUNT_PER_MEGACHUNK.getInt(); + int num = TConfig.c.STRUCTURES_SHIPWRECK_COUNT_PER_MEGACHUNK; int[][] coords = new int[num][2]; for (int i = 0; i < num; i++) { coords[i] = mc.getRandomCoords(tw.getHashedRand(mc.getX(), mc.getZ(), 191921 * (1 + i))); @@ -162,7 +162,7 @@ public int[] getNearestFeature(@NotNull TerraformWorld tw, int rawX, int rawZ) { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_SHIPWRECK_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_SHIPWRECK_SPAWNRATIO * 10000), 10000 ); } @@ -201,7 +201,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_SHIPWRECK_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_SHIPWRECK_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java index 6b4e534f..b4a410e4 100644 --- a/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java +++ b/common/src/main/java/org/terraform/structure/stronghold/StrongholdPopulator.java @@ -7,7 +7,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomLayout; @@ -126,15 +126,15 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract // Strongholds no longer calculate from the surface. // Just pick a directly underground location. int y = GenUtils.randInt( - TConfigOption.STRUCTURES_STRONGHOLD_MIN_Y.getInt(), - TConfigOption.STRUCTURES_STRONGHOLD_MAX_Y.getInt() + TConfig.c.STRUCTURES_STRONGHOLD_MIN_Y, + TConfig.c.STRUCTURES_STRONGHOLD_MAX_Y ); // Attempt to force strongholds further underground if // they're above the surface. if (y + 18 > GenUtils.getHighestGround(data, x, z)) { - if (y > TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt()) { - y = TConfigOption.STRUCTURES_STRONGHOLD_FAILSAFE_Y.getInt(); + if (y > TConfig.c.STRUCTURES_STRONGHOLD_FAILSAFE_Y) { + y = TConfig.c.STRUCTURES_STRONGHOLD_FAILSAFE_Y; } } @@ -284,7 +284,7 @@ public int[] getCoordsFromMegaChunk(@NotNull TerraformWorld tw, @NotNull MegaChu @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_STRONGHOLD_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_STRONGHOLD_ENABLED; } @Override diff --git a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java index 577919b5..76e4d287 100644 --- a/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java +++ b/common/src/main/java/org/terraform/structure/trailruins/TrailRuinsPopulator.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomLayout; @@ -101,16 +101,16 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.TAIGA) || BiomeBank.isBiomeEnabled(BiomeBank.SNOWY_TAIGA) || BiomeBank.isBiomeEnabled(BiomeBank.JUNGLE)) - && TConfigOption.STRUCTURES_TRAILRUINS_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_TRAILRUINS_ENABLED; } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 34122), - (int) (TConfigOption.STRUCTURES_TRAILRUINS_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_TRAILRUINS_SPAWNRATIO * 10000), 10000 ); } diff --git a/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java b/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java index d3feb2da..62f7d57b 100644 --- a/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java +++ b/common/src/main/java/org/terraform/structure/trialchamber/TrialChamberPopulator.java @@ -4,7 +4,7 @@ import org.terraform.biome.BiomeBank; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.VanillaStructurePopulator; import org.terraform.utils.GenUtils; @@ -32,13 +32,13 @@ public void populate(TerraformWorld tw, PopulatorDataAbstract data) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && TConfigOption.STRUCTURES_TRIALCHAMBER_ENABLED.getBoolean(); + return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_TRIALCHAMBER_ENABLED; } private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance( tw.getHashedRand(chunkX, chunkZ, 19650), - (int) (TConfigOption.STRUCTURES_TRIALCHAMBER_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_TRIALCHAMBER_SPAWNRATIO * 10000), 10000 ); } diff --git a/common/src/main/java/org/terraform/structure/village/VillagePopulator.java b/common/src/main/java/org/terraform/structure/village/VillagePopulator.java index 6e158c74..2370a278 100644 --- a/common/src/main/java/org/terraform/structure/village/VillagePopulator.java +++ b/common/src/main/java/org/terraform/structure/village/VillagePopulator.java @@ -6,7 +6,7 @@ import org.terraform.biome.BiomeBank; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.village.plains.PlainsVillagePopulator; import org.terraform.utils.GenUtils; @@ -21,7 +21,7 @@ public class VillagePopulator extends SingleMegaChunkStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance( tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_VILLAGE_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_VILLAGE_SPAWNRATIO * 10000), 10000 ); } @@ -83,18 +83,18 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract @Override public int getChunkBufferDistance() { - return TConfigOption.STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE.getInt(); + return TConfig.c.STRUCTURES_VILLAGE_CHUNK_EXCLUSION_ZONE; } @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.PLAINS) || BiomeBank.isBiomeEnabled(BiomeBank.FOREST) || BiomeBank.isBiomeEnabled(BiomeBank.SAVANNA) || BiomeBank.isBiomeEnabled(BiomeBank.TAIGA) || BiomeBank.isBiomeEnabled(BiomeBank.SCARLET_FOREST) || BiomeBank.isBiomeEnabled(BiomeBank.CHERRY_GROVE)) - && TConfigOption.STRUCTURES_PLAINSVILLAGE_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_PLAINSVILLAGE_ENABLED; } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java index 229f38ea..cb588a6a 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAbstractRoomPopulator.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomPopulatorAbstract; import org.terraform.utils.GenUtils; @@ -33,7 +33,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int[] corner : room.getAllCorners(2)) { SimpleBlock sb = new SimpleBlock(data, corner[0], roomY, corner[1]); int lowSb = sb.findFloor(worldHeight).getY(); - if (Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(lowSb - roomY) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { // place platform as uneven ground was detected. this.placeFixerPlatform(roomY, data, room); break; @@ -76,7 +76,7 @@ protected int calculateRoomY(@NotNull PopulatorDataAbstract data, @NotNull CubeR int centerHeight = GenUtils.getHighestGroundOrSeaLevel(data, room.getX(), room.getZ()); int pathHeight = getPathHeight(data, room); - if (Math.abs(centerHeight - pathHeight) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(centerHeight - pathHeight) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { return pathHeight; } else { @@ -90,7 +90,7 @@ protected boolean doesAreaFailTolerance(@NotNull PopulatorDataAbstract data, @No for (int[] corner : room.getAllCorners(2)) { SimpleBlock sb = new SimpleBlock(data, corner[0], roomY, corner[1]); int lowSb = sb.findFloor(worldHeight).getY(); - if (Math.abs(lowSb - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(lowSb - roomY) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { return true; } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java index e173915a..7ad093e3 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageAnimalPenPopulator.java @@ -7,7 +7,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.BlockUtils; @@ -107,7 +107,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // else // highest = roomY; - if (Math.abs(highest - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(highest - roomY) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { continue; } @@ -147,7 +147,7 @@ else if (rand.nextBoolean()) { // core.getAtY(roomY+1); if (Math.abs(core.getY() - roomY) - > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) + > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { continue; } @@ -210,7 +210,7 @@ else if (rand.nextBoolean()) { highest++; } if (threshold < 6) { - if (Math.abs(highest - roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(highest - roomY) <= TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { for (int i = 0; i < GenUtils.randInt(3, 7); i++) { data.addEntity(coords[0], highest + 1, coords[2], animal); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java index b3d36a78..0e44b405 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageCropFarmPopulator.java @@ -11,7 +11,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -71,7 +71,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int i = 0; i < entry.getValue(); i++) { // Added height tolerance check. Don't place anything on areas that deviate too far off. - if (Math.abs(w.getY() - roomY) <= TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(w.getY() - roomY) <= TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { if (w.getDirection().getOppositeFace() == dir) { // Entrance if (i <= 1 || i >= entry.getValue() - 1) { @@ -159,7 +159,7 @@ else if (i == entry.getValue() / 2) { height = GenUtils.getHighestGroundOrSeaLevel(data, x, z); // Forget populating areas that are too far up/down - if (Math.abs(height - roomY) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(height - roomY) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { continue; } // } else diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java index f57b2aad..aed92e6b 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePathPopulator.java @@ -11,7 +11,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.PathPopulatorAbstract; @@ -121,7 +121,7 @@ else if (GenUtils.chance(1, 5)) { // Flowers } else if (GenUtils.chance(1, 10)) { // Small cobble walls with lanterns target.getUp().setType(Material.COBBLESTONE_WALL, Material.MOSSY_COBBLESTONE_WALL); - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { target.getUp(2).setType(Material.LANTERN); } } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java index eb7254f3..566f3b6b 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillagePondPopulator.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.structure.room.CubeRoom; import org.terraform.structure.room.RoomPopulatorAbstract; @@ -56,9 +56,9 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // Carve hole in ground int depth = GenUtils.randInt(3, 5); BlockUtils.replaceLowerSphere(rand.nextInt(12222), - (room.getWidthX() / 2.0f) - 1.5f, + (room.getWidthX() / 2f) - 1.5f, (float) depth, - (room.getWidthZ() / 2.0f) - 1.5f, + (room.getWidthZ() / 2f) - 1.5f, core, true, Material.AIR @@ -131,7 +131,7 @@ else if (GenUtils.chance(1, 4)) { // Double Plants PlantBuilder.TALL_GRASS ); } - else if (!placedJobBlock && TConfigOption.areDecorationsEnabled() && GenUtils.chance(2, 5)) { + else if (!placedJobBlock && TConfig.areDecorationsEnabled() && GenUtils.chance(2, 5)) { target.setType(Material.BARREL); placedJobBlock = true; } @@ -152,7 +152,7 @@ else if (GenUtils.chance(1, 7)) // sea pickle growth CoralGenerator.generateSeaPickles(data, x, target.getY(), z); } - if (TConfigOption.areAnimalsEnabled() && GenUtils.chance(1, 20)) { // spawn fish + if (TConfig.areAnimalsEnabled() && GenUtils.chance(1, 20)) { // spawn fish core.getPopData() .addEntity(target.getX(), target.getY(), target.getZ(), EntityType.TROPICAL_FISH); } diff --git a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java index 915ee8e6..f12a6b83 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java +++ b/common/src/main/java/org/terraform/structure/village/plains/PlainsVillageWellPopulator.java @@ -10,7 +10,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.SchematicParser; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.room.CubeRoom; @@ -50,7 +50,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room for (int[] corner : room.getAllCorners()) { SimpleBlock sb = new SimpleBlock(data, corner[0], y, corner[1]); int lowSb = sb.findFloor(worldHeight).getY(); - if (Math.abs(lowSb - y) > TConfigOption.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE.getInt()) { + if (Math.abs(lowSb - y) > TConfig.c.STRUCTURES_PLAINSVILLAGE_HEIGHT_TOLERANCE) { // place platform as uneven ground was detected. this.placeFixerPlatform(y, data, room); break; diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java index bc616a43..dee5f66d 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleJigsawBuilder.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.jigsaw.JigsawBuilder; import org.terraform.structure.room.jigsaw.JigsawStructurePiece; import org.terraform.structure.room.jigsaw.JigsawType; @@ -121,7 +121,7 @@ protected static boolean hasAdjacentInwardWall(@NotNull JigsawStructurePiece pie @Override public void build(@NotNull Random random) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java index e52d139e..25efe74a 100644 --- a/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java +++ b/common/src/main/java/org/terraform/structure/village/plains/temple/PlainsVillageTempleLoungePiece.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.jigsaw.JigsawType; import org.terraform.structure.village.plains.PlainsVillagePopulator; import org.terraform.utils.BlockUtils; @@ -49,9 +49,9 @@ public void postBuildDecoration(@NotNull Random random, @NotNull PopulatorDataAb .apply(core.getRelative(face).getRelative(BlockUtils.getAdjacentFaces(face)[1])); } - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { core.setType(plainsVillagePopulator.woodLog, Material.CRAFTING_TABLE, plainsVillagePopulator.woodPlank); - if (!TConfigOption.arePlantsEnabled() || random.nextBoolean()) { + if (!TConfig.arePlantsEnabled() || random.nextBoolean()) { core.getUp().setType(Material.LANTERN); } else { diff --git a/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java index 6315b23b..e7f2f24e 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/VillageHousePopulator.java @@ -7,7 +7,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.villagehouse.animalfarm.AnimalFarmPopulator; import org.terraform.structure.villagehouse.farmhouse.FarmhousePopulator; @@ -26,7 +26,7 @@ public class VillageHousePopulator extends SingleMegaChunkStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance( tw.getHashedRand(chunkX, chunkZ, 12422), - (int) (TConfigOption.STRUCTURES_VILLAGEHOUSE_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_VILLAGEHOUSE_SPAWNRATIO * 10000), 10000 ); } @@ -48,7 +48,7 @@ public boolean canSpawn(@NotNull TerraformWorld tw, int chunkX, int chunkZ, @Not // If it is below sea level, DON'T SPAWN IT. if (HeightMap.getBlockHeight(tw, coords[0], coords[1]) > TerraformGenerator.seaLevel) { if (biome == (BiomeBank.DESERT) || biome == (BiomeBank.BADLANDS) || biome == (BiomeBank.ICE_SPIKES)) { - return TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean() && rollSpawnRatio(tw, + return TConfig.c.STRUCTURES_ANIMALFARM_ENABLED && rollSpawnRatio(tw, chunkX, chunkZ); } @@ -57,13 +57,13 @@ else if (biome == (BiomeBank.SNOWY_TAIGA) || biome == (BiomeBank.JUNGLE)) { - return TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw, + return TConfig.c.STRUCTURES_FARMHOUSE_ENABLED && rollSpawnRatio(tw, chunkX, chunkZ); } else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { - return TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean() && rollSpawnRatio(tw, + return TConfig.c.STRUCTURES_MOUNTAINHOUSE_ENABLED && rollSpawnRatio(tw, chunkX, chunkZ); } @@ -85,7 +85,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank(); // if (GenUtils.getHighestGround(data, coords[0], coords[1]) > TerraformGenerator.seaLevel) { if (biome == (BiomeBank.DESERT) || biome == (BiomeBank.BADLANDS) || biome == (BiomeBank.ICE_SPIKES)) { - if (!TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_ANIMALFARM_ENABLED) { return; } @@ -96,7 +96,7 @@ else if (biome == (BiomeBank.SNOWY_TAIGA) || biome == (BiomeBank.JUNGLE)) { - if (!TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_FARMHOUSE_ENABLED) { return; } @@ -104,7 +104,7 @@ else if (biome == (BiomeBank.SNOWY_TAIGA) } else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { - if (!TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean()) { + if (!TConfig.c.STRUCTURES_MOUNTAINHOUSE_ENABLED) { return; } @@ -115,15 +115,15 @@ else if (biome == (BiomeBank.ROCKY_MOUNTAINS)) { @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.DESERT) - || BiomeBank.isBiomeEnabled(BiomeBank.BADLANDS) - || BiomeBank.isBiomeEnabled(BiomeBank.ICE_SPIKES) - || BiomeBank.isBiomeEnabled(BiomeBank.SNOWY_TAIGA) - || BiomeBank.isBiomeEnabled(BiomeBank.SNOWY_WASTELAND) - || BiomeBank.isBiomeEnabled(BiomeBank.JUNGLE) - || BiomeBank.isBiomeEnabled(BiomeBank.ROCKY_MOUNTAINS)) && ( - TConfigOption.STRUCTURES_ANIMALFARM_ENABLED.getBoolean() - || TConfigOption.STRUCTURES_FARMHOUSE_ENABLED.getBoolean() - || TConfigOption.STRUCTURES_MOUNTAINHOUSE_ENABLED.getBoolean()); + return TConfig.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.DESERT) + || BiomeBank.isBiomeEnabled(BiomeBank.BADLANDS) + || BiomeBank.isBiomeEnabled(BiomeBank.ICE_SPIKES) + || BiomeBank.isBiomeEnabled(BiomeBank.SNOWY_TAIGA) + || BiomeBank.isBiomeEnabled(BiomeBank.SNOWY_WASTELAND) + || BiomeBank.isBiomeEnabled(BiomeBank.JUNGLE) + || BiomeBank.isBiomeEnabled(BiomeBank.ROCKY_MOUNTAINS)) && ( + TConfig.c.STRUCTURES_ANIMALFARM_ENABLED + || TConfig.c.STRUCTURES_FARMHOUSE_ENABLED + || TConfig.c.STRUCTURES_MOUNTAINHOUSE_ENABLED); } } diff --git a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java index 363aac8d..3078d34d 100644 --- a/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java +++ b/common/src/main/java/org/terraform/structure/villagehouse/farmhouse/FarmhousePopulator.java @@ -17,7 +17,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.TerraSchematic; import org.terraform.structure.villagehouse.VillageHousePopulator; import org.terraform.utils.BlockUtils; @@ -33,7 +33,7 @@ public class FarmhousePopulator extends VillageHousePopulator { @Override public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } @@ -52,7 +52,7 @@ public void spawnFarmHouse(@NotNull TerraformWorld tw, int y, int z) { - if (!TConfigOption.areStructuresEnabled()) { + if (!TConfig.areStructuresEnabled()) { return; } @@ -159,7 +159,7 @@ private void placeLamp(TerraformWorld tw, int y, int z) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java index 94db6eab..a64899fa 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanAltarRoom.java @@ -5,7 +5,7 @@ import org.terraform.coregen.TerraLootTable; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.GenUtils; import org.terraform.utils.blockdata.ChestBuilder; @@ -41,7 +41,7 @@ else if (i % 2 == 1 && rand.nextBoolean()) { new ChestBuilder(Material.CHEST).setFacing(w.getDirection()) .setLootTable(TerraLootTable.UNDERWATER_RUIN_SMALL) .setWaterlogged(w.getUp().getY() - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(w.getFront().getRight().getUp()); } w = w.getLeft().getGround(); diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java index 7da52a59..7ff9cda0 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanDomeHutRoom.java @@ -32,7 +32,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room // This is just a cylinder with an ellipse on it SimpleBlock centre = room.getCenterSimpleBlock(data); - float radius = Math.min(room.getWidthX(), room.getWidthZ()) / 3.0f; + float radius = Math.min(room.getWidthX(), room.getWidthZ()) / 3f; int cylSize = GenUtils.randInt(rand, 3, 5); // Carves the actual dome, with sandstone flooring diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java index c833d6a8..c4ae2a4f 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanLargeArcRoom.java @@ -12,7 +12,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.room.CubeRoom; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -44,7 +44,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room new ChestBuilder(Material.CHEST).setFacing(BlockUtils.getDirectBlockFace(rand)) .setLootTable(TerraLootTable.UNDERWATER_RUIN_BIG) .setWaterlogged(chestTarget.getY() - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(chestTarget); // Create a 3x3 pattern to use in the arc's walls @@ -87,7 +87,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room new StairBuilder(Material.SANDSTONE_STAIRS).setHalf(Bisected.Half.TOP) .setFacing(pillarDir) .setWaterlogged(pillarCore.getY() + 6 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(pillarCore.getUp(6) .getRelative(face, 2) .getRelative( @@ -95,7 +95,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room 3 )) .setWaterlogged(pillarCore.getY() + 7 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(pillarCore.getUp(7) .getRelative(face, 2) .getRelative( @@ -134,13 +134,13 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(dir) .setWaterlogged(pillarCore.getY() - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(pillarCore.getRelative(face, 3) .getRelative(dir, 2)); } new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(face.getOppositeFace()) .setWaterlogged(pillarCore.getY() - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(pillarCore.getRelative(face, 3)); // Place the patterns @@ -175,14 +175,14 @@ else if (Math.abs(lr) == 7 || Math.abs(fb) == 2) { else { new SlabBuilder(Material.CUT_SANDSTONE_SLAB).setType(Slab.Type.TOP) .setWaterlogged(core.getY() + 4 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(core.getLeft(lr).getFront(fb).getUp(4)); } } else { new SlabBuilder(Material.CUT_SANDSTONE_SLAB).setType(Slab.Type.TOP) .setWaterlogged(core.getY() - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(core.getLeft(lr).getFront(fb)); } } @@ -221,7 +221,7 @@ else if (Math.abs(lr) == 7 || Math.abs(fb) == 2) { .apply(w.getLeft()) .setHalf(Bisected.Half.TOP) .setWaterlogged(w.getY() + 2 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(w.getLeft().getUp(2)); } else if (i == entry.getValue() - 1) { @@ -230,7 +230,7 @@ else if (i == entry.getValue() - 1) { .apply(w.getRight()) .setHalf(Bisected.Half.TOP) .setWaterlogged(w.getY() + 2 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(w.getRight().getUp(2)); } else if (i == 4 || i == 10) { @@ -239,13 +239,13 @@ else if (i == 4 || i == 10) { .apply(w.getRight()) .setHalf(Bisected.Half.TOP) .setWaterlogged(w.getY() + 2 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(w.getRight().getUp(2)); new StairBuilder(Material.SANDSTONE_STAIRS).setFacing(BlockUtils.getRight(w.getDirection())) .apply(w.getLeft()) .setHalf(Bisected.Half.TOP) .setWaterlogged(w.getY() + 2 - <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt()) + <= TConfig.c.HEIGHT_MAP_SEA_LEVEL) .apply(w.getLeft().getUp(2)); } w = w.getLeft(); diff --git a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java index ac33ef1c..bbc10dc4 100644 --- a/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java +++ b/common/src/main/java/org/terraform/structure/warmoceanruins/WarmOceanRuinsPopulator.java @@ -6,7 +6,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.SingleMegaChunkStructurePopulator; import org.terraform.structure.room.RoomLayout; import org.terraform.structure.room.RoomLayoutGenerator; @@ -23,7 +23,7 @@ public class WarmOceanRuinsPopulator extends SingleMegaChunkStructurePopulator { private boolean rollSpawnRatio(@NotNull TerraformWorld tw, int chunkX, int chunkZ) { return GenUtils.chance(tw.getHashedRand(chunkX, chunkZ, 65732), - (int) (TConfigOption.STRUCTURES_WARMOCEANRUINS_SPAWNRATIO.getDouble() * 10000), + (int) (TConfig.c.STRUCTURES_WARMOCEANRUINS_SPAWNRATIO * 10000), 10000 ); } @@ -122,7 +122,7 @@ public int getChunkBufferDistance() { // spawn everywhere. @Override public boolean isEnabled() { - return TConfigOption.areStructuresEnabled() + return TConfig.areStructuresEnabled() && (BiomeBank.isBiomeEnabled(BiomeBank.DEEP_WARM_OCEAN) || BiomeBank.isBiomeEnabled(BiomeBank.WARM_OCEAN) || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_LUKEWARM_OCEAN) @@ -131,6 +131,6 @@ public boolean isEnabled() { || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_COLD_OCEAN) || BiomeBank.isBiomeEnabled(BiomeBank.FROZEN_OCEAN) || BiomeBank.isBiomeEnabled(BiomeBank.DEEP_FROZEN_OCEAN)) - && TConfigOption.STRUCTURES_WARMOCEANRUINS_ENABLED.getBoolean(); + && TConfig.c.STRUCTURES_WARMOCEANRUINS_ENABLED; } } diff --git a/common/src/main/java/org/terraform/tree/FractalLeaves.java b/common/src/main/java/org/terraform/tree/FractalLeaves.java index 7c998e56..fc7a5294 100644 --- a/common/src/main/java/org/terraform/tree/FractalLeaves.java +++ b/common/src/main/java/org/terraform/tree/FractalLeaves.java @@ -126,12 +126,12 @@ public void placeLeaves(TerraformWorld tw, int oriY, int maxHeight, @NotNull Sim effectiveY += radiusY / 2; // Shift center area downwards // Compress negative y if (effectiveY < 0) { - effectiveY = effectiveY * 2.0f; + effectiveY = effectiveY * 2f; } // Extend positive y and multiply it by a power to make it sharp if (effectiveY > 0) { - effectiveY = effectiveY * (2.0f / 3.0f); + effectiveY = effectiveY * (2f / 3f); effectiveY = (float) Math.pow(effectiveY, 1.3); if (effectiveY > radiusY) { effectiveY = radiusY; diff --git a/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java b/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java index 7b911e7e..95b3a58c 100644 --- a/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java +++ b/common/src/main/java/org/terraform/tree/FractalTreeBuilder.java @@ -16,7 +16,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.CoralGenerator; import org.terraform.utils.GenUtils; @@ -63,7 +63,7 @@ public class FractalTreeBuilder { double alwaysOneStraightBranchYawLowerMultiplier = 0.9; double alwaysOneStraightBranchYawUpperMultiplier = 1.1; boolean noMainStem = false; - double beeChance = 0.0f; + double beeChance = 0f; int vines = 0; int cocoaBeans = 0; int fractalThreshold = 1; @@ -84,9 +84,9 @@ public class FractalTreeBuilder { public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { switch (type) { case FOREST: - this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) + this.setBeeChance(TConfig.c.ANIMALS_BEE_HIVEFREQUENCY) .setBaseHeight(9) - .setBaseThickness(3.0f) + .setBaseThickness(3f) .setThicknessDecrement(0.3f) .setLengthDecrement(1.3f) .setMinBend(0.7 * Math.PI / 6) @@ -95,22 +95,22 @@ public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { .setHeightVariation(2) .setLeafBranchFrequency(0.05f) .setFractalLeaves(new FractalLeaves().setRadius(3) - .setLeafNoiseFrequency(1.0f) - .setLeafNoiseMultiplier(1.0f)); + .setLeafNoiseFrequency(1f) + .setLeafNoiseMultiplier(1f)); break; case NORMAL_SMALL: - this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) + this.setBeeChance(TConfig.c.ANIMALS_BEE_HIVEFREQUENCY) .setBaseHeight(5) .setBaseThickness(1) .setThicknessDecrement(1f) .setMaxDepth(1) .setFractalLeaves(new FractalLeaves().setRadius(3) - .setLeafNoiseFrequency(1.0f) - .setLeafNoiseMultiplier(1.0f)) + .setLeafNoiseFrequency(1f) + .setLeafNoiseMultiplier(1f)) .setHeightVariation(1); break; case AZALEA_TOP: - this.setBeeChance(TConfigOption.ANIMALS_BEE_HIVEFREQUENCY.getDouble()) + this.setBeeChance(TConfig.c.ANIMALS_BEE_HIVEFREQUENCY) .setBaseHeight(3) .setBaseThickness(1) .setThicknessDecrement(0.3f) @@ -123,8 +123,8 @@ public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { .setRadiusX(3) .setRadiusZ(3) .setRadiusY(1.5f) - .setLeafNoiseFrequency(1.0f) - .setLeafNoiseMultiplier(1.0f) + .setLeafNoiseFrequency(1f) + .setLeafNoiseMultiplier(1f) .setWeepingLeaves(0.3f, 3)) .setVines(3) .setMinBend(0.9 * Math.PI / 6) @@ -166,7 +166,7 @@ public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { .setMinBend(0.9 * Math.PI / 6) .setMaxBend(1.1 * Math.PI / 6) .setLengthDecrement(-0.5f) - .setMinThickness(1.0f) + .setMinThickness(1f) .setTrunkType(OneTwentyBlockHandler.CHERRY_LOG) .setFractalLeaves(new FractalLeaves().setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) .setRadius(3, 2f, 3)); @@ -183,7 +183,7 @@ public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { .setMinBend(0.9 * Math.PI / 6) .setMaxBend(1.1 * Math.PI / 6) .setLengthDecrement(0.3f) - .setMinThickness(1.0f) + .setMinThickness(1f) .setTrunkType(OneTwentyBlockHandler.CHERRY_WOOD) .setFractalLeaves(new FractalLeaves().setMaterial(OneTwentyBlockHandler.CHERRY_LEAVES) .setRadius(3, 2f, 3) @@ -587,7 +587,7 @@ public FractalTreeBuilder(FractalTypes.@NotNull Tree type) { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean checkGradient(PopulatorDataAbstract data, int x, int z) { heightGradientChecked = true; - return (HeightMap.getTrueHeightGradient(data, x, z, 3) <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); + return (HeightMap.getTrueHeightGradient(data, x, z, 3) <= TConfig.c.MISC_TREES_GRADIENT_LIMIT); } public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock block) { @@ -595,7 +595,7 @@ public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock block) { } public boolean build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return false; } @@ -608,7 +608,7 @@ public boolean build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract } } - if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) { + if (TConfig.c.MISC_TREES_FORCE_LOGS) { this.trunkType = Material.getMaterial(StringUtils.replace(this.trunkType.toString(), "WOOD", "LOG")); } this.oriX = x; diff --git a/common/src/main/java/org/terraform/tree/FractalTypes.java b/common/src/main/java/org/terraform/tree/FractalTypes.java index 4930ebe3..3a212b23 100644 --- a/common/src/main/java/org/terraform/tree/FractalTypes.java +++ b/common/src/main/java/org/terraform/tree/FractalTypes.java @@ -21,7 +21,7 @@ public enum Tree { .setInitialBranchRadius(1.6f) .setMinBranchHorizontalComponent(0.7) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f + * (1f - branchRatio / 1.7f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> @@ -37,7 +37,7 @@ public enum Tree { new NewFractalTreeBuilder().setOriginalTrunkLength(18) .setInitialBranchRadius(2f) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f + * (1f - branchRatio / 2f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> @@ -55,7 +55,7 @@ public enum Tree { .setMaxDepth(2) .setMinBranchHorizontalComponent(0.7) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f + * (1f - branchRatio / 1.5f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> @@ -74,7 +74,7 @@ public enum Tree { .setCrownBranches(3) .setInitialBranchRadius(0.8f) .setNoisePriority(0.05f) - .setFirstEnd(1.0f) + .setFirstEnd(1f) .setMinBranchHorizontalComponent(1.2) .setMaxBranchHorizontalComponent(2) .setMaxInitialNormalDelta(0) @@ -100,7 +100,7 @@ public enum Tree { .setCrownBranches(3) .setInitialBranchRadius(0.8f) .setNoisePriority(0.05f) - .setFirstEnd(1.0f) + .setFirstEnd(1f) .setMinBranchHorizontalComponent(1.2) .setMaxBranchHorizontalComponent(2) .setMaxInitialNormalDelta(0) @@ -121,7 +121,7 @@ public enum Tree { Material.AZALEA_LEAVES, Material.FLOWERING_AZALEA_LEAVES ))), - TAIGA_BIG(new NewFractalTreeBuilder().setFirstEnd(1.0f) + TAIGA_BIG(new NewFractalTreeBuilder().setFirstEnd(1f) .setTreeRootThreshold(2) .setTreeRootMultiplier(1.3f) .setBranchMaterial(Material.SPRUCE_LOG) @@ -226,7 +226,7 @@ public enum Tree { .setMaxDepth(4) .setInitialBranchRadius(2f) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f + * (1f - branchRatio / 2f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> @@ -263,7 +263,7 @@ public enum Tree { .setMaxBranchHorizontalComponent(0.9f) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f - branchRatio / 2f)) + * (1f - branchRatio / 2f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> currentBranchLength - 1) @@ -287,7 +287,7 @@ public enum Tree { .setMaxBranchHorizontalComponent(1.2f) .setGetBranchWidth((initialBranchWidth, branchRatio) -> initialBranchWidth - * (1.0f - branchRatio / 3f)) + * (1f - branchRatio / 3f)) .setBranchDecrement((currentBranchLength, totalTreeHeight) -> currentBranchLength - 0.5f) diff --git a/common/src/main/java/org/terraform/tree/MushroomBuilder.java b/common/src/main/java/org/terraform/tree/MushroomBuilder.java index e726452c..2fb78be1 100644 --- a/common/src/main/java/org/terraform/tree/MushroomBuilder.java +++ b/common/src/main/java/org/terraform/tree/MushroomBuilder.java @@ -7,7 +7,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.Vector2f; @@ -232,11 +232,11 @@ private void spawnSphericalCap(int seed, } public void build(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.areTallMushroomsEnabled()) { + if (!TConfig.areTallMushroomsEnabled()) { return; } - if (TConfigOption.DEVSTUFF_VANILLA_MUSHROOMS.getBoolean()) { + if (TConfig.c.DEVSTUFF_VANILLA_MUSHROOMS) { String schemName; if (this.type.toString().contains("RED")) { schemName = VanillaMushroomBuilder.RED_MUSHROOM_CAP; diff --git a/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java b/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java index 05e873ac..1334e81b 100644 --- a/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java +++ b/common/src/main/java/org/terraform/tree/NewFractalTreeBuilder.java @@ -7,7 +7,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; import org.terraform.utils.noise.FastNoise; @@ -67,8 +67,8 @@ public class NewFractalTreeBuilder implements Cloneable { * each recursion. */ private BiFunction getBranchWidth = (initialBranchWidth, branchRatio) -> initialBranchWidth * ( - 1.0f - - branchRatio / 2.0f); + 1f + - branchRatio / 2f); private Material branchMaterial = Material.OAK_LOG; private Material rootMaterial = Material.OAK_WOOD; @@ -78,7 +78,7 @@ public class NewFractalTreeBuilder implements Cloneable { public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return false; } @@ -136,7 +136,7 @@ public boolean build(@NotNull TerraformWorld tw, @NotNull SimpleBlock base) boolean checkGradient(PopulatorDataAbstract data, int x, int z) { return !checkGradient || (HeightMap.getTrueHeightGradient(data, x, z, 3) - <= TConfigOption.MISC_TREES_GRADIENT_LIMIT.getDouble()); + <= TConfig.c.MISC_TREES_GRADIENT_LIMIT); } public @NotNull NewFractalTreeBuilder setCheckGradient(boolean checkGradient) @@ -269,7 +269,7 @@ void branch(TerraformWorld tw, oriY, displacementTheta, branchDecrement.apply(length, (float) (lastOperatedCentre.getY() - oriY)), - 1.0f, + 1f, depth + 1, currentWidth, 0 @@ -293,7 +293,7 @@ void branch(TerraformWorld tw, oriY, displacementTheta, branchDecrement.apply(length, (float) (lastOperatedCentre.getY() - oriY)), - 1.0f, + 1f, depth + 1, currentWidth, 0 diff --git a/common/src/main/java/org/terraform/tree/SaplingOverrider.java b/common/src/main/java/org/terraform/tree/SaplingOverrider.java index a56d4cdf..49ca9224 100644 --- a/common/src/main/java/org/terraform/tree/SaplingOverrider.java +++ b/common/src/main/java/org/terraform/tree/SaplingOverrider.java @@ -12,7 +12,7 @@ import org.terraform.coregen.populatordata.PopulatorDataPostGen; import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.version.OneTwentyBlockHandler; import java.util.List; @@ -24,7 +24,7 @@ public class SaplingOverrider implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTreeGrow(@NotNull StructureGrowEvent event) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } @@ -68,7 +68,7 @@ public void onTreeGrow(@NotNull StructureGrowEvent event) { break; case JUNGLE_LEAVES: - if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() && isLarge) { + if (TConfig.c.MISC_SAPLING_CUSTOM_TREES_BIGTREES && isLarge) { new FractalTreeBuilder(FractalTypes.Tree.JUNGLE_BIG).skipGradientCheck().build(tw, data, x, y, z); } else { @@ -83,7 +83,7 @@ public void onTreeGrow(@NotNull StructureGrowEvent event) { ); break; case SPRUCE_LEAVES: - if (TConfigOption.MISC_SAPLING_CUSTOM_TREES_BIGTREES.getBoolean() && isLarge) { + if (TConfig.c.MISC_SAPLING_CUSTOM_TREES_BIGTREES && isLarge) { FractalTypes.Tree.TAIGA_BIG.build(tw, new SimpleBlock(data, x, y, z), (nt -> nt.setCheckGradient(false)) diff --git a/common/src/main/java/org/terraform/tree/TreeDB.java b/common/src/main/java/org/terraform/tree/TreeDB.java index f6b72985..34686d01 100644 --- a/common/src/main/java/org/terraform/tree/TreeDB.java +++ b/common/src/main/java/org/terraform/tree/TreeDB.java @@ -8,7 +8,7 @@ import org.terraform.data.SimpleBlock; import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.BlockUtils; import org.terraform.utils.GenUtils; @@ -33,7 +33,7 @@ public static void spawnAzalea(@NotNull Random random, int y, int z) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } @@ -66,7 +66,7 @@ public static void spawnCoconutTree(@NotNull TerraformWorld tw, int y, int z) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } @@ -80,7 +80,7 @@ public static void spawnCoconutTree(@NotNull TerraformWorld tw, // Spawn the base Material log = Material.JUNGLE_WOOD; - if (TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean()) { + if (TConfig.c.MISC_TREES_FORCE_LOGS) { log = Material.JUNGLE_LOG; } for (BlockFace face : BlockUtils.directBlockFaces) { @@ -96,7 +96,7 @@ public static void spawnSmallJungleTree(boolean skipGradientCheck, int y, int z) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } @@ -137,7 +137,7 @@ public static void spawnRandomGiantCoral(@NotNull TerraformWorld tw, * Roots will extend at least a little above sea level */ public static void spawnBreathingRoots(@NotNull TerraformWorld tw, @NotNull SimpleBlock centre, Material type) { - if (!TConfigOption.areTreesEnabled()) { + if (!TConfig.areTreesEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java b/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java index 746776dc..f76e9242 100644 --- a/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java +++ b/common/src/main/java/org/terraform/tree/VanillaMushroomBuilder.java @@ -7,7 +7,7 @@ import org.terraform.data.TerraformWorld; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.schematic.TerraSchematic; import org.terraform.utils.GenUtils; @@ -27,7 +27,7 @@ public static void buildVanillaMushroom(@NotNull TerraformWorld tw, int z, String capSchematic) { - if (!TConfigOption.areTallMushroomsEnabled()) { + if (!TConfig.areTallMushroomsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/utils/BlockUtils.java b/common/src/main/java/org/terraform/utils/BlockUtils.java index 5f8ce8dc..781086f2 100644 --- a/common/src/main/java/org/terraform/utils/BlockUtils.java +++ b/common/src/main/java/org/terraform/utils/BlockUtils.java @@ -15,7 +15,7 @@ import org.terraform.data.SimpleChunkLocation; import org.terraform.data.Wall; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.small_items.PlantBuilder; import org.terraform.utils.blockdata.StairBuilder; import org.terraform.utils.blockdata.fixers.v1_16_R1_BlockDataFixer; @@ -626,7 +626,7 @@ public static void horizontalGlazedTerracotta(@NotNull PopulatorDataAbstract dat } public static void setVines(@NotNull PopulatorDataAbstract data, int x, int y, int z, int maxLength) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -685,7 +685,7 @@ public static boolean isDirtLike(@NotNull Material mat) { } public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -698,7 +698,7 @@ public static void setPersistentLeaves(@NotNull PopulatorDataAbstract data, int z, @NotNull Material type) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -714,7 +714,7 @@ public static void setDoublePlant(@NotNull PopulatorDataAbstract data, int z, @NotNull Material doublePlant) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -789,7 +789,7 @@ public static void generateClayDeposit(int x, // CLAY DEPOSIT replaceCircularPatch( random.nextInt(9999), - TConfigOption.BIOME_CLAY_DEPOSIT_SIZE.getFloat(), + TConfig.c.BIOME_CLAY_DEPOSIT_SIZE, new SimpleBlock(data, x, y, z), Material.CLAY ); @@ -797,7 +797,7 @@ public static void generateClayDeposit(int x, } public static void vineUp(@NotNull SimpleBlock base, int maxLength) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -1594,11 +1594,11 @@ public static boolean isWet(@NotNull SimpleBlock target) { public static float yawFromBlockFace(@NotNull BlockFace face) { return switch (face) { - case EAST -> -90.0f; - case NORTH -> 180.0f; - case SOUTH -> 0.0f; - case WEST -> 90.0f; - default -> 180.0f; + case EAST -> -90f; + case NORTH -> 180f; + case SOUTH -> 0f; + case WEST -> 90f; + default -> 180f; }; } @@ -1626,7 +1626,7 @@ public static boolean isOre(Material mat) { } public static void placeCandle(@NotNull SimpleBlock block, int numCandles, boolean lit) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return; } @@ -1638,7 +1638,7 @@ public static void placeCandle(@NotNull SimpleBlock block, int numCandles, boole } public static void downLPointedDripstone(int height, @NotNull SimpleBlock base) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return; } @@ -1691,7 +1691,7 @@ public static Material stoneOrSlateWall(int y) } public static void upLPointedDripstone(int height, @NotNull SimpleBlock base) { - if (!TConfigOption.areDecorationsEnabled()) { + if (!TConfig.areDecorationsEnabled()) { return; } @@ -1751,7 +1751,7 @@ else if (realHeight >= 2) { } public static void downLCaveVines(int height, @NotNull SimpleBlock base) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/utils/CoralGenerator.java b/common/src/main/java/org/terraform/utils/CoralGenerator.java index 437f110d..ebeb4d9f 100644 --- a/common/src/main/java/org/terraform/utils/CoralGenerator.java +++ b/common/src/main/java/org/terraform/utils/CoralGenerator.java @@ -9,7 +9,7 @@ import org.terraform.coregen.bukkit.TerraformGenerator; import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.SimpleBlock; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Random; @@ -137,7 +137,7 @@ else if (GenUtils.chance(1, 5)) { * @param data refers to the block to replace with sea pickles */ public static void generateSeaPickles(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } @@ -156,7 +156,7 @@ public static void generateSeaPickles(@NotNull PopulatorDataAbstract data, int x * @param data refers to the block ABOVE the floor (lowest block of the kelp plant) */ public static void generateKelpGrowth(@NotNull PopulatorDataAbstract data, int x, int y, int z) { - if (!TConfigOption.arePlantsEnabled()) { + if (!TConfig.arePlantsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/utils/MazeSpawner.java b/common/src/main/java/org/terraform/utils/MazeSpawner.java index 113ba771..927f3b59 100644 --- a/common/src/main/java/org/terraform/utils/MazeSpawner.java +++ b/common/src/main/java/org/terraform/utils/MazeSpawner.java @@ -161,7 +161,7 @@ public void carveMaze(boolean carveInSolid, Material... materials) { // Carve Pathway if (wallllllllless.contains(dir)) { - for (int i = 0; i < Math.ceil(((float) this.mazePeriod) / 2.0f); i++) { + for (int i = 0; i < Math.ceil(((float) this.mazePeriod) / 2f); i++) { pathPopDatas.add(new PathPopulatorData(startPoint.getDown().get(), dir, mazePathWidth, false)); startPoint.Pillar(mazeHeight, rand, Material.CAVE_AIR); diff --git a/common/src/main/java/org/terraform/utils/StalactiteBuilder.java b/common/src/main/java/org/terraform/utils/StalactiteBuilder.java index b970d83d..18db6d01 100644 --- a/common/src/main/java/org/terraform/utils/StalactiteBuilder.java +++ b/common/src/main/java/org/terraform/utils/StalactiteBuilder.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.data.SimpleBlock; import org.terraform.data.Wall; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.ArrayDeque; import java.util.HashSet; @@ -25,7 +25,7 @@ public StalactiteBuilder(Material... wallType) { } public void build(@NotNull Random rand, @NotNull Wall w) { - if (TConfigOption.areDecorationsEnabled()) { + if (TConfig.areDecorationsEnabled()) { return; } diff --git a/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java b/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java index 7f19a1a6..421af85b 100644 --- a/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java +++ b/common/src/main/java/org/terraform/utils/bstats/TerraformGeneratorMetricsHandler.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; public class TerraformGeneratorMetricsHandler { @@ -13,13 +13,13 @@ public TerraformGeneratorMetricsHandler(@NotNull TerraformGeneratorPlugin plugin if (metrics.isEnabled()) { metrics.addCustomChart(new Metrics.SimplePie("onlyUseLogsNoWood", - () -> TConfigOption.MISC_TREES_FORCE_LOGS.getBoolean() + "" + () -> TConfig.c.MISC_TREES_FORCE_LOGS + "" )); metrics.addCustomChart(new Metrics.SimplePie("megaChunkNumBiomeSections", - () -> TConfigOption.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS.getInt() + "" + () -> TConfig.c.STRUCTURES_MEGACHUNK_NUMBIOMESECTIONS + "" )); metrics.addCustomChart(new Metrics.SimplePie("biomeSectionBitshifts", - () -> TConfigOption.BIOME_SECTION_BITSHIFTS.getInt() + "" + () -> TConfig.c.BIOME_SECTION_BITSHIFTS + "" )); TerraformGeneratorPlugin.logger.stdout("&abStats Metrics enabled."); } diff --git a/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java b/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java index 6b6b92a7..8469015a 100644 --- a/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java +++ b/common/src/main/java/org/terraform/watchdog/TfgWatchdogSuppressant.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.Nullable; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -21,7 +21,7 @@ public class TfgWatchdogSuppressant { Object watchdogThreadInstance = null; public TfgWatchdogSuppressant() { - if (TConfigOption.DEVSTUFF_SUPPRESS_WATCHDOG.getBoolean()) { + if (TConfig.c.DEVSTUFF_SUPPRESS_WATCHDOG) { try { TerraformGeneratorPlugin.logger.info("[NOTICE] TerraformGenerator will suppress the server's watchdog " + "while generating chunks to prevent unnecessary stacktrace warnings. Unless you specifically need the" diff --git a/common/src/main/resources/plugin.yml b/common/src/main/resources/plugin.yml index a9b733bb..e50b24f5 100644 --- a/common/src/main/resources/plugin.yml +++ b/common/src/main/resources/plugin.yml @@ -5,6 +5,7 @@ api-version: 1.18 description: World Generator main: org.terraform.main.TerraformGeneratorPlugin load: STARTUP +folia-supported: true commands: terraform: description: Main command diff --git a/implementation/v1_18_R2/build.gradle.kts b/implementation/v1_18_R2/build.gradle.kts index 02608136..4caeba07 100644 --- a/implementation/v1_18_R2/build.gradle.kts +++ b/implementation/v1_18_R2/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18.2-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java index bd2b73fa..4db5b2bd 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/NMSChunkGenerator.java @@ -27,7 +27,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -125,7 +125,7 @@ public WorldChunkManager e() { int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (structuregenerator == StructureGenerator.l) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -133,7 +133,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -145,7 +145,7 @@ else if (structuregenerator == StructureGenerator.d) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -159,7 +159,7 @@ else if (structuregenerator.getClass() tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java index 1772dd01..03b9edd9 100644 --- a/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java +++ b/implementation/v1_18_R2/src/main/java/org/terraform/v1_18_R2/PopulatorData.java @@ -27,7 +27,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.HashMap; @@ -213,7 +213,7 @@ public void addEntity(int rawX, int rawY, int rawZ, EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/implementation/v1_19_R3/build.gradle.kts b/implementation/v1_19_R3/build.gradle.kts index 2225ec5d..4aaf556a 100644 --- a/implementation/v1_19_R3/build.gradle.kts +++ b/implementation/v1_19_R3/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.19.4-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java index 739f0e14..b1bbdfd1 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/NMSChunkGenerator.java @@ -32,7 +32,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -101,7 +101,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -109,7 +109,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -121,7 +121,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -132,7 +132,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java index c2ccaba1..268ce07b 100644 --- a/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java +++ b/implementation/v1_19_R3/src/main/java/org/terraform/v1_19_R3/PopulatorData.java @@ -31,7 +31,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.HashMap; import java.util.Locale; @@ -209,7 +209,7 @@ public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/implementation/v1_20_R1/build.gradle.kts b/implementation/v1_20_R1/build.gradle.kts index 063912e9..5e6d13d9 100644 --- a/implementation/v1_20_R1/build.gradle.kts +++ b/implementation/v1_20_R1/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.20.1-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java index 81c9e661..8b155605 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/MapRenderWorldProviderBiome.java @@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock; import org.terraform.coregen.HeightMap; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Set; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // This will return river or plains depending on whether or not // the area is submerged. - return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + return HeightMap.getBlockHeight(tw, x, z) <= TConfig.c.HEIGHT_MAP_SEA_LEVEL ? river : plains; } } diff --git a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java index a14fa1b3..4a1197e5 100644 --- a/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java +++ b/implementation/v1_20_R1/src/main/java/org/terraform/v1_20_R1/NMSChunkGenerator.java @@ -32,7 +32,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -105,7 +105,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -113,7 +113,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -125,7 +125,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -136,7 +136,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_20_R2/build.gradle.kts b/implementation/v1_20_R2/build.gradle.kts index ce37b6e5..cb506855 100644 --- a/implementation/v1_20_R2/build.gradle.kts +++ b/implementation/v1_20_R2/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.20.2-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java index b7b5b69c..631670dc 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/MapRenderWorldProviderBiome.java @@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.v1_20_R2.block.CraftBiome; import org.terraform.coregen.HeightMap; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Set; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + return HeightMap.getBlockHeight(tw, x, z) <= TConfig.c.HEIGHT_MAP_SEA_LEVEL ? river : plains; } } diff --git a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java index 4243ec4d..9a27f11e 100644 --- a/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java +++ b/implementation/v1_20_R2/src/main/java/org/terraform/v1_20_R2/NMSChunkGenerator.java @@ -32,7 +32,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -105,7 +105,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -113,7 +113,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -125,7 +125,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -136,7 +136,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_20_R3/build.gradle.kts b/implementation/v1_20_R3/build.gradle.kts index eb0070f4..1af0ee19 100644 --- a/implementation/v1_20_R3/build.gradle.kts +++ b/implementation/v1_20_R3/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.20.3-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java index 5e565398..5fd7c2af 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/MapRenderWorldProviderBiome.java @@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.v1_20_R3.block.CraftBiome; import org.terraform.coregen.HeightMap; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Set; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + return HeightMap.getBlockHeight(tw, x, z) <= TConfig.c.HEIGHT_MAP_SEA_LEVEL ? river : plains; } } diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java index 50cbaac4..e05d7ab0 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/NMSChunkGenerator.java @@ -32,7 +32,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -105,7 +105,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -113,7 +113,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -125,7 +125,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -136,7 +136,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java index bb0b591d..f55edbd6 100644 --- a/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java +++ b/implementation/v1_20_R3/src/main/java/org/terraform/v1_20_R3/PopulatorData.java @@ -25,7 +25,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.HashMap; import java.util.Locale; @@ -207,7 +207,7 @@ public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/implementation/v1_20_R4/build.gradle.kts b/implementation/v1_20_R4/build.gradle.kts index a8b6e087..7cd2a5e9 100644 --- a/implementation/v1_20_R4/build.gradle.kts +++ b/implementation/v1_20_R4/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.20.5-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_21 diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java index 61de4a75..f608e524 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/MapRenderWorldProviderBiome.java @@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.v1_20_R4.block.CraftBiome; import org.terraform.coregen.HeightMap; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Set; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + return HeightMap.getBlockHeight(tw, x, z) <= TConfig.c.HEIGHT_MAP_SEA_LEVEL ? river : plains; } } diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java index f2ac3cf2..3c64c8ba 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/NMSChunkGenerator.java @@ -33,7 +33,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.StructureLocator; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -111,7 +111,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -119,7 +119,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -131,7 +131,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -142,7 +142,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java index 81468c0e..06d14d7c 100644 --- a/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java +++ b/implementation/v1_20_R4/src/main/java/org/terraform/v1_20_R4/PopulatorData.java @@ -24,7 +24,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.HashMap; @@ -204,7 +204,7 @@ public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } diff --git a/implementation/v1_21_R1/build.gradle.kts b/implementation/v1_21_R1/build.gradle.kts index 4c01359b..a923c7ed 100644 --- a/implementation/v1_21_R1/build.gradle.kts +++ b/implementation/v1_21_R1/build.gradle.kts @@ -2,6 +2,7 @@ dependencies { implementation(project(":common")) compileOnly(group = "org.spigotmc", name = "spigot", version = "1.21-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:20.1.0") + compileOnly("com.github.AvarionMC:yaml:1.1.1") } java { sourceCompatibility = JavaVersion.VERSION_21 diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java index dc73b094..3d636573 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/MapRenderWorldProviderBiome.java @@ -10,7 +10,7 @@ import org.bukkit.craftbukkit.v1_21_R1.block.CraftBiome; import org.terraform.coregen.HeightMap; import org.terraform.data.TerraformWorld; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import java.util.Set; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public Holder getNoiseBiome(int x, int y, int z, Sampler arg3) { // This will return river or plains depending on whether // the area is submerged. - return HeightMap.getBlockHeight(tw, x, z) <= TConfigOption.HEIGHT_MAP_SEA_LEVEL.getInt() ? river : plains; + return HeightMap.getBlockHeight(tw, x, z) <= TConfig.c.HEIGHT_MAP_SEA_LEVEL ? river : plains; } } diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java index 9c3ecdae..61cd735f 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/NMSChunkGenerator.java @@ -29,7 +29,7 @@ import org.terraform.data.MegaChunk; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.structure.*; import org.terraform.structure.monument.MonumentPopulator; import org.terraform.structure.pillager.mansion.MansionPopulator; @@ -133,7 +133,7 @@ public Pair> a(WorldServer worldserver, int[] coords = new StrongholdPopulator().getNearestFeature(tw, pX, pZ); return new Pair<>(new BlockPosition(coords[0], 20, coords[1]), holder); } - else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { + else if (!TConfig.c.DEVSTUFF_VANILLA_LOCATE_DISABLE) { if (holder.a().getClass() == OceanMonumentStructure.class) { // Monument int[] coords = StructureLocator.locateSingleMegaChunkStructure( @@ -141,7 +141,7 @@ else if (!TConfigOption.DEVSTUFF_VANILLA_LOCATE_DISABLE.getBoolean()) { pX, pZ, new MonumentPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -153,7 +153,7 @@ else if (holder.a().getClass() == WoodlandMansionStructure.class) { // Mansion pX, pZ, new MansionPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -168,7 +168,7 @@ else if (holder.a() instanceof JigsawStructure pX, pZ, new TrialChamberPopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); return new Pair<>(new BlockPosition(coords[0], 50, coords[1]), holder); @@ -179,7 +179,7 @@ else if (holder.a().getClass() == BuriedTreasureStructure.class) { tw, new MegaChunk(pX, 0, pZ), new BuriedTreasurePopulator(), - TConfigOption.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS.getInt() + TConfig.c.DEVSTUFF_VANILLA_LOCATE_TIMEOUTMILLIS ); if (coords == null) { return null; diff --git a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java index 2a1fb4f2..b3688f42 100644 --- a/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java +++ b/implementation/v1_21_R1/src/main/java/org/terraform/v1_21_R1/PopulatorData.java @@ -24,7 +24,7 @@ import org.terraform.coregen.populatordata.PopulatorDataAbstract; import org.terraform.data.TerraformWorld; import org.terraform.main.TerraformGeneratorPlugin; -import org.terraform.main.config.TConfigOption; +import org.terraform.main.config.TConfig; import org.terraform.utils.GenUtils; import java.util.HashMap; @@ -204,7 +204,7 @@ public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) { @Override public void setSpawner(int rawX, int rawY, int rawZ, EntityType type) { - if (!TConfigOption.areAnimalsEnabled()) { + if (!TConfig.areAnimalsEnabled()) { return; } From bae257a8f82c529bec54449b0af84400cbc181a7 Mon Sep 17 00:00:00 2001 From: Steven Van Ingelgem Date: Sun, 1 Sep 2024 09:11:55 +0200 Subject: [PATCH 3/4] Remove folia flag as I didn't fully test it. (#136) --- common/src/main/resources/plugin.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/resources/plugin.yml b/common/src/main/resources/plugin.yml index e50b24f5..a9b733bb 100644 --- a/common/src/main/resources/plugin.yml +++ b/common/src/main/resources/plugin.yml @@ -5,7 +5,6 @@ api-version: 1.18 description: World Generator main: org.terraform.main.TerraformGeneratorPlugin load: STARTUP -folia-supported: true commands: terraform: description: Main command From cca1daf99f87de2b40db3c1d52bd9a294ca008d3 Mon Sep 17 00:00:00 2001 From: Steven Van Ingelgem Date: Wed, 4 Sep 2024 14:29:57 +0200 Subject: [PATCH 4/4] I saw bees didn't behave. Bees are animals. When animals are disabled, they still popped up. So bad bad bees! (#138) Fixed that. --- .../coregen/populatordata/PopulatorDataSpigotAPI.java | 2 ++ .../main/java/org/terraform/utils/version/BeeHiveSpawner.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java index 6f4ee74d..19370ac3 100644 --- a/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java +++ b/common/src/main/java/org/terraform/coregen/populatordata/PopulatorDataSpigotAPI.java @@ -130,6 +130,8 @@ public TerraformWorld getTerraformWorld() { @Override public void setBeehiveWithBee(int rawX, int rawY, int rawZ) { + if (!TConfig.areAnimalsEnabled()) return; + if (!lr.isInRegion(rawX, rawY, rawZ)) { return; // just forget it } diff --git a/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java b/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java index 0fc3342b..70a6333b 100644 --- a/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java +++ b/common/src/main/java/org/terraform/utils/version/BeeHiveSpawner.java @@ -6,10 +6,13 @@ import org.terraform.coregen.populatordata.IPopulatorDataBeehiveEditor; import org.terraform.data.SimpleBlock; import org.terraform.main.TerraformGeneratorPlugin; +import org.terraform.main.config.TConfig; public class BeeHiveSpawner { public static void spawnFullBeeNest(@NotNull SimpleBlock block) { + if (!TConfig.areAnimalsEnabled()) return; + try { if (block.getPopData() instanceof IPopulatorDataBeehiveEditor ipopdata) { ipopdata.setBeehiveWithBee(block.getX(), block.getY(), block.getZ());