diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java b/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java index c3264f195..14a654d2a 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/WrapperFactory.java @@ -20,13 +20,12 @@ package com.seibel.lod.common.wrappers; import com.seibel.lod.common.wrappers.block.BlockStateWrapper; -import com.seibel.lod.common.wrappers.world.BiomeWrapper; +import com.seibel.lod.common.wrappers.block.BiomeWrapper; import com.seibel.lod.core.a7.level.ILevel; import com.seibel.lod.core.a7.level.IServerLevel; import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory; import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper; import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; -import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java new file mode 100644 index 000000000..78ef6f984 --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java @@ -0,0 +1,98 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.common.wrappers.block; + +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Function; + +import com.google.common.collect.ImmutableBiMap; +import com.google.gson.JsonParser; +import com.mojang.serialization.JsonOps; +import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; + +import net.minecraft.core.Holder; +import net.minecraft.data.BuiltinRegistries; +#if POST_MC_1_19 +import net.minecraft.data.worldgen.biome.EndBiomes; +import net.minecraft.data.worldgen.biome.NetherBiomes; +#endif +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.block.Blocks; + + +//This class wraps the minecraft BlockPos.Mutable (and BlockPos) class +public class BiomeWrapper implements IBiomeWrapper +{ + #if PRE_MC_1_18_2 + public static final ConcurrentMap biomeWrapperMap = new ConcurrentHashMap<>(); + private final Biome biome; + #else + public static final ConcurrentMap, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>(); + private final Holder biome; + #endif + + static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder #endif biome) + { + return biomeWrapperMap.computeIfAbsent(biome, BiomeWrapper::new); + } + + private BiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder #endif biome) + { + this.biome = biome; + } + + @Override + public String getName() + { + #if PRE_MC_1_18_2 + return biome.toString(); + #else + return biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString(); + #endif + } + + @Override + public String serialize() { + return Biome.CODEC.encodeStart(JsonOps.COMPRESSED, biome).get().orThrow().toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BiomeWrapper that = (BiomeWrapper) o; + return Objects.equals(biome, that.biome); + } + + @Override + public int hashCode() { + return Objects.hash(biome); + } + + public static IBiomeWrapper deserialize(String str) { + #if PRE_MC_1_18_2 Biome #else Holder #endif + biome = Biome.CODEC.decode(JsonOps.COMPRESSED, JsonParser.parseString(str)).get().orThrow().getFirst(); + return getBiomeWrapper(biome); + } +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockStateWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockStateWrapper.java index b3e5c50a0..0ce0da9e9 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockStateWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/BlockStateWrapper.java @@ -5,12 +5,24 @@ import com.mojang.serialization.JsonOps; import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper; import net.minecraft.world.level.block.state.BlockState; +import java.util.HashMap; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; public class BlockStateWrapper implements IBlockStateWrapper { public static final BlockStateWrapper AIR = new BlockStateWrapper(null); + + public static ConcurrentHashMap cache = new ConcurrentHashMap<>(); + + public static BlockStateWrapper fromBlockState(BlockState blockState) { + if (blockState == null || blockState.isAir()) return AIR; + if (blockState.getFluidState() != null) + return cache.computeIfAbsent(blockState.getFluidState().createLegacyBlock(), BlockStateWrapper::new); + return cache.computeIfAbsent(blockState, BlockStateWrapper::new); + } + public final BlockState blockState; - public BlockStateWrapper(BlockState blockState) { + private BlockStateWrapper(BlockState blockState) { this.blockState = blockState; } @@ -43,4 +55,12 @@ public class BlockStateWrapper implements IBlockStateWrapper { public int hashCode() { return Objects.hash(blockState); } + + + + + + + + } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java index df909f43c..ce16b0976 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/chunk/ChunkWrapper.java @@ -25,13 +25,12 @@ import com.seibel.lod.core.enums.ELodDirection; import com.seibel.lod.core.util.LevelPosUtil; import com.seibel.lod.core.util.LodUtil; import com.seibel.lod.core.wrapperInterfaces.block.IBlockDetailWrapper; -import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper; import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; import com.seibel.lod.common.wrappers.WrapperUtil; import com.seibel.lod.common.wrappers.block.BlockDetailMap; -import com.seibel.lod.common.wrappers.world.BiomeWrapper; +import com.seibel.lod.common.wrappers.block.BiomeWrapper; import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion; import net.minecraft.core.BlockPos; @@ -254,6 +253,6 @@ public class ChunkWrapper implements IChunkWrapper @Override public BlockStateWrapper getBlockState(int x, int y, int z) { - return new BlockStateWrapper(chunk.getBlockState(new BlockPos(x,y,z))); + return BlockStateWrapper.fromBlockState(chunk.getBlockState(new BlockPos(x,y,z))); } } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java index bbad24be1..8be14eb17 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftClientWrapper.java @@ -26,7 +26,8 @@ import java.util.Objects; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.platform.Window; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.enums.ELodDirection; import com.seibel.lod.core.logging.DhLoggerBuilder; @@ -41,8 +42,6 @@ import com.seibel.lod.core.objects.DHBlockPos; import com.seibel.lod.core.objects.DHChunkPos; import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.CrashReport; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -155,21 +154,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra return mc.getCurrentServer().version.getString(); } - /** Returns the dimension the player is currently in */ - @Override - public IDimensionTypeWrapper getCurrentDimension() - { - if (mc.player != null) - return DimensionTypeWrapper.getDimensionTypeWrapper(mc.player.level.dimensionType()); - else return null; - } - - @Override - public String getCurrentDimensionId() - { - return LodUtil.getDimensionIDFromWorld(LevelWrapper.getWorldWrapper(mc.level)); - } - //=============// // Simple gets // //=============// @@ -208,71 +192,11 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra return mc.getModelManager(); } - public ClientLevel getClientLevel() - { - return mc.level; - } - - @Override - public ILevelWrapper getWrappedServerWorld() - { - if (mc.level == null) - return null; - - DimensionType dimension = mc.level.dimensionType(); - IntegratedServer server = mc.getSingleplayerServer(); - - if (server == null) - return null; - - ServerLevel serverWorld = null; - Iterable worlds = server.getAllLevels(); - for (ServerLevel world : worlds) - { - if (world.dimensionType() == dimension) - { - serverWorld = world; - break; - } - } - return LevelWrapper.getWorldWrapper(serverWorld); - } - - public LevelWrapper getWrappedClientLevel() - { - return LevelWrapper.getWorldWrapper(mc.level); - } - - public LevelWrapper getWrappedServerLevel() - { - - if (mc.level == null) - return null; - DimensionType dimension = mc.level.dimensionType(); - IntegratedServer server = mc.getSingleplayerServer(); - if (server == null) - return null; - - Iterable worlds = server.getAllLevels(); - ServerLevel returnWorld = null; - - for (ServerLevel world : worlds) - { - if (world.dimensionType() == dimension) - { - returnWorld = world; - break; - } - } - - return LevelWrapper.getWorldWrapper(returnWorld); - } - @Nullable @Override public ILevelWrapper getWrappedClientWorld() { - return LevelWrapper.getWorldWrapper(mc.level); + return ClientLevelWrapper.getWrapper(mc.level); } @Override @@ -288,62 +212,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra profilerWrapper = new ProfilerWrapper(mc.getProfiler()); else if (mc.getProfiler() != profilerWrapper.profiler) profilerWrapper.profiler = mc.getProfiler(); - - return profilerWrapper; } - - public ClientPacketListener getConnection() - { - return mc.getConnection(); - } - - public GameRenderer getGameRenderer() - { - return mc.gameRenderer; - } - - public Entity getCameraEntity() - { - return mc.cameraEntity; - } - - public Window getWindow() - { - return mc.getWindow(); - } - - @Override - public float getSkyDarken(float partialTicks) - { - return mc.level.getSkyDarken(partialTicks); - } - - public IntegratedServer getSinglePlayerServer() - { - return mc.getSingleplayerServer(); - } - - @Override - public boolean connectedToServer() - { - return mc.getCurrentServer() != null; - } - - @Override - public int getPlayerSkylight() { - if (mc.level == null) return -1; - if (mc.player == null) return -1; - if (mc.player.blockPosition() == null) return -1; - return mc.level.getBrightness(LightLayer.SKY, mc.player.blockPosition()); - } - - public ServerData getCurrentServer() - { - return mc.getCurrentServer(); - } - - public LevelRenderer getLevelRenderer() - { - return mc.levelRenderer; + return profilerWrapper; } /** Returns all worlds available to the server */ @@ -355,7 +224,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra Iterable serverWorlds = mc.getSingleplayerServer().getAllLevels(); for (ServerLevel world : serverWorlds) { - worlds.add(LevelWrapper.getWorldWrapper(world)); + worlds.add(ServerLevelWrapper.getWrapper(world)); } return worlds; @@ -395,11 +264,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra return mc.options; } - @Override - public File getSinglePlayerServerFolder() { - return Objects.requireNonNull(mc.getSingleplayerServer()).getServerDirectory(); - } - @Override public boolean isDedicatedServer() { return false; diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java deleted file mode 100644 index 7ecc511a6..000000000 --- a/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.lod.common.wrappers.world; - -import java.awt.Color; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; -import java.util.function.Supplier; - -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableList; -import com.google.gson.JsonParser; -import com.mojang.serialization.JsonOps; -import com.seibel.lod.core.util.LodUtil; -import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; - -import net.minecraft.core.Holder; -import net.minecraft.data.BuiltinRegistries; -#if POST_MC_1_19 -import net.minecraft.data.worldgen.biome.EndBiomes; -import net.minecraft.data.worldgen.biome.NetherBiomes; -#endif -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; - - -//This class wraps the minecraft BlockPos.Mutable (and BlockPos) class -public class BiomeWrapper implements IBiomeWrapper -{ - #if PRE_MC_1_18_2 - public static final ConcurrentMap biomeWrapperMap = new ConcurrentHashMap<>(); - private final Biome biome; - #else - public static final ConcurrentMap, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>(); - private final Holder biome; - #endif - - public BiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder #endif biome) - { - this.biome = biome; - } - - static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder #endif biome) - { - //first we check if the biome has already been wrapped - if(biomeWrapperMap.containsKey(biome) && biomeWrapperMap.get(biome) != null) - return biomeWrapperMap.get(biome); - - //if it hasn't been created yet, we create it and save it in the map - BiomeWrapper biomeWrapper = new BiomeWrapper(biome); - biomeWrapperMap.put(biome, biomeWrapper); - - //we return the newly created wrapper - return biomeWrapper; - } - - private Biome _biome() { - return #if PRE_MC_1_18_2 biome #else biome.value() #endif; - } - - /** Returns a color int for the given biome. */ - #if PRE_MC_1_18_2 - @Override - public int getColorForBiome(int x, int z) - { - int colorInt; - - switch (biome.biomeCategory) - { - - case NETHER: - colorInt = Blocks.NETHERRACK.defaultBlockState().getMaterial().getColor().col; - break; - - case THEEND: - colorInt = Blocks.END_STONE.defaultBlockState().getMaterial().getColor().col; - break; - - case BEACH: - case DESERT: - colorInt = Blocks.SAND.defaultBlockState().getMaterial().getColor().col; - break; - - case EXTREME_HILLS: - colorInt = Blocks.STONE.defaultMaterialColor().col; - break; - - case MUSHROOM: - colorInt = MaterialColor.COLOR_LIGHT_GRAY.col; - break; - - case ICY: - colorInt = Blocks.SNOW.defaultMaterialColor().col; - break; - - case MESA: - colorInt = Blocks.RED_SAND.defaultMaterialColor().col; - break; - - case OCEAN: - case RIVER: - colorInt = biome.getWaterColor(); - break; - - case NONE: - case FOREST: - case TAIGA: - case JUNGLE: - case PLAINS: - case SAVANNA: - case SWAMP: - default: - colorInt = biome.getGrassColor(x,z); - //FIXME: Repair what James did - LeeTom -// Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z)); -// tmp = tmp.darker(); -// colorInt = LodUtil.colorToInt(tmp); - break; - - } - - return colorInt; - } - #else - private static int _colorEnd(Biome b) { - return Blocks.END_STONE.defaultMaterialColor().col; - } - private static int _colorNether(Biome b) { - return Blocks.NETHERRACK.defaultMaterialColor().col; - } - private static int _colorSand(Biome b) { - return Blocks.SAND.defaultMaterialColor().col; - } - private static int _colorStone(Biome b) { - return Blocks.STONE.defaultMaterialColor().col; - } - private static int _colorGravel(Biome b) { - return Blocks.GRAVEL.defaultMaterialColor().col; - } - private static int _colorDripStone(Biome b) { - return Blocks.DRIPSTONE_BLOCK.defaultMaterialColor().col; - } - private static int _colorMoss(Biome b) { - return Blocks.MOSS_BLOCK.defaultMaterialColor().col; - } - private static int _colorMushoom(Biome b) { - return Blocks.MYCELIUM.defaultMaterialColor().col; - } - private static int _colorBamboo(Biome b) { - return Blocks.BAMBOO.defaultMaterialColor().col; - } - private static int _colorSnow(Biome b) { - return Blocks.SNOW.defaultMaterialColor().col; - } - private static int _colorIce(Biome b) { - return Blocks.ICE.defaultMaterialColor().col; - } - private static int _colorRedSand(Biome b) { - return Blocks.RED_SAND.defaultMaterialColor().col; - } - private static int _colorSoulSand(Biome b) { - return Blocks.SOUL_SAND.defaultMaterialColor().col; - } - private static int _colorBasalt(Biome b) { - return Blocks.BASALT.defaultMaterialColor().col; - } - private static int _colorWater(Biome b) { - return b.getWaterColor(); - } - private static int _colorFoliage(Biome b) { - return b.getFoliageColor(); - } - #if POST_MC_1_19 - private static int _colorSculk(Biome b) { - return Blocks.SCULK.defaultMaterialColor().col; - } - #endif - - private static Biome _get(ResourceKey r) { - return BuiltinRegistries.BIOME.getOrThrow(r); - } - - //FIXME: THIS IS HELL! - private static final ImmutableBiMap> BIOME_COLOR_MAP = - ImmutableBiMap.>builder() - .put(_get(Biomes.SNOWY_PLAINS), BiomeWrapper::_colorSnow) - .put(_get(Biomes.ICE_SPIKES), BiomeWrapper::_colorIce) - .put(_get(Biomes.DESERT), BiomeWrapper::_colorSand) - .put(_get(Biomes.SWAMP), BiomeWrapper::_colorWater) - .put(_get(Biomes.FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.FLOWER_FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.BIRCH_FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.DARK_FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.OLD_GROWTH_BIRCH_FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.OLD_GROWTH_PINE_TAIGA), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.OLD_GROWTH_SPRUCE_TAIGA), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.TAIGA), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.SNOWY_TAIGA), BiomeWrapper::_colorSnow) - .put(_get(Biomes.WINDSWEPT_GRAVELLY_HILLS), BiomeWrapper::_colorGravel) - .put(_get(Biomes.WINDSWEPT_FOREST), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.JUNGLE), BiomeWrapper::_colorFoliage) - .put(_get(Biomes.BAMBOO_JUNGLE), BiomeWrapper::_colorBamboo) - .put(_get(Biomes.BADLANDS), BiomeWrapper::_colorRedSand) - .put(_get(Biomes.ERODED_BADLANDS), BiomeWrapper::_colorRedSand) - .put(_get(Biomes.WOODED_BADLANDS), BiomeWrapper::_colorStone) - .put(_get(Biomes.GROVE), BiomeWrapper::_colorSnow) - .put(_get(Biomes.SNOWY_SLOPES), BiomeWrapper::_colorSnow) - .put(_get(Biomes.FROZEN_PEAKS), BiomeWrapper::_colorIce) - .put(_get(Biomes.JAGGED_PEAKS), BiomeWrapper::_colorSnow) - .put(_get(Biomes.STONY_PEAKS), BiomeWrapper::_colorStone) - .put(_get(Biomes.RIVER), BiomeWrapper::_colorWater) - .put(_get(Biomes.FROZEN_RIVER), BiomeWrapper::_colorIce) - .put(_get(Biomes.BEACH), BiomeWrapper::_colorSand) - .put(_get(Biomes.SNOWY_BEACH), BiomeWrapper::_colorSnow) - .put(_get(Biomes.STONY_SHORE), BiomeWrapper::_colorStone) - .put(_get(Biomes.WARM_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.LUKEWARM_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.DEEP_LUKEWARM_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.DEEP_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.COLD_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.DEEP_COLD_OCEAN), BiomeWrapper::_colorWater) - .put(_get(Biomes.FROZEN_OCEAN), BiomeWrapper::_colorIce) - .put(_get(Biomes.DEEP_FROZEN_OCEAN), BiomeWrapper::_colorIce) - .put(_get(Biomes.MUSHROOM_FIELDS), BiomeWrapper::_colorMushoom) - .put(_get(Biomes.DRIPSTONE_CAVES), BiomeWrapper::_colorDripStone) - .put(_get(Biomes.LUSH_CAVES), BiomeWrapper::_colorMoss) - .put(_get(Biomes.NETHER_WASTES), BiomeWrapper::_colorNether) - .put(_get(Biomes.WARPED_FOREST), BiomeWrapper::_colorNether) - .put(_get(Biomes.CRIMSON_FOREST), BiomeWrapper::_colorNether) - .put(_get(Biomes.SOUL_SAND_VALLEY), BiomeWrapper::_colorSoulSand) - .put(_get(Biomes.BASALT_DELTAS), BiomeWrapper::_colorBasalt) - .put(_get(Biomes.THE_END), BiomeWrapper::_colorEnd) - .put(_get(Biomes.END_HIGHLANDS), BiomeWrapper::_colorEnd) - .put(_get(Biomes.END_MIDLANDS), BiomeWrapper::_colorEnd) - .put(_get(Biomes.SMALL_END_ISLANDS), BiomeWrapper::_colorEnd) - .put(_get(Biomes.END_BARRENS), BiomeWrapper::_colorEnd) - #if MC_1_19 - .put(_get(Biomes.MANGROVE_SWAMP), BiomeWrapper::_colorWater) - .put(_get(Biomes.DEEP_DARK), BiomeWrapper::_colorSculk) - #endif - .build(); - - @Override - public int getColorForBiome(int x, int z) - { - int colorInt; - Function colorFunction = BIOME_COLOR_MAP.get(biome.value()); - if (colorFunction != null) - { - colorInt = colorFunction.apply(biome.value()); - } - else - { - colorInt = biome.value().getGrassColor(x, z); - } - return colorInt; - } - #endif - - @Override - public String getName() - { - #if PRE_MC_1_18_2 - return biome.toString(); - #else - return biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString(); - #endif - } - - @Override - public int getGrassTint(int x, int z) - { - return _biome().getGrassColor(x, z); - } - - @Override - public int getFolliageTint() - { - return _biome().getFoliageColor(); - } - - @Override - public int getWaterTint() - { - return _biome().getWaterColor(); - } - - @Override - public String serialize() { - return Biome.CODEC.encodeStart(JsonOps.COMPRESSED, biome).get().orThrow().toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BiomeWrapper that = (BiomeWrapper) o; - return Objects.equals(biome, that.biome); - } - - @Override - public int hashCode() { - return Objects.hash(biome); - } - - public static IBiomeWrapper deserialize(String str) { - #if PRE_MC_1_18_2 Biome #else Holder #endif - biome = Biome.CODEC.decode(JsonOps.COMPRESSED, JsonParser.parseString(str)).get().orThrow().getFirst(); - return getBiomeWrapper(biome); - } -} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/ClientLevelWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/ClientLevelWrapper.java new file mode 100644 index 000000000..fc4af4466 --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/world/ClientLevelWrapper.java @@ -0,0 +1,148 @@ +package com.seibel.lod.common.wrappers.world; + +import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; +import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper; +import com.seibel.lod.core.api.internal.a7.ClientApi; +import com.seibel.lod.core.api.internal.a7.ServerApi; +import com.seibel.lod.core.enums.ELevelType; +import com.seibel.lod.core.objects.DHBlockPos; +import com.seibel.lod.core.objects.DHChunkPos; +import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper; +import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkSource; +import net.minecraft.world.level.chunk.ChunkStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.ConcurrentHashMap; + +public class ClientLevelWrapper implements IClientLevelWrapper +{ + private static final ConcurrentHashMap + levelWrapperMap = new ConcurrentHashMap<>(); + + public static ClientLevelWrapper getWrapper(ClientLevel level) { + return levelWrapperMap.computeIfAbsent(level, ClientLevelWrapper::new); + } + public static void closeWrapper(ClientLevel level) + { + levelWrapperMap.remove(level); + } + + private ClientLevelWrapper(ClientLevel level) { + this.level = level; + } + final ClientLevel level; + @Nullable + @Override + public IServerLevelWrapper tryGetServerSideWrapper() { + try { + return ServerLevelWrapper.getWrapper(MinecraftClientWrapper.INSTANCE.mc.getSingleplayerServer().getPlayerList() + .getPlayer(MinecraftClientWrapper.INSTANCE.mc.player.getUUID()).getLevel()); + } catch (Exception e) { + ClientApi.LOGGER.error("Failed to get server side wrapper for client level {}.", level); + return null; + } + } + public static void cleanCheck() { + if (!levelWrapperMap.isEmpty()) { + ServerApi.LOGGER.warn("{} client levels havn't been freed!", levelWrapperMap.size()); + levelWrapperMap.clear(); + } + } + + @Override + public int computeBaseColor(DHBlockPos pos, IBiomeWrapper biome, IBlockStateWrapper blockState) { + return 0; + } + + @Override + public DimensionTypeWrapper getDimensionType() + { + return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType()); + } + + @Override + public int getBlockLight(int x, int y, int z) + { + return level.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z)); + } + + @Override + public int getSkyLight(int x, int y, int z) + { + return level.getBrightness(LightLayer.SKY, new BlockPos(x,y,z)); + } + + public ClientLevel getLevel() + { + return level; + } + + @Override + public boolean hasCeiling() { + return level.dimensionType().hasCeiling(); + } + + @Override + public boolean hasSkyLight() { + return level.dimensionType().hasSkyLight(); + } + + @Override + public int getHeight() { + return level.getHeight(); + } + + @Override + public short getMinHeight() + { + #if PRE_MC_1_17_1 + return (short) 0; + #else + return (short) level.getMinBuildHeight(); + #endif + } + + @Override + public IChunkWrapper tryGetChunk(DHChunkPos pos) { + ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false); + if (chunk == null) return null; + return new ChunkWrapper(chunk, level); + } + + @Override + public boolean hasChunkLoaded(int chunkX, int chunkZ) { + ChunkSource source = level.getChunkSource(); + return source.hasChunk(chunkX, chunkZ); + } + + @Override + public IBlockStateWrapper getBlockState(DHBlockPos pos) { + return null; + } + + @Override + public IBiomeWrapper getBiome(DHBlockPos pos) { + return null; + } + + @Override + public ClientLevel unwrapLevel() + { + return level; + } + + @Override + public String toString() { + return "Wrapped{" + level.toString() + "@" + getDimensionType().getDimensionName() + "}"; + } + +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java deleted file mode 100644 index 302f0f5c9..000000000 --- a/common/src/main/java/com/seibel/lod/common/wrappers/world/LevelWrapper.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * This file is part of the Distant Horizons mod (formerly the LOD Mod), - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020-2022 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.lod.common.wrappers.world; - -import java.io.File; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper; -import com.seibel.lod.core.a7.world.WorldEnvironment; -import com.seibel.lod.core.api.internal.a7.SharedApi; -import com.seibel.lod.core.handlers.dependencyInjection.SingletonInjector; -import com.seibel.lod.core.objects.DHChunkPos; -import com.seibel.lod.core.enums.ELevelType; -import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; -import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; -import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; -import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerChunkCache; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LightLayer; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkSource; -import net.minecraft.world.level.chunk.ChunkStatus; - -import org.jetbrains.annotations.Nullable; - -/** - * @author James Seibel - * @author ?? - * @version 11-21-2021 - */ -public class LevelWrapper implements ILevelWrapper -{ - private static final ConcurrentMap levelWrapperMap = new ConcurrentHashMap<>(); - private final LevelAccessor level; - public final ELevelType levelType; - private static final IMinecraftSharedWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); - - - public LevelWrapper(LevelAccessor newWorld) - { - level = newWorld; - - if (level.getClass() == ServerLevel.class) - levelType = ELevelType.SERVER_LEVEL; - else if (level.getClass() == ClientLevel.class) - levelType = ELevelType.CLIENT_LEVEL; - else - levelType = ELevelType.UNKNOWN; - } - - //@Environment(EnvType.CLIENT) - private static LevelAccessor getSinglePlayerServerLevel() { - MinecraftClientWrapper client = MinecraftClientWrapper.INSTANCE; - return client.mc.getSingleplayerServer().getPlayerList() - .getPlayer(client.mc.player.getUUID()).getLevel(); - } - - - @Nullable - public static LevelWrapper getWorldWrapper(LevelAccessor level) - { - if (level == null) return null; - - if (level.isClientSide() && SharedApi.getEnvironment() - == WorldEnvironment.Client_Server) { - level = getSinglePlayerServerLevel(); - } - - //first we check if the level has already been wrapped - if(levelWrapperMap.containsKey(level) && levelWrapperMap.get(level) != null) - return levelWrapperMap.get(level); - - - //if it hasn't been created yet, we create it and save it in the map - LevelWrapper levelWrapper = new LevelWrapper(level); - levelWrapperMap.put(level, levelWrapper); - - //we return the newly created wrapper - return levelWrapper; - } - - public static void clearMap() - { - levelWrapperMap.clear(); - } - - @Override - public ELevelType getLevelType() - { - return levelType; - } - - @Override - public DimensionTypeWrapper getDimensionType() - { - return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType()); - } - - @Override - public int getBlockLight(int x, int y, int z) - { - return level.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z)); - } - - @Override - public int getSkyLight(int x, int y, int z) - { - return level.getBrightness(LightLayer.SKY, new BlockPos(x,y,z)); - } - - public LevelAccessor getLevel() - { - return level; - } - - @Override - public boolean hasCeiling() - { - return level.dimensionType().hasCeiling(); - } - - @Override - public boolean hasSkyLight() - { - return level.dimensionType().hasSkyLight(); - } - - @Override - public int getHeight() - { - return level.getHeight(); - } - - @Override - public short getMinHeight() - { - #if PRE_MC_1_17_1 - return (short) 0; - #else - return (short) level.getMinBuildHeight(); - #endif - } - - /** @throws UnsupportedOperationException if the WorldWrapper isn't for a ServerWorld */ - @Override - public File getSaveFolder() throws UnsupportedOperationException - { - if (levelType != ELevelType.SERVER_LEVEL) - throw new UnsupportedOperationException("getSaveFolder can only be called for ServerWorlds."); - - ServerChunkCache chunkSource = ((ServerLevel) level).getChunkSource(); - return chunkSource.getDataStorage().dataFolder; - } - - - /** @throws UnsupportedOperationException if the WorldWrapper isn't for a ServerWorld */ - public ServerLevel getServerWorld() throws UnsupportedOperationException - { - if (levelType != ELevelType.SERVER_LEVEL) - throw new UnsupportedOperationException("getSaveFolder can only be called for ServerWorlds."); - - return (ServerLevel) level; - } - - @Override - public int getSeaLevel() - { - // TODO this is depreciated, what should we use instead? - return level.getSeaLevel(); - } - - @Override - public IChunkWrapper tryGetChunk(DHChunkPos pos) { - ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false); - if (chunk == null) return null; - return new ChunkWrapper(chunk, level); - } - - @Override - public boolean hasChunkLoaded(int chunkX, int chunkZ) { - // world.hasChunk(chunkX, chunkZ); THIS DOES NOT WORK FOR CLIENT LEVEL CAUSE MOJANG ALWAYS RETURN TRUE FOR THAT! - ChunkSource source = level.getChunkSource(); - return source.hasChunk(chunkX, chunkZ); - } - - @Override - public String toString() { - return "Wrapped{" + level.toString() + "@" + getDimensionType().getDimensionName() + "}"; - } -} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/ServerLevelWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/ServerLevelWrapper.java new file mode 100644 index 000000000..01fe2a8a7 --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/world/ServerLevelWrapper.java @@ -0,0 +1,177 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.common.wrappers.world; + +import java.io.File; +import java.util.concurrent.ConcurrentHashMap; + +import com.seibel.lod.common.wrappers.minecraft.MinecraftClientWrapper; +import com.seibel.lod.core.api.internal.a7.ServerApi; +import com.seibel.lod.core.objects.DHBlockPos; +import com.seibel.lod.core.objects.DHChunkPos; +import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper; +import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper; +import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper; +import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; + +import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkSource; +import net.minecraft.world.level.chunk.ChunkStatus; + +import org.jetbrains.annotations.Nullable; + +/** + * @author James Seibel + * @author ?? + * @version 11-21-2021 + */ +public class ServerLevelWrapper implements IServerLevelWrapper +{ + private static final ConcurrentHashMap + levelWrapperMap = new ConcurrentHashMap<>(); + + public static ServerLevelWrapper getWrapper(ServerLevel level) + { + return levelWrapperMap.computeIfAbsent(level, ServerLevelWrapper::new); + } + public static void closeWrapper(ServerLevel level) + { + levelWrapperMap.remove(level); + } + public static void cleanCheck() { + if (!levelWrapperMap.isEmpty()) { + ServerApi.LOGGER.warn("{} server levels havn't been freed!", levelWrapperMap.size()); + levelWrapperMap.clear(); + } + } + + public ServerLevelWrapper(ServerLevel level) + { + this.level = level; + } + final ServerLevel level; + @Nullable + @Override + public IClientLevelWrapper tryGetClientSideWrapper() { + try { + MinecraftClientWrapper client = MinecraftClientWrapper.INSTANCE; + return ClientLevelWrapper.getWrapper(client.mc.level); + } catch (Exception e) { + ServerApi.LOGGER.error("Failed to get client side wrapper for server level {}.", level); + return null; + } + } + + @Override + public File getSaveFolder() + { + return level.getChunkSource().getDataStorage().dataFolder; + } + + @Override + public DimensionTypeWrapper getDimensionType() + { + return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType()); + } + + @Override + public int getBlockLight(int x, int y, int z) + { + return level.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z)); + } + + @Override + public int getSkyLight(int x, int y, int z) + { + return level.getBrightness(LightLayer.SKY, new BlockPos(x,y,z)); + } + + public ServerLevel getLevel() + { + return level; + } + + @Override + public boolean hasCeiling() + { + return level.dimensionType().hasCeiling(); + } + + @Override + public boolean hasSkyLight() + { + return level.dimensionType().hasSkyLight(); + } + + @Override + public int getHeight() + { + return level.getHeight(); + } + + @Override + public short getMinHeight() + { + #if PRE_MC_1_17_1 + return (short) 0; + #else + return (short) level.getMinBuildHeight(); + #endif + } + @Override + public IChunkWrapper tryGetChunk(DHChunkPos pos) { + ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false); + if (chunk == null) return null; + return new ChunkWrapper(chunk, level); + } + + @Override + public boolean hasChunkLoaded(int chunkX, int chunkZ) { + // world.hasChunk(chunkX, chunkZ); THIS DOES NOT WORK FOR CLIENT LEVEL CAUSE MOJANG ALWAYS RETURN TRUE FOR THAT! + ChunkSource source = level.getChunkSource(); + return source.hasChunk(chunkX, chunkZ); + } + + @Override + public IBlockStateWrapper getBlockState(DHBlockPos pos) { + return null; + } + + @Override + public IBiomeWrapper getBiome(DHBlockPos pos) { + return null; + } + + @Override + public ServerLevel unwrapLevel() + { + return level; + } + + @Override + public String toString() { + return "Wrapped{" + level.toString() + "@" + getDimensionType().getDimensionName() + "}"; + } +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 3df7a86d3..bf5b96655 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -21,25 +21,20 @@ package com.seibel.lod.common.wrappers.worldGeneration; -import com.seibel.lod.core.a7.datatype.full.ChunkSizedData; -import com.seibel.lod.core.a7.datatype.transform.LodDataBuilder; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.a7.level.IServerLevel; import com.seibel.lod.core.config.Config; import com.seibel.lod.core.logging.ConfigBasedLogger; import com.seibel.lod.core.logging.ConfigBasedSpamLogger; -import com.seibel.lod.core.builders.lodBuilding.LodBuilderConfig; import com.seibel.lod.core.enums.config.EDistanceGenerationMode; -import com.seibel.lod.core.enums.config.ELightGenerationMode; import com.seibel.lod.core.objects.DHChunkPos; import com.seibel.lod.core.util.EventTimer; import com.seibel.lod.core.util.LodUtil; import com.seibel.lod.core.util.gridList.ArrayGridList; import com.seibel.lod.core.util.LodThreadFactory; import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; -import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper; -import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -51,7 +46,6 @@ import java.util.concurrent.TimeUnit; import com.seibel.lod.common.wrappers.DependencySetupDoneCheck; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.LevelWrapper; import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.ChunkLoader; import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightGetterAdaptor; import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.LightedWorldGenRegion; @@ -79,7 +73,6 @@ import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.lighting.LevelLightEngine; import org.apache.logging.log4j.LogManager; -import org.checkerframework.checker.units.qual.C; /* Total: 3.135214124s @@ -268,7 +261,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv { super(serverlevel); EVENT_LOGGER.info("================WORLD_GEN_STEP_INITING============="); - ChunkGenerator generator = ((LevelWrapper) serverlevel.getLevelWrapper()).getServerWorld().getChunkSource().getGenerator(); + ChunkGenerator generator = ((ServerLevelWrapper) (serverlevel.getServerLevelWrapper())).getLevel().getChunkSource().getGenerator(); if (!(generator instanceof NoiseBasedChunkGenerator || generator instanceof DebugLevelSource || generator instanceof FlatLevelSource)) { diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java index 1fe3649de..068e14403 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java @@ -23,6 +23,7 @@ import java.lang.invoke.MethodHandles; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import com.seibel.lod.core.a7.util.UncheckedInterruptedException; import com.seibel.lod.core.config.Config; import com.seibel.lod.core.enums.config.ELightGenerationMode; import com.seibel.lod.core.logging.DhLoggerBuilder; @@ -101,6 +102,7 @@ public final class GenerationEvent public boolean hasTimeout(int duration, TimeUnit unit) { + if (timeoutTime == -1) return false; long currentTime = System.nanoTime(); long delta = currentTime - timeoutTime; return (delta > TimeUnit.NANOSECONDS.convert(duration, unit)); @@ -132,7 +134,7 @@ public final class GenerationEvent public void refreshTimeout() { timeoutTime = System.nanoTime(); - LodUtil.checkInterruptsUnchecked(); + UncheckedInterruptedException.throwIfInterrupted(); } @Override diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GlobalParameters.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GlobalParameters.java index 8e065c6f6..af700f5ce 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GlobalParameters.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GlobalParameters.java @@ -20,7 +20,7 @@ package com.seibel.lod.common.wrappers.worldGeneration; import com.mojang.datafixers.DataFixer; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.a7.level.IServerLevel; import net.minecraft.core.Registry; @@ -69,7 +69,7 @@ public final class GlobalParameters { this.lodLevel = lodLevel; - level = ((LevelWrapper)lodLevel.getLevelWrapper()).getServerWorld(); + level = ((ServerLevelWrapper)lodLevel.getServerLevelWrapper()).unwrapLevel(); lightEngine = (ThreadedLevelLightEngine) level.getLightEngine(); MinecraftServer server = level.getServer(); WorldData worldData = server.getWorldData(); diff --git a/core b/core index f08e7974c..695a25c73 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit f08e7974cd702bc2b6a0c5995a4366f1fe0c74e9 +Subproject commit 695a25c73ffa48634c06bae2b64cfd23aafe9233 diff --git a/fabric/src/main/java/com/seibel/lod/FabricClientProxy.java b/fabric/src/main/java/com/seibel/lod/FabricClientProxy.java index 8e617c48d..7d4c5a1e5 100644 --- a/fabric/src/main/java/com/seibel/lod/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/lod/FabricClientProxy.java @@ -20,8 +20,7 @@ package com.seibel.lod; import com.seibel.lod.common.wrappers.McObjectConverter; -import com.seibel.lod.common.wrappers.world.LevelWrapper; -import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; import com.seibel.lod.core.api.internal.a7.ClientApi; import com.seibel.lod.core.config.Config; import com.mojang.blaze3d.platform.InputConstants; @@ -35,10 +34,8 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; -import net.minecraft.world.level.Level; import java.util.HashSet; -import java.util.function.Supplier; import org.apache.logging.log4j.Logger; import org.lwjgl.glfw.GLFW; @@ -82,14 +79,14 @@ public class FabricClientProxy ClientChunkEvents.CHUNK_LOAD.register((level, chunk) -> ClientApi.INSTANCE.clientChunkLoadEvent( new ChunkWrapper(chunk, level), - LevelWrapper.getWorldWrapper(level) + ClientLevelWrapper.getWrapper(level) )); //#endif // ClientChunkSaveEvent ClientChunkEvents.CHUNK_UNLOAD.register((level, chunk)-> ClientApi.INSTANCE.clientChunkSaveEvent( new ChunkWrapper(chunk, level), - LevelWrapper.getWorldWrapper(level) + ClientLevelWrapper.getWrapper(level) )); // RendererStartupEvent - Done in MixinGameRenderer @@ -98,7 +95,7 @@ public class FabricClientProxy // ClientRenderLevelTerrainEvent WorldRenderEvents.AFTER_SETUP.register((renderContext) -> - clientApi.renderLods(getLevelWrapper(renderContext.world()), + clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()), McObjectConverter.Convert(renderContext.projectionMatrix()), McObjectConverter.Convert(renderContext.matrixStack().last().pose()), renderContext.tickDelta()) @@ -114,9 +111,6 @@ public class FabricClientProxy private boolean isValidTime() { return !(Minecraft.getInstance().screen instanceof TitleScreen); } - private LevelWrapper getLevelWrapper(Level level) { - return LevelWrapper.getWorldWrapper(level); - } // public void blockChangeEvent(LevelAccessor world, BlockPos pos) { // if (!isValidTime()) return; @@ -129,7 +123,7 @@ public class FabricClientProxy private static final int[] KEY_TO_CHECK_FOR = {GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8}; - HashSet previousKeyDown = new HashSet(); + HashSet previousKeyDown = new HashSet<>(); public void onKeyInput() { if (Config.Client.Advanced.Debugging.enableDebugKeybindings.get()) diff --git a/fabric/src/main/java/com/seibel/lod/FabricServerProxy.java b/fabric/src/main/java/com/seibel/lod/FabricServerProxy.java index 1ed508d22..aa3fa361a 100644 --- a/fabric/src/main/java/com/seibel/lod/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/lod/FabricServerProxy.java @@ -2,9 +2,11 @@ package com.seibel.lod; import com.seibel.lod.common.networking.Networking; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; import com.seibel.lod.core.api.internal.a7.ServerApi; +import com.seibel.lod.core.config.Config; import com.seibel.lod.core.logging.DhLoggerBuilder; import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; @@ -13,8 +15,10 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import org.apache.logging.log4j.Logger; @@ -46,8 +50,11 @@ public class FabricServerProxy { //FIXME: This may cause init issue... return !(Minecraft.getInstance().screen instanceof TitleScreen); } - private LevelWrapper getLevelWrapper(Level level) { - return LevelWrapper.getWorldWrapper(level); + private ClientLevelWrapper getLevelWrapper(ClientLevel level) { + return ClientLevelWrapper.getWrapper(level); + } + private ServerLevelWrapper getLevelWrapper(ServerLevel level) { + return ServerLevelWrapper.getWrapper(level); } /** * Registers Fabric Events @@ -89,7 +96,7 @@ public class FabricServerProxy { // ServerChunkLoadEvent ServerChunkEvents.CHUNK_LOAD.register((server, chunk) -> { - ILevelWrapper level = getLevelWrapper(chunk.getLevel()); + ILevelWrapper level = getLevelWrapper((ServerLevel) chunk.getLevel()); if (isValidTime()) ServerApi.INSTANCE.serverChunkLoadEvent( new ChunkWrapper(chunk, chunk.getLevel()), level); diff --git a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientLevel.java b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientLevel.java index c34513c14..3a36905c2 100644 --- a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientLevel.java +++ b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientLevel.java @@ -20,7 +20,8 @@ package com.seibel.lod.mixins.client; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.api.internal.a7.ClientApi; import net.minecraft.client.multiplayer.ClientLevel; #if POST_MC_1_18_2 @@ -54,7 +55,7 @@ public class MixinClientLevel { ClientLevel l = (ClientLevel) (Object) this; LevelChunk chunk = l.getChunkSource().getChunk(x, z, false); if (chunk!=null&& !chunk.isClientLightReady()) - ClientApi.INSTANCE.clientChunkLoadEvent(new ChunkWrapper(chunk, l), LevelWrapper.getWorldWrapper(l)); + ClientApi.INSTANCE.clientChunkLoadEvent(new ChunkWrapper(chunk, l), ClientLevelWrapper.getWrapper(l)); } #endif } diff --git a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientPacketListener.java b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientPacketListener.java index 47566acbe..9d749ebad 100644 --- a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientPacketListener.java +++ b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinClientPacketListener.java @@ -1,6 +1,6 @@ package com.seibel.lod.mixins.client; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; import com.seibel.lod.core.api.internal.a7.ClientApi; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; @@ -23,25 +23,25 @@ public class MixinClientPacketListener { */ @Inject(method = "handleLogin", at = @At("HEAD")) void onHandleLoginStart(CallbackInfo ci) { - if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level)); + if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); } @Inject(method = "handleLogin", at = @At("RETURN")) void onHandleLoginEnd(CallbackInfo ci) { - ClientApi.INSTANCE.clientLevelLoadEvent(LevelWrapper.getWorldWrapper(level)); + ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level)); } @Inject(method = "handleRespawn", at = @At("HEAD")) void onHandleRespawnStart(CallbackInfo ci) { - ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level)); + ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); } @Inject(method = "handleRespawn", at = @At("RETURN")) void onHandleRespawnEnd(CallbackInfo ci) { - ClientApi.INSTANCE.clientLevelLoadEvent(LevelWrapper.getWorldWrapper(level)); + ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level)); } @Inject(method = "cleanup", at = @At("HEAD")) void onCleanupStart(CallbackInfo ci) { - if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(LevelWrapper.getWorldWrapper(level)); + if (level != null) ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); } } diff --git a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java index 1cfdac454..161616e67 100644 --- a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java +++ b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java @@ -21,16 +21,15 @@ package com.seibel.lod.mixins.client; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.config.Config; import com.seibel.lod.common.wrappers.McObjectConverter; import com.seibel.lod.core.api.internal.a7.ClientApi; import com.seibel.lod.core.objects.math.Mat4f; -import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderType; -import org.lwjgl.opengl.GL15; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -110,7 +109,7 @@ public class MixinLevelRenderer Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose()); Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix); - ClientApi.INSTANCE.renderLods(LevelWrapper.getWorldWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks); + ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks); } if (Config.Client.Advanced.lodOnlyMode.get()) { callback.cancel(); diff --git a/fabric/src/main/java/com/seibel/lod/mixins/server/MixinChunkMap.java b/fabric/src/main/java/com/seibel/lod/mixins/server/MixinChunkMap.java index cc23a9b8a..3171aa3b7 100644 --- a/fabric/src/main/java/com/seibel/lod/mixins/server/MixinChunkMap.java +++ b/fabric/src/main/java/com/seibel/lod/mixins/server/MixinChunkMap.java @@ -1,7 +1,7 @@ package com.seibel.lod.mixins.server; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.api.internal.a7.ServerApi; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerLevel; @@ -31,7 +31,7 @@ public class MixinChunkMap { private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) { ServerApi.INSTANCE.serverChunkSaveEvent( new ChunkWrapper(chunk, level), - LevelWrapper.getWorldWrapper(level) + ServerLevelWrapper.getWrapper(level) ); } diff --git a/forge/src/main/java/com/seibel/lod/ForgeClientProxy.java b/forge/src/main/java/com/seibel/lod/ForgeClientProxy.java index 43657c8c1..b163967d8 100644 --- a/forge/src/main/java/com/seibel/lod/ForgeClientProxy.java +++ b/forge/src/main/java/com/seibel/lod/ForgeClientProxy.java @@ -19,7 +19,8 @@ package com.seibel.lod; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.api.internal.a7.ClientApi; import com.seibel.lod.core.logging.DhLoggerBuilder; import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; @@ -62,8 +63,7 @@ public class ForgeClientProxy { if (event.getWorld() instanceof ClientLevel) { - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientLevelLoadEvent(level); + ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld())); } } @SubscribeEvent @@ -71,8 +71,7 @@ public class ForgeClientProxy { if (event.getWorld() instanceof ClientLevel) { - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientLevelUnloadEvent(level); + ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld())); } } @@ -82,8 +81,7 @@ public class ForgeClientProxy if (event.getWorld() instanceof ClientLevel) { IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld()); - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientChunkLoadEvent(chunk, level); + ClientApi.INSTANCE.clientChunkLoadEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld())); } } @SubscribeEvent @@ -92,8 +90,7 @@ public class ForgeClientProxy if (event.getWorld() instanceof ClientLevel) { IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld()); - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientChunkSaveEvent(chunk, level); + ClientApi.INSTANCE.clientChunkSaveEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld())); } } diff --git a/forge/src/main/java/com/seibel/lod/ForgeServerProxy.java b/forge/src/main/java/com/seibel/lod/ForgeServerProxy.java index 1e8885b63..e670bd232 100644 --- a/forge/src/main/java/com/seibel/lod/ForgeServerProxy.java +++ b/forge/src/main/java/com/seibel/lod/ForgeServerProxy.java @@ -2,7 +2,7 @@ package com.seibel.lod; import com.seibel.lod.common.networking.Networking; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; import com.seibel.lod.core.api.internal.a7.ClientApi; import com.seibel.lod.core.api.internal.a7.ServerApi; @@ -41,8 +41,8 @@ public class ForgeServerProxy { //FIXME: This may cause init issue... return !(Minecraft.getInstance().screen instanceof TitleScreen); } - private LevelWrapper getLevelWrapper(Level level) { - return LevelWrapper.getWorldWrapper(level); + private ServerLevelWrapper getLevelWrapper(ServerLevel level) { + return ServerLevelWrapper.getWrapper(level); } @@ -71,7 +71,7 @@ public class ForgeServerProxy { private void serverLevelLoadEvent(WorldEvent.Load event) { if (isValidTime()) { if (event.getWorld() instanceof ServerLevel) { - serverApi.serverLevelLoadEvent(getLevelWrapper((Level) event.getWorld())); + serverApi.serverLevelLoadEvent(getLevelWrapper((ServerLevel) event.getWorld())); } } } @@ -81,7 +81,7 @@ public class ForgeServerProxy { private void serverLevelUnloadEvent(WorldEvent.Unload event) { if (isValidTime()) { if (event.getWorld() instanceof ServerLevel) { - serverApi.serverLevelUnloadEvent(getLevelWrapper((Level) event.getWorld())); + serverApi.serverLevelUnloadEvent(getLevelWrapper((ServerLevel) event.getWorld())); } } } @@ -92,8 +92,7 @@ public class ForgeServerProxy { if (isValidTime()) { if (event.getWorld() instanceof ServerLevel) { IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld()); - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientChunkLoadEvent(chunk, level); + serverApi.serverChunkLoadEvent(chunk, getLevelWrapper((ServerLevel) event.getWorld())); } } } @@ -103,8 +102,7 @@ public class ForgeServerProxy { if (isValidTime()) { if (event.getWorld() instanceof ServerLevel) { IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld()); - LevelWrapper level = new LevelWrapper(event.getWorld()); - ClientApi.INSTANCE.clientChunkSaveEvent(chunk, level); + serverApi.serverChunkSaveEvent(chunk, getLevelWrapper((ServerLevel) event.getWorld())); } } } diff --git a/forge/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java b/forge/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java index fb6e938b4..757f13a24 100644 --- a/forge/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java +++ b/forge/src/main/java/com/seibel/lod/mixins/client/MixinLevelRenderer.java @@ -22,7 +22,8 @@ package com.seibel.lod.mixins.client; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import com.seibel.lod.common.wrappers.McObjectConverter; -import com.seibel.lod.common.wrappers.world.LevelWrapper; +import com.seibel.lod.common.wrappers.world.ClientLevelWrapper; +import com.seibel.lod.common.wrappers.world.ServerLevelWrapper; import com.seibel.lod.core.config.Config; import com.seibel.lod.core.api.internal.a7.ClientApi; import com.seibel.lod.core.objects.math.Mat4f; @@ -36,8 +37,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.logging.Level; - /** * This class is used to mix in my rendering code * before Minecraft starts rendering blocks. @@ -113,7 +112,7 @@ public class MixinLevelRenderer Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose()); Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix); - ClientApi.INSTANCE.renderLods(LevelWrapper.getWorldWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks); + ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks); } if (Config.Client.Advanced.lodOnlyMode.get()) { callback.cancel();