From e178f935aa9a7f4ead9207b4a3118bacb43e9c6d Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Sun, 25 Jul 2021 13:08:40 +0200 Subject: [PATCH] Rewrite of the render-engine and big performance improvements - changed most immutable vectors with mutable ones - dropped 1.12.2 support - improved caching and block/chunk access - much more smaller tweaks --- .../bluemap/common/BlueMapService.java | 13 +- .../common/plugin/commands/Commands.java | 27 +- .../bluemap/core/config/BiomeConfig.java | 85 - .../bluemap/core/config/BlockIdConfig.java | 252 - .../core/config/BlockPropertiesConfig.java | 141 - .../bluemap/core/config/ConfigManager.java | 119 +- .../bluemap/core/debug/OneBlockWorld.java | 51 +- .../core/map/hires/BlockModelView.java | 24 + .../core/map/hires/HiresModelRenderer.java | 28 +- .../bluemap/core/map/hires/HiresTileMeta.java | 28 +- .../blockmodel/BlockStateModelFactory.java | 32 +- .../hires/blockmodel/LiquidModelBuilder.java | 63 +- .../blockmodel/ResourceModelBuilder.java | 71 +- .../bluemap/core/mca/ChunkAnvil112.java | 233 - .../bluemap/core/mca/ChunkAnvil113.java | 18 +- .../bluemap/core/mca/ChunkAnvil115.java | 20 +- .../bluemap/core/mca/ChunkAnvil116.java | 18 +- .../bluemap/core/mca/EmptyChunk.java | 4 +- .../bluemap/core/mca/MCAChunk.java | 12 +- .../bluemap/core/mca/MCAWorld.java | 184 +- .../core/mca/extensions/ConnectExtension.java | 57 - .../ConnectSameOrFullBlockExtension.java | 41 - .../core/mca/extensions/DoorExtension.java | 99 - .../mca/extensions/DoubleChestExtension.java | 61 - .../mca/extensions/DoublePlantExtension.java | 71 - .../core/mca/extensions/FireExtension.java | 67 - .../extensions/GlassPaneConnectExtension.java | 58 - .../NetherFenceConnectExtension.java | 43 - .../mca/extensions/RedstoneExtension.java | 96 - .../core/mca/extensions/SnowyExtension.java | 77 - .../mca/extensions/StairShapeExtension.java | 118 - .../mca/extensions/WallConnectExtension.java | 65 - .../WoodenFenceConnectExtension.java | 64 - .../core/mca/mapping/BlockIdMapper.java | 35 - .../mca/mapping/BlockPropertiesMapper.java | 35 - .../bluecolored/bluemap/core/model/Face.java | 34 +- .../BiomeConfig.java} | 49 +- .../BlockColorCalculatorFactory.java | 127 +- .../resourcepack/BlockPropertiesConfig.java | 82 + .../BlockStateMapping.java | 8 +- .../core/resourcepack/ResourcePack.java | 219 +- .../{ => blockmodel}/BlockModelResource.java | 23 +- .../{ => blockmodel}/ModelType.java | 2 +- .../TransformedBlockModelResource.java | 2 +- .../{ => blockstate}/BlockStateResource.java | 75 +- .../blockstate/Conditional.java} | 29 +- .../{ => blockstate}/PropertyCondition.java | 21 +- .../core/resourcepack/blockstate/Variant.java | 70 + .../blockstate/Weighted.java} | 25 +- .../resourcepack/{ => texture}/Texture.java | 2 +- .../{ => texture}/TextureGallery.java | 23 +- .../bluemap/core/util/ArrayPool.java | 59 - .../bluemap/core/util/MathUtils.java | 1 + .../bluemap/core/util/Tristate.java | 75 +- .../bluemap/core/util/math/Color.java | 24 + .../bluecolored/bluemap/core/world/Block.java | 171 +- .../bluemap/core/world/BlockNeighborhood.java | 90 + .../bluemap/core/world/BlockProperties.java | 117 +- .../bluemap/core/world/BlockState.java | 116 +- .../bluecolored/bluemap/core/world/Chunk.java | 2 +- .../bluemap/core/world/ResourcePackBlock.java | 63 +- .../bluemap/core/world/SlicedWorld.java | 22 - .../bluecolored/bluemap/core/world/World.java | 23 +- .../assets/bluemap/blockstates/missing.json | 5 - .../assets/bluemap/models/block/missing.json | 6 - .../bluemap/textures/blocks/missing.png | Bin 2826 -> 0 bytes .../assets/minecraft/blockstates/barrier.json | 5 - .../minecraft/blockstates/black_bed.json | 12 - .../minecraft/blockstates/blue_bed.json | 12 - .../minecraft/blockstates/brown_bed.json | 12 - .../minecraft/blockstates/bubble_column.json | 5 - .../assets/minecraft/blockstates/chest.json | 13 - .../minecraft/blockstates/cyan_bed.json | 12 - .../minecraft/blockstates/ender_chest.json | 8 - .../minecraft/blockstates/gray_bed.json | 12 - .../minecraft/blockstates/green_bed.json | 12 - .../assets/minecraft/blockstates/lava.json | 5 - .../minecraft/blockstates/light_blue_bed.json | 12 - .../minecraft/blockstates/light_gray_bed.json | 12 - .../minecraft/blockstates/lime_bed.json | 12 - .../minecraft/blockstates/magenta_bed.json | 12 - .../minecraft/blockstates/oak_sign.json | 20 - .../minecraft/blockstates/oak_wall_sign.json | 8 - .../minecraft/blockstates/orange_bed.json | 12 - .../minecraft/blockstates/pink_bed.json | 12 - .../minecraft/blockstates/purple_bed.json | 12 - .../assets/minecraft/blockstates/red_bed.json | 12 - .../minecraft/blockstates/trapped_chest.json | 13 - .../assets/minecraft/blockstates/water.json | 5 - .../minecraft/blockstates/white_bed.json | 12 - .../minecraft/blockstates/yellow_bed.json | 12 - .../minecraft/models/block/barrier.json | 1 - .../minecraft/models/block/bed/bed_foot.json | 39 - .../minecraft/models/block/bed/bed_head.json | 39 - .../models/block/bed/black_foot.json | 6 - .../models/block/bed/black_head.json | 6 - .../minecraft/models/block/bed/blue_foot.json | 6 - .../minecraft/models/block/bed/blue_head.json | 6 - .../models/block/bed/brown_foot.json | 6 - .../models/block/bed/brown_head.json | 6 - .../minecraft/models/block/bed/cyan_foot.json | 6 - .../minecraft/models/block/bed/cyan_head.json | 6 - .../minecraft/models/block/bed/gray_foot.json | 6 - .../minecraft/models/block/bed/gray_head.json | 6 - .../models/block/bed/green_foot.json | 6 - .../models/block/bed/green_head.json | 6 - .../models/block/bed/light_blue_foot.json | 6 - .../models/block/bed/light_blue_head.json | 6 - .../models/block/bed/light_gray_foot.json | 6 - .../models/block/bed/light_gray_head.json | 6 - .../minecraft/models/block/bed/lime_foot.json | 6 - .../minecraft/models/block/bed/lime_head.json | 6 - .../models/block/bed/magenta_foot.json | 6 - .../models/block/bed/magenta_head.json | 6 - .../models/block/bed/orange_foot.json | 6 - .../models/block/bed/orange_head.json | 6 - .../minecraft/models/block/bed/pink_foot.json | 6 - .../minecraft/models/block/bed/pink_head.json | 6 - .../models/block/bed/purple_foot.json | 6 - .../models/block/bed/purple_head.json | 6 - .../minecraft/models/block/bed/red_foot.json | 6 - .../minecraft/models/block/bed/red_head.json | 6 - .../models/block/bed/white_foot.json | 6 - .../models/block/bed/white_head.json | 6 - .../models/block/bed/yellow_foot.json | 6 - .../models/block/bed/yellow_head.json | 6 - .../minecraft/models/block/bubble_column.json | 2 - .../minecraft/models/block/chest/chest.json | 40 - .../models/block/chest/chest_double.json | 40 - .../minecraft/models/block/chest/ender.json | 6 - .../minecraft/models/block/chest/left.json | 1 - .../minecraft/models/block/chest/normal.json | 6 - .../models/block/chest/normal_double.json | 6 - .../minecraft/models/block/chest/trapped.json | 6 - .../models/block/chest/trapped_double.json | 6 - .../assets/minecraft/models/block/lava.json | 8 - .../minecraft/models/block/sign/oak.json | 6 - .../minecraft/models/block/sign/sign.json | 28 - .../minecraft/models/block/sign/wall_oak.json | 6 - .../models/block/sign/wall_sign.json | 16 - .../assets/minecraft/models/block/water.json | 8 - .../mc1_13/assets/minecraft}/biomes.json | 0 .../mc1_13/assets/minecraft}/blockColors.json | 0 .../assets/minecraft/blockProperties.json | 52 + .../mc1_15/assets/minecraft}/biomes.json | 0 .../mc1_15/assets/minecraft}/blockColors.json | 0 .../assets/minecraft/blockProperties.json | 52 + .../mc1_16/assets/minecraft}/biomes.json | 0 .../mc1_16/assets/minecraft}/blockColors.json | 0 .../assets/minecraft/blockProperties.json | 52 + .../bluemap/mc1_12/blockColors.json | 14 - .../bluecolored/bluemap/mc1_12/blockIds.json | 1537 ------ .../bluemap/mc1_12/blockProperties.json | 2262 --------- .../bluecolored/bluemap/mc1_13/blockIds.json | 1537 ------ .../bluemap/mc1_13/blockProperties.json | 4402 ----------------- .../bluecolored/bluemap/mc1_15/blockIds.json | 1537 ------ .../bluemap/mc1_15/blockProperties.json | 4402 ----------------- .../de/bluecolored/bluemap/mc1_16/biomes.json | 470 -- .../bluecolored/bluemap/mc1_16/blockIds.json | 1537 ------ .../bluemap/mc1_16/blockProperties.json | 4402 ----------------- .../bluemap/core/world/BlockStateTest.java | 38 +- gradle.properties | 2 +- implementations/sponge-7.2.0/build.gradle | 46 - .../bluemap/sponge/SpongeCommandSource.java | 78 - .../bluemap/sponge/SpongeCommands.java | 161 - .../bluemap/sponge/SpongePlayer.java | 143 - .../bluemap/sponge/SpongePlugin.java | 274 - .../de/bluecolored/bluemap/core-defaults.conf | 4 - .../de/bluecolored/bluemap/core.conf | 24 - .../bluecolored/bluemap/plugin-defaults.conf | 6 - .../de/bluecolored/bluemap/plugin.conf | 32 - .../bluecolored/bluemap/render-defaults.conf | 4 - .../de/bluecolored/bluemap/render.conf | 130 - .../bluemap/webserver-defaults.conf | 4 - .../de/bluecolored/bluemap/webserver.conf | 29 - .../src/main/resources/mcmod.info | 18 - .../bluemap/sponge8/SpongePlugin.java | 2 +- settings.gradle | 2 - 178 files changed, 1317 insertions(+), 26641 deletions(-) delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BiomeConfig.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockPropertiesConfig.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectSameOrFullBlockExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoorExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoubleChestExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoublePlantExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/FireExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/GlassPaneConnectExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/NetherFenceConnectExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/RedstoneExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/SnowyExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/StairShapeExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WallConnectExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WoodenFenceConnectExtension.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockPropertiesMapper.java rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/{mca/mapping/BiomeMapper.java => resourcepack/BiomeConfig.java} (55%) create mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockPropertiesConfig.java rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/{config => resourcepack}/BlockStateMapping.java (97%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => blockmodel}/BlockModelResource.java (95%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => blockmodel}/ModelType.java (95%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => blockmodel}/TransformedBlockModelResource.java (97%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => blockstate}/BlockStateResource.java (87%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/{mca/extensions/TripwireConnectExtension.java => resourcepack/blockstate/Conditional.java} (74%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => blockstate}/PropertyCondition.java (90%) create mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Variant.java rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/{mca/extensions/BlockStateExtension.java => resourcepack/blockstate/Weighted.java} (77%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => texture}/Texture.java (98%) rename BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/{ => texture}/TextureGallery.java (92%) delete mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ArrayPool.java rename implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/Slf4jLogger.java => BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Tristate.java (57%) create mode 100644 BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockNeighborhood.java rename implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/EventForwarder.java => BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/ResourcePackBlock.java (54%) delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/blockstates/missing.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/models/block/missing.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/textures/blocks/missing.png delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/barrier.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/black_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/blue_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/brown_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/bubble_column.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/chest.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/cyan_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/ender_chest.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/gray_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/green_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/lava.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/light_blue_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/light_gray_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/lime_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/magenta_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/oak_sign.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/oak_wall_sign.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/orange_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/pink_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/purple_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/red_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/trapped_chest.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/water.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/white_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/blockstates/yellow_bed.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/barrier.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/bed_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/bed_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/black_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/black_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/blue_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/blue_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/brown_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/brown_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/cyan_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/cyan_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/gray_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/gray_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/green_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/green_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/light_blue_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/light_blue_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/light_gray_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/light_gray_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/lime_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/lime_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/magenta_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/magenta_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/orange_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/orange_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/pink_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/pink_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/purple_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/purple_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/red_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/red_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/white_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/white_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/yellow_foot.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bed/yellow_head.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/bubble_column.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/chest.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/chest_double.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/ender.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/left.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/normal.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/normal_double.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/trapped.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/chest/trapped_double.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/lava.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/sign/oak.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/sign/sign.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/sign/wall_oak.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/sign/wall_sign.json delete mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_12/assets/minecraft/models/block/water.json rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_12 => resourceExtensions/mc1_13/assets/minecraft}/biomes.json (100%) rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_13 => resourceExtensions/mc1_13/assets/minecraft}/blockColors.json (100%) create mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_13/assets/minecraft/blockProperties.json rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_13 => resourceExtensions/mc1_15/assets/minecraft}/biomes.json (100%) rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_15 => resourceExtensions/mc1_15/assets/minecraft}/blockColors.json (100%) create mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_15/assets/minecraft/blockProperties.json rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_15 => resourceExtensions/mc1_16/assets/minecraft}/biomes.json (100%) rename BlueMapCore/src/main/{resources/de/bluecolored/bluemap/mc1_16 => resourceExtensions/mc1_16/assets/minecraft}/blockColors.json (100%) create mode 100644 BlueMapCore/src/main/resourceExtensions/mc1_16/assets/minecraft/blockProperties.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_12/blockColors.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_12/blockIds.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_12/blockProperties.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_13/blockIds.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_13/blockProperties.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_15/blockIds.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_15/blockProperties.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_16/biomes.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_16/blockIds.json delete mode 100644 BlueMapCore/src/main/resources/de/bluecolored/bluemap/mc1_16/blockProperties.json delete mode 100644 implementations/sponge-7.2.0/build.gradle delete mode 100644 implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommandSource.java delete mode 100644 implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommands.java delete mode 100644 implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java delete mode 100644 implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core-defaults.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin-defaults.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render-defaults.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver-defaults.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver.conf delete mode 100644 implementations/sponge-7.2.0/src/main/resources/mcmod.info diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java index 43af4672..6fc63b29 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java @@ -30,7 +30,6 @@ import de.bluecolored.bluemap.common.web.WebSettings; import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.config.*; import de.bluecolored.bluemap.core.debug.DebugDump; -import de.bluecolored.bluemap.core.debug.OneBlockWorld; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.BmMap; import de.bluecolored.bluemap.core.map.hires.RenderSettings; @@ -136,9 +135,6 @@ public class BlueMapService { maps = new HashMap<>(); worlds = new HashMap<>(); - ConfigManager configManager = getConfigManager(); - configManager.loadResourceConfigs(configFolder, getResourcePack()); - for (MapConfig mapConfig : getRenderConfig().getMapConfigs()) { String id = mapConfig.getId(); String name = mapConfig.getName(); @@ -160,7 +156,7 @@ public class BlueMapService { World world = worlds.get(worldUUID); if (world == null) { try { - world = MCAWorld.load(worldFolder.toPath(), worldUUID, minecraftVersion, configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig(), worldNameProvider.apply(worldUUID), mapConfig.isIgnoreMissingLightData()); + world = MCAWorld.load(worldFolder.toPath(), worldUUID, worldNameProvider.apply(worldUUID), mapConfig.isIgnoreMissingLightData()); worlds.put(worldUUID, world); } catch (MissingResourcesException e) { throw e; // rethrow this to stop loading and display resource-missing message @@ -230,7 +226,10 @@ public class BlueMapService { if (resourceExtensionsFile.exists()) FileUtils.forceDelete(resourceExtensionsFile); FileUtils.forceMkdirParent(resourceExtensionsFile); - FileUtils.copyURLToFile(Plugin.class.getResource("/de/bluecolored/bluemap/" + minecraftVersion.getResource().getResourcePrefix() + "/resourceExtensions.zip"), resourceExtensionsFile, 10000, 10000); + URL resourceExtensionsUrl = Objects.requireNonNull( + Plugin.class.getResource("/de/bluecolored/bluemap/" + minecraftVersion.getResource().getResourcePrefix() + "/resourceExtensions.zip") + ); + FileUtils.copyURLToFile(resourceExtensionsUrl, resourceExtensionsFile, 10000, 10000); //find more resource packs File[] resourcePacks = resourcePackFolder.listFiles(); @@ -243,7 +242,7 @@ public class BlueMapService { resources.add(resourceExtensionsFile); try { - resourcePack = new ResourcePack(minecraftVersion); + resourcePack = new ResourcePack(); if (textureExportFile.exists()) resourcePack.loadTextureFile(textureExportFile); resourcePack.load(resources); resourcePack.saveTextureFile(textureExportFile); diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java index 851ee753..36b60797 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java @@ -59,10 +59,8 @@ import de.bluecolored.bluemap.core.debug.StateDumper; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.BmMap; import de.bluecolored.bluemap.core.map.MapRenderState; -import de.bluecolored.bluemap.core.mca.ChunkAnvil112; import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; import de.bluecolored.bluemap.core.world.Block; -import de.bluecolored.bluemap.core.world.Chunk; import de.bluecolored.bluemap.core.world.World; import java.io.IOException; @@ -528,24 +526,21 @@ public class Commands { new Thread(() -> { // collect and output debug info Vector3i blockPos = position.floor().toInt(); - Block block = world.getBlock(blockPos); - Block blockBelow = world.getBlock(blockPos.add(0, -1, 0)); + Block block = new Block<>(world, blockPos.getX(), blockPos.getY(), blockPos.getZ()); + Block blockBelow = new Block<>(null, 0, 0, 0).copy(block, 0, -1, 0); - String blockIdMeta = ""; - String blockBelowIdMeta = ""; + // populate lazy-loaded values + block.getBlockState(); + block.getBiomeId(); + block.getLightData(); - Vector2i chunkPos = world.getChunkGrid().getCell(blockPos.toVector2(true)); - Chunk chunk = world.getChunk(chunkPos.getX(), chunkPos.getY()); + blockBelow.getBlockState(); + blockBelow.getBiomeId(); + blockBelow.getLightData(); - if (chunk instanceof ChunkAnvil112) { - blockIdMeta = " (" + ((ChunkAnvil112) chunk).getBlockIdMeta(blockPos) + ")"; - blockBelowIdMeta = " (" + ((ChunkAnvil112) chunk).getBlockIdMeta(blockPos.add(0, -1, 0)) + ")"; - } - source.sendMessages(Arrays.asList( - Text.of(TextColor.GOLD, "Block at you: ", TextColor.WHITE, block, TextColor.GRAY, blockIdMeta), - Text.of(TextColor.GOLD, "Block below you: ", TextColor.WHITE, blockBelow, TextColor.GRAY, blockBelowIdMeta), - Text.of(TextColor.GOLD, "Chunk: ", TextColor.WHITE, chunk) + Text.of(TextColor.GOLD, "Block at you: ", TextColor.WHITE, block), + Text.of(TextColor.GOLD, "Block below you: ", TextColor.WHITE, blockBelow) )); }).start(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BiomeConfig.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BiomeConfig.java deleted file mode 100644 index a74e7f27..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BiomeConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.config; - -import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; -import de.bluecolored.bluemap.core.world.Biome; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.loader.ConfigurationLoader; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -public class BiomeConfig implements BiomeMapper { - - private final ConfigurationLoader autopoulationConfigLoader; - private final Map biomes; - - public BiomeConfig(ConfigurationNode node) { - this(node, null); - } - - public BiomeConfig(ConfigurationNode node, ConfigurationLoader autopoulationConfigLoader) { - this.autopoulationConfigLoader = autopoulationConfigLoader; - - biomes = new ConcurrentHashMap<>(200, 0.5f, 8); - - for (Entry e : node.childrenMap().entrySet()){ - String id = e.getKey().toString(); - Biome biome = Biome.create(id, e.getValue()); - biomes.put(biome.getNumeralId(), biome); - } - - } - - @Override - public Biome get(int id) { - Biome biome = biomes.get(id); - - if (biome == null) { - if (autopoulationConfigLoader != null) { - biomes.put(id, Biome.DEFAULT); - - synchronized (autopoulationConfigLoader) { - try { - ConfigurationNode node = autopoulationConfigLoader.load(); - node.node("unknown:" + id).node("id").set(id); - autopoulationConfigLoader.save(node); - } catch (IOException ex) { - Logger.global.noFloodError("biomeconf-autopopulate-ioex", "Failed to auto-populate BiomeConfig!", ex); - } - } - } - - return Biome.DEFAULT; - } - - return biome; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java deleted file mode 100644 index 1d0fd0fa..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.config; - -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BlockIdMapper; -import de.bluecolored.bluemap.core.world.BlockState; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.loader.ConfigurationLoader; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public class BlockIdConfig implements BlockIdMapper { - - private final ConfigurationLoader autopoulationConfigLoader; - private final Map numeralMappings; - private final Map idMappings; - - private final ReentrantReadWriteLock lock; - - public BlockIdConfig(ConfigurationNode node) { - this(node, null); - } - - public BlockIdConfig(ConfigurationNode node, ConfigurationLoader autopoulationConfigLoader) { - this.autopoulationConfigLoader = autopoulationConfigLoader; - - this.numeralMappings = new ConcurrentHashMap<>(200, 0.5f, 8); - this.idMappings = new ConcurrentHashMap<>(200, 0.5f, 8); - - this.lock = new ReentrantReadWriteLock(); - - for (Entry e : node.childrenMap().entrySet()){ - String key = e.getKey().toString(); - String value = e.getValue().getString(); - - try { - int splitIndex = key.lastIndexOf(':'); - - if (splitIndex <= 0 || splitIndex >= key.length() - 1) { - Logger.global.logWarning("Loading BlockIdConfig: Failed to parse blockid:meta from key '" + key + "'"); - continue; - } - - String blockId = key.substring(0, splitIndex); - int blockNumeralId; - try { - blockNumeralId = Integer.parseInt(blockId); - } catch (NumberFormatException ex) { - blockNumeralId = -1; - } - int blockMeta = Integer.parseInt(key.substring(splitIndex + 1)); - BlockState state = BlockState.fromString(MinecraftVersion.EARLIEST_SUPPORTED, value); - - if (blockNumeralId >= 0) { - BlockNumeralIDMeta idmeta = new BlockNumeralIDMeta(blockNumeralId, blockMeta); - if (blockNumeralId == 0) state = BlockState.AIR; //use the static field to increase render speed (== comparison) - numeralMappings.put(idmeta, state); - } else { - BlockIDMeta idmeta = new BlockIDMeta(blockId, blockMeta); - idMappings.put(idmeta, state); - } - } catch (NumberFormatException ex) { - Logger.global.logWarning("Loading BlockIdConfig: Failed to parse blockid:meta from key '" + key + "'"); - } catch (IllegalArgumentException ex) { - Logger.global.logWarning("Loading BlockIdConfig: Failed to parse BlockState from value '" + value + "'"); - } - } - } - - @Override - public BlockState get(int numeralId, int meta) { - if (numeralId == 0) return BlockState.AIR; - - BlockNumeralIDMeta numidmeta; - BlockState state; - - try { lock.readLock().lock(); - - numidmeta = new BlockNumeralIDMeta(numeralId, meta); - state = numeralMappings.get(numidmeta); - - } finally { lock.readLock().unlock(); } - - if (state == null) { - - try { lock.writeLock().lock(); - - state = numeralMappings.getOrDefault(new BlockNumeralIDMeta(numeralId, 0), BlockState.MISSING); //meta-fallback - numeralMappings.put(numidmeta, state); - - if (autopoulationConfigLoader != null) { - try { - ConfigurationNode node = autopoulationConfigLoader.load(); - node.node(numeralId + ":" + meta).set(state.toString()); - autopoulationConfigLoader.save(node); - } catch (IOException ex) { - Logger.global.noFloodError("blockidconf-autopopulate-ioex", "Failed to auto-populate BlockIdConfig!", ex); - } - } - - } finally { lock.writeLock().unlock(); } - - } - - return state; - - } - - @Override - public BlockState get(String id, int numeralId, int meta) { - if (numeralId == 0) return BlockState.AIR; - - BlockNumeralIDMeta numidmeta; - BlockState state; - BlockIDMeta idmeta = null; - - try { lock.readLock().lock(); - - numidmeta = new BlockNumeralIDMeta(numeralId, meta); - state = numeralMappings.get(numidmeta); - - if (state == null) { - idmeta = new BlockIDMeta(id, meta); - state = idMappings.get(idmeta); - } - - } finally { lock.readLock().unlock(); } - - if (state == null) { - - try { lock.writeLock().lock(); - - state = idMappings.get(new BlockIDMeta(id, 0)); - if (state == null) { - state = numeralMappings.get(new BlockNumeralIDMeta(numeralId, 0)); - if (state == null) state = new BlockState(MinecraftVersion.EARLIEST_SUPPORTED, id); - } - - idMappings.put(idmeta, state); - - if (autopoulationConfigLoader != null) { - try { - ConfigurationNode node = autopoulationConfigLoader.load(); - node.node(id + ":" + meta).set(state.toString()); - autopoulationConfigLoader.save(node); - } catch (IOException ex) { - Logger.global.noFloodError("blockidconf-autopopulate-ioex", "Failed to auto-populate BlockIdConfig!", ex); - } - } - - } finally { lock.writeLock().unlock(); } - - } - - return state; - } - - static class BlockNumeralIDMeta { - private final int id; - private final int meta; - - public BlockNumeralIDMeta(int id, int meta) { - this.id = id; - this.meta = meta; - } - - public int getId() { - return id; - } - - public int getMeta() { - return meta; - } - - @Override - public int hashCode() { - return id * 16 + meta; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof BlockNumeralIDMeta) { - BlockNumeralIDMeta other = (BlockNumeralIDMeta) obj; - return other.id == id && other.meta == meta; - } - - return false; - } - } - - static class BlockIDMeta { - private final String id; - private final int meta; - - public BlockIDMeta(String id, int meta) { - this.id = id; - this.meta = meta; - } - - public String getId() { - return id; - } - - public int getMeta() { - return meta; - } - - @Override - public int hashCode() { - return id.hashCode() * 16 + meta; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof BlockIDMeta) { - BlockIDMeta other = (BlockIDMeta) obj; - return other.id.equals(id) && other.meta == meta; - } - - return false; - } - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockPropertiesConfig.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockPropertiesConfig.java deleted file mode 100644 index 8654aee7..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockPropertiesConfig.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.config; - -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; -import de.bluecolored.bluemap.core.BlueMap; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BlockPropertiesMapper; -import de.bluecolored.bluemap.core.resourcepack.NoSuchResourceException; -import de.bluecolored.bluemap.core.resourcepack.ResourcePack; -import de.bluecolored.bluemap.core.resourcepack.TransformedBlockModelResource; -import de.bluecolored.bluemap.core.world.BlockProperties; -import de.bluecolored.bluemap.core.world.BlockState; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.loader.ConfigurationLoader; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -public class BlockPropertiesConfig implements BlockPropertiesMapper { - - private final ConfigurationLoader autopoulationConfigLoader; - - private final Map>> mappings; - private final LoadingCache mappingCache; - - private final ResourcePack resourcePack; - - public BlockPropertiesConfig(ConfigurationNode node, ResourcePack resourcePack) { - this(node, resourcePack, null); - } - - public BlockPropertiesConfig(ConfigurationNode node, ResourcePack resourcePack, ConfigurationLoader autopoulationConfigLoader) { - this.resourcePack = resourcePack; - this.autopoulationConfigLoader = autopoulationConfigLoader; - - mappings = new ConcurrentHashMap<>(); - - for (Entry e : node.childrenMap().entrySet()){ - String key = e.getKey().toString(); - try { - BlockState bsKey = BlockState.fromString(resourcePack.getMinecraftVersion(), key); - BlockProperties bsValue = new BlockProperties( - e.getValue().node("culling").getBoolean(true), - e.getValue().node("occluding").getBoolean(true), - e.getValue().node("flammable").getBoolean(false) - ); - BlockStateMapping mapping = new BlockStateMapping<>(bsKey, bsValue); - mappings.computeIfAbsent(bsKey.getFullId(), k -> new ArrayList<>()).add(mapping); - } catch (IllegalArgumentException ex) { - Logger.global.logWarning("Loading BlockPropertiesConfig: Failed to parse BlockState from key '" + key + "'"); - } - } - - mappingCache = Caffeine.newBuilder() - .executor(BlueMap.THREAD_POOL) - .maximumSize(10000) - .build(this::mapNoCache); - } - - @Override - public BlockProperties get(BlockState from){ - return mappingCache.get(from); - } - - private BlockProperties mapNoCache(BlockState bs){ - for (BlockStateMapping bm : mappings.getOrDefault(bs.getFullId(), Collections.emptyList())){ - if (bm.fitsTo(bs)){ - return bm.getMapping(); - } - } - - BlockProperties generated = BlockProperties.SOLID; - MinecraftVersion version = MinecraftVersion.LATEST_SUPPORTED; - - if (resourcePack != null) { - try { - boolean culling = false; - boolean occluding = false; - - for(TransformedBlockModelResource model : resourcePack.getBlockStateResource(bs).getModels(bs, new ArrayList<>(10))) { - culling = culling || model.getModel().isCulling(); - occluding = occluding || model.getModel().isOccluding(); - if (culling && occluding) break; - } - - generated = new BlockProperties(culling, occluding, generated.isFlammable()); - } catch (NoSuchResourceException ignore) {} //ignoring this because it will be logged later again if we try to render that block - - version = resourcePack.getMinecraftVersion(); - } - - mappings.computeIfAbsent(bs.getFullId(), k -> new ArrayList<>()).add(new BlockStateMapping<>(new BlockState(version, bs.getFullId()), generated)); - if (autopoulationConfigLoader != null) { - synchronized (autopoulationConfigLoader) { - try { - ConfigurationNode node = autopoulationConfigLoader.load(); - ConfigurationNode bpNode = node.node(bs.getFullId()); - bpNode.node("culling").set(generated.isCulling()); - bpNode.node("occluding").set(generated.isOccluding()); - bpNode.node("flammable").set(generated.isFlammable()); - autopoulationConfigLoader.save(node); - } catch (IOException ex) { - Logger.global.noFloodError("blockpropsconf-autopopulate-ioex", "Failed to auto-populate BlockPropertiesConfig!", ex); - } - } - } - - return generated; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java index 03f52c96..d1d9969e 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java @@ -26,16 +26,16 @@ package de.bluecolored.bluemap.core.config; import de.bluecolored.bluemap.core.BlueMap; -import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resourcepack.ResourcePack; -import de.bluecolored.bluemap.core.resourcepack.ResourcePack.Resource; import de.bluecolored.bluemap.core.util.FileUtils; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.gson.GsonConfigurationLoader; import org.spongepowered.configurate.hocon.HoconConfigurationLoader; import org.spongepowered.configurate.loader.ConfigurationLoader; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -53,11 +53,7 @@ public class ConfigManager { CONFIG_PLACEHOLDERS.add(new Placeholder("version", BlueMap.VERSION)); CONFIG_PLACEHOLDERS.add(new Placeholder("datetime-iso", () -> LocalDateTime.now().withNano(0).toString())); } - - private BlockIdConfig blockIdConfig; - private BlockPropertiesConfig blockPropertiesConfig; - private BiomeConfig biomeConfig; - + /** * Loads or creates a config file for BlueMap. * @@ -66,8 +62,8 @@ public class ConfigManager { * @param defaultValues The default values used if a key is not present in the config (can be null) * @param usePlaceholders Whether to replace placeholders from the defaultConfig if it is newly generated * @param generateEmptyConfig Whether to generate an empty config file if no default config is provided - * @return - * @throws IOException + * @return The loaded configuration node + * @throws IOException if an IOException occurs while loading */ public ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL defaultValues, boolean usePlaceholders, boolean generateEmptyConfig) throws IOException { @@ -116,107 +112,6 @@ public class ConfigManager { return configNode; } - public void loadResourceConfigs(File configFolder, ResourcePack resourcePack) throws IOException { - - //load blockColors.json from resources, config-folder and resourcepack - URL blockColorsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockColors.json"); - File blockColorsConfigFile = new File(configFolder, "blockColors.json"); - ConfigurationNode blockColorsConfigNode = loadOrCreate( - blockColorsConfigFile, - null, - blockColorsConfigUrl, - false, - false - ); - blockColorsConfigNode = joinFromResourcePack(resourcePack, "blockColors.json", blockColorsConfigNode); - resourcePack.getBlockColorCalculatorFactory().loadColorConfig(blockColorsConfigNode); - - //load blockIds.json from resources, config-folder and resourcepack - URL blockIdsConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockIds.json"); - File blockIdsConfigFile = new File(configFolder, "blockIds.json"); - ConfigurationNode blockIdsConfigNode = loadOrCreate( - blockIdsConfigFile, - null, - blockIdsConfigUrl, - false, - false - ); - blockIdsConfigNode = joinFromResourcePack(resourcePack, "blockIds.json", blockIdsConfigNode); - blockIdConfig = new BlockIdConfig( - blockIdsConfigNode - ); - - //load blockProperties.json from resources, config-folder and resourcepack - URL blockPropertiesConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/blockProperties.json"); - File blockPropertiesConfigFile = new File(configFolder, "blockProperties.json"); - ConfigurationNode blockPropertiesConfigNode = loadOrCreate( - blockPropertiesConfigFile, - null, - blockPropertiesConfigUrl, - false, - false - ); - blockPropertiesConfigNode = joinFromResourcePack(resourcePack, "blockProperties.json", blockPropertiesConfigNode); - blockPropertiesConfig = new BlockPropertiesConfig( - blockPropertiesConfigNode, - resourcePack - ); - - //load biomes.json from resources, config-folder and resourcepack - URL biomeConfigUrl = BlueMap.class.getResource("/de/bluecolored/bluemap/" + resourcePack.getMinecraftVersion().getResource().getResourcePrefix() + "/biomes.json"); - File biomeConfigFile = new File(configFolder, "biomes.json"); - ConfigurationNode biomeConfigNode = loadOrCreate( - biomeConfigFile, - null, - biomeConfigUrl, - false, - false - ); - biomeConfigNode = joinFromResourcePack(resourcePack, "biomes.json", biomeConfigNode); - biomeConfig = new BiomeConfig( - biomeConfigNode - ); - - } - - public BlockIdConfig getBlockIdConfig() { - return blockIdConfig; - } - - public BlockPropertiesConfig getBlockPropertiesConfig() { - return blockPropertiesConfig; - } - - public BiomeConfig getBiomeConfig() { - return biomeConfig; - } - - private ConfigurationNode joinFromResourcePack(ResourcePack resourcePack, String configFileName, ConfigurationNode defaultConfig) { - ConfigurationNode joinedNode = null; - for (Resource resource : resourcePack.getConfigAdditions(configFileName)) { - try { - ConfigurationNode node = getLoader(configFileName, resource.read()).load(); - if (joinedNode == null) joinedNode = node; - else joinedNode.mergeFrom(node); - } catch (IOException ex) { - Logger.global.logWarning("Failed to load an additional " + configFileName + " from the resource-pack! " + ex); - } - } - - if (joinedNode == null) return defaultConfig; - - joinedNode.mergeFrom(defaultConfig); - - return joinedNode; - } - - private ConfigurationLoader getLoader(String filename, InputStream is){ - BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); - - if (filename.endsWith(".json")) return GsonConfigurationLoader.builder().source(() -> reader).build(); - else return HoconConfigurationLoader.builder().source(() -> reader).build(); - } - private ConfigurationLoader getLoader(URL url){ if (url.getFile().endsWith(".json")) return GsonConfigurationLoader.builder().url(url).build(); else return HoconConfigurationLoader.builder().url(url).build(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/OneBlockWorld.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/OneBlockWorld.java index 439ea52a..ceaa470b 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/OneBlockWorld.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/debug/OneBlockWorld.java @@ -1,9 +1,35 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.core.debug; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.mapping.BlockPropertiesMapper; -import de.bluecolored.bluemap.core.world.*; +import de.bluecolored.bluemap.core.world.Chunk; +import de.bluecolored.bluemap.core.world.Grid; +import de.bluecolored.bluemap.core.world.Region; +import de.bluecolored.bluemap.core.world.World; import java.nio.file.Path; import java.util.Collection; @@ -62,22 +88,6 @@ public class OneBlockWorld implements World { return delegate.getRegionGrid(); } - @Override - public Biome getBiome(int x, int y, int z) { - return Biome.DEFAULT; - } - - @Override - public BlockState getBlockState(int x, int y, int z) { - if (x == 0 && z == 0 && y == 70) return BlockState.MISSING; - return BlockState.AIR; - } - - @Override - public BlockProperties getBlockProperties(BlockState blockState) { - return delegate.getBlockProperties(blockState); - } - @Override public Chunk getChunkAtBlock(int x, int y, int z) { return delegate.getChunkAtBlock(x, y, z); @@ -113,9 +123,4 @@ public class OneBlockWorld implements World { delegate.cleanUpChunkCache(); } - @Override - public BlockPropertiesMapper getBlockPropertiesMapper() { - return delegate.getBlockPropertiesMapper(); - } - } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/BlockModelView.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/BlockModelView.java index fdddcb59..9820f50c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/BlockModelView.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/BlockModelView.java @@ -1,3 +1,27 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.core.map.hires; import de.bluecolored.bluemap.core.util.math.MatrixM3f; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java index 06d1498d..1d143185 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresModelRenderer.java @@ -29,7 +29,7 @@ import de.bluecolored.bluemap.core.map.hires.blockmodel.BlockStateModelFactory; import de.bluecolored.bluemap.core.resourcepack.NoSuchResourceException; import de.bluecolored.bluemap.core.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.util.math.Color; -import de.bluecolored.bluemap.core.world.Block; +import de.bluecolored.bluemap.core.world.BlockNeighborhood; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.World; @@ -54,9 +54,8 @@ public class HiresModelRenderer { BlockStateModelFactory modelFactory = new BlockStateModelFactory(resourcePack, renderSettings); int maxHeight, minY, maxY; - float dx, dz; Color columnColor = new Color(), blockColor = new Color(); - Block block = new Block(world, 0, 0, 0); + BlockNeighborhood block = new BlockNeighborhood<>(resourcePack, world, 0, 0, 0); BlockModelView blockModel = new BlockModelView(model); int x, y, z; @@ -96,13 +95,6 @@ public class HiresModelRenderer { maxHeight = y; columnColor.overlay(blockColor); } - - //random offset - if (block.getBlockState().isRandomOffset){ - dx = (hashToFloat(x, z, 123984) - 0.5f) * 0.75f; - dz = (hashToFloat(x, z, 345542) - 0.5f) * 0.75f; - blockModel.translate(dx, 0, dz); - } } tileMeta.setHeight(x, z, maxHeight); @@ -113,20 +105,4 @@ public class HiresModelRenderer { return tileMeta; } - - /** - * Hashes the provided position to a random float between 0 and 1.
- *
- * (Implementation adapted from https://github.com/SpongePowered/SpongeAPI/blob/ecd761a70219e467dea47a09fc310e8238e9911f/src/main/java/org/spongepowered/api/extra/skylands/SkylandsUtil.java) - * - * @param x The x component of the position - * @param z The z component of the position - * @param seed A seed for the hashing - * @return The hashed value between 0 and 1 - */ - public static float hashToFloat(int x, int z, long seed) { - final long hash = x * 73428767 ^ z * 4382893 ^ seed * 457; - return (hash * (hash + 456149) & 0x00ffffff) / (float) 0x01000000; - } - } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresTileMeta.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresTileMeta.java index 722498f6..713e3480 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresTileMeta.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/HiresTileMeta.java @@ -1,3 +1,27 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.core.map.hires; import de.bluecolored.bluemap.core.util.math.Color; @@ -37,7 +61,7 @@ public class HiresTileMeta { } private void setColor(int x, int z, float r, float g, float b, float a) { - int index = (x - minX) * sizeZ + (z - minZ) * 4; + int index = ((x - minX) * sizeZ + (z - minZ)) * 4; colors[index ] = r; colors[index + 1] = g; colors[index + 2] = b; @@ -45,7 +69,7 @@ public class HiresTileMeta { } public Color getColor(int x, int z, Color target) { - int index = (x - minX) * sizeZ + (z - minZ) * 4; + int index = ((x - minX) * sizeZ + (z - minZ)) * 4; return target.set( colors[index ], colors[index + 1], diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockStateModelFactory.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockStateModelFactory.java index 60b98130..1f994433 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockStateModelFactory.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockStateModelFactory.java @@ -24,12 +24,14 @@ */ package de.bluecolored.bluemap.core.map.hires.blockmodel; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.map.hires.BlockModelView; import de.bluecolored.bluemap.core.map.hires.RenderSettings; -import de.bluecolored.bluemap.core.resourcepack.*; +import de.bluecolored.bluemap.core.resourcepack.blockstate.BlockStateResource; +import de.bluecolored.bluemap.core.resourcepack.NoSuchResourceException; +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; import de.bluecolored.bluemap.core.util.math.Color; -import de.bluecolored.bluemap.core.world.Block; +import de.bluecolored.bluemap.core.world.BlockNeighborhood; import de.bluecolored.bluemap.core.world.BlockState; import java.util.ArrayList; @@ -46,25 +48,20 @@ public class BlockStateModelFactory { public BlockStateModelFactory(ResourcePack resourcePack, RenderSettings renderSettings) { this.resourcePack = resourcePack; - Block[] neighborCache = new Block[3 * 3 * 3]; - for (int i = 0; i < neighborCache.length; i++) { - neighborCache[i] = new Block(null, 0, 0, 0); - } - - this.resourceModelBuilder = new ResourceModelBuilder(resourcePack, renderSettings, neighborCache); - this.liquidModelBuilder = new LiquidModelBuilder(resourcePack, renderSettings, neighborCache); + this.resourceModelBuilder = new ResourceModelBuilder(resourcePack, renderSettings); + this.liquidModelBuilder = new LiquidModelBuilder(resourcePack, renderSettings); this.bmrs = new ArrayList<>(); } - public void render(Block block, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { + public void render(BlockNeighborhood block, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { render(block, block.getBlockState(), blockModel, blockColor); } - public void render(Block block, BlockState blockState, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { + public void render(BlockNeighborhood block, BlockState blockState, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { //shortcut for air - if (blockState.isAir) return; + if (blockState.isAir()) return; int modelStart = blockModel.getStart(); @@ -72,15 +69,14 @@ public class BlockStateModelFactory { renderModel(block, blockState, blockModel.initialize(), blockColor); // add water if block is waterlogged - if (blockState.isWaterlogged) { + if (blockState.isWaterlogged() || block.getProperties().isAlwaysWaterlogged()) { renderModel(block, WATERLOGGED_BLOCKSTATE, blockModel.initialize(), blockColor); } blockModel.initialize(modelStart); - } - private void renderModel(Block block, BlockState blockState, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { + private void renderModel(BlockNeighborhood block, BlockState blockState, BlockModelView blockModel, Color blockColor) throws NoSuchResourceException { int modelStart = blockModel.getStart(); BlockStateResource resource = resourcePack.getBlockStateResource(blockState); @@ -97,7 +93,7 @@ public class BlockStateModelFactory { blockModel.initialize(modelStart); } - - private final static BlockState WATERLOGGED_BLOCKSTATE = new BlockState(MinecraftVersion.LATEST_SUPPORTED, "minecraft:water"); + + private final static BlockState WATERLOGGED_BLOCKSTATE = new BlockState("minecraft:water"); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java index 97188fde..a5fa0cf3 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/LiquidModelBuilder.java @@ -26,22 +26,21 @@ package de.bluecolored.bluemap.core.map.hires.blockmodel; import com.flowpowered.math.TrigMath; import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.hires.BlockModelView; import de.bluecolored.bluemap.core.map.hires.HiresTileModel; import de.bluecolored.bluemap.core.map.hires.RenderSettings; import de.bluecolored.bluemap.core.resourcepack.BlockColorCalculatorFactory; import de.bluecolored.bluemap.core.resourcepack.ResourcePack; -import de.bluecolored.bluemap.core.resourcepack.Texture; -import de.bluecolored.bluemap.core.resourcepack.TransformedBlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Direction; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.util.math.MatrixM3f; import de.bluecolored.bluemap.core.util.math.VectorM2f; import de.bluecolored.bluemap.core.util.math.VectorM3f; -import de.bluecolored.bluemap.core.world.Block; +import de.bluecolored.bluemap.core.world.BlockNeighborhood; import de.bluecolored.bluemap.core.world.BlockState; +import de.bluecolored.bluemap.core.world.ResourcePackBlock; /** * A model builder for all liquid blocks @@ -57,24 +56,19 @@ public class LiquidModelBuilder { private final BlockColorCalculatorFactory.BlockColorCalculator blockColorCalculator; private final RenderSettings renderSettings; - private final boolean useWaterColorMap; - private final VectorM3f[] corners; - private final Block[] blocksAround; private final VectorM2f[] uvs = new VectorM2f[4]; - private Block block; + private BlockNeighborhood block; private BlockState blockState; private TransformedBlockModelResource blockModelResource; private BlockModelView blockModel; private Color blockColor; - public LiquidModelBuilder(ResourcePack resourcePack, RenderSettings renderSettings, Block[] neighborCache) { + public LiquidModelBuilder(ResourcePack resourcePack, RenderSettings renderSettings) { this.blockColorCalculator = resourcePack.getBlockColorCalculatorFactory().createCalculator(); this.renderSettings = renderSettings; - this.useWaterColorMap = resourcePack.getMinecraftVersion().isAtLeast(new MinecraftVersion(1, 13)); - corners = new VectorM3f[]{ new VectorM3f( 0, 0, 0 ), new VectorM3f( 0, 0, 16 ), @@ -86,12 +80,10 @@ public class LiquidModelBuilder { new VectorM3f( 16, 16, 16 ), }; - this.blocksAround = neighborCache; - for (int i = 0; i < uvs.length; i++) uvs[i] = new VectorM2f(0, 0); } - public void build(Block block, BlockState blockState, TransformedBlockModelResource bmr, BlockModelView blockModel, Color color) { + public void build(BlockNeighborhood block, BlockState blockState, TransformedBlockModelResource bmr, BlockModelView blockModel, Color color) { this.block = block; this.blockState = blockState; this.blockModelResource = bmr; @@ -107,7 +99,7 @@ public class LiquidModelBuilder { int level = getLiquidLevel(blockState); - if (level < 8 && !(level == 0 && isSameLiquid(getNeighborBlock(0, 1, 0).getBlockState()))){ + if (level < 8 && !(level == 0 && isSameLiquid(block.getNeighborBlock(0, 1, 0)))){ corners[4].y = getLiquidCornerHeight(-1, -1); corners[5].y = getLiquidCornerHeight(-1, 0); corners[6].y = getLiquidCornerHeight(0, -1); @@ -126,7 +118,7 @@ public class LiquidModelBuilder { int flowTextureId = flowTexture.getId(); tintcolor.set(1f, 1f, 1f, 1f, true); - if (useWaterColorMap && blockState.isWater) { + if (blockState.isWater()) { blockColorCalculator.getWaterAverageColor(block, tintcolor); } @@ -166,7 +158,7 @@ public class LiquidModelBuilder { for (ix = x; ix <= x+1; ix++){ for (iz = z; iz<= z+1; iz++){ - if (isSameLiquid(getNeighborBlock(ix, 1, iz).getBlockState())){ + if (isSameLiquid(block.getNeighborBlock(ix, 1, iz))){ return 16f; } } @@ -174,12 +166,14 @@ public class LiquidModelBuilder { float sumHeight = 0f; int count = 0; + ResourcePackBlock neighbor; BlockState neighborBlockState; for (ix = x; ix <= x+1; ix++){ for (iz = z; iz<= z+1; iz++){ - neighborBlockState = getNeighborBlock(ix, 0, iz).getBlockState(); - if (isSameLiquid(neighborBlockState)){ + neighbor = block.getNeighborBlock(ix, 0, iz); + neighborBlockState = neighbor.getBlockState(); + if (isSameLiquid(neighbor)){ if (getLiquidLevel(neighborBlockState) == 0) return 14f; sumHeight += getLiquidBaseHeight(neighborBlockState); @@ -203,9 +197,9 @@ public class LiquidModelBuilder { return !blockState.equals(BlockState.AIR); } - private boolean isSameLiquid(BlockState blockState){ - if (blockState.getFullId().equals(this.blockState.getFullId())) return true; - return this.blockState.isWater && blockState.isWaterlogged; + private boolean isSameLiquid(ResourcePackBlock block){ + if (block.getBlockState().getFullId().equals(this.blockState.getFullId())) return true; + return this.blockState.isWater() && (block.getBlockState().isWaterlogged() || block.getProperties().isAlwaysWaterlogged()); } private float getLiquidBaseHeight(BlockState block){ @@ -223,13 +217,13 @@ public class LiquidModelBuilder { Vector3i faceDirVector = faceDir.toVector(); //face culling - Block bl = getNeighborBlock( + ResourcePackBlock bl = block.getNeighborBlock( faceDirVector.getX(), faceDirVector.getY(), faceDirVector.getZ() ); - if (isSameLiquid(bl.getBlockState()) || (faceDir != Direction.UP && bl.isCullingNeighborFaces())) return false; + if (isSameLiquid(bl) || (faceDir != Direction.UP && bl.getProperties().isCulling())) return false; // initialize the faces blockModel.initialize(); @@ -327,17 +321,6 @@ public class LiquidModelBuilder { return true; } - private Block getNeighborBlock(int dx, int dy, int dz) { - int i = (dx + 1) * 9 + (dy + 1) * 3 + (dz + 1); - if (i == 13) return block; - return blocksAround[i].set( - block.getWorld(), - block.getX() + dx, - block.getY() + dy, - block.getZ() + dz - ); - } - private final VectorM2f flowingVector = new VectorM2f(0, 0); private int getFlowingAngle() { float own = getLiquidBaseHeight(blockState) * BLOCK_SCALE; @@ -358,11 +341,11 @@ public class LiquidModelBuilder { } private float compareLiquidHeights(float ownHeight, int dx, int dz) { - BlockState state = getNeighborBlock(dx, 0, dz).getBlockState(); - if (state.isAir) return 0; - if (!isSameLiquid(state)) return 0; + ResourcePackBlock neighbor = block.getNeighborBlock(dx, 0, dz); + if (neighbor.getBlockState().isAir()) return 0; + if (!isSameLiquid(neighbor)) return 0; - float otherHeight = getLiquidBaseHeight(state) * BLOCK_SCALE; + float otherHeight = getLiquidBaseHeight(neighbor.getBlockState()) * BLOCK_SCALE; return otherHeight - ownHeight; } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java index 26659101..83b3bb39 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/ResourceModelBuilder.java @@ -32,13 +32,19 @@ import com.flowpowered.math.vector.Vector4f; import de.bluecolored.bluemap.core.map.hires.BlockModelView; import de.bluecolored.bluemap.core.map.hires.HiresTileModel; import de.bluecolored.bluemap.core.map.hires.RenderSettings; -import de.bluecolored.bluemap.core.resourcepack.*; +import de.bluecolored.bluemap.core.resourcepack.BlockColorCalculatorFactory; +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.BlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Direction; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.util.math.MatrixM4f; import de.bluecolored.bluemap.core.util.math.VectorM2f; import de.bluecolored.bluemap.core.util.math.VectorM3f; -import de.bluecolored.bluemap.core.world.Block; +import de.bluecolored.bluemap.core.world.BlockNeighborhood; +import de.bluecolored.bluemap.core.world.LightData; +import de.bluecolored.bluemap.core.world.ResourcePackBlock; /** * This model builder creates a BlockStateModel using the information from parsed resource-pack json files. @@ -54,24 +60,22 @@ public class ResourceModelBuilder { private final VectorM2f[] uvs = new VectorM2f[4]; private final Color tintColor = new Color(); private final Color mapColor = new Color(); - private final Block[] blocksAround; - private Block block; + private BlockNeighborhood block; private TransformedBlockModelResource blockModelResource; private BlockModelView blockModel; private Color blockColor; - public ResourceModelBuilder(ResourcePack resourcePack, RenderSettings renderSettings, Block[] neighborCache) { + public ResourceModelBuilder(ResourcePack resourcePack, RenderSettings renderSettings) { this.blockColorCalculator = resourcePack.getBlockColorCalculatorFactory().createCalculator(); this.renderSettings = renderSettings; - this.blocksAround = neighborCache; for (int i = 0; i < corners.length; i++) corners[i] = new VectorM3f(0, 0, 0); for (int i = 0; i < uvs.length; i++) rawUvs[i] = new VectorM2f(0, 0); } private final MatrixM4f modelTransform = new MatrixM4f(); - public void build(Block block, TransformedBlockModelResource bmr, BlockModelView blockModel, Color color) { + public void build(BlockNeighborhood block, TransformedBlockModelResource bmr, BlockModelView blockModel, Color color) { this.block = block; this.blockModel = blockModel; this.blockColor = color; @@ -97,6 +101,13 @@ public class ResourceModelBuilder { ); } + //random offset + if (block.getProperties().isRandomOffset()){ + float dx = (hashToFloat(block.getX(), block.getZ(), 123984) - 0.5f) * 0.75f; + float dz = (hashToFloat(block.getX(), block.getZ(), 345542) - 0.5f) * 0.75f; + blockModel.translate(dx, 0, dz); + } + } private final MatrixM4f modelElementTransform = new MatrixM4f(); @@ -149,14 +160,17 @@ public class ResourceModelBuilder { // face culling if (face.getCullface() != null) { - Block b = getRotationRelativeBlock(face.getCullface()); - if (b.isCullingNeighborFaces()) return; + ResourcePackBlock b = getRotationRelativeBlock(face.getCullface()); + if (b.getProperties().isCulling()) return; } // light calculation - Block facedBlockNeighbor = getRotationRelativeBlock(faceDir); - int sunLight = facedBlockNeighbor.getPassedSunLight(); - int blockLight = facedBlockNeighbor.getPassedBlockLight(); + ResourcePackBlock facedBlockNeighbor = getRotationRelativeBlock(faceDir); + LightData blockLightData = block.getLightData(); + LightData facedLightData = facedBlockNeighbor.getLightData(); + + int sunLight = Math.max(blockLightData.getSkyLight(), facedLightData.getSkyLight()); + int blockLight = Math.max(blockLightData.getBlockLight(), facedLightData.getBlockLight()); // filter out faces that are not sun-lighted if (sunLight == 0f && renderSettings.isExcludeFacesWithoutSunlight()) return; @@ -302,23 +316,11 @@ public class ResourceModelBuilder { } } - private Block getNeighborBlock(int dx, int dy, int dz) { - int i = (dx + 1) * 9 + (dy + 1) * 3 + (dz + 1); - if (i == 13) return block; - return blocksAround[i].set( - block.getWorld(), - block.getX() + dx, - block.getY() + dy, - block.getZ() + dz - ); - } - - private Block getRotationRelativeBlock(Direction direction){ + private ResourcePackBlock getRotationRelativeBlock(Direction direction){ return getRotationRelativeBlock(direction.toVector()); } - - private Block getRotationRelativeBlock(Vector3i direction){ + private ResourcePackBlock getRotationRelativeBlock(Vector3i direction){ return getRotationRelativeBlock( direction.getX(), direction.getY(), @@ -327,11 +329,11 @@ public class ResourceModelBuilder { } private final VectorM3f rotationRelativeBlockDirection = new VectorM3f(0, 0, 0); - private Block getRotationRelativeBlock(int dx, int dy, int dz){ + private ResourcePackBlock getRotationRelativeBlock(int dx, int dy, int dz){ rotationRelativeBlockDirection.set(dx, dy, dz); makeRotationRelative(rotationRelativeBlockDirection); - return getNeighborBlock( + return block.getNeighborBlock( Math.round(rotationRelativeBlockDirection.x), Math.round(rotationRelativeBlockDirection.y), Math.round(rotationRelativeBlockDirection.z) @@ -369,23 +371,28 @@ public class ResourceModelBuilder { if (x * dirVec.getX() + y * dirVec.getY() > 0){ - if (getRotationRelativeBlock(x, y, 0).isOccludingNeighborFaces()) occluding++; + if (getRotationRelativeBlock(x, y, 0).getProperties().isOccluding()) occluding++; } if (x * dirVec.getX() + z * dirVec.getZ() > 0){ - if (getRotationRelativeBlock(x, 0, z).isOccludingNeighborFaces()) occluding++; + if (getRotationRelativeBlock(x, 0, z).getProperties().isOccluding()) occluding++; } if (y * dirVec.getY() + z * dirVec.getZ() > 0){ - if (getRotationRelativeBlock(0, y, z).isOccludingNeighborFaces()) occluding++; + if (getRotationRelativeBlock(0, y, z).getProperties().isOccluding()) occluding++; } if (x * dirVec.getX() + y * dirVec.getY() + z * dirVec.getZ() > 0){ - if (getRotationRelativeBlock(x, y, z).isOccludingNeighborFaces()) occluding++; + if (getRotationRelativeBlock(x, y, z).getProperties().isOccluding()) occluding++; } if (occluding > 3) occluding = 3; return Math.max(0f, Math.min(1f - occluding * 0.25f, 1f)); } + private static float hashToFloat(int x, int z, long seed) { + final long hash = x * 73428767 ^ z * 4382893 ^ seed * 457; + return (hash * (hash + 456149) & 0x00ffffff) / (float) 0x01000000; + } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java deleted file mode 100644 index 4a02590f..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; -import de.bluecolored.bluemap.core.mca.mapping.BlockIdMapper; -import de.bluecolored.bluemap.core.world.Biome; -import de.bluecolored.bluemap.core.world.BlockState; -import de.bluecolored.bluemap.core.world.LightData; -import net.querz.nbt.CompoundTag; -import net.querz.nbt.ListTag; -import net.querz.nbt.NumberTag; - -import java.util.Arrays; -import java.util.function.IntFunction; - -public class ChunkAnvil112 extends MCAChunk { - private final BiomeMapper biomeIdMapper; - private final BlockIdMapper blockIdMapper; - private final IntFunction forgeBlockIdMapper; - - private boolean isGenerated; - private boolean hasLight; - private Section[] sections; - private byte[] biomes; - - @SuppressWarnings("unchecked") - public ChunkAnvil112(CompoundTag chunkTag, boolean ignoreMissingLightData, BiomeMapper biomeIdMapper, BlockIdMapper blockIdMapper, IntFunction forgeBlockIdMapper) { - super(chunkTag); - - this.blockIdMapper = blockIdMapper; - this.biomeIdMapper = biomeIdMapper; - this.forgeBlockIdMapper = forgeBlockIdMapper; - - CompoundTag levelData = chunkTag.getCompoundTag("Level"); - - hasLight = levelData.getBoolean("LightPopulated"); - - isGenerated = - (hasLight || ignoreMissingLightData) && - levelData.getBoolean("TerrainPopulated"); - - sections = new Section[32]; //32 supports a max world-height of 512 which is the max that the hightmaps of Minecraft V1.13+ can store with 9 bits, i believe? - if (levelData.containsKey("Sections")) { - for (CompoundTag sectionTag : ((ListTag) levelData.getListTag("Sections"))) { - Section section = new Section(sectionTag); - if (section.getSectionY() >= 0 && section.getSectionY() < sections.length) sections[section.getSectionY()] = section; - } - } - - biomes = levelData.getByteArray("Biomes"); - - if (biomes == null || biomes.length == 0) { - biomes = new byte[256]; - } - - if (biomes.length < 256) { - biomes = Arrays.copyOf(biomes, 256); - } - } - - @Override - public boolean isGenerated() { - return isGenerated; - } - - @Override - public BlockState getBlockState(int x, int y, int z) { - int sectionY = y >> 4; - if (sectionY < 0 || sectionY >= this.sections.length) return BlockState.AIR; - - Section section = this.sections[sectionY]; - if (section == null) return BlockState.AIR; - - return section.getBlockState(x, y, z); - } - - public String getBlockIdMeta(Vector3i pos) { - int sectionY = pos.getY() >> 4; - if (sectionY < 0 || sectionY >= this.sections.length) return "0:0"; - - Section section = this.sections[sectionY]; - if (section == null) return "0:0"; - - return section.getBlockIdMeta(pos); - } - - @Override - public LightData getLightData(int x, int y, int z, LightData target) { - if (!hasLight) return target.set(15, 0); - - int sectionY = y >> 4; - if (sectionY < 0 || sectionY >= this.sections.length) - return (y < 0) ? target.set(0, 0) : target.set(15, 0); - - Section section = this.sections[sectionY]; - if (section == null) return target.set(15, 0); - - return section.getLightData(x, y, z, target); - } - - @Override - public Biome getBiome(int x, int y, int z) { - x = x & 0xF; // Math.floorMod(pos.getX(), 16) - z = z & 0xF; - int biomeByteIndex = z * 16 + x; - - if (biomeByteIndex >= this.biomes.length) return Biome.DEFAULT; - - return biomeIdMapper.get(biomes[biomeByteIndex] & 0xFF); - } - - private class Section { - private int sectionY; - private byte[] blocks; - private byte[] add; - private byte[] blockLight; - private byte[] skyLight; - private byte[] data; - - public Section(CompoundTag sectionData) { - this.sectionY = sectionData.get("Y", NumberTag.class).asInt(); - this.blocks = sectionData.getByteArray("Blocks"); - this.add = sectionData.getByteArray("Add"); - this.blockLight = sectionData.getByteArray("BlockLight"); - this.skyLight = sectionData.getByteArray("SkyLight"); - this.data = sectionData.getByteArray("Data"); - - if (blocks.length < 4096) blocks = Arrays.copyOf(blocks, 4096); - if (blockLight.length < 2048) blockLight = Arrays.copyOf(blockLight, 2048); - if (skyLight.length < 2048) skyLight = Arrays.copyOf(skyLight, 2048); - if (data.length < 2048) data = Arrays.copyOf(data, 2048); - } - - public int getSectionY() { - return sectionY; - } - - public BlockState getBlockState(int x, int y, int z) { - x &= 0xF; y &= 0xF; z &= 0xF; // Math.floorMod(pos.getX(), 16) - - int blockByteIndex = y * 256 + z * 16 + x; - int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 - boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0 - - int blockId = this.blocks[blockByteIndex] & 0xFF; - - if (this.add.length > blockHalfByteIndex) { - blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8); - } - - int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf); - - String forgeIdMapping = forgeBlockIdMapper.apply(blockId); - if (forgeIdMapping != null) { - return blockIdMapper.get(forgeIdMapping, blockId, blockData); - } else { - return blockIdMapper.get(blockId, blockData); - } - } - - public String getBlockIdMeta(Vector3i pos) { - int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16) - int y = pos.getY() & 0xF; - int z = pos.getZ() & 0xF; - int blockByteIndex = y * 256 + z * 16 + x; - int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 - boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0 - - int blockId = this.blocks[blockByteIndex] & 0xFF; - - if (this.add.length > blockHalfByteIndex) { - blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8); - } - - int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf); - String forgeIdMapping = forgeBlockIdMapper.apply(blockId); - - return blockId + ":" + blockData + " " + forgeIdMapping; - } - - public LightData getLightData(int x, int y, int z, LightData target) { - x &= 0xF; y &= 0xF; z &= 0xF; // Math.floorMod(pos.getX(), 16) - - int blockByteIndex = y * 256 + z * 16 + x; - int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 - boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0 - - int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf); - int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf); - - return target.set(skyLight, blockLight); - } - - /** - * Extracts the 4 bits of the left (largeHalf = true) or the right (largeHalf = false) side of the byte stored in value.
- * The value is treated as an unsigned byte. - */ - private int getByteHalf(int value, boolean largeHalf) { - value = value & 0xFF; - if (largeHalf) { - value = value >> 4; - } - value = value & 0xF; - return value; - } - - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java index e9bc60e5..809aa525 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil113.java @@ -24,9 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; import de.bluecolored.bluemap.core.world.Biome; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.LightData; @@ -38,21 +36,15 @@ import java.util.Map; import java.util.Map.Entry; public class ChunkAnvil113 extends MCAChunk { - private static final MinecraftVersion VERSION = new MinecraftVersion(1, 13); - - private BiomeMapper biomeIdMapper; - private boolean isGenerated; private boolean hasLight; private Section[] sections; private int[] biomes; @SuppressWarnings("unchecked") - public ChunkAnvil113(CompoundTag chunkTag, boolean ignoreMissingLightData, BiomeMapper biomeIdMapper) { + public ChunkAnvil113(CompoundTag chunkTag, boolean ignoreMissingLightData) { super(chunkTag); - this.biomeIdMapper = biomeIdMapper; - CompoundTag levelData = chunkTag.getCompoundTag("Level"); String status = levelData.getString("Status"); @@ -124,14 +116,14 @@ public class ChunkAnvil113 extends MCAChunk { } @Override - public Biome getBiome(int x, int y, int z) { + public int getBiome(int x, int y, int z) { x = x & 0xF; // Math.floorMod(pos.getX(), 16) z = z & 0xF; int biomeIntIndex = z * 16 + x; - if (biomeIntIndex >= this.biomes.length) return Biome.DEFAULT; + if (biomeIntIndex >= this.biomes.length) return Biome.DEFAULT.getNumeralId(); - return biomeIdMapper.get(biomes[biomeIntIndex]); + return biomes[biomeIntIndex]; } private class Section { @@ -178,7 +170,7 @@ public class ChunkAnvil113 extends MCAChunk { } } - palette[i] = new BlockState(VERSION, id, properties); + palette[i] = new BlockState(id, properties); } } else { this.palette = new BlockState[0]; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java index ffb7f451..7f34eb7b 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil115.java @@ -24,9 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; import de.bluecolored.bluemap.core.world.Biome; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.LightData; @@ -38,21 +36,15 @@ import java.util.Map; import java.util.Map.Entry; public class ChunkAnvil115 extends MCAChunk { - private static final MinecraftVersion VERSION = new MinecraftVersion(1, 15); - - private BiomeMapper biomeIdMapper; - private boolean isGenerated; private boolean hasLight; private Section[] sections; private int[] biomes; @SuppressWarnings("unchecked") - public ChunkAnvil115(CompoundTag chunkTag, boolean ignoreMissingLightData, BiomeMapper biomeIdMapper) { + public ChunkAnvil115(CompoundTag chunkTag, boolean ignoreMissingLightData) { super(chunkTag); - this.biomeIdMapper = biomeIdMapper; - CompoundTag levelData = chunkTag.getCompoundTag("Level"); String status = levelData.getString("Status"); @@ -124,16 +116,16 @@ public class ChunkAnvil115 extends MCAChunk { } @Override - public Biome getBiome(int x, int y, int z) { + public int getBiome(int x, int y, int z) { x = (x & 0xF) / 4; // Math.floorMod(pos.getX(), 16) z = (z & 0xF) / 4; y = y / 4; int biomeIntIndex = y * 16 + z * 4 + x; - if (biomeIntIndex < 0) return Biome.DEFAULT; - if (biomeIntIndex >= this.biomes.length) return Biome.DEFAULT; + if (biomeIntIndex < 0) return Biome.DEFAULT.getNumeralId(); + if (biomeIntIndex >= this.biomes.length) return Biome.DEFAULT.getNumeralId(); - return biomeIdMapper.get(biomes[biomeIntIndex]); + return biomes[biomeIntIndex]; } private static class Section { @@ -180,7 +172,7 @@ public class ChunkAnvil115 extends MCAChunk { } } - palette[i] = new BlockState(VERSION, id, properties); + palette[i] = new BlockState(id, properties); } } else { this.palette = new BlockState[0]; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java index 28c8f5d1..10e693fb 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil116.java @@ -24,9 +24,7 @@ */ package de.bluecolored.bluemap.core.mca; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; import de.bluecolored.bluemap.core.world.Biome; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.LightData; @@ -39,10 +37,6 @@ import java.util.Map; import java.util.Map.Entry; public class ChunkAnvil116 extends MCAChunk { - private static final MinecraftVersion VERSION = new MinecraftVersion(1, 16); - - private BiomeMapper biomeIdMapper; - private boolean isGenerated; private boolean hasLight; @@ -52,11 +46,9 @@ public class ChunkAnvil116 extends MCAChunk { private int[] biomes; @SuppressWarnings("unchecked") - public ChunkAnvil116(CompoundTag chunkTag, boolean ignoreMissingLightData, BiomeMapper biomeIdMapper) { + public ChunkAnvil116(CompoundTag chunkTag, boolean ignoreMissingLightData) { super(chunkTag); - this.biomeIdMapper = biomeIdMapper; - CompoundTag levelData = chunkTag.getCompoundTag("Level"); String status = levelData.getString("Status"); @@ -138,8 +130,8 @@ public class ChunkAnvil116 extends MCAChunk { } @Override - public Biome getBiome(int x, int y, int z) { - if (biomes.length < 16) return Biome.DEFAULT; + public int getBiome(int x, int y, int z) { + if (biomes.length < 16) return Biome.DEFAULT.getNumeralId(); x = (x & 0xF) / 4; // Math.floorMod(pos.getX(), 16) z = (z & 0xF) / 4; @@ -150,7 +142,7 @@ public class ChunkAnvil116 extends MCAChunk { if (biomeIntIndex >= biomes.length) biomeIntIndex -= (((biomeIntIndex - biomes.length) >> 4) + 1) * 16; if (biomeIntIndex < 0) biomeIntIndex -= (biomeIntIndex >> 4) * 16; - return biomeIdMapper.get(biomes[biomeIntIndex]); + return biomes[biomeIntIndex]; } @Override @@ -213,7 +205,7 @@ public class ChunkAnvil116 extends MCAChunk { } } - palette[i] = new BlockState(VERSION, id, properties); + palette[i] = new BlockState(id, properties); } } else { this.palette = new BlockState[0]; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/EmptyChunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/EmptyChunk.java index 15e7dfd3..01c635c2 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/EmptyChunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/EmptyChunk.java @@ -48,8 +48,8 @@ public class EmptyChunk extends MCAChunk { } @Override - public Biome getBiome(int x, int y, int z) { - return Biome.DEFAULT; + public int getBiome(int x, int y, int z) { + return Biome.DEFAULT.getNumeralId(); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java index 4752bae7..a8eacc5d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAChunk.java @@ -24,7 +24,6 @@ */ package de.bluecolored.bluemap.core.mca; -import de.bluecolored.bluemap.core.world.Biome; import de.bluecolored.bluemap.core.world.BlockState; import de.bluecolored.bluemap.core.world.Chunk; import de.bluecolored.bluemap.core.world.LightData; @@ -59,7 +58,7 @@ public abstract class MCAChunk implements Chunk { public abstract LightData getLightData(int x, int y, int z, LightData target); @Override - public abstract Biome getBiome(int x, int y, int z); + public abstract int getBiome(int x, int y, int z); @Override public int getMaxY(int x, int z) { @@ -73,11 +72,10 @@ public abstract class MCAChunk implements Chunk { public static MCAChunk create(MCAWorld world, CompoundTag chunkTag, boolean ignoreMissingLightData) throws IOException { int version = chunkTag.getInt("DataVersion"); - - if (version < 1400) return new ChunkAnvil112(chunkTag, ignoreMissingLightData, world.getBiomeIdMapper(), world.getBlockIdMapper(), world::getForgeBlockIdMapping); - if (version < 2200) return new ChunkAnvil113(chunkTag, ignoreMissingLightData, world.getBiomeIdMapper()); - if (version < 2500) return new ChunkAnvil115(chunkTag, ignoreMissingLightData, world.getBiomeIdMapper()); - return new ChunkAnvil116(chunkTag, ignoreMissingLightData, world.getBiomeIdMapper()); + + if (version < 2200) return new ChunkAnvil113(chunkTag, ignoreMissingLightData); + if (version < 2500) return new ChunkAnvil115(chunkTag, ignoreMissingLightData); + return new ChunkAnvil116(chunkTag, ignoreMissingLightData); } public static MCAChunk empty() { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java index 21b807f6..75fc2a65 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java @@ -29,20 +29,13 @@ import com.flowpowered.math.vector.Vector3i; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import de.bluecolored.bluemap.core.BlueMap; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.debug.DebugDump; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.mca.extensions.*; -import de.bluecolored.bluemap.core.mca.mapping.BiomeMapper; -import de.bluecolored.bluemap.core.mca.mapping.BlockIdMapper; -import de.bluecolored.bluemap.core.mca.mapping.BlockPropertiesMapper; -import de.bluecolored.bluemap.core.util.ArrayPool; -import de.bluecolored.bluemap.core.util.math.VectorM2i; -import de.bluecolored.bluemap.core.world.*; +import de.bluecolored.bluemap.core.world.BlockState; +import de.bluecolored.bluemap.core.world.Grid; +import de.bluecolored.bluemap.core.world.World; import net.querz.nbt.CompoundTag; -import net.querz.nbt.ListTag; import net.querz.nbt.NBTUtil; -import net.querz.nbt.Tag; import java.io.File; import java.io.FileNotFoundException; @@ -58,62 +51,28 @@ public class MCAWorld implements World { @DebugDump private final UUID uuid; @DebugDump private final Path worldFolder; - private final MinecraftVersion minecraftVersion; @DebugDump private final String name; @DebugDump private final Vector3i spawnPoint; + @DebugDump private final boolean ignoreMissingLightData; + private final LoadingCache regionCache; private final LoadingCache chunkCache; - - private BlockIdMapper blockIdMapper; - private BlockPropertiesMapper blockPropertiesMapper; - private BiomeMapper biomeMapper; - - private final Map> blockStateExtensions; - - @DebugDump private final boolean ignoreMissingLightData; - - private final Map forgeBlockMappings; private MCAWorld( Path worldFolder, - UUID uuid, - MinecraftVersion minecraftVersion, + UUID uuid, String name, - Vector3i spawnPoint, - BlockIdMapper blockIdMapper, - BlockPropertiesMapper blockPropertiesMapper, - BiomeMapper biomeMapper, + Vector3i spawnPoint, boolean ignoreMissingLightData ) { this.uuid = uuid; this.worldFolder = worldFolder; - this.minecraftVersion = minecraftVersion; this.name = name; this.spawnPoint = spawnPoint; - this.blockIdMapper = blockIdMapper; - this.blockPropertiesMapper = blockPropertiesMapper; - this.biomeMapper = biomeMapper; - this.ignoreMissingLightData = ignoreMissingLightData; - - this.forgeBlockMappings = new HashMap<>(); - - this.blockStateExtensions = new HashMap<>(); - registerBlockStateExtension(new SnowyExtension(minecraftVersion)); - registerBlockStateExtension(new StairShapeExtension()); - registerBlockStateExtension(new FireExtension()); - registerBlockStateExtension(new RedstoneExtension()); - registerBlockStateExtension(new DoorExtension(minecraftVersion)); - registerBlockStateExtension(new NetherFenceConnectExtension()); - registerBlockStateExtension(new TripwireConnectExtension()); - registerBlockStateExtension(new WallConnectExtension()); - registerBlockStateExtension(new WoodenFenceConnectExtension(minecraftVersion)); - registerBlockStateExtension(new GlassPaneConnectExtension()); - registerBlockStateExtension(new DoublePlantExtension(minecraftVersion)); - registerBlockStateExtension(new DoubleChestExtension()); - + this.regionCache = Caffeine.newBuilder() .executor(BlueMap.THREAD_POOL) .maximumSize(100) @@ -130,34 +89,6 @@ public class MCAWorld implements World { public BlockState getBlockState(Vector3i pos) { return getChunk(pos.getX() >> 4, pos.getZ() >> 4).getBlockState(pos.getX(), pos.getY(), pos.getZ()); } - - @Override - public Biome getBiome(int x, int y, int z) { - return getChunk(x >> 4, z >> 4).getBiome(x, y, z); - } - - @Override - public BlockState getBlockState(int x, int y, int z) { - MCAChunk chunk = getChunk(x >> 4, z >> 4); - BlockState blockState = chunk.getBlockState(x, y, z); - - if (chunk instanceof ChunkAnvil112) { // only use extensions if old format chunk (1.12) in the new format block-states are saved with extensions - List applicableExtensions = blockStateExtensions.getOrDefault(blockState.getFullId(), Collections.emptyList()); - if (!applicableExtensions.isEmpty()) { - Vector3i pos = new Vector3i(x, y, z); - for (BlockStateExtension ext : applicableExtensions) { - blockState = ext.extend(this, pos, blockState); - } - } - } - - return blockState; - } - - @Override - public BlockProperties getBlockProperties(BlockState blockState) { - return blockPropertiesMapper.get(blockState); - } @Override public MCAChunk getChunkAtBlock(int x, int y, int z) { @@ -166,19 +97,19 @@ public class MCAWorld implements World { @Override public MCAChunk getChunk(int x, int z) { - return getChunk(new Vector2i(x, z)); + return getChunk(vec2i(x, z)); } - public MCAChunk getChunk(Vector2i pos) { + private MCAChunk getChunk(Vector2i pos) { return chunkCache.get(pos); } @Override public MCARegion getRegion(int x, int z) { - return getRegion(new Vector2i(x, z)); + return getRegion(vec2i(x, z)); } - public MCARegion getRegion(Vector2i pos) { + private MCARegion getRegion(Vector2i pos) { return regionCache.get(pos); } @@ -264,42 +195,10 @@ public class MCAWorld implements World { public void cleanUpChunkCache() { chunkCache.cleanUp(); } - - public BlockIdMapper getBlockIdMapper() { - return blockIdMapper; - } - - public BlockPropertiesMapper getBlockPropertiesMapper() { - return blockPropertiesMapper; - } - - public BiomeMapper getBiomeIdMapper() { - return biomeMapper; - } - - public void setBlockIdMapper(BlockIdMapper blockIdMapper) { - this.blockIdMapper = blockIdMapper; - } - - public void setBlockPropertiesMapper(BlockPropertiesMapper blockPropertiesMapper) { - this.blockPropertiesMapper = blockPropertiesMapper; - } - - public void setBiomeMapper(BiomeMapper biomeMapper) { - this.biomeMapper = biomeMapper; - } public Path getWorldFolder() { return worldFolder; } - - public String getForgeBlockIdMapping(int id) { - return forgeBlockMappings.get(id); - } - - public MinecraftVersion getMinecraftVersion() { - return minecraftVersion; - } private Path getRegionFolder() { return worldFolder.resolve("region"); @@ -309,12 +208,6 @@ public class MCAWorld implements World { return getRegionFolder().resolve("r." + regionX + "." + regionZ + ".mca").toFile(); } - private void registerBlockStateExtension(BlockStateExtension extension) { - for (String id : extension.getAffectedBlockIds()) { - this.blockStateExtensions.computeIfAbsent(id, t -> new ArrayList<>()).add(extension); - } - } - private MCARegion loadRegion(Vector2i regionPos) { return loadRegion(regionPos.getX(), regionPos.getY()); } @@ -356,11 +249,11 @@ public class MCAWorld implements World { return MCAChunk.empty(); } - public static MCAWorld load(Path worldFolder, UUID uuid, MinecraftVersion version, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper) throws IOException { - return load(worldFolder, uuid, version, blockIdMapper, blockPropertiesMapper, biomeIdMapper, null, false); + public static MCAWorld load(Path worldFolder, UUID uuid) throws IOException { + return load(worldFolder, uuid, null, false); } - public static MCAWorld load(Path worldFolder, UUID uuid, MinecraftVersion version, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper, String name, boolean ignoreMissingLightData) throws IOException { + public static MCAWorld load(Path worldFolder, UUID uuid, String name, boolean ignoreMissingLightData) throws IOException { try { StringBuilder subDimensionName = new StringBuilder(); @@ -392,37 +285,15 @@ public class MCAWorld implements World { levelData.getInt("SpawnX"), levelData.getInt("SpawnY"), levelData.getInt("SpawnZ") - ); - - MCAWorld world = new MCAWorld( - worldFolder, - uuid, - version, + ); + + return new MCAWorld( + worldFolder, + uuid, name, spawnPoint, - blockIdMapper, - blockPropertiesMapper, - biomeIdMapper, ignoreMissingLightData - ); - - try { - CompoundTag fmlTag = level.getCompoundTag("FML"); - if (fmlTag == null) fmlTag = level.getCompoundTag("fml"); - - ListTag> blockIdReg = fmlTag.getCompoundTag("Registries").getCompoundTag("minecraft:blocks").getListTag("ids"); - for (Tag tag : blockIdReg) { - if (tag instanceof CompoundTag) { - CompoundTag entry = (CompoundTag) tag; - String blockId = entry.getString("K"); - int numeralId = entry.getInt("V"); - - world.forgeBlockMappings.put(numeralId, blockId); - } - } - } catch (NullPointerException ignore) {} - - return world; + ); } catch (ClassCastException | NullPointerException ex) { throw new IOException("Invaid level.dat format!", ex); } @@ -437,4 +308,17 @@ public class MCAWorld implements World { '}'; } + private static final int VEC_2I_CACHE_SIZE = 0x4000; + private static final int VEC_2I_CACHE_MASK = VEC_2I_CACHE_SIZE - 1; + private static final Vector2i[] VEC_2I_CACHE = new Vector2i[VEC_2I_CACHE_SIZE]; + private static Vector2i vec2i(int x, int y) { + int cacheIndex = (x * 1456 ^ y * 948375892) & VEC_2I_CACHE_MASK; + Vector2i possibleMatch = VEC_2I_CACHE[cacheIndex]; + + if (possibleMatch != null && possibleMatch.getX() == x && possibleMatch.getY() == y) + return possibleMatch; + + return VEC_2I_CACHE[cacheIndex] = new Vector2i(x, y); + } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectExtension.java deleted file mode 100644 index d29c5d05..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectExtension.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import java.util.Set; - -import com.flowpowered.math.vector.Vector3i; - -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -public abstract class ConnectExtension implements BlockStateExtension { - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - return state - .with("north", String.valueOf(connectsTo(world, pos.add(Direction.NORTH.toVector())))) - .with("east", String.valueOf(connectsTo(world, pos.add(Direction.EAST.toVector())))) - .with("south", String.valueOf(connectsTo(world, pos.add(Direction.SOUTH.toVector())))) - .with("west", String.valueOf(connectsTo(world, pos.add(Direction.WEST.toVector())))); - } - - public boolean connectsTo(MCAWorld world, Vector3i pos) { - return connectsTo(world, pos, world.getBlockState(pos)); - } - - public boolean connectsTo(MCAWorld world, Vector3i pos, BlockState block) { - return getAffectedBlockIds().contains(block.getFullId()); - } - - @Override - public abstract Set getAffectedBlockIds(); - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectSameOrFullBlockExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectSameOrFullBlockExtension.java deleted file mode 100644 index 275d5514..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/ConnectSameOrFullBlockExtension.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; - -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.world.BlockState; - -public abstract class ConnectSameOrFullBlockExtension extends ConnectExtension { - - @Override - public boolean connectsTo(MCAWorld world, Vector3i pos, BlockState block) { - if (super.connectsTo(world, pos, block)) return true; - - return world.getBlockPropertiesMapper().get(block).isCulling(); - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoorExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoorExtension.java deleted file mode 100644 index 179aa39f..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoorExtension.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -public class DoorExtension implements BlockStateExtension { - private final Set affectedBlockIds; - - public DoorExtension(MinecraftVersion version) { - if (version.isBefore(MinecraftVersion.THE_FLATTENING)) { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:wooden_door", - "minecraft:iron_door", - "minecraft:spruce_door", - "minecraft:birch_door", - "minecraft:jungle_door", - "minecraft:acacia_door", - "minecraft:dark_oak_door" - )); - } else { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:oak_door", - "minecraft:iron_door", - "minecraft:spruce_door", - "minecraft:birch_door", - "minecraft:jungle_door", - "minecraft:acacia_door", - "minecraft:dark_oak_door" - )); - } - } - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - BlockState otherDoor; - - boolean isLower = Objects.equals(state.getProperties().get("half"), "lower"); - - if (isLower) { - otherDoor = world.getBlockState(pos.add(Direction.UP.toVector())); - } else { - otherDoor = world.getBlockState(pos.add(Direction.DOWN.toVector())); - } - - //copy all properties from the other door - for (Entry prop : otherDoor.getProperties().entrySet()) { - if ( - !state.getProperties().containsKey(prop.getKey()) || - (isLower && prop.getKey().equals("hinge")) || - (isLower && prop.getKey().equals("powered")) || - (!isLower && prop.getKey().equals("open")) || - (!isLower && prop.getKey().equals("facing")) - ) { - state = state.with(prop.getKey(), prop.getValue()); - } - } - - return state; - } - - @Override - public Set getAffectedBlockIds() { - return affectedBlockIds; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoubleChestExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoubleChestExtension.java deleted file mode 100644 index 09e1f51b..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoubleChestExtension.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class DoubleChestExtension implements BlockStateExtension { - - private static final Set AFFECTED_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:chest", - "minecraft:trapped_chest" - )); - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - Direction dir = Direction.fromString(state.getProperties().getOrDefault("facing", "north")); - - BlockState left = world.getBlockState(pos.add(dir.left().toVector())); - if (left.getFullId().equals(state.getFullId())) return state.with("type", "right"); - - BlockState right = world.getBlockState(pos.add(dir.right().toVector())); - if (right.getFullId().equals(state.getFullId())) return state.with("type", "left"); - - return state.with("type", "single"); - } - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoublePlantExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoublePlantExtension.java deleted file mode 100644 index 7fae0f51..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/DoublePlantExtension.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.*; - -public class DoublePlantExtension implements BlockStateExtension { - private final Set affectedBlockIds; - - public DoublePlantExtension(MinecraftVersion version) { - if (version.isBefore(MinecraftVersion.THE_FLATTENING)) { - affectedBlockIds = new HashSet<>(Collections.singletonList( - "minecraft:double_plant" - )); - } else { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:sunflower", - "minecraft:lilac", - "minecraft:tall_grass", - "minecraft:large_fern", - "minecraft:rose_bush", - "minecraft:peony" - )); - } - } - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - if (Objects.equals(state.getProperties().get("half"), "upper")) { - BlockState otherPlant = world.getBlockState(pos.add(Direction.DOWN.toVector())); - - return otherPlant.with("half", "upper"); - } - - return state; - } - - @Override - public Set getAffectedBlockIds() { - return affectedBlockIds; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/FireExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/FireExtension.java deleted file mode 100644 index 17c7fa0f..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/FireExtension.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public class FireExtension implements BlockStateExtension { - - private static final Set AFFECTED_BLOCK_IDS = new HashSet<>(Collections.singletonList( - "minecraft:fire" - )); - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - BlockState below = world.getBlockState(pos.add(0, -1, 0)); - - boolean isOnGround = world.getBlockPropertiesMapper().get(below).isCulling(); - for (Direction dir : Direction.values()) { - if (dir != Direction.DOWN) { - if (!isOnGround) { - BlockState neighbor = world.getBlockState(pos.add(dir.toVector())); - - state = state.with(dir.name().toLowerCase(), String.valueOf(!world.getBlockPropertiesMapper().get(neighbor).isCulling())); - } else { - state = state.with(dir.name().toLowerCase(), "false"); - } - } - } - - return state; - } - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/GlassPaneConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/GlassPaneConnectExtension.java deleted file mode 100644 index 352ef0a5..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/GlassPaneConnectExtension.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class GlassPaneConnectExtension extends ConnectSameOrFullBlockExtension { - - private static final HashSet AFFECTED_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:glass_pane", - "minecraft:white_stained_glass_pane", - "minecraft:orange_stained_glass_pane", - "minecraft:magenta_stained_glass_pane", - "minecraft:light_blue_white_stained_glass_pane", - "minecraft:yellow_stained_glass_pane", - "minecraft:lime_stained_glass_pane", - "minecraft:pink_stained_glass_pane", - "minecraft:gray_stained_glass_pane", - "minecraft:light_gray_stained_glass_pane", - "minecraft:cyan_stained_glass_pane", - "minecraft:purple_stained_glass_pane", - "minecraft:blue_stained_glass_pane", - "minecraft:green_stained_glass_pane", - "minecraft:red_stained_glass_pane", - "minecraft:black_stained_glass_pane", - "minecraft:iron_bars" - )); - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/NetherFenceConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/NetherFenceConnectExtension.java deleted file mode 100644 index dfe3f0bd..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/NetherFenceConnectExtension.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public class NetherFenceConnectExtension extends ConnectSameOrFullBlockExtension { - - private static final HashSet AFFECTED_BLOCK_IDS = new HashSet<>(Collections.singletonList( - "minecraft:nether_brick_fence" - )); - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/RedstoneExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/RedstoneExtension.java deleted file mode 100644 index 33c43ac1..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/RedstoneExtension.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public class RedstoneExtension implements BlockStateExtension { - - private static final Set AFFECTED_BLOCK_IDS = new HashSet<>(Collections.singletonList( - "minecraft:redstone_wire" - )); - - - private static final Set CONNECTIBLE = new HashSet<>(Arrays.asList( - "minecraft:redstone_wire", - "minecraft:redstone_wall_torch", - "minecraft:redstone_torch", - "minecraft:stone_button", - "minecraft:oak_button", - "minecraft:stone_button", - "minecraft:lever", - "minecraft:stone_pressure_plate", - "minecraft:oak_pressure_plate", - "minecraft:light_weighted_pressure_plate", - "minecraft:heavy_weighted_pressure_plate" - )); - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - BlockState up = world.getBlockState(pos.add(0, 1, 0)); - boolean upBlocking = !up.equals(BlockState.AIR); - - state = state - .with("north", connection(world, pos, upBlocking, Direction.NORTH)) - .with("east", connection(world, pos, upBlocking, Direction.EAST)) - .with("south", connection(world, pos, upBlocking, Direction.SOUTH)) - .with("west", connection(world, pos, upBlocking, Direction.WEST)); - - return state; - } - - private String connection(MCAWorld world, Vector3i pos, boolean upBlocking, Direction direction) { - Vector3i directionVector = direction.toVector(); - - BlockState next = world.getBlockState(pos.add(directionVector)); - if (CONNECTIBLE.contains(next.getFullId())) return "side"; - - if (next.equals(BlockState.AIR)) { - BlockState nextdown = world.getBlockState(pos.add(directionVector.getX(), directionVector.getY() - 1, directionVector.getZ())); - if (nextdown.getFullId().equals("minecraft:redstone_wire")) return "side"; - } - - if (!upBlocking) { - BlockState nextup = world.getBlockState(pos.add(directionVector.getX(), directionVector.getY() + 1, directionVector.getZ())); - if (nextup.getFullId().equals("minecraft:redstone_wire")) return "up"; - } - - return "none"; - } - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/SnowyExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/SnowyExtension.java deleted file mode 100644 index b03cc95f..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/SnowyExtension.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class SnowyExtension implements BlockStateExtension { - - private final Set affectedBlockIds; - - private final String snowLayerId; - private final String snowBlockId; - - public SnowyExtension(MinecraftVersion version) { - if (version.isBefore(MinecraftVersion.THE_FLATTENING)) { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:grass", - "minecraft:mycelium" - )); - snowLayerId = "minecraft:snow_layer"; - snowBlockId = "minecraft:snow"; - } else { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:grass_block", - "minecraft:podzol" - )); - snowLayerId = "minecraft:snow"; - snowBlockId = "minecraft:snow_block"; - } - } - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - BlockState above = world.getBlockState(pos.add(0, 1, 0)); - - if (above.getFullId().equals(snowLayerId) || above.getFullId().equals(snowBlockId)) { - return state.with("snowy", "true"); - } else { - return state.with("snowy", "false"); - } - } - - @Override - public Set getAffectedBlockIds() { - return affectedBlockIds; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/StairShapeExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/StairShapeExtension.java deleted file mode 100644 index 38782bd5..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/StairShapeExtension.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class StairShapeExtension implements BlockStateExtension { - - private static final Set AFFECTED_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:oak_stairs", - "minecraft:cobblestone_stairs", - "minecraft:brick_stairs", - "minecraft:stone_brick_stairs", - "minecraft:nether_brick_stairs", - "minecraft:sandstone_stairs", - "minecraft:spruce_stairs", - "minecraft:birch_stairs", - "minecraft:jungle_stairs", - "minecraft:quartz_stairs", - "minecraft:acacia_stairs", - "minecraft:dark_oak_stairs", - "minecraft:red_sandstone_stairs", - "minecraft:purpur_stairs" - )); - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - try { - Direction facing = Direction.fromString(state.getProperties().get("facing")); - BlockState back = world.getBlockState(pos.add(facing.toVector())); - - if (isStairs(back) && state.getProperties().get("half").equals(back.getProperties().get("half"))) { - Direction backFacing = Direction.fromString(back.getProperties().get("facing")); - - if (facing.getAxis() != backFacing.getAxis()){ - BlockState next = world.getBlockState(pos.add(backFacing.opposite().toVector())); - - if (!isStairs(next) || !isEqualStairs(state, next)) { - - if (backFacing == facing.left()){ - return state.with("shape", "outer_left"); - } - - return state.with("shape", "outer_right"); - } - } - } - - BlockState front = world.getBlockState(pos.add(facing.opposite().toVector())); - - if (isStairs(front) && state.getProperties().get("half").equals(front.getProperties().get("half"))) { - Direction frontFacing = Direction.fromString(front.getProperties().get("facing")); - - if (facing.getAxis() != frontFacing.getAxis()){ - BlockState next = world.getBlockState(pos.add(frontFacing.toVector())); - - if (!isStairs(next) || !isEqualStairs(state, next)) { - if (frontFacing == facing.left()){ - return state.with("shape", "inner_left"); - } - - return state.with("shape", "inner_right"); - } - } - } - - return state.with("shape", "straight"); - - } catch (IllegalArgumentException | NullPointerException ex) { - return state.with("shape", "straight"); - } - } - - private boolean isStairs(BlockState state) { - return AFFECTED_BLOCK_IDS.contains(state.getFullId()); - } - - private boolean isEqualStairs(BlockState stair1, BlockState stair2) { - return - stair1.getProperties().get("facing").equals(stair2.getProperties().get("facing")) && - stair1.getProperties().get("half").equals(stair2.getProperties().get("half")); - } - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WallConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WallConnectExtension.java deleted file mode 100644 index ff0f0148..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WallConnectExtension.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.util.Direction; -import de.bluecolored.bluemap.core.world.BlockState; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class WallConnectExtension extends ConnectSameOrFullBlockExtension { - - private static final HashSet AFFECTED_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:cobblestone_wall", - "minecraft:mossy_cobblestone_wall" - )); - - @Override - public BlockState extend(MCAWorld world, Vector3i pos, BlockState state) { - state = super.extend(world, pos, state); - - if ( - Objects.equals(state.getProperties().get("north"), state.getProperties().get("south")) && - Objects.equals(state.getProperties().get("east"), state.getProperties().get("west")) && - !Objects.equals(state.getProperties().get("north"), state.getProperties().get("east")) && - !connectsTo(world, pos.add(Direction.UP.toVector())) - ) { - return state.with("up", "false"); - } else { - return state.with("up", "true"); - } - } - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WoodenFenceConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WoodenFenceConnectExtension.java deleted file mode 100644 index e70ac9d1..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/WoodenFenceConnectExtension.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.extensions; - -import de.bluecolored.bluemap.core.MinecraftVersion; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class WoodenFenceConnectExtension extends ConnectSameOrFullBlockExtension { - - private final Set affectedBlockIds; - - public WoodenFenceConnectExtension(MinecraftVersion version) { - if (version.isBefore(MinecraftVersion.THE_FLATTENING)) { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:fence", - "minecraft:spruce_fence", - "minecraft:birch_fence", - "minecraft:jungle_fence", - "minecraft:dark_oak_fence", - "minecraft:acacia_fence" - )); - } else { - affectedBlockIds = new HashSet<>(Arrays.asList( - "minecraft:oak_fence", - "minecraft:spruce_fence", - "minecraft:birch_fence", - "minecraft:jungle_fence", - "minecraft:dark_oak_fence", - "minecraft:acacia_fence" - )); - } - } - - @Override - public Set getAffectedBlockIds() { - return affectedBlockIds; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java deleted file mode 100644 index 9af9ca0d..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.mapping; - -import de.bluecolored.bluemap.core.world.BlockState; - -public interface BlockIdMapper { - - BlockState get(int id, int meta); - - BlockState get(String id, int numeralId, int meta); - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockPropertiesMapper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockPropertiesMapper.java deleted file mode 100644 index b0efdf61..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockPropertiesMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.mca.mapping; - -import de.bluecolored.bluemap.core.world.BlockProperties; -import de.bluecolored.bluemap.core.world.BlockState; - -@FunctionalInterface -public interface BlockPropertiesMapper { - - BlockProperties get(BlockState blockState); - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/model/Face.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/model/Face.java index 02ed76fd..776a1f39 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/model/Face.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/model/Face.java @@ -28,7 +28,6 @@ import com.flowpowered.math.imaginary.Quaternionf; import com.flowpowered.math.matrix.Matrix3f; import com.flowpowered.math.vector.Vector2f; import com.flowpowered.math.vector.Vector3f; -import de.bluecolored.bluemap.core.util.MathUtils; @Deprecated public class Face { @@ -51,7 +50,7 @@ public class Face { this.materialIndex = materialIndex; - this.n1 = getFaceNormal(); + this.n1 = calculateSurfaceNormal(new VectorM3f(0, 0, 0)); this.n2 = new VectorM3f(n1); this.n3 = new VectorM3f(n1); this.normalizedNormals = true; @@ -202,10 +201,6 @@ public class Face { this.materialIndex = materialIndex; } - private VectorM3f getFaceNormal() { - return MathUtils.getSurfaceNormal(p1, p2, p3); - } - private void normalizeNormals() { if (normalizedNormals) return; @@ -216,4 +211,31 @@ public class Face { normalizedNormals = true; } + private VectorM3f calculateSurfaceNormal( + VectorM3f target + ){ + double + p1x = p1.x, p1y = p1.y, p1z = p1.z, + p2x = p2.x, p2y = p2.y, p2z = p2.z, + p3x = p3.x, p3y = p3.y, p3z = p3.z; + + p2x -= p1x; p2y -= p1y; p2z -= p1z; + p3x -= p1x; p3y -= p1y; p3z -= p1z; + + p1x = p2y * p3z - p2z * p3y; + p1y = p2z * p3x - p2x * p3z; + p1z = p2x * p3y - p2y * p3x; + + double length = Math.sqrt(p1x * p1x + p1y * p1y + p1z * p1z); + p1x /= length; + p1y /= length; + p1z /= length; + + target.x = (float) p1x; + target.y = (float) p1y; + target.z = (float) p1z; + + return target; + } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BiomeMapper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BiomeConfig.java similarity index 55% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BiomeMapper.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BiomeConfig.java index a8563f08..f35daa4d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BiomeMapper.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BiomeConfig.java @@ -22,13 +22,52 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.mca.mapping; +package de.bluecolored.bluemap.core.resourcepack; import de.bluecolored.bluemap.core.world.Biome; +import org.spongepowered.configurate.ConfigurationNode; -@FunctionalInterface -public interface BiomeMapper { +import java.util.Map.Entry; + +public class BiomeConfig { + + private Biome[] biomes; + + public BiomeConfig() { + biomes = new Biome[10]; + } + + public void load(ConfigurationNode node) { + for (Entry e : node.childrenMap().entrySet()){ + String id = e.getKey().toString(); + Biome biome = Biome.create(id, e.getValue()); + + int numeralId = biome.getNumeralId(); + ensureAvailability(numeralId); + biomes[numeralId] = biome; + } + } + + public Biome getBiome(int id) { + if (id < biomes.length) { + Biome biome = biomes[id]; + return biome != null ? biome : Biome.DEFAULT; + } + + return Biome.DEFAULT; + } + + private void ensureAvailability(int id) { + if (id >= biomes.length) { + int newSize = biomes.length; + do { + newSize = (int) (newSize * 1.5) + 1; + } while (id >= newSize); + + Biome[] newArray = new Biome[newSize]; + System.arraycopy(biomes, 0, newArray, 0, biomes.length); + biomes = newArray; + } + } - Biome get(int id); - } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockColorCalculatorFactory.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockColorCalculatorFactory.java index f4fc1925..0f04a5cb 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockColorCalculatorFactory.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockColorCalculatorFactory.java @@ -29,7 +29,7 @@ import de.bluecolored.bluemap.core.debug.DebugDump; import de.bluecolored.bluemap.core.util.ConfigUtils; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.world.Biome; -import de.bluecolored.bluemap.core.world.Block; +import de.bluecolored.bluemap.core.world.BlockNeighborhood; import org.spongepowered.configurate.ConfigurationNode; import java.awt.image.BufferedImage; @@ -40,21 +40,16 @@ import java.util.Map.Entry; @DebugDump public class BlockColorCalculatorFactory { - private BufferedImage foliageMap; - private BufferedImage grassMap; + private final int[] foliageMap = new int[65536]; + private final int[] grassMap = new int[65536]; private final Map blockColorMap; - public BlockColorCalculatorFactory(BufferedImage foliageMap, BufferedImage grassMap) { - this.foliageMap = foliageMap; - this.grassMap = grassMap; - + public BlockColorCalculatorFactory() { this.blockColorMap = new HashMap<>(); } - public void loadColorConfig(ConfigurationNode colorConfig) { - blockColorMap.clear(); - + public void load(ConfigurationNode colorConfig) { for (Entry entry : colorConfig.childrenMap().entrySet()){ String key = entry.getKey().toString(); String value = entry.getValue().getString(""); @@ -85,19 +80,11 @@ public class BlockColorCalculatorFactory { } public void setFoliageMap(BufferedImage foliageMap) { - this.foliageMap = foliageMap; - } - - public BufferedImage getFoliageMap() { - return foliageMap; + foliageMap.getRGB(0, 0, 256, 256, this.foliageMap, 0, 256); } public void setGrassMap(BufferedImage grassMap) { - this.grassMap = grassMap; - } - - public BufferedImage getGrassMap() { - return grassMap; + grassMap.getRGB(0, 0, 256, 256, this.grassMap, 0, 256); } public BlockColorCalculator createCalculator() { @@ -106,14 +93,14 @@ public class BlockColorCalculatorFactory { @FunctionalInterface private interface ColorFunction { - Color invoke(BlockColorCalculator calculator, Block block, Color target); + Color invoke(BlockColorCalculator calculator, BlockNeighborhood block, Color target); } public class BlockColorCalculator { private final Color tempColor = new Color(); - public Color getBlockColor(Block block, Color target) { + public Color getBlockColor(BlockNeighborhood block, Color target) { String blockId = block.getBlockState().getFullId(); ColorFunction colorFunction = blockColorMap.get(blockId); @@ -123,7 +110,7 @@ public class BlockColorCalculatorFactory { return colorFunction.invoke(this, block, target); } - public Color getRedstoneColor(Block block, Color target) { + public Color getRedstoneColor(BlockNeighborhood block, Color target) { String powerString = block.getBlockState().getProperties().get("power"); int power = 15; @@ -137,25 +124,23 @@ public class BlockColorCalculatorFactory { ); } - public Color getWaterAverageColor(Block block, Color target) { + public Color getWaterAverageColor(BlockNeighborhood block, Color target) { target.set(0, 0, 0, 0, true); int x, y, z, - minX = block.getX() - 2, - maxX = block.getX() + 2, - minY = block.getY() - 1, - maxY = block.getY() + 1, - minZ = block.getZ() - 2, - maxZ = block.getZ() + 2; + minX = - 2, + maxX = + 2, + minY = - 1, + maxY = + 1, + minZ = - 2, + maxZ = + 2; + Biome biome; for (x = minX; x <= maxX; x++) { for (y = minY; y <= maxY; y++) { for (z = minZ; z <= maxZ; z++) { - target.add(block - .getWorld() - .getBiome(x, y, z) - .getWaterColor() - ); + biome = block.getNeighborBlock(x, y, z).getBiome(); + target.add(biome.getWaterColor()); } } } @@ -163,28 +148,23 @@ public class BlockColorCalculatorFactory { return target.flatten(); } - public Color getFoliageAverageColor(Block block, Color target) { + public Color getFoliageAverageColor(BlockNeighborhood block, Color target) { target.set(0, 0, 0, 0, true); int x, y, z, - minX = block.getX() - 2, - maxX = block.getX() + 2, - minY = block.getY() - 1, - maxY = block.getY() + 1, - minZ = block.getZ() - 2, - maxZ = block.getZ() + 2; + minX = - 2, + maxX = + 2, + minY = - 1, + maxY = + 1, + minZ = - 2, + maxZ = + 2; - int seaLevel = block.getWorld().getSeaLevel(); - int blocksAboveSeaLevel; Biome biome; - for (y = minY; y <= maxY; y++) { - blocksAboveSeaLevel = Math.max(block.getY() - seaLevel, 0); - for (x = minX; x <= maxX; x++) { for (z = minZ; z <= maxZ; z++) { - biome = block.getWorld().getBiome(x, y, z); - target.add(getFoliageColor(biome, blocksAboveSeaLevel, tempColor)); + biome = block.getNeighborBlock(x, y, z).getBiome(); + target.add(getFoliageColor(biome, tempColor)); } } } @@ -192,33 +172,28 @@ public class BlockColorCalculatorFactory { return target.flatten(); } - public Color getFoliageColor(Biome biome, int blocksAboveSeaLevel, Color target) { - getColorFromMap(biome, blocksAboveSeaLevel, foliageMap, target); + public Color getFoliageColor(Biome biome, Color target) { + getColorFromMap(biome, foliageMap, 4764952, target); return target.overlay(biome.getOverlayFoliageColor()); } - public Color getGrassAverageColor(Block block, Color target) { + public Color getGrassAverageColor(BlockNeighborhood block, Color target) { target.set(0, 0, 0, 0, true); int x, y, z, - minX = block.getX() - 2, - maxX = block.getX() + 2, - minY = block.getY() - 1, - maxY = block.getY() + 1, - minZ = block.getZ() - 2, - maxZ = block.getZ() + 2; + minX = - 2, + maxX = + 2, + minY = - 1, + maxY = + 1, + minZ = - 2, + maxZ = + 2; - int seaLevel = block.getWorld().getSeaLevel(); - int blocksAboveSeaLevel; Biome biome; - for (y = minY; y <= maxY; y++) { - blocksAboveSeaLevel = Math.max(block.getY() - seaLevel, 0); - for (x = minX; x <= maxX; x++) { for (z = minZ; z <= maxZ; z++) { - biome = block.getWorld().getBiome(x, y, z); - target.add(getGrassColor(biome, blocksAboveSeaLevel, tempColor)); + biome = block.getNeighborBlock(x, y, z).getBiome(); + target.add(getGrassColor(biome, tempColor)); } } } @@ -226,24 +201,22 @@ public class BlockColorCalculatorFactory { return target.flatten(); } - public Color getGrassColor(Biome biome, int blocksAboveSeaLevel, Color target) { - getColorFromMap(biome, blocksAboveSeaLevel, grassMap, target); + public Color getGrassColor(Biome biome, Color target) { + getColorFromMap(biome, grassMap, 0xff52952f, target); return target.overlay(biome.getOverlayGrassColor()); } - private void getColorFromMap(Biome biome, int blocksAboveSeaLevel, BufferedImage map, Color target) { - float adjTemp = (float) GenericMath.clamp(biome.getTemp() - (0.00166667 * blocksAboveSeaLevel), 0, 1); - float adjHumidity = (float) GenericMath.clamp(biome.getHumidity(), 0, 1) * adjTemp; + private void getColorFromMap(Biome biome, int[] colorMap, int defaultColor, Color target) { + double temperature = GenericMath.clamp(biome.getTemp(), 0, 1); + double humidity = GenericMath.clamp(biome.getHumidity(), 0, 1) * temperature; - int x = (int) ((1 - adjTemp) * map.getWidth()); - int y = (int) ((1 - adjHumidity) * map.getHeight()); + int x = (int) ((1.0 - temperature) * 255.0); + int y = (int) ((1.0 - humidity) * 255.0); - int cValue = map.getRGB( - GenericMath.clamp(x, 0, map.getWidth() - 1), - GenericMath.clamp(y, 0, map.getHeight() - 1) - ); + int index = y << 8 | x; + int color = index >= colorMap.length ? defaultColor : colorMap[index]; - target.set(cValue); + target.set(color); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockPropertiesConfig.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockPropertiesConfig.java new file mode 100644 index 00000000..75122ec5 --- /dev/null +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockPropertiesConfig.java @@ -0,0 +1,82 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.bluecolored.bluemap.core.resourcepack; + +import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.world.BlockProperties; +import de.bluecolored.bluemap.core.world.BlockState; +import org.spongepowered.configurate.ConfigurationNode; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; + +public class BlockPropertiesConfig { + + private final Map>> mappings; + + public BlockPropertiesConfig() { + mappings = new ConcurrentHashMap<>(); + } + + public void load(ConfigurationNode node) { + for (Entry e : node.childrenMap().entrySet()){ + String key = e.getKey().toString(); + try { + BlockState bsKey = BlockState.fromString(key); + BlockProperties.Builder bsValueBuilder = BlockProperties.builder(); + + readBool(e.getValue().node("culling"), bsValueBuilder::culling); + readBool(e.getValue().node("occluding"), bsValueBuilder::occluding); + readBool(e.getValue().node("alwaysWaterlogged"), bsValueBuilder::alwaysWaterlogged); + readBool(e.getValue().node("randomOffset"), bsValueBuilder::randomOffset); + + BlockStateMapping mapping = new BlockStateMapping<>(bsKey, bsValueBuilder.build()); + mappings.computeIfAbsent(bsKey.getFullId(), k -> new LinkedList<>()).add(0, mapping); + } catch (IllegalArgumentException ex) { + Logger.global.logWarning("Loading BlockPropertiesConfig: Failed to parse BlockState from key '" + key + "'"); + } + } + } + + private void readBool(ConfigurationNode node, Consumer target) { + if (!node.virtual()) target.accept(node.getBoolean()); + } + + public BlockProperties getBlockProperties(BlockState from){ + for (BlockStateMapping bm : mappings.getOrDefault(from.getFullId(), Collections.emptyList())){ + if (bm.fitsTo(from)){ + return bm.getMapping(); + } + } + + return BlockProperties.DEFAULT; + } + +} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockStateMapping.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateMapping.java similarity index 97% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockStateMapping.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateMapping.java index 6acf2109..6021b303 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockStateMapping.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateMapping.java @@ -22,12 +22,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.config; - -import java.util.Map.Entry; +package de.bluecolored.bluemap.core.resourcepack; import de.bluecolored.bluemap.core.world.BlockState; +import java.util.Map.Entry; + class BlockStateMapping { private BlockState blockState; private T mapping; @@ -59,5 +59,5 @@ class BlockStateMapping { public T getMapping(){ return mapping; } - + } \ No newline at end of file diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ResourcePack.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ResourcePack.java index 53a5a12d..3efc6a85 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ResourcePack.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ResourcePack.java @@ -24,83 +24,64 @@ */ package de.bluecolored.bluemap.core.resourcepack; -import de.bluecolored.bluemap.core.MinecraftVersion; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.debug.DebugDump; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resourcepack.BlockStateResource.Builder; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.BlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockstate.BlockStateResource; +import de.bluecolored.bluemap.core.resourcepack.blockstate.BlockStateResource.Builder; import de.bluecolored.bluemap.core.resourcepack.fileaccess.BluemapAssetOverrideFileAccess; import de.bluecolored.bluemap.core.resourcepack.fileaccess.CaseInsensitiveFileAccess; import de.bluecolored.bluemap.core.resourcepack.fileaccess.CombinedFileAccess; import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess; +import de.bluecolored.bluemap.core.resourcepack.texture.Texture; +import de.bluecolored.bluemap.core.resourcepack.texture.TextureGallery; +import de.bluecolored.bluemap.core.util.Tristate; +import de.bluecolored.bluemap.core.world.Biome; +import de.bluecolored.bluemap.core.world.BlockProperties; import de.bluecolored.bluemap.core.world.BlockState; import org.apache.commons.io.output.ByteArrayOutputStream; +import org.spongepowered.configurate.gson.GsonConfigurationLoader; import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.io.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; /** * Represents all resources (BlockStates / BlockModels and Textures) that are loaded and used to generate map-models. */ @DebugDump public class ResourcePack { - - private static final String[] CONFIG_FILES = { - "blockColors.json", - "blockIds.json", - "blockProperties.json", - "biomes.json" - }; - - private final MinecraftVersion minecraftVersion; - - protected final Map blockStateResources; - protected final Map blockModelResources; - protected final TextureGallery textures; - - private final BlockColorCalculatorFactory blockColorCalculatorFactory; - - private final Map> configs; - private BufferedImage foliageMap; - private BufferedImage grassMap; - - public ResourcePack(MinecraftVersion minecraftVersion) { - this.minecraftVersion = minecraftVersion; - + private final Map blockStateResources; + private final Map blockModelResources; + private final TextureGallery textures; + + private final BlockPropertiesConfig blockPropertiesConfig; + private final BiomeConfig biomeConfig; + private final BlockColorCalculatorFactory blockColorCalculatorFactory; + + private final LoadingCache blockPropertiesCache; + + public ResourcePack() { blockStateResources = new HashMap<>(); blockModelResources = new HashMap<>(); textures = new TextureGallery(); - foliageMap = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - foliageMap.setRGB(0, 0, 0xFF00FF00); - grassMap = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - grassMap.setRGB(0, 0, 0xFF00FF00); - blockColorCalculatorFactory = new BlockColorCalculatorFactory(foliageMap, grassMap); - configs = new HashMap<>(); - } - - /** - * Returns all config-files found in the namespaces of the ResourcePack with that filename - */ - public Collection getConfigAdditions(String configFileName){ - return configs.getOrDefault(configFileName, Collections.emptyList()); - } - - /** - * See {@link TextureGallery#loadTextureFile(File)} - * @see TextureGallery#loadTextureFile(File) - */ - public void loadTextureFile(File file) throws IOException, ParseResourceException { - textures.loadTextureFile(file); - } - - /** - * See {@link TextureGallery#saveTextureFile(File)} - * @see TextureGallery#saveTextureFile(File) - */ - public void saveTextureFile(File file) throws IOException { - textures.saveTextureFile(file); + + blockPropertiesConfig = new BlockPropertiesConfig(); + biomeConfig = new BiomeConfig(); + blockColorCalculatorFactory = new BlockColorCalculatorFactory(); + + blockPropertiesCache = Caffeine.newBuilder() + .executor(BlueMap.THREAD_POOL) + .maximumSize(10000) + .build(this::getBlockPropertiesNoCache); } /** @@ -159,37 +140,61 @@ public class ResourcePack { String filename = FileAccess.getFileName(blockstateFile); if (!filename.endsWith(".json")) continue; + String jsonFileName = filename.substring(0, filename.length() - 5); try { - blockStateResources.put(namespace + ":" + filename.substring(0, filename.length() - 5), builder.build(blockstateFile)); + blockStateResources.put(namespace + ":" + jsonFileName, builder.build(blockstateFile)); } catch (IOException ex) { - Logger.global.logError("Failed to load blockstate: " + namespace + ":" + filename.substring(0, filename.length() - 5), ex); + Logger.global.logError("Failed to load blockstate: " + namespace + ":" + jsonFileName, ex); } } - - //load configs - for (String configName : CONFIG_FILES) { - try { - Resource config = new Resource(sourcesAccess.readFile( - "assets/" + namespace + "/" + configName)); - configs.computeIfAbsent(configName, t -> new ArrayList<>()).add(config); - } catch (FileNotFoundException ignore) { - } catch (IOException ex) { - Logger.global.logError("Failed to load config for " + namespace + ": " + configName, ex); - } + + //load biomes + try { + GsonConfigurationLoader loader = GsonConfigurationLoader.builder() + .source(() -> new BufferedReader(new InputStreamReader(sourcesAccess.readFile( + "assets/" + namespace + "/biomes.json")))) + .build(); + biomeConfig.load(loader.load()); + } catch (IOException ex) { + Logger.global.logError("Failed to load biomes.conf from: " + namespace, ex); + } + + //load block properties + try { + GsonConfigurationLoader loader = GsonConfigurationLoader.builder() + .source(() -> new BufferedReader(new InputStreamReader(sourcesAccess.readFile( + "assets/" + namespace + "/blockProperties.json")))) + .build(); + blockPropertiesConfig.load(loader.load()); + } catch (IOException ex) { + Logger.global.logError("Failed to load biomes.conf from: " + namespace, ex); + } + + //load block colors + try { + GsonConfigurationLoader loader = GsonConfigurationLoader.builder() + .source(() -> new BufferedReader(new InputStreamReader(sourcesAccess.readFile( + "assets/" + namespace + "/blockColors.json")))) + .build(); + blockColorCalculatorFactory.load(loader.load()); + } catch (IOException ex) { + Logger.global.logError("Failed to load biomes.conf from: " + namespace, ex); } } try { - foliageMap = ImageIO.read(sourcesAccess.readFile("assets/minecraft/textures/colormap/foliage.png")); - blockColorCalculatorFactory.setFoliageMap(foliageMap); - } catch (IOException ex) { + blockColorCalculatorFactory.setFoliageMap( + ImageIO.read(sourcesAccess.readFile("assets/minecraft/textures/colormap/foliage.png")) + ); + } catch (IOException | ArrayIndexOutOfBoundsException ex) { Logger.global.logError("Failed to load foliagemap!", ex); } try { - grassMap = ImageIO.read(sourcesAccess.readFile("assets/minecraft/textures/colormap/grass.png")); - blockColorCalculatorFactory.setGrassMap(grassMap); - } catch (IOException ex) { + blockColorCalculatorFactory.setGrassMap( + ImageIO.read(sourcesAccess.readFile("assets/minecraft/textures/colormap/grass.png")) + ); + } catch (IOException | ArrayIndexOutOfBoundsException ex) { Logger.global.logError("Failed to load grassmap!", ex); } @@ -197,6 +202,22 @@ public class ResourcePack { Logger.global.logError("Failed to close FileAccess!", ex); } } + + /** + * See {@link TextureGallery#loadTextureFile(File)} + * @see TextureGallery#loadTextureFile(File) + */ + public void loadTextureFile(File file) throws IOException, ParseResourceException { + textures.loadTextureFile(file); + } + + /** + * See {@link TextureGallery#saveTextureFile(File)} + * @see TextureGallery#saveTextureFile(File) + */ + public void saveTextureFile(File file) throws IOException { + textures.saveTextureFile(file); + } /** * Returns a {@link BlockStateResource} for the given {@link BlockState} if found. @@ -209,16 +230,48 @@ public class ResourcePack { if (resource == null) throw new NoSuchResourceException("No resource for blockstate: " + state.getFullId()); return resource; } - + + public BlockProperties getBlockProperties(BlockState state) { + return blockPropertiesCache.get(state); + } + + private BlockProperties getBlockPropertiesNoCache(BlockState state) { + BlockProperties.Builder props = blockPropertiesConfig.getBlockProperties(state).toBuilder(); + + if (props.isOccluding() == Tristate.UNDEFINED || props.isCulling() == Tristate.UNDEFINED) { + try { + BlockStateResource resource = getBlockStateResource(state); + for (TransformedBlockModelResource bmr : resource.getModels(state, new ArrayList<>())) { + if (props.isOccluding() == Tristate.UNDEFINED) props.occluding(bmr.getModel().isOccluding()); + if (props.isCulling() == Tristate.UNDEFINED) props.culling(bmr.getModel().isCulling()); + } + } catch (NoSuchResourceException ignore) {} + } + + return props.build(); + } + + public Biome getBiome(int id) { + return biomeConfig.getBiome(id); + } + + public Map getBlockStateResources() { + return blockStateResources; + } + + public Map getBlockModelResources() { + return blockModelResources; + } + + public TextureGallery getTextures() { + return textures; + } + public BlockColorCalculatorFactory getBlockColorCalculatorFactory() { return blockColorCalculatorFactory; } - - public MinecraftVersion getMinecraftVersion() { - return minecraftVersion; - } - - protected static String namespacedToAbsoluteResourcePath(String namespacedPath, String resourceTypeFolder) { + + public static String namespacedToAbsoluteResourcePath(String namespacedPath, String resourceTypeFolder) { String path = namespacedPath; resourceTypeFolder = FileAccess.normalize(resourceTypeFolder); @@ -246,7 +299,7 @@ public class ResourcePack { private final byte[] data; - public Resource(InputStream data) throws FileNotFoundException, IOException { + public Resource(InputStream data) throws IOException { try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { bout.write(data); this.data = bout.toByteArray(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockModelResource.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/BlockModelResource.java similarity index 95% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockModelResource.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/BlockModelResource.java index fe83444e..bfa5258d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockModelResource.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/BlockModelResource.java @@ -22,13 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.blockmodel; import com.flowpowered.math.TrigMath; import com.flowpowered.math.vector.Vector3f; import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector4f; -import de.bluecolored.bluemap.core.resourcepack.BlockModelResource.Element.Face; +import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; +import de.bluecolored.bluemap.core.resourcepack.texture.Texture; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.BlockModelResource.Element.Face; import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess; import de.bluecolored.bluemap.core.util.Direction; import de.bluecolored.bluemap.core.util.math.Axis; @@ -45,13 +48,13 @@ public class BlockModelResource { private static final double FIT_TO_BLOCK_SCALE_MULTIPLIER = 2 - Math.sqrt(2); private ModelType modelType = ModelType.NORMAL; - + private boolean culling = false; - private boolean occluding = false; - - private boolean ambientOcclusion = true; - private Collection elements = new ArrayList<>(); - private Map textures = new HashMap<>(); + private boolean occluding = false; + + private final boolean ambientOcclusion = true; //TODO: wat? + private final Collection elements = new ArrayList<>(); + private final Map textures = new HashMap<>(); private BlockModelResource() {} @@ -477,9 +480,9 @@ public class BlockModelResource { Texture texture; try { - texture = resourcePack.textures.get(path); + texture = resourcePack.getTextures().get(path); } catch (NoSuchElementException ex) { - texture = resourcePack.textures.loadTexture(sourcesAccess, path); + texture = resourcePack.getTextures().loadTexture(sourcesAccess, path); } return texture; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ModelType.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/ModelType.java similarity index 95% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ModelType.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/ModelType.java index 26a13a94..128aa480 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/ModelType.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/ModelType.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.blockmodel; public enum ModelType { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TransformedBlockModelResource.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/TransformedBlockModelResource.java similarity index 97% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TransformedBlockModelResource.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/TransformedBlockModelResource.java index c44bcb4f..e42f2c14 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TransformedBlockModelResource.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockmodel/TransformedBlockModelResource.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.blockmodel; import com.flowpowered.math.vector.Vector2f; import de.bluecolored.bluemap.core.util.math.MatrixM3f; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/BlockStateResource.java similarity index 87% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/BlockStateResource.java index 0873eb11..8996d5c5 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/BlockStateResource.java @@ -22,19 +22,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.blockstate; import com.flowpowered.math.vector.Vector2f; -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.MinecraftVersion; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resourcepack.PropertyCondition.All; +import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.BlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; +import de.bluecolored.bluemap.core.resourcepack.blockstate.PropertyCondition.All; import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess; -import de.bluecolored.bluemap.core.util.MathUtils; import de.bluecolored.bluemap.core.world.BlockState; +import org.apache.commons.lang3.StringUtils; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.gson.GsonConfigurationLoader; -import org.apache.commons.lang3.StringUtils; import java.io.BufferedReader; import java.io.IOException; @@ -46,8 +47,6 @@ import java.util.Map.Entry; public class BlockStateResource { - private static final MinecraftVersion NEW_MODEL_PATH_VERSION = new MinecraftVersion(1, 13); - private final List variants = new ArrayList<>(0); private final Collection multipart = new ArrayList<>(0); @@ -92,53 +91,6 @@ public class BlockStateResource { return targetCollection; } - private static class Variant { - - private PropertyCondition condition = PropertyCondition.all(); - private Collection> models = new ArrayList<>(); - - private double totalWeight; - - private Variant() { - } - - public TransformedBlockModelResource getModel(int x, int y, int z) { - if (models.isEmpty()) throw new IllegalStateException("A variant must have at least one model!"); - - double selection = MathUtils.hashToFloat(x, y, z, 827364) * totalWeight; // random based on position - for (Weighted w : models) { - selection -= w.weight; - if (selection <= 0) return w.value; - } - - throw new RuntimeException("This line should never be reached!"); - } - - public void checkValid() throws ParseResourceException { - if (models.isEmpty()) throw new ParseResourceException("A variant must have at least one model!"); - } - - public void updateTotalWeight() { - totalWeight = 0d; - for (Weighted w : models) { - totalWeight += w.weight; - } - } - - } - - private static class Weighted { - - private final T value; - private final double weight; - - public Weighted(T value, double weight) { - this.value = value; - this.weight = weight; - } - - } - public static Builder builder(FileAccess sourcesAccess, ResourcePack resourcePack) { return new Builder(sourcesAccess, resourcePack); } @@ -241,16 +193,9 @@ public class BlockStateResource { String namespacedModelPath = node.node("model").getString(); if (namespacedModelPath == null) throw new ParseResourceException("No model defined!"); - - - String modelPath; - if (resourcePack.getMinecraftVersion().isBefore(NEW_MODEL_PATH_VERSION)) { - modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models/block") + ".json"; - }else { - modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models") + ".json"; - } - BlockModelResource model = resourcePack.blockModelResources.get(modelPath); + String modelPath = ResourcePack.namespacedToAbsoluteResourcePath(namespacedModelPath, "models") + ".json"; + BlockModelResource model = resourcePack.getBlockModelResources().get(modelPath); if (model == null) { BlockModelResource.Builder builder = BlockModelResource.builder(sourcesAccess, resourcePack); try { @@ -260,7 +205,7 @@ public class BlockStateResource { throw new ParseResourceException("Failed to load model " + modelPath, e); } - resourcePack.blockModelResources.put(modelPath, model); + resourcePack.getBlockModelResources().put(modelPath, model); } Vector2f rotation = new Vector2f(node.node("x").getFloat(0), node.node("y").getFloat(0)); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/TripwireConnectExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Conditional.java similarity index 74% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/TripwireConnectExtension.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Conditional.java index fbec3254..cf49c455 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/TripwireConnectExtension.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Conditional.java @@ -22,21 +22,24 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.mca.extensions; +package de.bluecolored.bluemap.core.resourcepack.blockstate; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +public class Conditional { -public class TripwireConnectExtension extends ConnectExtension { + private final PropertyCondition condition; + private final T value; - private static final HashSet AFFECTED_BLOCK_IDS = new HashSet<>(Collections.singletonList( - "minecraft:tripwire" - )); - - @Override - public Set getAffectedBlockIds() { - return AFFECTED_BLOCK_IDS; - } + public Conditional(PropertyCondition condition, T value) { + this.condition = condition; + this.value = value; + } + + public PropertyCondition getCondition() { + return condition; + } + + public T getValue() { + return value; + } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/PropertyCondition.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/PropertyCondition.java similarity index 90% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/PropertyCondition.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/PropertyCondition.java index cc8ad49d..1ade1599 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/PropertyCondition.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/PropertyCondition.java @@ -22,12 +22,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.blockstate; import de.bluecolored.bluemap.core.util.Preconditions; import de.bluecolored.bluemap.core.world.BlockState; +import java.util.Map; + @FunctionalInterface public interface PropertyCondition { @@ -35,7 +37,7 @@ public interface PropertyCondition { PropertyCondition MATCH_NONE = new None(); boolean matches(BlockState state); - + class Property implements PropertyCondition { private final String key; @@ -151,5 +153,18 @@ public interface PropertyCondition { return or(conditions); } - + + static PropertyCondition blockState(BlockState state) { + Map props = state.getProperties(); + if (props.isEmpty()) return all(); + + PropertyCondition[] conditions = new Property[props.size()]; + int i = 0; + for (Map.Entry prop : props.entrySet()) { + conditions[i++] = property(prop.getKey(), prop.getValue()); + } + + return and(conditions); + } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Variant.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Variant.java new file mode 100644 index 00000000..343cc371 --- /dev/null +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Variant.java @@ -0,0 +1,70 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.bluecolored.bluemap.core.resourcepack.blockstate; + +import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; +import de.bluecolored.bluemap.core.resourcepack.blockmodel.TransformedBlockModelResource; + +import java.util.ArrayList; +import java.util.Collection; + +public class Variant { + + PropertyCondition condition = PropertyCondition.all(); + Collection> models = new ArrayList<>(0); + + private double totalWeight; + + Variant() {} + + public TransformedBlockModelResource getModel(int x, int y, int z) { + if (models.isEmpty()) throw new IllegalStateException("A variant must have at least one model!"); + + double selection = hashToFloat(x, y, z) * totalWeight; // random based on position + for (Weighted w : models) { + selection -= w.getWeight(); + if (selection <= 0) return w.getValue(); + } + + throw new RuntimeException("This line should never be reached!"); + } + + public void checkValid() throws ParseResourceException { + if (models.isEmpty()) throw new ParseResourceException("A variant must have at least one model!"); + } + + public void updateTotalWeight() { + totalWeight = 0d; + for (Weighted w : models) { + totalWeight += w.getWeight(); + } + } + + private static float hashToFloat(int x, int y, int z) { + final long hash = x * 73438747 ^ y * 9357269 ^ z * 4335792; + return (hash * (hash + 456149) & 0x00ffffff) / (float) 0x01000000; + } + +} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/BlockStateExtension.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Weighted.java similarity index 77% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/BlockStateExtension.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Weighted.java index c46c3ac5..df04950e 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/extensions/BlockStateExtension.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/blockstate/Weighted.java @@ -22,19 +22,24 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.mca.extensions; +package de.bluecolored.bluemap.core.resourcepack.blockstate; -import java.util.Set; +public class Weighted { -import com.flowpowered.math.vector.Vector3i; + private final T value; + private final double weight; -import de.bluecolored.bluemap.core.mca.MCAWorld; -import de.bluecolored.bluemap.core.world.BlockState; + public Weighted(T value, double weight) { + this.value = value; + this.weight = weight; + } -public interface BlockStateExtension { + public double getWeight() { + return weight; + } + + public T getValue() { + return value; + } - BlockState extend(MCAWorld world, Vector3i pos, BlockState state); - - Set getAffectedBlockIds(); - } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/Texture.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/Texture.java similarity index 98% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/Texture.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/Texture.java index 7624a05b..69a9d09d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/Texture.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/Texture.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.texture; import de.bluecolored.bluemap.core.util.math.Color; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TextureGallery.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/TextureGallery.java similarity index 92% rename from BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TextureGallery.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/TextureGallery.java index ce653215..4c6aa93c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/TextureGallery.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/texture/TextureGallery.java @@ -22,10 +22,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.core.resourcepack; +package de.bluecolored.bluemap.core.resourcepack.texture; import com.google.gson.*; import de.bluecolored.bluemap.core.logger.Logger; +import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; import de.bluecolored.bluemap.core.resourcepack.fileaccess.FileAccess; import de.bluecolored.bluemap.core.util.FileUtils; import de.bluecolored.bluemap.core.util.math.Color; @@ -37,14 +38,14 @@ import java.util.*; /** * A {@link TextureGallery} is managing {@link Texture}s and their id's and path's.
- * I can also load and generate the texture.json file, or load new {@link Texture}s from a {@link FileAccess}. + * I can also load and generate the texture.json file, or load new {@link Texture}s from a {@link FileAccess}. */ public class TextureGallery { private static final String EMPTY_BASE64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAEUlEQVR42mNkIAAYRxWMJAUAE5gAEdz4t9QAAAAASUVORK5CYII="; - private Map textureMap; - private List textureList; + private final Map textureMap; + private final List textureList; public TextureGallery() { textureMap = new HashMap<>(); @@ -129,7 +130,7 @@ public class TextureGallery { * Loads all the {@link Texture}s from the provided texture.json file, removes any existing {@link Texture}s from this gallery. * @param file The texture.json file. * @throws IOException If an IOException occurs while reading the file. - * @throws ParseResourceException If the whole file can not be read. Errors with single textures are logged and ignored. + * @throws ParseResourceException If the whole file can not be read. Errors with single textures are logged and ignored. */ public synchronized void loadTextureFile(File file) throws IOException, ParseResourceException { textureList.clear(); @@ -149,13 +150,11 @@ public class TextureGallery { String path = texture.get("id").getAsString(); boolean transparent = texture.get("transparent").getAsBoolean(); Color color = readColor(texture.get("color").getAsJsonArray()); - textureList.set(i, new Texture(i, path, color, transparent, EMPTY_BASE64)); + textureList.set(i, new Texture(i, path, color, transparent, texture.get("texture").getAsString())); } catch (ParseResourceException | RuntimeException ex) { Logger.global.logWarning("Failed to load texture with id " + i + " from texture file " + file + "!"); } } - } catch (IOException ex) { - throw ex; } catch (RuntimeException ex) { throw new ParseResourceException("Invalid texture file format!", ex); } finally { @@ -210,7 +209,7 @@ public class TextureGallery { return texture; } } - + /** * Tries to reload all {@link Texture}s from the given {@link FileAccess}
*
@@ -221,11 +220,7 @@ public class TextureGallery { for (Texture texture : textureList.toArray(new Texture[textureList.size()])) { try { loadTexture(fileAccess, texture.getPath()); - } catch (IOException e) { - Logger.global.noFloodWarning("TextureGallery-uiz78tef5", "Failed to reload texture: " + texture.getPath()); - Logger.global.noFloodWarning("TextureGallery-89763455h", "This happens if the resource-packs have changed, but you have not deleted your already generated maps. This might result in broken map-models!"); - Logger.global.noFloodWarning("TextureGallery-re56ugb56", "(Future warnings of this will be suppressed, so more textures might have failed to load after this)"); - } + } catch (IOException ignored) {} } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ArrayPool.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ArrayPool.java deleted file mode 100644 index ac3721b3..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ArrayPool.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.bluecolored.bluemap.core.util; - -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; - -/** - * A pool of objects that (lazily) maintains a specific size of objects. - * that threads can take, use and return. - * It discards excessive objects and creates new ones when needed. - */ -public class ArrayPool { - - private final Object[] objects; - private final int capacity, maxConcurrency; - private final Supplier supplier; - - private final AtomicInteger head, tail; // head is excluded, tail included - private int size; - - public ArrayPool(int capacity, int maxConcurrency, Supplier supplier) { - this.capacity = capacity; - this.objects = new Object[capacity + maxConcurrency * 2]; - this.maxConcurrency = maxConcurrency; - this.supplier = supplier; - - this.head = new AtomicInteger(0); - this.tail = new AtomicInteger(0); - this.size = 0; - } - - @SuppressWarnings("unchecked") - public T take() { - while (size < maxConcurrency) add(supplier.get()); - - size --; - return (T) objects[tail.getAndUpdate(this::nextPointer)]; - } - - - public void add(T resource) { - while (size > capacity + maxConcurrency) take(); - - objects[head.getAndUpdate(this::nextPointer)] = resource; - size ++; - } - - public int size() { - return size; - } - - public int capacity() { - return capacity; - } - - private int nextPointer(int prev) { - return (prev + 1) % objects.length; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/MathUtils.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/MathUtils.java index d944ec71..d06a5572 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/MathUtils.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/MathUtils.java @@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3f; import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector4f; +import de.bluecolored.bluemap.core.util.math.VectorM3f; @Deprecated //TODO public class MathUtils { diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/Slf4jLogger.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Tristate.java similarity index 57% rename from implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/Slf4jLogger.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Tristate.java index 7c873747..ea818f0e 100644 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/Slf4jLogger.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Tristate.java @@ -22,48 +22,51 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.sponge; +package de.bluecolored.bluemap.core.util; -import org.slf4j.Logger; +import java.util.function.BooleanSupplier; -import de.bluecolored.bluemap.core.logger.AbstractLogger; +public enum Tristate { -public class Slf4jLogger extends AbstractLogger { + TRUE (true), + UNDEFINED (false) { + @Override + public Tristate getOr(Tristate other) { + return other; + } - private Logger out; - - public Slf4jLogger(Logger out) { - this.out = out; - } + @Override + public boolean getOr(BooleanSupplier other) { + return other.getAsBoolean(); + } - @Override - public void logError(String message, Throwable throwable) { - out.error(message, throwable); - } + @Override + public boolean getOr(boolean defaultValue) { + return defaultValue; + } + }, + FALSE (false); - @Override - public void logWarning(String message) { - out.warn(message); - } + private final boolean value; - @Override - public void logInfo(String message) { - out.info(message); - } + Tristate(boolean value ) { + this.value = value; + } - @Override - public void logDebug(String message) { - if (out.isDebugEnabled()) out.debug(message); - } - - @Override - public void noFloodDebug(String message) { - if (out.isDebugEnabled()) super.noFloodDebug(message); - } - - @Override - public void noFloodDebug(String key, String message) { - if (out.isDebugEnabled()) super.noFloodDebug(key, message); - } - + public Tristate getOr(Tristate other) { + return this; + } + + public boolean getOr(BooleanSupplier other) { + return value; + } + + public boolean getOr(boolean defaultValue) { + return value; + } + + @Override + public String toString() { + return "Tristate." + name(); + } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java index e314ce73..3f50c819 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java @@ -1,3 +1,27 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package de.bluecolored.bluemap.core.util.math; public class Color { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java index e39868fa..4d907d09 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Block.java @@ -24,10 +24,7 @@ */ package de.bluecolored.bluemap.core.world; -import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.util.Direction; - -public class Block { +public class Block> { private World world; private int x, y, z; @@ -35,23 +32,19 @@ public class Block { private Chunk chunk; private BlockState blockState; - private BlockProperties properties; private LightData lightData; - private Biome biome; - - private int sunLight; - private int blockLight; - - private final transient LightData tempLight; + private int biomeId; public Block(World world, int x, int y, int z) { - tempLight = new LightData(0, 0); - set(world, x, y, z); } - public Block set(World world, int x, int y, int z) { - if (this.x == x && this.y == y && this.z == z && this.world == world) return this; + public T set(World world, int x, int y, int z) { + if (this.x == x && this.z == z && this.world == world){ + if (this.y == y) return self(); + } else { + this.chunk = null; //only reset the chunk if x or z have changed + } this.world = world; this.x = x; @@ -60,11 +53,15 @@ public class Block { reset(); - return this; + return self(); } - public Block set(int x, int y, int z) { - if (this.x == x && this.y == y && this.z == z) return this; + public T set(int x, int y, int z) { + if (this.x == x && this.z == z){ + if (this.y == y) return self(); + } else { + this.chunk = null; //only reset the chunk if x or z have changed + } this.x = x; this.y = y; @@ -72,27 +69,49 @@ public class Block { reset(); - return this; + return self(); } - private void reset() { - this.chunk = null; - + protected void reset() { this.blockState = null; - this.properties = null; this.lightData = new LightData(-1, -1); - this.biome = null; - - this.blockLight = -1; - this.sunLight = -1; + this.biomeId = -1; } - public Block add(int dx, int dy, int dz) { + public T add(int dx, int dy, int dz) { return set(x + dx, y + dy, z + dz); } - public Block copy(Block source) { - return set(source.world, source.x, source.y, source.z); + public T copy(Block source) { + this.world = source.world; + this.chunk = source.chunk; + this.x = source.x; + this.y = source.y; + this.z = source.z; + + reset(); + + this.blockState = source.blockState; + this.lightData = new LightData(source.lightData.getSkyLight(), source.lightData.getBlockLight()); + this.biomeId = source.biomeId; + + return self(); + } + + /** + * copy with offset + */ + public T copy(Block source, int dx, int dy, int dz) { + this.world = source.world; + this.x = source.x + dx; + this.y = source.y + dy; + this.z = source.z + dz; + + this.chunk = null; + + reset(); + + return self(); } public World getWorld() { @@ -121,19 +140,14 @@ public class Block { return blockState; } - public BlockProperties getProperties() { - if (properties == null) properties = world.getBlockProperties(getBlockState()); - return properties; - } - public LightData getLightData() { if (lightData.getSkyLight() < 0) getChunk().getLightData(x, y, z, lightData); return lightData; } - public Biome getBiome() { - if (biome == null) biome = getChunk().getBiome(x, y, z); - return biome; + public int getBiomeId() { + if (biomeId == -1) biomeId = getChunk().getBiome(x, y, z); + return biomeId; } public int getSunLightLevel() { @@ -144,67 +158,32 @@ public class Block { return getLightData().getBlockLight(); } - public boolean isCullingNeighborFaces() { - return getProperties().isCulling(); - } - - public boolean isFlammable() { - return getProperties().isFlammable(); - } - - public boolean isOccludingNeighborFaces(){ - return getProperties().isOccluding(); - } - - /** - * This is internally used for light rendering - * It is basically the sun light that is projected onto adjacent faces - */ - public int getPassedSunLight() { - if (sunLight < 0) calculateLight(); - return sunLight; - } - - /** - * This is internally used for light rendering - * It is basically the block light that is projected onto adjacent faces - */ - public int getPassedBlockLight() { - if (blockLight < 0) calculateLight(); - return blockLight; - } - - private void calculateLight() { - sunLight = getSunLightLevel(); - blockLight = getBlockLightLevel(); - - if (blockLight > 0 || sunLight > 0) return; - - Vector3i dirV; - int nx, ny, nz; - for (Direction direction : Direction.values()) { - dirV = direction.toVector(); - nx = dirV.getX() + x; - ny = dirV.getY() + y; - nz = dirV.getZ() + z; - - world.getLightData(nx, ny, nz, tempLight); - - sunLight = Math.max(tempLight.getSkyLight(), sunLight); - blockLight = Math.max(tempLight.getBlockLight(), blockLight); + @Override + public String toString() { + if (world != null) { + return "Block{" + + "world=" + world + + ", x=" + x + + ", y=" + y + + ", z=" + z + + ", chunk=" + getChunk() + + ", blockState=" + getBlockState() + + ", lightData=" + getLightData() + + ", biomeId=" + getBiomeId() + + '}'; + } else { + return "Block{" + + "world=" + world + + ", x=" + x + + ", y=" + y + + ", z=" + z + + '}'; } } - @Override - public String toString() { - return "Block{" + - "world=" + world + - ", x=" + x + - ", y=" + y + - ", z=" + z + - ", sunLight=" + sunLight + - ", blockLight=" + blockLight + - '}'; + @SuppressWarnings("unchecked") + protected T self() { + return (T) this; } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockNeighborhood.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockNeighborhood.java new file mode 100644 index 00000000..47dd3aab --- /dev/null +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockNeighborhood.java @@ -0,0 +1,90 @@ +/* + * This file is part of BlueMap, licensed under the MIT License (MIT). + * + * Copyright (c) Blue (Lukas Rieger) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package de.bluecolored.bluemap.core.world; + +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; + +public class BlockNeighborhood> extends ResourcePackBlock { + + private static final int DIAMETER = 8; + private static final int DIAMETER_MASK = DIAMETER - 1; + private static final int DIAMETER_SQUARED = DIAMETER * DIAMETER; + + private final ResourcePackBlock[] neighborhood; + + private int thisIndex; + + public BlockNeighborhood(ResourcePackBlock center) { + super(center.getResourcePack(), null, 0, 0, 0); + copy(center); + + neighborhood = new ResourcePackBlock[DIAMETER * DIAMETER * DIAMETER]; + init(); + } + + public BlockNeighborhood(ResourcePack resourcePack, World world, int x, int y, int z) { + super(resourcePack, world, x, y, z); + + neighborhood = new ResourcePackBlock[DIAMETER * DIAMETER * DIAMETER]; + init(); + } + + @Override + protected void reset() { + super.reset(); + + this.thisIndex = -1; + } + + private void init() { + this.thisIndex = -1; + for (int i = 0; i < neighborhood.length; i++) { + neighborhood[i] = new ResourcePackBlock<>(this.getResourcePack(), null, 0, 0, 0); + } + } + + public ResourcePackBlock getNeighborBlock(int dx, int dy, int dz) { + int i = neighborIndex(dx, dy, dz); + if (i == thisIndex()) return this; + return neighborhood[i].set( + getWorld(), + getX() + dx, + getY() + dy, + getZ() + dz + ); + } + + private int thisIndex() { + if (thisIndex == -1) thisIndex = neighborIndex(0, 0, 0); + return thisIndex; + } + + private int neighborIndex(int dx, int dy, int dz) { + return ((getX() + dx) & DIAMETER_MASK) * DIAMETER_SQUARED + + ((getY() + dy) & DIAMETER_MASK) * DIAMETER + + ((getZ() + dz) & DIAMETER_MASK); + } + +} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockProperties.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockProperties.java index 5fb2a60b..1a9e66ef 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockProperties.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockProperties.java @@ -24,29 +24,122 @@ */ package de.bluecolored.bluemap.core.world; +import de.bluecolored.bluemap.core.util.Tristate; + public class BlockProperties { - public static final BlockProperties SOLID = new BlockProperties(true, true, false); - public static final BlockProperties TRANSPARENT = new BlockProperties(false, false, false); + public static final BlockProperties DEFAULT = new BlockProperties(); - private final boolean culling, occluding, flammable; - - public BlockProperties(boolean culling, boolean occluding, boolean flammable) { + private Tristate culling, occluding, alwaysWaterlogged, randomOffset; + + public BlockProperties() { + this.culling = Tristate.UNDEFINED; + this.occluding = Tristate.UNDEFINED; + this.alwaysWaterlogged = Tristate.UNDEFINED; + this.randomOffset = Tristate.UNDEFINED; + } + + public BlockProperties( + Tristate culling, + Tristate occluding, + Tristate alwaysWaterlogged, + Tristate randomOffset + ) { this.culling = culling; this.occluding = occluding; - this.flammable = flammable; + this.alwaysWaterlogged = alwaysWaterlogged; + this.randomOffset = randomOffset; } public boolean isCulling() { - return culling; + return culling.getOr(true); } public boolean isOccluding() { - return occluding; + return occluding.getOr(true); } - - public boolean isFlammable() { - return flammable; + + public boolean isAlwaysWaterlogged() { + return alwaysWaterlogged.getOr(false); } - + + public boolean isRandomOffset() { + return randomOffset.getOr(false); + } + + public Builder toBuilder() { + return new BlockProperties( + culling, + occluding, + alwaysWaterlogged, + randomOffset + ).new Builder(); + } + + public static Builder builder() { + return new BlockProperties().new Builder(); + } + + public class Builder { + + public Builder culling(boolean culling) { + BlockProperties.this.culling = culling ? Tristate.TRUE : Tristate.FALSE; + return this; + } + + public Builder occluding(boolean occluding) { + BlockProperties.this.occluding = occluding ? Tristate.TRUE : Tristate.FALSE; + return this; + } + + public Builder alwaysWaterlogged(boolean alwaysWaterlogged) { + BlockProperties.this.alwaysWaterlogged = alwaysWaterlogged ? Tristate.TRUE : Tristate.FALSE; + return this; + } + + public Builder randomOffset(boolean randomOffset) { + BlockProperties.this.randomOffset = randomOffset ? Tristate.TRUE : Tristate.FALSE; + return this; + } + + public Builder from(BlockProperties other) { + culling = other.culling.getOr(culling); + occluding = other.occluding.getOr(occluding); + alwaysWaterlogged = other.alwaysWaterlogged.getOr(alwaysWaterlogged); + randomOffset = other.randomOffset.getOr(randomOffset); + return this; + } + + public BlockProperties build() { + return BlockProperties.this; + } + + public Tristate isCulling() { + return culling; + } + + public Tristate isOccluding() { + return occluding; + } + + public Tristate isAlwaysWaterlogged() { + return alwaysWaterlogged; + } + + public Tristate isRandomOffset() { + return randomOffset; + } + + } + + @Override + public String toString() { + return "BlockProperties{" + + "culling=" + culling + + ", occluding=" + occluding + + ", alwaysWaterlogged=" + alwaysWaterlogged + + ", randomOffset=" + randomOffset + + '}'; + } + } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java index 9fb26843..95c29b27 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/BlockState.java @@ -24,8 +24,6 @@ */ package de.bluecolored.bluemap.core.world; -import de.bluecolored.bluemap.core.MinecraftVersion; - import java.util.*; import java.util.Map.Entry; import java.util.regex.Matcher; @@ -39,46 +37,10 @@ import java.util.regex.Pattern; */ public class BlockState { - private static final Pattern BLOCKSTATE_SERIALIZATION_PATTERN = Pattern.compile("^(.+?)(?:\\[(.*)\\])?$"); + private static final Pattern BLOCKSTATE_SERIALIZATION_PATTERN = Pattern.compile("^(.+?)(?:\\[(.*)])?$"); - private static final HashSet DEFAULT_WATERLOGGED_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:seagrass", - "minecraft:tall_seagrass", - "minecraft:kelp", - "minecraft:kelp_plant", - "minecraft:bubble_column" - )); - - private static final HashSet OFFSET_BLOCK_IDS = new HashSet<>(Arrays.asList( - "minecraft:grass", - "minecraft:tall_grass", - "minecraft:fern", - "minecraft:dandelion", - "minecraft:cornflower", - "minecraft:poppy", - "minecraft:blue_orchid", - "minecraft:allium", - "minecraft:azure_bluet", - "minecraft:red_tulip", - "minecraft:orange_tulip", - "minecraft:white_tulip", - "minecraft:pink_tulip", - "minecraft:oxeye_daisy", - "minecraft:lily_of_the_valley", - "minecraft:wither_rose", - "minecraft:crimson_roots", - "minecraft:warped_roots", - "minecraft:nether_sprouts", - "minecraft:rose_bush", - "minecraft:peony", - "minecraft:lilac", - "minecraft:sunflower", - "minecraft:hanging_roots", - "minecraft:small_dripleaf" - )); - - public static final BlockState AIR = new BlockState(MinecraftVersion.LATEST_SUPPORTED, "minecraft:air", Collections.emptyMap()); - public static final BlockState MISSING = new BlockState(MinecraftVersion.LATEST_SUPPORTED, "bluemap:missing", Collections.emptyMap()); + public static final BlockState AIR = new BlockState("minecraft:air"); + public static final BlockState MISSING = new BlockState("bluemap:missing"); private boolean hashed; private int hash; @@ -88,14 +50,13 @@ public class BlockState { private final String fullId; private final Map properties; - // special fast-access properties - public final boolean isAir, isWater, isWaterlogged, isRandomOffset; + private final boolean isAir, isWater, isWaterlogged; - public BlockState(MinecraftVersion version, String id) { - this(version, id, Collections.emptyMap()); + public BlockState(String id) { + this(id, Collections.emptyMap()); } - public BlockState(MinecraftVersion version, String id, Map properties) { + public BlockState(String id, Map properties) { this.hashed = false; this.hash = 0; @@ -121,38 +82,7 @@ public class BlockState { "minecraft:void_air".equals(this.fullId); this.isWater = "minecraft:water".equals(this.fullId); - - this.isWaterlogged = - DEFAULT_WATERLOGGED_BLOCK_IDS.contains(this.fullId) || - "true".equals(this.properties.get("waterlogged")); - - if (version.isAtLeast(MinecraftVersion.THE_FLATTENING)) { - this.isRandomOffset = OFFSET_BLOCK_IDS.contains(this.fullId); - } else { - this.isRandomOffset = - "minecraft:tall_grass".equals(this.fullId); - } - } - - private BlockState(BlockState blockState, String withKey, String withValue) { - this.hashed = false; - this.hash = 0; - - Map props = new HashMap<>(blockState.getProperties()); - props.put(withKey, withValue); - - this.id = blockState.getId(); - this.namespace = blockState.getNamespace(); - this.fullId = namespace + ":" + id; - this.properties = props; - - // special fast-access properties - this.isAir = blockState.isAir; - this.isWater = blockState.isWater; - this.isWaterlogged = - DEFAULT_WATERLOGGED_BLOCK_IDS.contains(this.fullId) || - "true".equals(this.properties.get("waterlogged")); - this.isRandomOffset = blockState.isRandomOffset; + this.isWaterlogged = "true".equals(properties.get("waterlogged")); } /** @@ -190,14 +120,19 @@ public class BlockState { public Map getProperties() { return properties; } - - /** - * Returns a new BlockState with the given property changed - */ - public BlockState with(String property, String value) { - return new BlockState(this, property, value); + + public boolean isAir() { + return isAir; } - + + public boolean isWater() { + return isWater; + } + + public boolean isWaterlogged() { + return isWaterlogged; + } + @Override public boolean equals(Object obj) { if (this == obj) return true; @@ -205,8 +140,7 @@ public class BlockState { if (!(obj instanceof BlockState)) return false; BlockState b = (BlockState) obj; if (!Objects.equals(getFullId(), b.getFullId())) return false; - if (!Objects.equals(getProperties(), b.getProperties())) return false; - return true; + return Objects.equals(getProperties(), b.getProperties()); } @Override @@ -229,10 +163,12 @@ public class BlockState { return getFullId() + "[" + sj.toString() + "]"; } - public static BlockState fromString(MinecraftVersion version, String serializedBlockState) throws IllegalArgumentException { + public static BlockState fromString(String serializedBlockState) throws IllegalArgumentException { try { Matcher m = BLOCKSTATE_SERIALIZATION_PATTERN.matcher(serializedBlockState); - m.find(); + + if (!m.find()) + throw new IllegalArgumentException("'" + serializedBlockState + "' could not be parsed to a BlockState!"); Map pt = new HashMap<>(); String g2 = m.group(2); @@ -246,7 +182,7 @@ public class BlockState { String blockId = m.group(1).trim(); - return new BlockState(version, blockId, pt); + return new BlockState(blockId, pt); } catch (RuntimeException ex) { throw new IllegalArgumentException("'" + serializedBlockState + "' could not be parsed to a BlockState!"); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java index 0565c3b1..d9559fe6 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/Chunk.java @@ -34,7 +34,7 @@ public interface Chunk { LightData getLightData(int x, int y, int z, LightData target); - Biome getBiome(int x, int y, int z); + int getBiome(int x, int y, int z); int getMaxY(int x, int z); diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/EventForwarder.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/ResourcePackBlock.java similarity index 54% rename from implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/EventForwarder.java rename to BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/ResourcePackBlock.java index e033141c..e54ff511 100644 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/EventForwarder.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/ResourcePackBlock.java @@ -22,36 +22,43 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package de.bluecolored.bluemap.sponge; +package de.bluecolored.bluemap.core.world; -import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener; -import de.bluecolored.bluemap.common.plugin.text.Text; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.message.MessageChannelEvent; -import org.spongepowered.api.event.network.ClientConnectionEvent; +import de.bluecolored.bluemap.core.resourcepack.ResourcePack; -public class EventForwarder { +import java.util.Objects; - private final ServerEventListener listener; - - public EventForwarder(ServerEventListener listener) { - this.listener = listener; - } +public class ResourcePackBlock> extends Block { + + private final ResourcePack resourcePack; + private BlockProperties properties; + private Biome biome; + + public ResourcePackBlock(ResourcePack resourcePack, World world, int x, int y, int z) { + super(world, x, y, z); + this.resourcePack = Objects.requireNonNull(resourcePack); + } + + @Override + protected void reset() { + super.reset(); + + this.properties = null; + this.biome = null; + } + + public BlockProperties getProperties() { + if (properties == null) properties = resourcePack.getBlockProperties(getBlockState()); + return properties; + } + + public Biome getBiome() { + if (biome == null) biome = resourcePack.getBiome(getBiomeId()); + return biome; + } + + public ResourcePack getResourcePack() { + return resourcePack; + } - @Listener(order = Order.POST) - public void onPlayerJoin(ClientConnectionEvent.Join evt) { - listener.onPlayerJoin(evt.getTargetEntity().getUniqueId()); - } - - @Listener(order = Order.POST) - public void onPlayerLeave(ClientConnectionEvent.Disconnect evt) { - listener.onPlayerJoin(evt.getTargetEntity().getUniqueId()); - } - - @Listener(order = Order.POST) - public void onPlayerChat(MessageChannelEvent.Chat evt) { - listener.onChatMessage(Text.of(evt.getMessage().toPlain())); - } - } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java index 9c97f0b3..a746be97 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java @@ -26,7 +26,6 @@ package de.bluecolored.bluemap.core.world; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.mapping.BlockPropertiesMapper; import java.nio.file.Path; import java.util.ArrayList; @@ -93,22 +92,6 @@ public class SlicedWorld implements World { return world.getRegionGrid(); } - @Override - public Biome getBiome(int x, int y, int z) { - return world.getBiome(x, y, z); - } - - @Override - public BlockProperties getBlockProperties(BlockState blockState) { - return world.getBlockProperties(blockState); - } - - @Override - public BlockState getBlockState(int x, int y, int z) { - if (!isInside(x, y, z)) return BlockState.AIR; - return world.getBlockState(x, y, z); - } - @Override public Chunk getChunk(int x, int z) { return world.getChunk(x, z); @@ -153,11 +136,6 @@ public class SlicedWorld implements World { world.cleanUpChunkCache(); } - @Override - public BlockPropertiesMapper getBlockPropertiesMapper() { - return world.getBlockPropertiesMapper(); - } - private boolean isInside(int x, int z) { return x >= min.getX() && diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/World.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/World.java index 89f05b94..6a7cb24d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/World.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/World.java @@ -26,7 +26,6 @@ package de.bluecolored.bluemap.core.world; import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3i; -import de.bluecolored.bluemap.core.mca.mapping.BlockPropertiesMapper; import java.nio.file.Path; import java.util.Collection; @@ -57,21 +56,6 @@ public interface World { Grid getRegionGrid(); - /** - * Returns the {@link Biome} on the specified position or the default biome if the block is not generated yet. - */ - Biome getBiome(int x, int y, int z); - - /** - * Returns the {@link BlockState} on the specified position or an air-block if the block is not generated yet. - */ - BlockState getBlockState(int x, int y, int z); - - /** - * Returns the BlockProperties for a block-state - */ - BlockProperties getBlockProperties(BlockState blockState); - /** * Returns the {@link Chunk} on the specified block-position */ @@ -83,7 +67,7 @@ public interface World { Chunk getChunk(int x, int z); /** - * Returns the Chunk on the specified chunk-position + * Returns the {@link Region} on the specified region-position */ Region getRegion(int x, int z); @@ -107,10 +91,5 @@ public interface World { * Cleans up invalid cache-entries to free up memory */ void cleanUpChunkCache(); - - /** - * Returns the block-properties manager used for this world - */ - BlockPropertiesMapper getBlockPropertiesMapper(); } diff --git a/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/blockstates/missing.json b/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/blockstates/missing.json deleted file mode 100644 index 2cca3c30..00000000 --- a/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/blockstates/missing.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "variants": { - "": { "model": "bluemap:missing" } - } -} \ No newline at end of file diff --git a/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/models/block/missing.json b/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/models/block/missing.json deleted file mode 100644 index bb27488b..00000000 --- a/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/models/block/missing.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "block/cube_all", - "textures": { - "all": "bluemap:blocks/missing" - } -} \ No newline at end of file diff --git a/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/textures/blocks/missing.png b/BlueMapCore/src/main/resourceExtensions/mc1_12/assets/bluemap/textures/blocks/missing.png deleted file mode 100644 index bbfd3944cfa4f8ecf201c7fb575dab9b75b9b23c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2826 zcmV+l3-$DgP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq3?Wo(Y?l$ge?uXo;%ru`Vo>?<<(8I_>;8Eq#KMS9gFl*neeosSB zfoHYnBQIkwkyowPu(zdms`p{<7e4kra-ZWq<2*OsGTvEV%s0Td$hXT+!*8Bnh2KMe zBmZRodjHV?r+_5^X9J0WL4jKW`}lf%A-|44I@@LTvf1rHjG(ze6+w@Jt%Bvjts!X0 z?2xS?_ve_-kiKB_KiJlZ$9G`c^=E@oNG)mWWaNo-3TIW8)$Hg0Ub-~8?KhvJ>$ z3*&nim@mj(aCxE5!t{lw7O5^0EIO7zOo&c6l<+|iDySBWCGrz@C5{St!X3hAA}`T4 z(TLbXTq+(;@<=L8dXnssyft|w#WSTW<++3>sgS%(4NTpeI-VAqb|7ssJvzNHgOZVu zaYCvgO_R1~>SyL=cFU|~g|hy|Zi}}s9+d~lYqOB71z9Z$wnC=pR9Yz4DhIM>Wmjgu z&56o6maCpC&F##y%G;1PobR9i?GnNg;gYtchD%p19a!eQtZF&3JaKv33gZ<8D~47E ztUS1iwkmDaPpj=$m#%)jCVEY4fnLGNg2A-`YwHVD3gv};>)hAvT~AmqS>Lr``i7kw zJ{5_It`yrBmlc25DBO7E8;5VoznR>Ww5hAaxn$2~(q`%A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0000rNklW(DG!Tb}0RR91 c0RR6305SRo8w1WgjsO4v07*qoM6N<$f Map mapOf(L key, V value) { + Map map = new HashMap<>(); + map.put(key, value); + return Collections.unmodifiableMap(map); + } + + private Map mapOf(L key, V value, L key2, V value2) { + Map map = new HashMap<>(); + map.put(key, value); + map.put(key2, value2); + return Collections.unmodifiableMap(map); + } + } diff --git a/gradle.properties b/gradle.properties index eb489683..eb97465f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -coreVersion=1.5.5 +coreVersion=1.6.0 diff --git a/implementations/sponge-7.2.0/build.gradle b/implementations/sponge-7.2.0/build.gradle deleted file mode 100644 index 72a1151f..00000000 --- a/implementations/sponge-7.2.0/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -dependencies { - shadow "org.spongepowered:spongeapi:7.2.0" - - implementation group: 'org.bstats', name: 'bstats-sponge', version: '2.2.1' - - implementation (project(':BlueMapCommon')) { - //exclude dependencies provided by sponge - exclude group: 'com.google.guava', module: 'guava' - exclude group: 'com.google.code.gson', module: 'gson' - exclude group: 'org.apache.commons', module: 'commons-lang3' - exclude group: 'com.flowpowered', module: 'flow-math' - exclude group: 'javax.inject' - exclude group: 'com.google.inject' - } -} - -build.dependsOn shadowJar { - destinationDirectory = file '../../build/release' - archiveFileName.set("BlueMap-${archiveVersion.get()}-sponge-7.2.0.jar") - - relocate 'net.querz.nbt', 'de.bluecolored.shadow.querz.nbt' - relocate 'org.apache.commons.io', 'de.bluecolored.shadow.apache.commons.io' - relocate 'com.mojang.brigadier', 'de.bluecolored.shadow.mojang.brigadier' - relocate 'com.github.benmanes.caffeine', 'de.bluecolored.shadow.benmanes.caffeine' - relocate 'com.google.errorprone', 'de.bluecolored.shadow.google.errorprone' - relocate 'org.spongepowered.configurate', 'de.bluecolored.shadow.configurate' - relocate 'org.aopalliance', 'de.bluecolored.shadow.aopalliance' - relocate 'org.bstats', 'de.bluecolored.shadow.bstats' - relocate 'com.typesafe.config', 'de.bluecolored.shadow.typesafe.config' - relocate 'org.checkerframework', 'de.bluecolored.shadow.checkerframework' - relocate 'org.codehaus', 'de.bluecolored.shadow.codehaus' - relocate 'io.leangen.geantyref', 'de.bluecolored.shadow.geantyref' - - exclude 'META-INF/versions/**' -} - -processResources { - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - duplicatesStrategy = DuplicatesStrategy.WARN - - expand ( - version: project.version - ) - } -} diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommandSource.java b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommandSource.java deleted file mode 100644 index 21f455d3..00000000 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommandSource.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.sponge; - -import java.util.Optional; - -import org.spongepowered.api.text.serializer.TextSerializers; -import org.spongepowered.api.world.Locatable; - -import com.flowpowered.math.vector.Vector3d; - -import de.bluecolored.bluemap.common.plugin.Plugin; -import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource; -import de.bluecolored.bluemap.common.plugin.text.Text; -import de.bluecolored.bluemap.core.world.World; - -public class SpongeCommandSource implements CommandSource { - - private Plugin plugin; - private org.spongepowered.api.command.CommandSource delegate; - - public SpongeCommandSource(Plugin plugin, org.spongepowered.api.command.CommandSource delegate) { - this.plugin = plugin; - this.delegate = delegate; - } - - @Override - public void sendMessage(Text text) { - org.spongepowered.api.text.Text spongeText = TextSerializers.JSON.deserializeUnchecked(text.toJSONString()); - delegate.sendMessage(spongeText); - } - - @Override - public boolean hasPermission(String permission) { - return delegate.hasPermission(permission); - } - - @Override - public Optional getPosition() { - if (delegate instanceof Locatable) { - return Optional.of(((Locatable) delegate).getLocation().getPosition()); - } - - return Optional.empty(); - } - - @Override - public Optional getWorld() { - if (delegate instanceof Locatable) { - return Optional.ofNullable(plugin.getWorld(((Locatable) delegate).getLocation().getExtent().getUniqueId())); - } - - return Optional.empty(); - } - -} diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommands.java b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommands.java deleted file mode 100644 index e9dc4bf8..00000000 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommands.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.sponge; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.spongepowered.api.command.CommandCallable; -import org.spongepowered.api.command.CommandException; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.format.TextColors; -import org.spongepowered.api.world.Location; -import org.spongepowered.api.world.World; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestion; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.tree.CommandNode; - -import de.bluecolored.bluemap.common.plugin.Plugin; -import de.bluecolored.bluemap.common.plugin.commands.Commands; - -public class SpongeCommands { - - private CommandDispatcher dispatcher; - - public SpongeCommands(final Plugin plugin) { - this.dispatcher = new CommandDispatcher<>(); - - // register commands - new Commands<>(plugin, dispatcher, bukkitSender -> new SpongeCommandSource(plugin, bukkitSender)); - } - - public Collection getRootCommands(){ - Collection rootCommands = new ArrayList<>(); - - for (CommandNode node : this.dispatcher.getRoot().getChildren()) { - rootCommands.add(new SpongeCommandProxy(node.getName())); - } - - return rootCommands; - } - - public class SpongeCommandProxy implements CommandCallable { - - private String label; - - protected SpongeCommandProxy(String label) { - this.label = label; - } - - @Override - public CommandResult process(CommandSource source, String arguments) throws CommandException { - String command = label; - if (!arguments.isEmpty()) { - command += " " + arguments; - } - - try { - return CommandResult.successCount(dispatcher.execute(command, source)); - } catch (CommandSyntaxException ex) { - source.sendMessage(Text.of(TextColors.RED, ex.getRawMessage().getString())); - - String context = ex.getContext(); - if (context != null) source.sendMessage(Text.of(TextColors.GRAY, context)); - - return CommandResult.empty(); - } - } - - @Override - public List getSuggestions(CommandSource source, String arguments, Location targetPosition) throws CommandException { - String command = label; - if (!arguments.isEmpty()) { - command += " " + arguments; - } - - List completions = new ArrayList<>(); - - try { - Suggestions suggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(command, source)).get(100, TimeUnit.MILLISECONDS); - for (Suggestion suggestion : suggestions.getList()) { - String text = suggestion.getText(); - - if (text.indexOf(' ') == -1) { - completions.add(text); - } - } - } catch (InterruptedException ignore) { - Thread.currentThread().interrupt(); - } catch (ExecutionException | TimeoutException ignore) {} - - completions.sort((s1, s2) -> s1.compareToIgnoreCase(s2)); - return completions; - } - - @Override - public boolean testPermission(CommandSource source) { - return true; - } - - @Override - public Optional getShortDescription(CommandSource source) { - return Optional.empty(); - } - - @Override - public Optional getHelp(CommandSource source) { - return Optional.empty(); - } - - @Override - public Text getUsage(CommandSource source) { - CommandNode node = dispatcher.getRoot().getChild(label); - if (node == null) return Text.of("/" + label); - - List lines = new ArrayList<>(); - for (String usageString : dispatcher.getSmartUsage(node, source).values()) { - lines.add(Text.of(TextColors.WHITE, "/" + label + " ", TextColors.GRAY, usageString)); - } - - return Text.joinWith(Text.NEW_LINE, lines); - } - - public String getLabel() { - return label; - } - - } - -} diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java deleted file mode 100644 index 4ac33aa3..00000000 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.sponge; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.data.key.Keys; -import org.spongepowered.api.effect.potion.PotionEffect; -import org.spongepowered.api.effect.potion.PotionEffectTypes; -import org.spongepowered.api.entity.living.player.gamemode.GameMode; -import org.spongepowered.api.entity.living.player.gamemode.GameModes; - -import com.flowpowered.math.vector.Vector3d; - -import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode; -import de.bluecolored.bluemap.common.plugin.serverinterface.Player; -import de.bluecolored.bluemap.common.plugin.text.Text; - -public class SpongePlayer implements Player { - - private static final Map GAMEMODE_MAP = new HashMap<>(5); - static { - GAMEMODE_MAP.put(GameModes.ADVENTURE, Gamemode.ADVENTURE); - GAMEMODE_MAP.put(GameModes.SURVIVAL, Gamemode.SURVIVAL); - GAMEMODE_MAP.put(GameModes.CREATIVE, Gamemode.CREATIVE); - GAMEMODE_MAP.put(GameModes.SPECTATOR, Gamemode.SPECTATOR); - GAMEMODE_MAP.put(GameModes.NOT_SET, Gamemode.SURVIVAL); - } - - private UUID uuid; - private Text name; - private UUID world; - private Vector3d position; - private boolean online; - private boolean sneaking; - private boolean invisible; - private Gamemode gamemode; - - public SpongePlayer(UUID playerUUID) { - this.uuid = playerUUID; - update(); - } - - @Override - public UUID getUuid() { - return this.uuid; - } - - @Override - public Text getName() { - return this.name; - } - - @Override - public UUID getWorld() { - return this.world; - } - - @Override - public Vector3d getPosition() { - return this.position; - } - - @Override - public boolean isOnline() { - return this.online; - } - - @Override - public boolean isSneaking() { - return this.sneaking; - } - - @Override - public boolean isInvisible() { - return this.invisible; - } - - @Override - public Gamemode getGamemode() { - return this.gamemode; - } - - /** - * API access, only call on server thread! - */ - public void update() { - org.spongepowered.api.entity.living.player.Player player = Sponge.getServer().getPlayer(uuid).orElse(null); - if (player == null) { - this.online = false; - return; - } - - this.gamemode = GAMEMODE_MAP.get(player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET)); - if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; - - boolean invis = player.get(Keys.VANISH).orElse(false); - if (!invis && player.get(Keys.INVISIBLE).orElse(false)) invis = true; - if (!invis) { - Optional> effects = player.get(Keys.POTION_EFFECTS); - if (effects.isPresent()) { - for (PotionEffect effect : effects.get()) { - if (effect.getType().equals(PotionEffectTypes.INVISIBILITY) && effect.getDuration() > 0) invis = true; - } - } - } - this.invisible = invis; - - this.name = Text.of(player.getName()); - this.online = player.isOnline(); - this.position = player.getPosition(); - this.sneaking = player.get(Keys.IS_SNEAKING).orElse(false); - this.world = player.getWorld().getUniqueId(); - } - -} diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java deleted file mode 100644 index b47d0a1d..00000000 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.sponge; - -import de.bluecolored.bluemap.common.plugin.Plugin; -import de.bluecolored.bluemap.common.plugin.serverinterface.Player; -import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener; -import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface; -import de.bluecolored.bluemap.core.MinecraftVersion; -import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resourcepack.ParseResourceException; -import de.bluecolored.bluemap.sponge.SpongeCommands.SpongeCommandProxy; -import net.querz.nbt.CompoundTag; -import net.querz.nbt.NBTUtil; -import org.bstats.sponge.Metrics; -import org.spongepowered.api.Sponge; -import org.spongepowered.api.config.ConfigDir; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.game.GameReloadEvent; -import org.spongepowered.api.event.game.state.GameStartingServerEvent; -import org.spongepowered.api.event.game.state.GameStoppingEvent; -import org.spongepowered.api.event.network.ClientConnectionEvent; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.scheduler.SpongeExecutorService; -import org.spongepowered.api.scheduler.Task; -import org.spongepowered.api.util.Tristate; -import org.spongepowered.api.world.World; -import org.spongepowered.api.world.storage.WorldProperties; - -import javax.inject.Inject; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; - -@org.spongepowered.api.plugin.Plugin ( - id = Plugin.PLUGIN_ID, - name = Plugin.PLUGIN_NAME, - authors = { "Blue (Lukas Rieger)" }, - description = "This plugin provides a fully 3D map of your world for your browser!" - ) -public class SpongePlugin implements ServerInterface { - - @Inject - @ConfigDir(sharedRoot = false) - private Path configurationDir; - - private final Plugin pluginInstance; - private final SpongeCommands commands; - - private SpongeExecutorService asyncExecutor; - private SpongeExecutorService syncExecutor; - - private int playerUpdateIndex = 0; - private final Map onlinePlayerMap; - private final List onlinePlayerList; - - @Inject - public SpongePlugin(org.slf4j.Logger logger, Metrics.Factory metricsFactory) { - Logger.global = new Slf4jLogger(logger); - - this.onlinePlayerMap = new ConcurrentHashMap<>(); - this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>()); - - MinecraftVersion version = new MinecraftVersion(1, 12); - try { - version = MinecraftVersion.of(Sponge.getPlatform().getMinecraftVersion().getName()); - } catch (IllegalArgumentException e) { - Logger.global.logWarning("Failed to find a matching version for version-name '" + Sponge.getPlatform().getMinecraftVersion().getName() + "'! Using latest known sponge-version: " + version.getVersionString()); - } - - this.pluginInstance = new Plugin(version, "sponge-7.2.0", this); - this.commands = new SpongeCommands(pluginInstance); - - //bstats - metricsFactory.make(5911); - } - - @Listener - public void onServerStart(GameStartingServerEvent evt) { - asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this); - syncExecutor = Sponge.getScheduler().createSyncExecutor(this); - - //save all world properties to generate level_sponge.dat files - for (WorldProperties properties : Sponge.getServer().getAllWorldProperties()) { - Sponge.getServer().saveWorldProperties(properties); - } - - //register commands - for(SpongeCommandProxy command : commands.getRootCommands()) { - Sponge.getCommandManager().register(this, command, command.getLabel()); - } - - //start updating players - Task.builder() - .intervalTicks(1) - .execute(this::updateSomePlayers) - .submit(this); - - asyncExecutor.execute(() -> { - try { - Logger.global.logInfo("Loading..."); - pluginInstance.load(); - if (pluginInstance.isLoaded()) Logger.global.logInfo("Loaded!"); - } catch (IOException | ParseResourceException | RuntimeException e) { - Logger.global.logError("Failed to load!", e); - pluginInstance.unload(); - } - }); - } - - @Listener - public void onServerStop(GameStoppingEvent evt) { - Logger.global.logInfo("Stopping..."); - Sponge.getScheduler().getScheduledTasks(this).forEach(Task::cancel); - pluginInstance.unload(); - Logger.global.logInfo("Saved and stopped!"); - } - - @Listener - public void onServerReload(GameReloadEvent evt) { - asyncExecutor.execute(() -> { - try { - Logger.global.logInfo("Reloading..."); - pluginInstance.reload(); - Logger.global.logInfo("Reloaded!"); - } catch (IOException | ParseResourceException | RuntimeException e) { - Logger.global.logError("Failed to load!", e); - pluginInstance.unload(); - } - }); - } - - @Listener - public void onPlayerJoin(ClientConnectionEvent.Join evt) { - SpongePlayer player = new SpongePlayer(evt.getTargetEntity().getUniqueId()); - onlinePlayerMap.put(evt.getTargetEntity().getUniqueId(), player); - onlinePlayerList.add(player); - } - - @Listener - public void onPlayerLeave(ClientConnectionEvent.Disconnect evt) { - UUID playerUUID = evt.getTargetEntity().getUniqueId(); - onlinePlayerMap.remove(playerUUID); - synchronized (onlinePlayerList) { - onlinePlayerList.removeIf(p -> p.getUuid().equals(playerUUID)); - } - } - - @Override - public void registerListener(ServerEventListener listener) { - Sponge.getEventManager().registerListeners(this, new EventForwarder(listener)); - } - - @Override - public void unregisterAllListeners() { - Sponge.getEventManager().unregisterPluginListeners(this); - Sponge.getEventManager().registerListeners(this, this); - } - - @Override - public UUID getUUIDForWorld(File worldFolder) throws IOException { - try { - CompoundTag levelSponge = (CompoundTag) NBTUtil.readTag(new File(worldFolder, "level_sponge.dat")); - CompoundTag spongeData = levelSponge.getCompoundTag("SpongeData"); - long most = spongeData.getLong("UUIDMost"); - long least = spongeData.getLong("UUIDLeast"); - return new UUID(most, least); - } catch (IOException | RuntimeException e) { - throw new IOException("Failed to read level_sponge.dat", e); - } - } - - @Override - public String getWorldName(UUID worldUUID) { - Optional world = Sponge.getServer().getWorld(worldUUID); - return world.map(World::getName).orElse(null); - } - - @Override - public File getConfigFolder() { - return configurationDir.toFile(); - } - - @Override - public Collection getOnlinePlayers() { - return onlinePlayerMap.values(); - } - - @Override - public Optional getPlayer(UUID uuid) { - return Optional.ofNullable(onlinePlayerMap.get(uuid)); - } - - @Override - public boolean isMetricsEnabled(boolean configValue) { - PluginContainer pluginContainer = Sponge.getPluginManager().fromInstance(this).orElse(null); - if (pluginContainer != null) { - Tristate metricsEnabled = Sponge.getMetricsConfigManager().getCollectionState(pluginContainer); - if (metricsEnabled != Tristate.UNDEFINED) { - return metricsEnabled == Tristate.TRUE; - } - } - - return Sponge.getMetricsConfigManager().getGlobalCollectionState().asBoolean(); - } - - @Override - public boolean persistWorldChanges(UUID worldUUID) throws IOException, IllegalArgumentException { - try { - return syncExecutor.submit(() -> { - World world = Sponge.getServer().getWorld(worldUUID).orElse(null); - if (world == null) throw new IllegalArgumentException("There is no world with this uuid: " + worldUUID); - world.save(); - - return true; - }).get(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IOException(e); - } catch (ExecutionException e) { - Throwable t = e.getCause(); - if (t instanceof IOException) throw (IOException) t; - if (t instanceof IllegalArgumentException) throw (IllegalArgumentException) t; - throw new IOException(t); - } - } - - /** - * Only update some of the online players each tick to minimize performance impact on the server-thread. - * Only call this method on the server-thread. - */ - private void updateSomePlayers() { - int onlinePlayerCount = onlinePlayerList.size(); - if (onlinePlayerCount == 0) return; - - int playersToBeUpdated = onlinePlayerCount / 20; //with 20 tps, each player is updated once a second - if (playersToBeUpdated == 0) playersToBeUpdated = 1; - - for (int i = 0; i < playersToBeUpdated; i++) { - playerUpdateIndex++; - if (playerUpdateIndex >= 20 && playerUpdateIndex >= onlinePlayerCount) playerUpdateIndex = 0; - - if (playerUpdateIndex < onlinePlayerCount) { - onlinePlayerList.get(playerUpdateIndex).update(); - } - } - } - -} diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core-defaults.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core-defaults.conf deleted file mode 100644 index e51cf511..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core-defaults.conf +++ /dev/null @@ -1,4 +0,0 @@ -accept-download: false -renderThreadCount: -2 -metrics: false -data: "bluemap" \ No newline at end of file diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core.conf deleted file mode 100644 index 0b85eb35..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/core.conf +++ /dev/null @@ -1,24 +0,0 @@ -## ## -## BlueMap ## -## Core-Config ## -## ## - -# By changing the setting (accept-download) below to TRUE you are indicating that you have accepted mojang's EULA (https://account.mojang.com/documents/minecraft_eula), -# you confirm that you own a license to Minecraft (Java Edition) -# and you agree that BlueMap will download and use a minecraft-client file (depending on the minecraft-version) from mojangs servers (https://launcher.mojang.com/) for you. -# This file contains resources that belong to mojang and you must not redistribute it or do anything else that is not compliant with mojang's EULA. -# BlueMap uses resources in this file to generate the 3D-Models used for the map and texture them. (BlueMap will not work without those resources.) -# %datetime-iso% -accept-download: false - -# This changes the amount of threads that BlueMap will use to render the maps. -# A higher value can improve render-speed but could impact performance on the host machine. -# This should be always below or equal to the number of available processor-cores. -# Zero or a negative value means the amount of of available processor-cores subtracted by the value. -# (So a value of -2 with 6 cores results in 4 render-processes) -# Default is -2 -renderThreadCount: -2 - -# The folder where bluemap saves data-files it needs during runtime or to save e.g. the render-progress to resume it later. -# Default is "bluemap" -data: "bluemap" \ No newline at end of file diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin-defaults.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin-defaults.conf deleted file mode 100644 index cb654cb8..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin-defaults.conf +++ /dev/null @@ -1,6 +0,0 @@ -liveUpdates: true -skinDownload: false -hiddenGameModes: [] -hideInvisible: true -hideSneaking: false -fullUpdateInterval: 1440 \ No newline at end of file diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin.conf deleted file mode 100644 index bf2feedc..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/plugin.conf +++ /dev/null @@ -1,32 +0,0 @@ -## ## -## BlueMap ## -## Plugin-Config ## -## ## - -# If the server should send live-updates and player-positions. -# This only works if the integrated webserver is enabled. -# Default is true -liveUpdates: true - -# Download the skin from mojang-serves when a player joins your server, so it can be used for the player-markers. -# Default is false -skinDownload: false - -# A list of gamemodes that will prevent a player from appearing on the map. -# Possible values are: survival, creative, spectator, adventure -hiddenGameModes: [ - "spectator" -] - -# If this is true, players that have an invisibility (potion-)effect will be hidden on the map. -# Default is true -hideInvisible: true - -# If this is true, players that are sneaking will be hidden on the map. -# Default is false -hideSneaking: false - -# The interval in minutes in which a full map-update will be triggered. -# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes). -# Default is 1440 (24 hours) -fullUpdateInterval: 1440 diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render-defaults.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render-defaults.conf deleted file mode 100644 index 3b775ae3..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render-defaults.conf +++ /dev/null @@ -1,4 +0,0 @@ -webroot: "bluemap/web" -useCookies: true -enableFreeFlight: true -maps: [] diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render.conf deleted file mode 100644 index 4a602264..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/render.conf +++ /dev/null @@ -1,130 +0,0 @@ -## ## -## BlueMap ## -## Render-Config ## -## ## - -# The folder (webroot) where the map-data and web-application files will be saved. -# Default is "bluemap/web" -webroot: "bluemap/web" - -# If the web-application should use cookies to save the configurations of a user. -# Default is true -useCookies: true - -# If the free-flight-mode in the web-application is enabled or not. -# Default is true -enableFreeFlight: true - -# This is an array with multiple configured maps. -# You can define multiple maps, for different worlds with different render-settings here -maps: [ - - { - # The id of this map - # Should only contain word-charactes: [a-zA-Z0-9_] - # Changing this value breaks your existing renders. - id: "world" - - # The name of this map - # This defines the display name of this map, you can change this at any time. - # Default is the id of this map - name: "World" - - # The path to the save-folder of the world to render. - world: "world" - - # The position on the world where the map will be centered if you open it. - # You can change this at any time. - # This defaults to the world-spawn if you don't set it. - #startPos: [500, -820] - - # The color of thy sky as a hex-color - # You can change this at any time. - # Default is "#7dabff" - skyColor: "#7dabff" - - # Defines the ambient light-strength that every block is recieving, regardless of the sunlight/blocklight. - # 0 is no ambient light, 1 is fully lighted. - # You can change this at any time. - # Default is 0 - ambientLight: 0 - - # If this is false, BlueMap tries to omit all blocks that are not visible from above-ground. - # More specific: Block-Faces that have a sunlight/skylight value of 0 are removed. - # This improves the performance of the map on slower devices by a lot, but might cause some blocks to disappear that should normally be visible. - # Changing this value requires a re-render of the map. - # Default is false - renderCaves: false - - # With the below values you can limit the map-render. - # This can be used to ignore the nethers ceiling or render only a certain part of a world. - # Changing this values might require a re-render of the map, already rendered tiles outside the limits will not be deleted. - # Default is no min or max value (= infinite bounds) - #minX: -4000 - #maxX: 4000 - #minZ: -4000 - #maxZ: 4000 - #minY: 50 - #maxY: 126 - - # Using this, BlueMap pretends that every Block out of the defined render-bounds is AIR, - # this means you can see the blocks where the world is cut (instead of having a see-through/xray view). - # This has only an effect if you set some render-bounds above. - # Changing this value requires a re-render of the map. - # Default is true - renderEdges: true - - # With this set to true, the generated files for this world are compressed using gzip to save A LOT of space. - # Files will be only 5% as big with compression! - # Note: If you are using NGINX or Apache to host your map, you can configure them to serve the compressed files directly. - # This is much better than disabling the compression. - # Changing this value requires a re-render of the map. - # Default is true - useCompression: true - - # Normally BlueMap detects if a chunk has not yet generated it's light-data and omits rendering those chunks. - # If this is set to true BlueMap will render Chunks even if there is no light-data! - # This can be usefull for example if some mod prevents light-data from being saved correctly. - # However, this also has a few drawbacks: - # - For those chunks, every block will always be fully lit - # - Night-mode might not work correctly - # - Caves will always be rendered (ignoring the 'renderCaves' setting) - # Default is false - ignoreMissingLightData: false - } - - # Here another example for the End-Map - # Things we don't want to change from default we can just omit - { - id: "end" - name: "End" - world: "world/DIM1" - - # We dont want a blue sky in the end - skyColor: "#080010" - - # In the end is no sky-light, so we need to enable this or we won't see anything. - renderCaves: true - - # Same here, we don't want a dark map. But not completely lighted, so we see the effect of e.g torches. - ambientLight: 0.6 - } - - # Here another example for the Nether-Map - { - id: "nether" - name: "Nether" - world: "world/DIM-1" - - skyColor: "#290000" - - renderCaves: true - ambientLight: 0.6 - - # We slice the whole world at y:90 so every block above 90 will be air. - # This way we don't render the nethers ceiling. - maxY: 90 - renderEdges: true - } - -] diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver-defaults.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver-defaults.conf deleted file mode 100644 index 55e8c255..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver-defaults.conf +++ /dev/null @@ -1,4 +0,0 @@ -enabled: true -webroot: "bluemap/web" -port: 8100 -maxConnectionCount: 100 \ No newline at end of file diff --git a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver.conf b/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver.conf deleted file mode 100644 index 6af072df..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/de/bluecolored/bluemap/webserver.conf +++ /dev/null @@ -1,29 +0,0 @@ -## ## -## BlueMap ## -## Webserver-Config ## -## ## - -# With this setting you can disable the integrated web-server. -# This is usefull if you want to only render the map-data for later use, or if you setup your own webserver. -# Default is enabled -enabled: true - -# The webroot that the server will host to the web. -# Usually this should be set to the same directory like in the render.conf! -# Default is "bluemap/web" -webroot: "bluemap/web" - -# The IP-Adress that the webserver binds to. -# Use "0.0.0.0" to bind to all available local adresses. -# If you only want to access it locally use "localhost". -# Default is "0.0.0.0" -#ip: "localhost" -#ip: "123.45.6.78" - -# The port that the webserver listenes to. -# Default is 8100 -port: 8100 - -# Max number of simultaneous connections that the webserver allows -# Default is 100 -maxConnectionCount: 100 \ No newline at end of file diff --git a/implementations/sponge-7.2.0/src/main/resources/mcmod.info b/implementations/sponge-7.2.0/src/main/resources/mcmod.info deleted file mode 100644 index d30be9cb..00000000 --- a/implementations/sponge-7.2.0/src/main/resources/mcmod.info +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "modid": "bluemap", - "name": "BlueMap", - "version": "${version}", - "description": "A 3d-map of your Minecraft worlds view-able in your browser using three.js (WebGL)", - "url": "https://github.com/BlueMap-Minecraft", - "authorList": [ - "Blue (TBlueF, Lukas Rieger)" - ], - "dependencies": [ - "spongeapi@7.2.0" - ], - "requiredMods": [ - "spongeapi@7.2.0" - ] - } -] diff --git a/implementations/sponge-8.0.0/src/main/java/de/bluecolored/bluemap/sponge8/SpongePlugin.java b/implementations/sponge-8.0.0/src/main/java/de/bluecolored/bluemap/sponge8/SpongePlugin.java index fa976c4f..ff30c930 100644 --- a/implementations/sponge-8.0.0/src/main/java/de/bluecolored/bluemap/sponge8/SpongePlugin.java +++ b/implementations/sponge-8.0.0/src/main/java/de/bluecolored/bluemap/sponge8/SpongePlugin.java @@ -186,7 +186,7 @@ public class SpongePlugin implements ServerInterface { @Override public void unregisterAllListeners() { - Sponge.eventManager().unregisterPluginListeners(this.pluginContainer); + Sponge.eventManager().unregisterListeners(this.pluginContainer); Sponge.eventManager().registerListeners(this.pluginContainer, this); } diff --git a/settings.gradle b/settings.gradle index 7002a9f2..6bfc9665 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,7 +18,6 @@ include ':BlueMapCommon' include ':cli' -include ':sponge-7.2.0' include ':sponge-8.0.0' include ':spigot' @@ -39,7 +38,6 @@ project(':BlueMapCommon').projectDir = "$rootDir/BlueMapCommon" as File project(':cli').projectDir = "$rootDir/implementations/cli" as File -project(':sponge-7.2.0').projectDir = "$rootDir/implementations/sponge-7.2.0" as File project(':sponge-8.0.0').projectDir = "$rootDir/implementations/sponge-8.0.0" as File project(':spigot').projectDir = "$rootDir/implementations/spigot" as File