diff --git a/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java b/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
index 9e4e94ec6..11e4ac676 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/LodCommonMain.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common;
import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
@@ -28,35 +28,36 @@ import com.seibel.distanthorizons.core.config.ConfigBase;
/**
* This is the common main class
+ *
* @author Ran
*/
-public class LodCommonMain
+public class LodCommonMain
{
- public static boolean forge = false;
- public static LodForgeMethodCaller forgeMethodCaller;
+ public static boolean forge = false;
+ public static LodForgeMethodCaller forgeMethodCaller;
- public static void startup(LodForgeMethodCaller forgeMethodCaller)
+ public static void startup(LodForgeMethodCaller forgeMethodCaller)
{
- if (forgeMethodCaller != null)
+ if (forgeMethodCaller != null)
{
- LodCommonMain.forge = true;
- LodCommonMain.forgeMethodCaller = forgeMethodCaller;
- }
+ LodCommonMain.forge = true;
+ LodCommonMain.forgeMethodCaller = forgeMethodCaller;
+ }
- DependencySetup.createSharedBindings();
- SharedApi.init();
+ DependencySetup.createSharedBindings();
+ SharedApi.init();
// if (!serverSided) {
// new NetworkReceiver().register_Client();
// } else {
// new NetworkReceiver().register_Server();
// }
- }
-
- public static void initConfig()
+ }
+
+ public static void initConfig()
{
- ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class,1);
+ ConfigBase.INSTANCE = new ConfigBase(ModInfo.ID, ModInfo.NAME, Config.class, 1);
Config.completeDelayedSetup();
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/forge/LodForgeMethodCaller.java b/common/src/main/java/com/seibel/distanthorizons/common/forge/LodForgeMethodCaller.java
index 2b73515c7..4bda7c1aa 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/forge/LodForgeMethodCaller.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/forge/LodForgeMethodCaller.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.forge;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
@@ -36,14 +36,17 @@ import java.util.Random;
/**
* used for calling methods that forge modified
* (forge modifies vanilla methods for some reason)
+ *
* @author Ran
*/
-public interface LodForgeMethodCaller {
- #if PRE_MC_1_19_2
- List getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, Random random); // FIXME: For 1.19
- #else
- List getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random); // FIXME: For 1.19
+public interface LodForgeMethodCaller
+{
+ #if PRE_MC_1_19_2
+ List getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, Random random); // FIXME: For 1.19
+ #else
+ List getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random); // FIXME: For 1.19
#endif
-
- int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z);
+
+ int colorResolverGetColor(ColorResolver resolver, Biome biome, double x, double z);
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java b/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java
index b1c6548a8..c2aaf49d4 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/rendering/SeamlessOverdraw.java
@@ -1,8 +1,10 @@
package com.seibel.distanthorizons.common.rendering;
#if PRE_MC_1_19_4
+
import com.mojang.math.Matrix4f;
#else
+
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.core.config.Config;
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java
index 3e32636ea..9fa88020f 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java
@@ -48,28 +48,28 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSha
public class DependencySetup
{
- public static void createSharedBindings()
- {
- SingletonInjector.INSTANCE.bind(ILangWrapper.class, LangWrapper.INSTANCE);
- SingletonInjector.INSTANCE.bind(IVersionConstants.class, VersionConstants.INSTANCE);
- SingletonInjector.INSTANCE.bind(IWrapperFactory.class, WrapperFactory.INSTANCE);
- SingletonInjector.INSTANCE.bind(IKeyedClientLevelManager.class, KeyedClientLevelManager.INSTANCE);
- DependencySetupDoneCheck.isDone = true;
- }
-
- //@Environment(EnvType.SERVER)
- public static void createServerBindings()
+ public static void createSharedBindings()
{
- SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftDedicatedServerWrapper.INSTANCE);
- }
-
- //@Environment(EnvType.CLIENT)
- public static void createClientBindings()
+ SingletonInjector.INSTANCE.bind(ILangWrapper.class, LangWrapper.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IVersionConstants.class, VersionConstants.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IWrapperFactory.class, WrapperFactory.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IKeyedClientLevelManager.class, KeyedClientLevelManager.INSTANCE);
+ DependencySetupDoneCheck.isDone = true;
+ }
+
+ //@Environment(EnvType.SERVER)
+ public static void createServerBindings()
{
- SingletonInjector.INSTANCE.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE);
- SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftClientWrapper.INSTANCE);
- SingletonInjector.INSTANCE.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE);
- SingletonInjector.INSTANCE.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE);
- }
+ SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftDedicatedServerWrapper.INSTANCE);
+ }
+
+ //@Environment(EnvType.CLIENT)
+ public static void createClientBindings()
+ {
+ SingletonInjector.INSTANCE.bind(IMinecraftClientWrapper.class, MinecraftClientWrapper.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftClientWrapper.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE);
+ SingletonInjector.INSTANCE.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE);
+ }
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java
index 3564e1262..271abd82d 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetupDoneCheck.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers;
import java.util.function.Supplier;
@@ -26,6 +26,6 @@ public class DependencySetupDoneCheck
// TODO move to DependencySetup
public static boolean isDone = false;
// TODO why is this here and what is its purpose?
- public static Supplier getIsCurrentThreadDistantGeneratorThread = (() -> {return false;});
+ public static Supplier getIsCurrentThreadDistantGeneratorThread = (() -> { return false; });
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java
index 8e24373e7..c4409ffb4 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java
@@ -47,53 +47,56 @@ import net.minecraft.world.level.ChunkPos;
*/
public class McObjectConverter
{
- private static int bufferIndex(int x, int y) {
- return y * 4 + x;
- }
- /** Taken from Minecraft's com.mojang.math.Matrix4f class from 1.18.2 */
- private static void storeMatrix(Matrix4f matrix, FloatBuffer buffer) {
+ private static int bufferIndex(int x, int y)
+ {
+ return y * 4 + x;
+ }
+ /** Taken from Minecraft's com.mojang.math.Matrix4f class from 1.18.2 */
+ private static void storeMatrix(Matrix4f matrix, FloatBuffer buffer)
+ {
#if PRE_MC_1_19_4
- matrix.store(buffer);
+ matrix.store(buffer);
#else
- // Mojang starts to use joml's Matrix4f libary in 1.19.3 so we copy their store method and use it here if its newer than 1.19.3
- buffer.put(bufferIndex(0, 0), matrix.m00());
- buffer.put(bufferIndex(0, 1), matrix.m01());
- buffer.put(bufferIndex(0, 2), matrix.m02());
- buffer.put(bufferIndex(0, 3), matrix.m03());
- buffer.put(bufferIndex(1, 0), matrix.m10());
- buffer.put(bufferIndex(1, 1), matrix.m11());
- buffer.put(bufferIndex(1, 2), matrix.m12());
- buffer.put(bufferIndex(1, 3), matrix.m13());
- buffer.put(bufferIndex(2, 0), matrix.m20());
- buffer.put(bufferIndex(2, 1), matrix.m21());
- buffer.put(bufferIndex(2, 2), matrix.m22());
- buffer.put(bufferIndex(2, 3), matrix.m23());
- buffer.put(bufferIndex(3, 0), matrix.m30());
- buffer.put(bufferIndex(3, 1), matrix.m31());
- buffer.put(bufferIndex(3, 2), matrix.m32());
- buffer.put(bufferIndex(3, 3), matrix.m33());
+ // Mojang starts to use joml's Matrix4f libary in 1.19.3 so we copy their store method and use it here if its newer than 1.19.3
+ buffer.put(bufferIndex(0, 0), matrix.m00());
+ buffer.put(bufferIndex(0, 1), matrix.m01());
+ buffer.put(bufferIndex(0, 2), matrix.m02());
+ buffer.put(bufferIndex(0, 3), matrix.m03());
+ buffer.put(bufferIndex(1, 0), matrix.m10());
+ buffer.put(bufferIndex(1, 1), matrix.m11());
+ buffer.put(bufferIndex(1, 2), matrix.m12());
+ buffer.put(bufferIndex(1, 3), matrix.m13());
+ buffer.put(bufferIndex(2, 0), matrix.m20());
+ buffer.put(bufferIndex(2, 1), matrix.m21());
+ buffer.put(bufferIndex(2, 2), matrix.m22());
+ buffer.put(bufferIndex(2, 3), matrix.m23());
+ buffer.put(bufferIndex(3, 0), matrix.m30());
+ buffer.put(bufferIndex(3, 1), matrix.m31());
+ buffer.put(bufferIndex(3, 2), matrix.m32());
+ buffer.put(bufferIndex(3, 3), matrix.m33());
#endif
- }
-
- /** 4x4 float matrix converter */
- public static Mat4f Convert(Matrix4f mcMatrix)
- {
- FloatBuffer buffer = FloatBuffer.allocate(16);
- storeMatrix(mcMatrix, buffer);
- Mat4f matrix = new Mat4f(buffer);
+ }
+
+ /** 4x4 float matrix converter */
+ public static Mat4f Convert(Matrix4f mcMatrix)
+ {
+ FloatBuffer buffer = FloatBuffer.allocate(16);
+ storeMatrix(mcMatrix, buffer);
+ Mat4f matrix = new Mat4f(buffer);
#if PRE_MC_1_19_4
- matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it
+ matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it
#endif
- return matrix;
- }
-
-
- static final Direction[] directions;
- static final EDhDirection[] lodDirections;
- static {
- EDhDirection[] lodDirs = EDhDirection.values();
- directions = new Direction[lodDirs.length];
- lodDirections = new EDhDirection[lodDirs.length];
+ return matrix;
+ }
+
+
+ static final Direction[] directions;
+ static final EDhDirection[] lodDirections;
+ static
+ {
+ EDhDirection[] lodDirs = EDhDirection.values();
+ directions = new Direction[lodDirs.length];
+ lodDirections = new EDhDirection[lodDirs.length];
for (EDhDirection lodDir : lodDirs)
{
Direction dir;
@@ -129,39 +132,43 @@ public class McObjectConverter
directions[lodDir.ordinal()] = dir;
lodDirections[dir.ordinal()] = lodDir;
}
- }
-
- public static BlockPos Convert(DhBlockPos wrappedPos) {
- return new BlockPos(wrappedPos.x, wrappedPos.y, wrappedPos.z);
- }
- public static ChunkPos Convert(DhChunkPos wrappedPos) {
- return new ChunkPos(wrappedPos.x, wrappedPos.z);
- }
-
- public static Direction Convert(EDhDirection lodDirection)
- {
- return directions[lodDirection.ordinal()];
- }
- public static EDhDirection Convert(Direction direction)
- {
- return lodDirections[direction.ordinal()];
- }
- public static void DebugCheckAllPackers() {
- BiConsumer func = (x, z) -> DhChunkPos._DebugCheckPacker(x,z,ChunkPos.asLong(x,z));
- func.accept(0,0);
- func.accept(12345,134);
- func.accept(-12345,-134);
- func.accept(-30000000/16,30000000/16);
- func.accept(30000000/16,-30000000/16);
- func.accept(30000000/16,30000000/16);
- func.accept(-30000000/16,-30000000/16);
- Consumer func2 = (p) -> DhBlockPos._DebugCheckPacker(p.getX(),p.getY(),p.getZ(),p.asLong());
- func2.accept(new BlockPos(0,0,0));
- func2.accept(new BlockPos(12345,134,123));
- func2.accept(new BlockPos(-12345,-134,-80));
- func2.accept(new BlockPos(-30000000, 2047, 30000000));
- func2.accept(new BlockPos(30000000, -2048, -30000000));
- func2.accept(new BlockPos(30000000, 2047, 30000000));
- func2.accept(new BlockPos(-30000000, -2048, -30000000));
- }
+ }
+
+ public static BlockPos Convert(DhBlockPos wrappedPos)
+ {
+ return new BlockPos(wrappedPos.x, wrappedPos.y, wrappedPos.z);
+ }
+ public static ChunkPos Convert(DhChunkPos wrappedPos)
+ {
+ return new ChunkPos(wrappedPos.x, wrappedPos.z);
+ }
+
+ public static Direction Convert(EDhDirection lodDirection)
+ {
+ return directions[lodDirection.ordinal()];
+ }
+ public static EDhDirection Convert(Direction direction)
+ {
+ return lodDirections[direction.ordinal()];
+ }
+ public static void DebugCheckAllPackers()
+ {
+ BiConsumer func = (x, z) -> DhChunkPos._DebugCheckPacker(x, z, ChunkPos.asLong(x, z));
+ func.accept(0, 0);
+ func.accept(12345, 134);
+ func.accept(-12345, -134);
+ func.accept(-30000000 / 16, 30000000 / 16);
+ func.accept(30000000 / 16, -30000000 / 16);
+ func.accept(30000000 / 16, 30000000 / 16);
+ func.accept(-30000000 / 16, -30000000 / 16);
+ Consumer func2 = (p) -> DhBlockPos._DebugCheckPacker(p.getX(), p.getY(), p.getZ(), p.asLong());
+ func2.accept(new BlockPos(0, 0, 0));
+ func2.accept(new BlockPos(12345, 134, 123));
+ func2.accept(new BlockPos(-12345, -134, -80));
+ func2.accept(new BlockPos(-30000000, 2047, 30000000));
+ func2.accept(new BlockPos(30000000, -2048, -30000000));
+ func2.accept(new BlockPos(30000000, 2047, 30000000));
+ func2.accept(new BlockPos(-30000000, -2048, -30000000));
+ }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java
index 5a60af01b..3c25fa0e4 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers;
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
@@ -43,25 +43,27 @@ public class VersionConstants implements IVersionConstants
{
return 0;
}
-
+
@Override
public int getWorldGenerationCountPerThread()
{
return 1;
}
-
+
@Override
public boolean isVanillaRenderedChunkSquare()
{
return false;
}
-
+
@Override
- public String getMinecraftVersion() {
+ public String getMinecraftVersion()
+ {
#if PRE_MC_1_19_2
return Minecraft.getInstance().getGame().getVersion().getId();
#else
return SharedConstants.getCurrentVersion().getId();
#endif
}
+
}
\ No newline at end of file
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java
index 5d6268da4..85fee0a84 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/WrapperFactory.java
@@ -38,6 +38,7 @@ import java.io.IOException;
/**
* This handles creating abstract wrapper objects.
+ *
* @author James Seibel
* @version 2022-12-5
*/
@@ -74,8 +75,9 @@ public class WrapperFactory implements IWrapperFactory
/**
* Note: when this is updated for different MC versions, make sure you also update the documentation in
* {@link IDhApiWorldGenerator#generateChunks} and the type list in {@link WrapperFactory#createChunkWrapperErrorMessage}.
- *
+ *
* For full method documentation please see: {@link IWrapperFactory#createChunkWrapper}
+ *
* @see IWrapperFactory#createChunkWrapper
*/
public IChunkWrapper createChunkWrapper(Object[] objectArray) throws ClassCastException
@@ -105,14 +107,14 @@ public class WrapperFactory implements IWrapperFactory
{
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
}
- ChunkAccess chunk = (ChunkAccess)objectArray[0];
+ ChunkAccess chunk = (ChunkAccess) objectArray[0];
// light source
if (!(objectArray[1] instanceof LevelReader))
{
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
}
- LevelReader lightSource = (LevelReader)objectArray[1];
+ LevelReader lightSource = (LevelReader) objectArray[1];
return new ChunkWrapper(chunk, lightSource, /*A DH wrapped level isn't necessary*/null);
@@ -133,9 +135,9 @@ public class WrapperFactory implements IWrapperFactory
not implemented for this version of Minecraft!
#endif
}
- /**
- * Note: when this is updated for different MC versions,
- * make sure you also update the documentation in {@link IDhApiWorldGenerator#generateChunks}.
+ /**
+ * Note: when this is updated for different MC versions,
+ * make sure you also update the documentation in {@link IDhApiWorldGenerator#generateChunks}.
*/
private static String createChunkWrapperErrorMessage(Object[] objectArray)
{
@@ -145,8 +147,8 @@ public class WrapperFactory implements IWrapperFactory
// MC 1.16, 1.18, 1.19, 1.20
#if POST_MC_1_17_1 || MC_1_16_5
- message.append("["+ChunkAccess.class.getName()+"], \n");
- message.append("["+LevelReader.class.getName()+"]. \n");
+ message.append("[" + ChunkAccess.class.getName() + "], \n");
+ message.append("[" + LevelReader.class.getName() + "]. \n");
#else
// See preprocessor comment in createChunkWrapper() for full documentation
not implemented for this version of Minecraft!
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java
index eb225280e..be8e7620c 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -63,15 +64,15 @@ public class BiomeWrapper implements IBiomeWrapper
private static final Logger LOGGER = LogManager.getLogger();
- #if PRE_MC_1_18_2
- public static final ConcurrentMap biomeWrapperMap = new ConcurrentHashMap<>();
- public final Biome biome;
- #else
- public static final ConcurrentMap, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
- public final Holder biome;
+ #if PRE_MC_1_18_2
+ public static final ConcurrentMap biomeWrapperMap = new ConcurrentHashMap<>();
+ public final Biome biome;
+ #else
+ public static final ConcurrentMap, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
+ public final Holder biome;
#endif
- /**
+ /**
* Cached so it can be quickly used as a semi-stable hashing method.
* This may also fix the issue where we can serialize and save after a level has been shut down.
*/
@@ -83,15 +84,15 @@ public class BiomeWrapper implements IBiomeWrapper
// constructors //
//==============//
- 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;
- }
+ 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;
+ }
@@ -100,34 +101,34 @@ public class BiomeWrapper implements IBiomeWrapper
//=========//
@Override
- public String getName()
- {
+ public String getName()
+ {
#if PRE_MC_1_18_2
- return biome.toString();
+ return biome.toString();
#else
- return this.biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString();
+ return this.biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString();
#endif
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
return true;
- }
- else if (obj == null || this.getClass() != obj.getClass())
- {
+ }
+ else if (obj == null || this.getClass() != obj.getClass())
+ {
return false;
- }
+ }
- BiomeWrapper that = (BiomeWrapper) obj;
- // the serialized value is used so we can test the contents instead of the references
- return Objects.equals(this.serialize(), that.serialize());
- }
-
- @Override
- public int hashCode() { return Objects.hash(this.serialize()); }
+ BiomeWrapper that = (BiomeWrapper) obj;
+ // the serialized value is used so we can test the contents instead of the references
+ return Objects.equals(this.serialize(), that.serialize());
+ }
+
+ @Override
+ public int hashCode() { return Objects.hash(this.serialize()); }
@Override
public String serialize() // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
@@ -154,13 +155,13 @@ public class BiomeWrapper implements IBiomeWrapper
biomeName = this.biome.value().toString();
#endif
- LOGGER.warn("unable to serialize: "+biomeName);
+ LOGGER.warn("unable to serialize: " + biomeName);
// shouldn't normally happen, but just in case
this.serializationResult = "";
}
else
{
- this.serializationResult = resourceLocation.getNamespace()+":"+resourceLocation.getPath();
+ this.serializationResult = resourceLocation.getNamespace() + ":" + resourceLocation.getPath();
}
}
@@ -182,9 +183,9 @@ public class BiomeWrapper implements IBiomeWrapper
int separatorIndex = resourceLocationString.indexOf(":");
if (separatorIndex == -1)
{
- throw new IOException("Unable to parse resource location string: ["+resourceLocationString+"].");
+ throw new IOException("Unable to parse resource location string: [" + resourceLocationString + "].");
}
- ResourceLocation resourceLocation = new ResourceLocation(resourceLocationString.substring(0, separatorIndex), resourceLocationString.substring(separatorIndex+1));
+ ResourceLocation resourceLocation = new ResourceLocation(resourceLocationString.substring(0, separatorIndex), resourceLocationString.substring(separatorIndex + 1));
try
@@ -200,7 +201,7 @@ public class BiomeWrapper implements IBiomeWrapper
Biome unwrappedBiome = registryAccess.registryOrThrow(Registries.BIOME).get(resourceLocation);
if (unwrappedBiome == null)
{
- LOGGER.warn("null biome string deserialized from string: "+resourceLocationString);
+ LOGGER.warn("null biome string deserialized from string: " + resourceLocationString);
}
Holder biome = new Holder.Direct<>(unwrappedBiome);
#endif
@@ -209,12 +210,12 @@ public class BiomeWrapper implements IBiomeWrapper
}
catch (Exception e)
{
- throw new IOException("Failed to deserialize the string ["+resourceLocationString+"] into a BiomeWrapper: "+e.getMessage(), e);
+ throw new IOException("Failed to deserialize the string [" + resourceLocationString + "] into a BiomeWrapper: " + e.getMessage(), e);
}
}
- @Override
+ @Override
public Object getWrappedMcObject() { return this.biome; }
@Override
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java
index 6a1c5f430..817dfcab8 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java
@@ -40,7 +40,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
public static final BlockStateWrapper AIR = new BlockStateWrapper(null);
- public static final ConcurrentHashMap cache = new ConcurrentHashMap<>();
+ public static final ConcurrentHashMap cache = new ConcurrentHashMap<>();
/**
* Cached so it can be quickly used as a semi-stable hashing method.
@@ -53,22 +53,22 @@ public class BlockStateWrapper implements IBlockStateWrapper
// constructors //
//==============//
- public static BlockStateWrapper fromBlockState(BlockState blockState)
+ public static BlockStateWrapper fromBlockState(BlockState blockState)
{
- if (blockState == null || blockState.isAir())
- {
- return AIR;
- }
+ if (blockState == null || blockState.isAir())
+ {
+ return AIR;
+ }
- return cache.computeIfAbsent(blockState, BlockStateWrapper::new);
- }
-
- public final BlockState blockState;
- BlockStateWrapper(BlockState blockState)
- {
- this.blockState = blockState;
- LOGGER.trace("Created BlockStateWrapper for ["+blockState+"]");
- }
+ return cache.computeIfAbsent(blockState, BlockStateWrapper::new);
+ }
+
+ public final BlockState blockState;
+ BlockStateWrapper(BlockState blockState)
+ {
+ this.blockState = blockState;
+ LOGGER.trace("Created BlockStateWrapper for [" + blockState + "]");
+ }
@@ -97,7 +97,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
@Override
- public String serialize() // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
+ public String serialize() // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
{
// cache the serialization result so it can be quickly used as a semi-stable hashing method
if (this.serializationResult == null)
@@ -120,7 +120,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
if (resourceLocation == null)
{
- LOGGER.warn("unable to serialize: "+this.blockState);
+ LOGGER.warn("unable to serialize: " + this.blockState);
}
this.serializationResult = resourceLocation.getNamespace() + RESOURCE_LOCATION_SEPARATOR + resourceLocation.getPath()
@@ -144,18 +144,18 @@ public class BlockStateWrapper implements IBlockStateWrapper
int stateSeparatorIndex = resourceStateString.indexOf(STATE_STRING_SEPARATOR);
if (stateSeparatorIndex == -1)
{
- throw new IOException("Unable to parse BlockState out of string: ["+resourceStateString+"].");
+ throw new IOException("Unable to parse BlockState out of string: [" + resourceStateString + "].");
}
- String blockStatePropertiesString = resourceStateString.substring(stateSeparatorIndex+STATE_STRING_SEPARATOR.length());
- resourceStateString = resourceStateString.substring(0, stateSeparatorIndex);
+ String blockStatePropertiesString = resourceStateString.substring(stateSeparatorIndex + STATE_STRING_SEPARATOR.length());
+ resourceStateString = resourceStateString.substring(0, stateSeparatorIndex);
// parse the resource location
int resourceSeparatorIndex = resourceStateString.indexOf(RESOURCE_LOCATION_SEPARATOR);
if (resourceSeparatorIndex == -1)
{
- throw new IOException("Unable to parse Resource Location out of string: ["+resourceStateString+"].");
+ throw new IOException("Unable to parse Resource Location out of string: [" + resourceStateString + "].");
}
- ResourceLocation resourceLocation = new ResourceLocation(resourceStateString.substring(0, resourceSeparatorIndex), resourceStateString.substring(resourceSeparatorIndex+1));
+ ResourceLocation resourceLocation = new ResourceLocation(resourceStateString.substring(0, resourceSeparatorIndex), resourceStateString.substring(resourceSeparatorIndex + 1));
@@ -190,16 +190,16 @@ public class BlockStateWrapper implements IBlockStateWrapper
// use the default if no state was found
if (foundState == null)
{
- LOGGER.warn("Unable to find BlockState for Block ["+resourceLocation+"] with properties: ["+blockStatePropertiesString+"].");
+ LOGGER.warn("Unable to find BlockState for Block [" + resourceLocation + "] with properties: [" + blockStatePropertiesString + "].");
foundState = block.defaultBlockState();
}
return new BlockStateWrapper(foundState);
}
catch (Exception e)
{
- throw new IOException("Failed to deserialize the string ["+resourceStateString+"] into a BlockStateWrapper: "+e.getMessage(), e);
+ throw new IOException("Failed to deserialize the string [" + resourceStateString + "] into a BlockStateWrapper: " + e.getMessage(), e);
}
- }
+ }
/** used to compare and save BlockStates based on their properties */
private static String serializeBlockStateProperties(BlockState blockState)
@@ -209,7 +209,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
// alphabetically sort the list so they are always in the same order
List> sortedBlockPropteryList = new ArrayList<>(blockPropertyCollection);
- sortedBlockPropteryList.sort((a,b) -> a.getName().compareTo(b.getName()));
+ sortedBlockPropteryList.sort((a, b) -> a.getName().compareTo(b.getName()));
StringBuilder stringBuilder = new StringBuilder();
@@ -232,26 +232,26 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
{
return true;
- }
+ }
- if (obj == null || this.getClass() != obj.getClass())
- {
+ if (obj == null || this.getClass() != obj.getClass())
+ {
return false;
- }
+ }
- BlockStateWrapper that = (BlockStateWrapper) obj;
- // the serialized value is used so we can test the contents instead of the references
- return Objects.equals(this.serialize(), that.serialize());
- }
-
- @Override
- public int hashCode() { return Objects.hash(this.serialize()); }
+ BlockStateWrapper that = (BlockStateWrapper) obj;
+ // the serialized value is used so we can test the contents instead of the references
+ return Objects.equals(this.serialize(), that.serialize());
+ }
+
+ @Override
+ public int hashCode() { return Objects.hash(this.serialize()); }
@Override
@@ -262,17 +262,17 @@ public class BlockStateWrapper implements IBlockStateWrapper
public boolean isAir(BlockState blockState) { return blockState == null || blockState.isAir(); }
@Override
- public boolean isSolid()
+ public boolean isSolid()
{
#if PRE_MC_1_20_1
- return this.blockState.getMaterial().isSolid();
+ return this.blockState.getMaterial().isSolid();
#else
- return !this.blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).isEmpty();
+ return !this.blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO).isEmpty();
#endif
- }
+ }
@Override
- public boolean isLiquid()
+ public boolean isLiquid()
{
if (this.isAir())
{
@@ -280,11 +280,11 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
#if PRE_MC_1_20_1
- return this.blockState.getMaterial().isLiquid();
+ return this.blockState.getMaterial().isLiquid();
#else
- return !this.blockState.getFluidState().isEmpty();
+ return !this.blockState.getFluidState().isEmpty();
#endif
- }
+ }
@Override
public String toString() { return this.serialize(); }
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TextureAtlasSpriteWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TextureAtlasSpriteWrapper.java
index 6b2bc4dd0..1be216135 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TextureAtlasSpriteWrapper.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TextureAtlasSpriteWrapper.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block;
@@ -24,36 +24,42 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
/**
* For wrapping/utilizing around TextureAtlasSprite
+ *
* @author Ran
*/
-public class TextureAtlasSpriteWrapper {
-
- /**
- * This code is from Minecraft Forge
- * Which is licensed under the terms of GNU Lesser General Public License
- * as published by the Free Software Foundation version 2.1
- * of the License.
- *
- * The code has been modified to use TextureAtlasSprite
- */
- public static int getPixelRGBA(TextureAtlasSprite sprite, int frameIndex, int x, int y) {
+public class TextureAtlasSpriteWrapper
+{
+
+ /**
+ * This code is from Minecraft Forge
+ * Which is licensed under the terms of GNU Lesser General Public License
+ * as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * The code has been modified to use TextureAtlasSprite
+ */
+ public static int getPixelRGBA(TextureAtlasSprite sprite, int frameIndex, int x, int y)
+ {
#if PRE_MC_1_17_1
return sprite.mainImage[0].getPixelRGBA(
x + sprite.framesX[frameIndex] * sprite.getWidth(),
y + sprite.framesY[frameIndex] * sprite.getHeight());
#elif PRE_MC_1_19_4
- if (sprite.animatedTexture != null) {
- x += sprite.animatedTexture.getFrameX(frameIndex) * sprite.width;
- y += sprite.animatedTexture.getFrameY(frameIndex) * sprite.height;
- }
- return sprite.mainImage[0].getPixelRGBA(x, y);
+ if (sprite.animatedTexture != null)
+ {
+ x += sprite.animatedTexture.getFrameX(frameIndex) * sprite.width;
+ y += sprite.animatedTexture.getFrameY(frameIndex) * sprite.height;
+ }
+ return sprite.mainImage[0].getPixelRGBA(x, y);
#else
- if (sprite.contents().animatedTexture != null) {
- x += sprite.contents().animatedTexture.getFrameX(frameIndex) * sprite.contents().width();
- y += sprite.contents().animatedTexture.getFrameY(frameIndex) * sprite.contents().width();
- }
- return sprite.contents().originalImage.getPixelRGBA(x, y);
+ if (sprite.contents().animatedTexture != null)
+ {
+ x += sprite.contents().animatedTexture.getFrameX(frameIndex) * sprite.contents().width();
+ y += sprite.contents().animatedTexture.getFrameY(frameIndex) * sprite.contents().width();
+ }
+ return sprite.contents().originalImage.getPixelRGBA(x, y);
#endif
-
- }
+
+ }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideFast.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideFast.java
index 8242a139a..434d5a3c5 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideFast.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideFast.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block;
import com.seibel.distanthorizons.common.LodCommonMain;
@@ -39,171 +39,205 @@ import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
-public class TintGetterOverrideFast implements BlockAndTintGetter {
- LevelReader parent;
-
- public TintGetterOverrideFast(LevelReader parent) {
- this.parent = parent;
- }
-
- private Biome _getBiome(BlockPos pos) {
+public class TintGetterOverrideFast implements BlockAndTintGetter
+{
+ LevelReader parent;
+
+ public TintGetterOverrideFast(LevelReader parent)
+ {
+ this.parent = parent;
+ }
+
+ private Biome _getBiome(BlockPos pos)
+ {
#if POST_MC_1_18_2
- return parent.getBiome(pos).value();
+ return parent.getBiome(pos).value();
#else
return parent.getBiome(pos);
#endif
- }
-
- @Override
- public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
- if (LodCommonMain.forgeMethodCaller != null) {
- return LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(blockPos),
- blockPos.getX(), blockPos.getZ());
- } else {
- return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
- }
- }
-
- @Override
- public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
-
- @Override
- public LevelLightEngine getLightEngine() {
- return parent.getLightEngine();
- }
-
- @Override
- public int getBrightness(LightLayer lightLayer, BlockPos blockPos) {
- return parent.getBrightness(lightLayer, blockPos);
- }
-
- @Override
- public int getRawBrightness(BlockPos blockPos, int i) {
- return parent.getRawBrightness(blockPos, i);
- }
-
- @Override
- public boolean canSeeSky(BlockPos blockPos) {
- return parent.canSeeSky(blockPos);
- }
-
- @Override
- @Nullable
- public BlockEntity getBlockEntity(BlockPos blockPos) {
- return parent.getBlockEntity(blockPos);
- }
-
-
- @Override
- public BlockState getBlockState(BlockPos blockPos) {
- return parent.getBlockState(blockPos);
- }
-
- @Override
- public FluidState getFluidState(BlockPos blockPos) {
- return parent.getFluidState(blockPos);
- }
-
- @Override
- public int getLightEmission(BlockPos blockPos) {
- return parent.getLightEmission(blockPos);
- }
-
- @Override
- public int getMaxLightLevel() {
- return parent.getMaxLightLevel();
- }
-
- @Override
- public Stream getBlockStates(AABB aABB) {
- return parent.getBlockStates(aABB);
- }
-
- @Override
- public BlockHitResult clip(ClipContext clipContext) {
- return parent.clip(clipContext);
- }
-
- @Override
- @Nullable
- public BlockHitResult clipWithInteractionOverride(Vec3 vec3, Vec3 vec32, BlockPos blockPos, VoxelShape voxelShape, BlockState blockState) {
- return parent.clipWithInteractionOverride(vec3, vec32, blockPos, voxelShape, blockState);
- }
-
- @Override
- public double getBlockFloorHeight(VoxelShape voxelShape, Supplier supplier) {
- return parent.getBlockFloorHeight(voxelShape, supplier);
- }
-
- @Override
- public double getBlockFloorHeight(BlockPos blockPos) {
- return parent.getBlockFloorHeight(blockPos);
- }
-
- @Override
- public int getMaxBuildHeight() {
- return parent.getMaxBuildHeight();
- }
-
- #if POST_MC_1_17_1
- @Override
- public Optional getBlockEntity(BlockPos blockPos, BlockEntityType blockEntityType) {
- return parent.getBlockEntity(blockPos, blockEntityType);
- }
-
- @Override
- public BlockHitResult isBlockInLine(ClipBlockStateContext clipBlockStateContext) {
- return parent.isBlockInLine(clipBlockStateContext);
- }
-
- @Override
- public int getHeight() {
- return parent.getHeight();
- }
-
- @Override
- public int getMinBuildHeight() {
- return parent.getMinBuildHeight();
- }
-
- @Override
- public int getSectionsCount() {
- return parent.getSectionsCount();
- }
-
- @Override
- public int getMinSection() {
- return parent.getMinSection();
- }
-
- @Override
- public int getMaxSection() {
- return parent.getMaxSection();
- }
-
- @Override
- public boolean isOutsideBuildHeight(BlockPos blockPos) {
- return parent.isOutsideBuildHeight(blockPos);
- }
-
- @Override
- public boolean isOutsideBuildHeight(int i) {
- return parent.isOutsideBuildHeight(i);
- }
-
- @Override
- public int getSectionIndex(int i) {
- return parent.getSectionIndex(i);
- }
-
- @Override
- public int getSectionIndexFromSectionY(int i) {
- return parent.getSectionIndexFromSectionY(i);
- }
-
- @Override
- public int getSectionYFromSectionIndex(int i) {
- return parent.getSectionYFromSectionIndex(i);
- }
+ }
+
+ @Override
+ public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver)
+ {
+ if (LodCommonMain.forgeMethodCaller != null)
+ {
+ return LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(blockPos),
+ blockPos.getX(), blockPos.getZ());
+ }
+ else
+ {
+ return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
+ }
+ }
+
+ @Override
+ public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
+
+ @Override
+ public LevelLightEngine getLightEngine()
+ {
+ return parent.getLightEngine();
+ }
+
+ @Override
+ public int getBrightness(LightLayer lightLayer, BlockPos blockPos)
+ {
+ return parent.getBrightness(lightLayer, blockPos);
+ }
+
+ @Override
+ public int getRawBrightness(BlockPos blockPos, int i)
+ {
+ return parent.getRawBrightness(blockPos, i);
+ }
+
+ @Override
+ public boolean canSeeSky(BlockPos blockPos)
+ {
+ return parent.canSeeSky(blockPos);
+ }
+
+ @Override
+ @Nullable
+ public BlockEntity getBlockEntity(BlockPos blockPos)
+ {
+ return parent.getBlockEntity(blockPos);
+ }
+
+
+ @Override
+ public BlockState getBlockState(BlockPos blockPos)
+ {
+ return parent.getBlockState(blockPos);
+ }
+
+ @Override
+ public FluidState getFluidState(BlockPos blockPos)
+ {
+ return parent.getFluidState(blockPos);
+ }
+
+ @Override
+ public int getLightEmission(BlockPos blockPos)
+ {
+ return parent.getLightEmission(blockPos);
+ }
+
+ @Override
+ public int getMaxLightLevel()
+ {
+ return parent.getMaxLightLevel();
+ }
+
+ @Override
+ public Stream getBlockStates(AABB aABB)
+ {
+ return parent.getBlockStates(aABB);
+ }
+
+ @Override
+ public BlockHitResult clip(ClipContext clipContext)
+ {
+ return parent.clip(clipContext);
+ }
+
+ @Override
+ @Nullable
+ public BlockHitResult clipWithInteractionOverride(Vec3 vec3, Vec3 vec32, BlockPos blockPos, VoxelShape voxelShape, BlockState blockState)
+ {
+ return parent.clipWithInteractionOverride(vec3, vec32, blockPos, voxelShape, blockState);
+ }
+
+ @Override
+ public double getBlockFloorHeight(VoxelShape voxelShape, Supplier supplier)
+ {
+ return parent.getBlockFloorHeight(voxelShape, supplier);
+ }
+
+ @Override
+ public double getBlockFloorHeight(BlockPos blockPos)
+ {
+ return parent.getBlockFloorHeight(blockPos);
+ }
+
+ @Override
+ public int getMaxBuildHeight()
+ {
+ return parent.getMaxBuildHeight();
+ }
+
+ #if POST_MC_1_17_1
+ @Override
+ public Optional getBlockEntity(BlockPos blockPos, BlockEntityType blockEntityType)
+ {
+ return parent.getBlockEntity(blockPos, blockEntityType);
+ }
+
+ @Override
+ public BlockHitResult isBlockInLine(ClipBlockStateContext clipBlockStateContext)
+ {
+ return parent.isBlockInLine(clipBlockStateContext);
+ }
+
+ @Override
+ public int getHeight()
+ {
+ return parent.getHeight();
+ }
+
+ @Override
+ public int getMinBuildHeight()
+ {
+ return parent.getMinBuildHeight();
+ }
+
+ @Override
+ public int getSectionsCount()
+ {
+ return parent.getSectionsCount();
+ }
+
+ @Override
+ public int getMinSection()
+ {
+ return parent.getMinSection();
+ }
+
+ @Override
+ public int getMaxSection()
+ {
+ return parent.getMaxSection();
+ }
+
+ @Override
+ public boolean isOutsideBuildHeight(BlockPos blockPos)
+ {
+ return parent.isOutsideBuildHeight(blockPos);
+ }
+
+ @Override
+ public boolean isOutsideBuildHeight(int i)
+ {
+ return parent.isOutsideBuildHeight(i);
+ }
+
+ @Override
+ public int getSectionIndex(int i)
+ {
+ return parent.getSectionIndex(i);
+ }
+
+ @Override
+ public int getSectionIndexFromSectionY(int i)
+ {
+ return parent.getSectionIndexFromSectionY(i);
+ }
+
+ @Override
+ public int getSectionYFromSectionIndex(int i)
+ {
+ return parent.getSectionYFromSectionIndex(i);
+ }
#endif
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideSmooth.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideSmooth.java
index a1e7e9e03..a078107b0 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideSmooth.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverrideSmooth.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block;
import com.seibel.distanthorizons.common.LodCommonMain;
@@ -40,196 +40,230 @@ import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
-public class TintGetterOverrideSmooth implements BlockAndTintGetter {
- LevelReader parent;
- public int smoothingRange;
-
- public TintGetterOverrideSmooth(LevelReader parent, int smoothingRange) {
- this.parent = parent;
- this.smoothingRange = smoothingRange;
- }
-
- private Biome _getBiome(BlockPos pos) {
+public class TintGetterOverrideSmooth implements BlockAndTintGetter
+{
+ LevelReader parent;
+ public int smoothingRange;
+
+ public TintGetterOverrideSmooth(LevelReader parent, int smoothingRange)
+ {
+ this.parent = parent;
+ this.smoothingRange = smoothingRange;
+ }
+
+ private Biome _getBiome(BlockPos pos)
+ {
#if POST_MC_1_18_2
- return parent.getBiome(pos).value();
+ return parent.getBiome(pos).value();
#else
- return parent.getBiome(pos);
+ return parent.getBiome(pos);
#endif
- }
-
- public int calculateBlockTint(BlockPos blockPos, ColorResolver colorResolver)
- {
- int i = smoothingRange;
- if (i == 0)
- return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
- int j = (i * 2 + 1) * (i * 2 + 1);
- int k = 0;
- int l = 0;
- int m = 0;
- Cursor3D cursor3D = new Cursor3D(blockPos.getX() - i, blockPos.getY(), blockPos.getZ() - i, blockPos.getX() + i, blockPos.getY(), blockPos.getZ() + i);
- BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
- while (cursor3D.advance())
- {
- mutableBlockPos.set(cursor3D.nextX(), cursor3D.nextY(), cursor3D.nextZ());
- int n;
- if (LodCommonMain.forgeMethodCaller != null) {
- n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos),
- mutableBlockPos.getX(), mutableBlockPos.getZ());
- } else {
- n = colorResolver.getColor(_getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ());
- }
-
- k += (n & 0xFF0000) >> 16;
- l += (n & 0xFF00) >> 8;
- m += n & 0xFF;
- }
- return (k / j & 0xFF) << 16 | (l / j & 0xFF) << 8 | m / j & 0xFF;
- }
-
- @Override
- public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
- return calculateBlockTint(blockPos, colorResolver);
- }
-
- @Override
- public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
-
- @Override
- public LevelLightEngine getLightEngine() {
- return parent.getLightEngine();
- }
-
- @Override
- public int getBrightness(LightLayer lightLayer, BlockPos blockPos) {
- return parent.getBrightness(lightLayer, blockPos);
- }
-
- @Override
- public int getRawBrightness(BlockPos blockPos, int i) {
- return parent.getRawBrightness(blockPos, i);
- }
-
- @Override
- public boolean canSeeSky(BlockPos blockPos) {
- return parent.canSeeSky(blockPos);
- }
-
- @Override
- @Nullable
- public BlockEntity getBlockEntity(BlockPos blockPos) {
- return parent.getBlockEntity(blockPos);
- }
-
- @Override
- public BlockState getBlockState(BlockPos blockPos) {
- return parent.getBlockState(blockPos);
- }
-
- @Override
- public FluidState getFluidState(BlockPos blockPos) {
- return parent.getFluidState(blockPos);
- }
-
- @Override
- public int getLightEmission(BlockPos blockPos) {
- return parent.getLightEmission(blockPos);
- }
-
- @Override
- public int getMaxLightLevel() {
- return parent.getMaxLightLevel();
- }
-
- @Override
- public Stream getBlockStates(AABB aABB) {
- return parent.getBlockStates(aABB);
- }
-
- @Override
- public BlockHitResult clip(ClipContext clipContext) {
- return parent.clip(clipContext);
- }
-
- @Override
- @Nullable
- public BlockHitResult clipWithInteractionOverride(Vec3 vec3, Vec3 vec32, BlockPos blockPos, VoxelShape voxelShape, BlockState blockState) {
- return parent.clipWithInteractionOverride(vec3, vec32, blockPos, voxelShape, blockState);
- }
-
- @Override
- public double getBlockFloorHeight(VoxelShape voxelShape, Supplier supplier) {
- return parent.getBlockFloorHeight(voxelShape, supplier);
- }
-
- @Override
- public double getBlockFloorHeight(BlockPos blockPos) {
- return parent.getBlockFloorHeight(blockPos);
- }
-
- @Override
- public int getMaxBuildHeight() {
- return parent.getMaxBuildHeight();
- }
-
- #if POST_MC_1_17_1
- @Override
- public Optional getBlockEntity(BlockPos blockPos, BlockEntityType blockEntityType) {
- return parent.getBlockEntity(blockPos, blockEntityType);
- }
-
- @Override
- public BlockHitResult isBlockInLine(ClipBlockStateContext clipBlockStateContext) {
- return parent.isBlockInLine(clipBlockStateContext);
- }
-
- @Override
- public int getHeight() {
- return parent.getHeight();
- }
-
- @Override
- public int getMinBuildHeight() {
- return parent.getMinBuildHeight();
- }
-
- @Override
- public int getSectionsCount() {
- return parent.getSectionsCount();
- }
-
- @Override
- public int getMinSection() {
- return parent.getMinSection();
- }
-
- @Override
- public int getMaxSection() {
- return parent.getMaxSection();
- }
-
- @Override
- public boolean isOutsideBuildHeight(BlockPos blockPos) {
- return parent.isOutsideBuildHeight(blockPos);
- }
-
- @Override
- public boolean isOutsideBuildHeight(int i) {
- return parent.isOutsideBuildHeight(i);
- }
-
- @Override
- public int getSectionIndex(int i) {
- return parent.getSectionIndex(i);
- }
-
- @Override
- public int getSectionIndexFromSectionY(int i) {
- return parent.getSectionIndexFromSectionY(i);
- }
-
- @Override
- public int getSectionYFromSectionIndex(int i) {
- return parent.getSectionYFromSectionIndex(i);
- }
+ }
+
+ public int calculateBlockTint(BlockPos blockPos, ColorResolver colorResolver)
+ {
+ int i = smoothingRange;
+ if (i == 0)
+ return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ());
+ int j = (i * 2 + 1) * (i * 2 + 1);
+ int k = 0;
+ int l = 0;
+ int m = 0;
+ Cursor3D cursor3D = new Cursor3D(blockPos.getX() - i, blockPos.getY(), blockPos.getZ() - i, blockPos.getX() + i, blockPos.getY(), blockPos.getZ() + i);
+ BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+ while (cursor3D.advance())
+ {
+ mutableBlockPos.set(cursor3D.nextX(), cursor3D.nextY(), cursor3D.nextZ());
+ int n;
+ if (LodCommonMain.forgeMethodCaller != null)
+ {
+ n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos),
+ mutableBlockPos.getX(), mutableBlockPos.getZ());
+ }
+ else
+ {
+ n = colorResolver.getColor(_getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ());
+ }
+
+ k += (n & 0xFF0000) >> 16;
+ l += (n & 0xFF00) >> 8;
+ m += n & 0xFF;
+ }
+ return (k / j & 0xFF) << 16 | (l / j & 0xFF) << 8 | m / j & 0xFF;
+ }
+
+ @Override
+ public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver)
+ {
+ return calculateBlockTint(blockPos, colorResolver);
+ }
+
+ @Override
+ public float getShade(Direction direction, boolean bl) { return this.parent.getShade(direction, bl); }
+
+ @Override
+ public LevelLightEngine getLightEngine()
+ {
+ return parent.getLightEngine();
+ }
+
+ @Override
+ public int getBrightness(LightLayer lightLayer, BlockPos blockPos)
+ {
+ return parent.getBrightness(lightLayer, blockPos);
+ }
+
+ @Override
+ public int getRawBrightness(BlockPos blockPos, int i)
+ {
+ return parent.getRawBrightness(blockPos, i);
+ }
+
+ @Override
+ public boolean canSeeSky(BlockPos blockPos)
+ {
+ return parent.canSeeSky(blockPos);
+ }
+
+ @Override
+ @Nullable
+ public BlockEntity getBlockEntity(BlockPos blockPos)
+ {
+ return parent.getBlockEntity(blockPos);
+ }
+
+ @Override
+ public BlockState getBlockState(BlockPos blockPos)
+ {
+ return parent.getBlockState(blockPos);
+ }
+
+ @Override
+ public FluidState getFluidState(BlockPos blockPos)
+ {
+ return parent.getFluidState(blockPos);
+ }
+
+ @Override
+ public int getLightEmission(BlockPos blockPos)
+ {
+ return parent.getLightEmission(blockPos);
+ }
+
+ @Override
+ public int getMaxLightLevel()
+ {
+ return parent.getMaxLightLevel();
+ }
+
+ @Override
+ public Stream getBlockStates(AABB aABB)
+ {
+ return parent.getBlockStates(aABB);
+ }
+
+ @Override
+ public BlockHitResult clip(ClipContext clipContext)
+ {
+ return parent.clip(clipContext);
+ }
+
+ @Override
+ @Nullable
+ public BlockHitResult clipWithInteractionOverride(Vec3 vec3, Vec3 vec32, BlockPos blockPos, VoxelShape voxelShape, BlockState blockState)
+ {
+ return parent.clipWithInteractionOverride(vec3, vec32, blockPos, voxelShape, blockState);
+ }
+
+ @Override
+ public double getBlockFloorHeight(VoxelShape voxelShape, Supplier supplier)
+ {
+ return parent.getBlockFloorHeight(voxelShape, supplier);
+ }
+
+ @Override
+ public double getBlockFloorHeight(BlockPos blockPos)
+ {
+ return parent.getBlockFloorHeight(blockPos);
+ }
+
+ @Override
+ public int getMaxBuildHeight()
+ {
+ return parent.getMaxBuildHeight();
+ }
+
+ #if POST_MC_1_17_1
+ @Override
+ public Optional getBlockEntity(BlockPos blockPos, BlockEntityType blockEntityType)
+ {
+ return parent.getBlockEntity(blockPos, blockEntityType);
+ }
+
+ @Override
+ public BlockHitResult isBlockInLine(ClipBlockStateContext clipBlockStateContext)
+ {
+ return parent.isBlockInLine(clipBlockStateContext);
+ }
+
+ @Override
+ public int getHeight()
+ {
+ return parent.getHeight();
+ }
+
+ @Override
+ public int getMinBuildHeight()
+ {
+ return parent.getMinBuildHeight();
+ }
+
+ @Override
+ public int getSectionsCount()
+ {
+ return parent.getSectionsCount();
+ }
+
+ @Override
+ public int getMinSection()
+ {
+ return parent.getMinSection();
+ }
+
+ @Override
+ public int getMaxSection()
+ {
+ return parent.getMaxSection();
+ }
+
+ @Override
+ public boolean isOutsideBuildHeight(BlockPos blockPos)
+ {
+ return parent.isOutsideBuildHeight(blockPos);
+ }
+
+ @Override
+ public boolean isOutsideBuildHeight(int i)
+ {
+ return parent.isOutsideBuildHeight(i);
+ }
+
+ @Override
+ public int getSectionIndex(int i)
+ {
+ return parent.getSectionIndex(i);
+ }
+
+ @Override
+ public int getSectionIndexFromSectionY(int i)
+ {
+ return parent.getSectionIndexFromSectionY(i);
+ }
+
+ @Override
+ public int getSectionYFromSectionIndex(int i)
+ {
+ return parent.getSectionYFromSectionIndex(i);
+ }
#endif
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelOverrider.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelOverrider.java
index 9fece690a..6a098e593 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelOverrider.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelOverrider.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block;
import net.minecraft.core.BlockPos;
@@ -33,57 +33,68 @@ import org.jetbrains.annotations.Nullable;
import net.minecraft.core.Holder;
#endif
-public class TintWithoutLevelOverrider implements BlockAndTintGetter {
- final BiomeWrapper biome;
-
- public TintWithoutLevelOverrider(BiomeWrapper biome) {
- this.biome = biome;
- }
- @Override
- public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
- return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
- }
- private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome) {
+public class TintWithoutLevelOverrider implements BlockAndTintGetter
+{
+ final BiomeWrapper biome;
+
+ public TintWithoutLevelOverrider(BiomeWrapper biome)
+ {
+ this.biome = biome;
+ }
+ @Override
+ public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver)
+ {
+ return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
+ }
+ private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome)
+ {
#if POST_MC_1_18_2
- return biome.value();
+ return biome.value();
#else
- return biome;
+ return biome;
#endif
- }
-
- @Override
- public float getShade(Direction direction, boolean shade) {
- throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public LevelLightEngine getLightEngine() {
- throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Nullable
- @Override
- public BlockEntity getBlockEntity(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
-
- @Override
- public BlockState getBlockState(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public FluidState getFluidState(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
+ }
+
+ @Override
+ public float getShade(Direction direction, boolean shade)
+ {
+ throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public LevelLightEngine getLightEngine()
+ {
+ throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Nullable
+ @Override
+ public BlockEntity getBlockEntity(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+
+ @Override
+ public BlockState getBlockState(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public FluidState getFluidState(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
#if MC_1_17_1 || POST_MC_1_18_2
- @Override
- public int getHeight() {
- throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public int getMinBuildHeight() {
- throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
+ @Override
+ public int getHeight()
+ {
+ throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public int getMinBuildHeight()
+ {
+ throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
#endif
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelSmoothOverrider.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelSmoothOverrider.java
index 9e3562e5b..6bbce5bab 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelSmoothOverrider.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintWithoutLevelSmoothOverrider.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block;
import net.minecraft.core.BlockPos;
@@ -34,25 +34,29 @@ import org.jetbrains.annotations.Nullable;
import net.minecraft.core.Holder;
#endif
-public class TintWithoutLevelSmoothOverrider implements BlockAndTintGetter {
- final BiomeWrapper biome;
- public int smoothingRange;
-
- public TintWithoutLevelSmoothOverrider(BiomeWrapper biome, int smoothingRange) {
- this.biome = biome;
- this.smoothingRange = smoothingRange;
- }
- @Override
- public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
- return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
- }
- private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome) {
+public class TintWithoutLevelSmoothOverrider implements BlockAndTintGetter
+{
+ final BiomeWrapper biome;
+ public int smoothingRange;
+
+ public TintWithoutLevelSmoothOverrider(BiomeWrapper biome, int smoothingRange)
+ {
+ this.biome = biome;
+ this.smoothingRange = smoothingRange;
+ }
+ @Override
+ public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver)
+ {
+ return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ());
+ }
+ private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome)
+ {
#if POST_MC_1_18_2
- return biome.value();
+ return biome.value();
#else
- return biome;
+ return biome;
#endif
- }
+ }
//
// public int calculateBlockTint(BlockPos blockPos, ColorResolver colorResolver)
// {
@@ -82,40 +86,47 @@ public class TintWithoutLevelSmoothOverrider implements BlockAndTintGetter {
// }
// return (k / j & 0xFF) << 16 | (l / j & 0xFF) << 8 | m / j & 0xFF;
// }
-
- @Override
- public float getShade(Direction direction, boolean shade) {
- throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public LevelLightEngine getLightEngine() {
- throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Nullable
- @Override
- public BlockEntity getBlockEntity(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
-
- @Override
- public BlockState getBlockState(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public FluidState getFluidState(BlockPos pos) {
- throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
-
+
+ @Override
+ public float getShade(Direction direction, boolean shade)
+ {
+ throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public LevelLightEngine getLightEngine()
+ {
+ throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Nullable
+ @Override
+ public BlockEntity getBlockEntity(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+
+ @Override
+ public BlockState getBlockState(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public FluidState getFluidState(BlockPos pos)
+ {
+ throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+
#if MC_1_17_1 || POST_MC_1_18_2
- @Override
- public int getHeight() {
- throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
- @Override
- public int getMinBuildHeight() {
- throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
- }
+ @Override
+ public int getHeight()
+ {
+ throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
+ @Override
+ public int getMinBuildHeight()
+ {
+ throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only.");
+ }
#endif
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockDetailMap.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockDetailMap.java
index e8bfdce3f..5e5bc36f8 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockDetailMap.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockDetailMap.java
@@ -7,19 +7,23 @@ import net.minecraft.world.level.block.state.BlockState;
import java.util.concurrent.ConcurrentHashMap;
-public class ClientBlockDetailMap {
- private final ConcurrentHashMap blockCache = new ConcurrentHashMap<>();
- //private final ConcurrentHashMap<#if PRE_MC_1_18_2 Biome #else Holder #endif, Biome> biomeMap = new ConcurrentHashMap<>();
- private final ClientLevelWrapper level;
- public ClientBlockDetailMap(ClientLevelWrapper level) { this.level = level; }
-
- public ClientBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos) { //TODO: Allow a per pos unique setting
- return blockCache.computeIfAbsent(state, (s) -> new ClientBlockStateCache(s, level, new DhBlockPos(0,0,0)));
- }
-
- public void clear() { blockCache.clear(); }
-
- public int getColor(BlockState state, BiomeWrapper biome, DhBlockPos pos) {
- return getBlockStateData(state, pos).getAndResolveFaceColor(biome);
- }
+public class ClientBlockDetailMap
+{
+ private final ConcurrentHashMap blockCache = new ConcurrentHashMap<>();
+ //private final ConcurrentHashMap<#if PRE_MC_1_18_2 Biome #else Holder #endif, Biome> biomeMap = new ConcurrentHashMap<>();
+ private final ClientLevelWrapper level;
+ public ClientBlockDetailMap(ClientLevelWrapper level) { this.level = level; }
+
+ public ClientBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos)
+ { //TODO: Allow a per pos unique setting
+ return blockCache.computeIfAbsent(state, (s) -> new ClientBlockStateCache(s, level, new DhBlockPos(0, 0, 0)));
+ }
+
+ public void clear() { blockCache.clear(); }
+
+ public int getColor(BlockState state, BiomeWrapper biome, DhBlockPos pos)
+ {
+ return getBlockStateData(state, pos).getAndResolveFaceColor(biome);
+ }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockStateCache.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockStateCache.java
index e080f600e..ea5512f28 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockStateCache.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ClientBlockStateCache.java
@@ -29,178 +29,196 @@ import java.util.List;
import java.util.Random;
/**
- *
* @version 2022-9-16
*/
public class ClientBlockStateCache
{
-
- private static final Logger LOGGER = DhLoggerBuilder.getLogger();
-
+
+ private static final Logger LOGGER = DhLoggerBuilder.getLogger();
+
#if PRE_MC_1_19_2
- public static final Random random = new Random(0);
+ public static final Random random = new Random(0);
#else
- public static final RandomSource random = RandomSource.create();
+ public static final RandomSource random = RandomSource.create();
#endif
-
- public final BlockState state;
- public final LevelReader level;
- public final BlockPos pos;
- public ClientBlockStateCache(BlockState blockState, IClientLevelWrapper samplingLevel, DhBlockPos samplingPos) {
- state = blockState;
- level = (LevelReader) samplingLevel.getWrappedMcObject();
- pos = McObjectConverter.Convert(samplingPos);
- resolveColors();
- //LOGGER.info("ClientBlocKCache created for {}", blockState);
- }
-
- boolean isColorResolved = false;
- int baseColor = 0; //TODO: Impl per-face color
- boolean needShade = true;
- boolean needPostTinting = false;
- int tintIndex = 0;
-
-
- public static final int FLOWER_COLOR_SCALE = 5;
-
- enum ColorMode {
- Default,
- Flower,
- Leaves;
- static ColorMode getColorMode(Block b) {
- if (b instanceof LeavesBlock) return Leaves;
- if (b instanceof FlowerBlock) return Flower;
- return Default;
- }
- }
-
- private static int getWidth(TextureAtlasSprite texture) {
+
+ public final BlockState state;
+ public final LevelReader level;
+ public final BlockPos pos;
+ public ClientBlockStateCache(BlockState blockState, IClientLevelWrapper samplingLevel, DhBlockPos samplingPos)
+ {
+ state = blockState;
+ level = (LevelReader) samplingLevel.getWrappedMcObject();
+ pos = McObjectConverter.Convert(samplingPos);
+ resolveColors();
+ //LOGGER.info("ClientBlocKCache created for {}", blockState);
+ }
+
+ boolean isColorResolved = false;
+ int baseColor = 0; //TODO: Impl per-face color
+ boolean needShade = true;
+ boolean needPostTinting = false;
+ int tintIndex = 0;
+
+
+ public static final int FLOWER_COLOR_SCALE = 5;
+
+ enum ColorMode
+ {
+ Default,
+ Flower,
+ Leaves;
+ static ColorMode getColorMode(Block b)
+ {
+ if (b instanceof LeavesBlock) return Leaves;
+ if (b instanceof FlowerBlock) return Flower;
+ return Default;
+ }
+ }
+
+ private static int getWidth(TextureAtlasSprite texture)
+ {
#if PRE_MC_1_19_4
- return texture.getWidth();
+ return texture.getWidth();
#else
- return texture.contents().width();
+ return texture.contents().width();
#endif
- }
-
- private static int getHeight(TextureAtlasSprite texture) {
+ }
+
+ private static int getHeight(TextureAtlasSprite texture)
+ {
#if PRE_MC_1_19_4
- return texture.getHeight();
+ return texture.getHeight();
#else
- return texture.contents().height();
+ return texture.contents().height();
#endif
- }
-
- //TODO: Perhaps make this not just use the first frame?
- private static int calculateColorFromTexture(TextureAtlasSprite texture, ColorMode colorMode) {
- int count = 0;
- double alpha = 0;
- double red = 0;
- double green = 0;
- double blue = 0;
- int tempColor;
- {
- // textures normally use u and v instead of x and y
- for (int u = 0; u < getWidth(texture); u++)
- {
- for (int v = 0; v < getHeight(texture); v++)
- {
- //note: Minecraft color format is: 0xAA BB GG RR
- //________ DH mod color format is: 0xAA RR GG BB
- //OpenGL RGBA format native order: 0xRR GG BB AA
- //_ OpenGL RGBA format Java Order: 0xAA BB GG RR
- tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
-
- double r = ((tempColor & 0x000000FF) )/255.;
- double g = ((tempColor & 0x0000FF00) >>> 8)/255.;
- double b = ((tempColor & 0x00FF0000) >>> 16)/255.;
- double a = ((tempColor & 0xFF000000) >>> 24)/255.;
- int scale = 1;
-
- if (colorMode == ColorMode.Leaves) {
- r *= a;
- g *= a;
- b *= a;
- a = 1.;
- } else if (a==0.) {
- continue;
- } else if (colorMode == ColorMode.Flower && (g+0.1 quads = null;
- for (Direction direction : DIRECTION_ORDER)
- {
- quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
- getBlockModel(state).getQuads(state, direction, random);
- if (quads != null && !quads.isEmpty() &&
- !(state.getBlock() instanceof RotatedPillarBlock && direction == Direction.UP))
- break;
- };
- if (quads == null || quads.isEmpty()) {
- quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
- getBlockModel(state).getQuads(state, null, random);
- }
- if (quads != null && !quads.isEmpty()) {
- needPostTinting = quads.get(0).isTinted();
- needShade = quads.get(0).isShade();
- tintIndex = quads.get(0).getTintIndex();
- baseColor = calculateColorFromTexture(
+ }
+
+ //TODO: Perhaps make this not just use the first frame?
+ private static int calculateColorFromTexture(TextureAtlasSprite texture, ColorMode colorMode)
+ {
+ int count = 0;
+ double alpha = 0;
+ double red = 0;
+ double green = 0;
+ double blue = 0;
+ int tempColor;
+ {
+ // textures normally use u and v instead of x and y
+ for (int u = 0; u < getWidth(texture); u++)
+ {
+ for (int v = 0; v < getHeight(texture); v++)
+ {
+ //note: Minecraft color format is: 0xAA BB GG RR
+ //________ DH mod color format is: 0xAA RR GG BB
+ //OpenGL RGBA format native order: 0xRR GG BB AA
+ //_ OpenGL RGBA format Java Order: 0xAA BB GG RR
+ tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, 0, u, v);
+
+ double r = ((tempColor & 0x000000FF)) / 255.;
+ double g = ((tempColor & 0x0000FF00) >>> 8) / 255.;
+ double b = ((tempColor & 0x00FF0000) >>> 16) / 255.;
+ double a = ((tempColor & 0xFF000000) >>> 24) / 255.;
+ int scale = 1;
+
+ if (colorMode == ColorMode.Leaves)
+ {
+ r *= a;
+ g *= a;
+ b *= a;
+ a = 1.;
+ }
+ else if (a == 0.)
+ {
+ continue;
+ }
+ else if (colorMode == ColorMode.Flower && (g + 0.1 < b || g + 0.1 < r))
+ {
+ scale = FLOWER_COLOR_SCALE;
+ }
+
+ count += scale;
+ alpha += a * a * scale;
+ red += r * r * scale;
+ green += g * g * scale;
+ blue += b * b * scale;
+ }
+ }
+ }
+
+ if (count == 0)
+ // this block is entirely transparent
+ tempColor = ColorUtil.rgbToInt(0, 255, 255, 255);
+ else
+ {
+ // determine the average color
+ tempColor = ColorUtil.rgbToInt(
+ (int) (Math.sqrt(alpha / count) * 255.),
+ (int) (Math.sqrt(red / count) * 255.),
+ (int) (Math.sqrt(green / count) * 255.),
+ (int) (Math.sqrt(blue / count) * 255.));
+ }
+ return tempColor;
+ }
+ private static final Direction[] DIRECTION_ORDER = {Direction.UP, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.SOUTH, Direction.DOWN};
+
+ private void resolveColors()
+ {
+ if (isColorResolved) return;
+ if (state.getFluidState().isEmpty())
+ {
+ List quads = null;
+ for (Direction direction : DIRECTION_ORDER)
+ {
+ quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
+ getBlockModel(state).getQuads(state, direction, random);
+ if (quads != null && !quads.isEmpty() &&
+ !(state.getBlock() instanceof RotatedPillarBlock && direction == Direction.UP))
+ break;
+ } ;
+ if (quads == null || quads.isEmpty())
+ {
+ quads = Minecraft.getInstance().getModelManager().getBlockModelShaper().
+ getBlockModel(state).getQuads(state, null, random);
+ }
+ if (quads != null && !quads.isEmpty())
+ {
+ needPostTinting = quads.get(0).isTinted();
+ needShade = quads.get(0).isShade();
+ tintIndex = quads.get(0).getTintIndex();
+ baseColor = calculateColorFromTexture(
#if PRE_MC_1_17_1 quads.get(0).sprite,
#else quads.get(0).getSprite(), #endif
- ColorMode.getColorMode(state.getBlock()));
- } else { // Backup method.
- needPostTinting = false;
- needShade = false;
- tintIndex = 0;
- baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
- ColorMode.getColorMode(state.getBlock()));
- }
- } else { // Liquid Block
- needPostTinting = true;
- needShade = false;
- tintIndex = 0;
- baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
- ColorMode.getColorMode(state.getBlock()));
- }
- isColorResolved = true;
- }
-
- public int getAndResolveFaceColor(BiomeWrapper biome)
- {
- // FIXME: impl per-face colors
- if (!needPostTinting) return baseColor;
- int tintColor = Minecraft.getInstance().getBlockColors()
- .getColor(state, new TintWithoutLevelOverrider(biome), pos, tintIndex);
- if (tintColor == -1) return baseColor;
- return ColorUtil.multiplyARGBwithRGB(baseColor, tintColor);
- }
-
+ ColorMode.getColorMode(state.getBlock()));
+ }
+ else
+ { // Backup method.
+ needPostTinting = false;
+ needShade = false;
+ tintIndex = 0;
+ baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
+ ColorMode.getColorMode(state.getBlock()));
+ }
+ }
+ else
+ { // Liquid Block
+ needPostTinting = true;
+ needShade = false;
+ tintIndex = 0;
+ baseColor = calculateColorFromTexture(Minecraft.getInstance().getModelManager().getBlockModelShaper().getParticleIcon(state),
+ ColorMode.getColorMode(state.getBlock()));
+ }
+ isColorResolved = true;
+ }
+
+ public int getAndResolveFaceColor(BiomeWrapper biome)
+ {
+ // FIXME: impl per-face colors
+ if (!needPostTinting) return baseColor;
+ int tintColor = Minecraft.getInstance().getBlockColors()
+ .getColor(state, new TintWithoutLevelOverrider(biome), pos, tintIndex);
+ if (tintColor == -1) return baseColor;
+ return ColorUtil.multiplyARGBwithRGB(baseColor, tintColor);
+ }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockDetailMap.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockDetailMap.java
index 7eaa8e0e0..d7d3a2646 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockDetailMap.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockDetailMap.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.block.cache;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,10 +32,12 @@ public class ServerBlockDetailMap
//private final ConcurrentHashMap<#if PRE_MC_1_18_2 Biome #else Holder #endif, Biome> biomeMap = new ConcurrentHashMap<>();
private final ServerLevelWrapper level;
public ServerBlockDetailMap(ServerLevelWrapper level) { this.level = level; }
-
- public ServerBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos) { //TODO: Allow a per pos unique setting
- return blockCache.computeIfAbsent(state, (s) -> new ServerBlockStateCache(s, level, new DhBlockPos(0,0,0)));
+
+ public ServerBlockStateCache getBlockStateData(BlockState state, DhBlockPos pos)
+ { //TODO: Allow a per pos unique setting
+ return blockCache.computeIfAbsent(state, (s) -> new ServerBlockStateCache(s, level, new DhBlockPos(0, 0, 0)));
}
-
+
public void clear() { blockCache.clear(); }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockStateCache.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockStateCache.java
index 60c2fe44e..55b7beb36 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockStateCache.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/cache/ServerBlockStateCache.java
@@ -15,63 +15,71 @@ import org.apache.logging.log4j.Logger;
import java.util.Arrays;
/**
- *
* @version 2022-9-16
*/
public class ServerBlockStateCache
{
- private static final Logger LOGGER = DhLoggerBuilder.getLogger();
-
- public final BlockState state;
- public final LevelReader level;
- public final BlockPos pos;
-
- public ServerBlockStateCache(BlockState blockState, ILevelWrapper samplingLevel, DhBlockPos samplingPos) {
- state = blockState;
- level = (LevelReader) samplingLevel.getWrappedMcObject();
- pos = McObjectConverter.Convert(samplingPos);
- resolveShapes();
- //LOGGER.info("ServerBlockState created for {}", blockState);
- }
-
- boolean noCollision = false;
- boolean[] occludeFaces = null;
- boolean[] fullFaces = null;
- boolean isShapeResolved = false;
- public void resolveShapes() {
- if (isShapeResolved) return;
- if (state.getFluidState().isEmpty()) {
- noCollision = state.getCollisionShape(level, pos).isEmpty();
- occludeFaces = new boolean[6];
- if (state.canOcclude()) {
- for (Direction dir : Direction.values()) {
- // Note: isEmpty() isn't quite correct... best would be a isFull() or something...
- occludeFaces[McObjectConverter.Convert(dir).ordinal()]
+ private static final Logger LOGGER = DhLoggerBuilder.getLogger();
+
+ public final BlockState state;
+ public final LevelReader level;
+ public final BlockPos pos;
+
+ public ServerBlockStateCache(BlockState blockState, ILevelWrapper samplingLevel, DhBlockPos samplingPos)
+ {
+ state = blockState;
+ level = (LevelReader) samplingLevel.getWrappedMcObject();
+ pos = McObjectConverter.Convert(samplingPos);
+ resolveShapes();
+ //LOGGER.info("ServerBlockState created for {}", blockState);
+ }
+
+ boolean noCollision = false;
+ boolean[] occludeFaces = null;
+ boolean[] fullFaces = null;
+ boolean isShapeResolved = false;
+ public void resolveShapes()
+ {
+ if (isShapeResolved) return;
+ if (state.getFluidState().isEmpty())
+ {
+ noCollision = state.getCollisionShape(level, pos).isEmpty();
+ occludeFaces = new boolean[6];
+ if (state.canOcclude())
+ {
+ for (Direction dir : Direction.values())
+ {
+ // Note: isEmpty() isn't quite correct... best would be a isFull() or something...
+ occludeFaces[McObjectConverter.Convert(dir).ordinal()]
= !state.getFaceOcclusionShape(level, pos, dir).isEmpty();
}
- }
-
- VoxelShape voxelShape = state.getShape(level, pos);
- fullFaces = new boolean[6];
- if (!voxelShape.isEmpty()) {
- for (Direction dir : Direction.values()) {
- VoxelShape faceShape = voxelShape.getFaceShape(dir);
- AABB aabb = faceShape.bounds();
- boolean xFull = aabb.minX <= 0.01 && aabb.maxX >= 0.99;
- boolean yFull = aabb.minY <= 0.01 && aabb.maxY >= 0.99;
- boolean zFull = aabb.minZ <= 0.01 && aabb.maxZ >= 0.99;
- fullFaces[McObjectConverter.Convert(dir).ordinal()] =
- (xFull || dir.getAxis().equals(Direction.Axis.X))
- && (yFull || dir.getAxis().equals(Direction.Axis.Y))
- && (zFull || dir.getAxis().equals(Direction.Axis.Z));
- }
- }
- } else { // Liquid Block. Treat as full block
- occludeFaces = new boolean[6];
- Arrays.fill(occludeFaces, true);
- fullFaces = new boolean[6];
- Arrays.fill(fullFaces, true);
- }
- }
-
+ }
+
+ VoxelShape voxelShape = state.getShape(level, pos);
+ fullFaces = new boolean[6];
+ if (!voxelShape.isEmpty())
+ {
+ for (Direction dir : Direction.values())
+ {
+ VoxelShape faceShape = voxelShape.getFaceShape(dir);
+ AABB aabb = faceShape.bounds();
+ boolean xFull = aabb.minX <= 0.01 && aabb.maxX >= 0.99;
+ boolean yFull = aabb.minY <= 0.01 && aabb.maxY >= 0.99;
+ boolean zFull = aabb.minZ <= 0.01 && aabb.maxZ >= 0.99;
+ fullFaces[McObjectConverter.Convert(dir).ordinal()] =
+ (xFull || dir.getAxis().equals(Direction.Axis.X))
+ && (yFull || dir.getAxis().equals(Direction.Axis.Y))
+ && (zFull || dir.getAxis().equals(Direction.Axis.Z));
+ }
+ }
+ }
+ else
+ { // Liquid Block. Treat as full block
+ occludeFaces = new boolean[6];
+ Arrays.fill(occludeFaces, true);
+ fullFaces = new boolean[6];
+ Arrays.fill(fullFaces, true);
+ }
+ }
+
}
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java
index dce2ed586..ed0a612cb 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
-
+
package com.seibel.distanthorizons.common.wrappers.chunk;
import com.seibel.distanthorizons.api.enums.config.ELightGenerationMode;
@@ -78,7 +78,7 @@ public class ChunkWrapper implements IChunkWrapper
* just before the light engine is ticked, (right after all light changes is marked to the engine to be processed).
* To fix this, on client-only mode, we mixin-redirect the `isClientLightReady()` so that after the call, it will
* trigger a synchronous update of this flag here on all chunks that are wrapped.
- *
+ *
* Note: Using a static weak hash map to store the chunks that need to be updated, as instance of chunk wrapper
* can be duplicated, with same chunk instance. And the data stored here are all temporary, and thus will not be
* visible when a chunk is re-wrapped later.
@@ -169,10 +169,10 @@ public class ChunkWrapper implements IChunkWrapper
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)));
#endif
}
-
+
@Override
public DhChunkPos getChunkPos() { return this.chunkPos; }
-
+
public ChunkAccess getChunk() { return this.chunk; }
@Override
@@ -217,29 +217,29 @@ public class ChunkWrapper implements IChunkWrapper
weakMapLock.readLock().unlock();
return fixedIsClientLightReady;
}
-
+
// called when in single player or in dedicated server, and the chunk is a level chunk (active)
return this.chunk.isLightCorrect() && levelChunk.loaded;
}
else
{
// called when in a single player world and the chunk is a proto chunk (in world gen, and not active)
- return this.chunk.isLightCorrect();
+ return this.chunk.isLightCorrect();
}
#endif
}
@Override
- public int getDhBlockLight(int relX, int y, int relZ)
+ public int getDhBlockLight(int relX, int y, int relZ)
{
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
int index = this.relativeBlockPosToIndex(relX, y, relZ);
- return this.blockLightArray[index];
+ return this.blockLightArray[index];
}
@Override
- public void setDhBlockLight(int relX, int y, int relZ, int lightValue)
+ public void setDhBlockLight(int relX, int y, int relZ, int lightValue)
{
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
@@ -248,7 +248,7 @@ public class ChunkWrapper implements IChunkWrapper
}
@Override
- public int getDhSkyLight(int relX, int y, int relZ)
+ public int getDhSkyLight(int relX, int y, int relZ)
{
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
@@ -256,7 +256,7 @@ public class ChunkWrapper implements IChunkWrapper
return this.skyLightArray[index];
}
@Override
- public void setDhSkyLight(int relX, int y, int relZ, int lightValue)
+ public void setDhSkyLight(int relX, int y, int relZ, int lightValue)
{
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
@@ -282,7 +282,7 @@ public class ChunkWrapper implements IChunkWrapper
// note: this returns 0 if the chunk is unload
// MC lighting method
- return this.lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(relX +this.getMinBlockX(), y, relZ +this.getMinBlockZ()));
+ return this.lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ()));
}
}
@@ -301,11 +301,11 @@ public class ChunkWrapper implements IChunkWrapper
else
{
// MC lighting method
- return this.lightSource.getBrightness(LightLayer.SKY, new BlockPos(relX +this.getMinBlockX(), y, relZ +this.getMinBlockZ()));
+ return this.lightSource.getBrightness(LightLayer.SKY, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ()));
}
}
- @Override
+ @Override
public List getBlockLightPosList()
{
// only populate the list once
@@ -315,12 +315,12 @@ public class ChunkWrapper implements IChunkWrapper
#if PRE_MC_1_20_1
- this.chunk.getLights().forEach((blockPos) ->
+ this.chunk.getLights().forEach((blockPos) ->
{
this.blockLightPosList.add(new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
});
#elif MC_1_20_1
- this.chunk.findBlockLightSources((blockPos, blockState) ->
+ this.chunk.findBlockLightSources((blockPos, blockState) ->
{
this.blockLightPosList.add(new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
});
@@ -357,49 +357,52 @@ public class ChunkWrapper implements IChunkWrapper
}
public LevelReader getColorResolver() { return this.lightSource; }
-
+
@Override
public String toString() { return this.chunk.getClass().getSimpleName() + this.chunk.getPos(); }
-
+
@Override
public IBlockStateWrapper getBlockState(int relX, int relY, int relZ)
{
//if (wrappedLevel != null) return wrappedLevel.getBlockState(new DhBlockPos(x + getMinX(), y, z + getMinZ()));
return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(new BlockPos(relX, relY, relZ)));
}
-
+
@Override
public boolean isStillValid() { return this.wrappedLevel == null || this.wrappedLevel.tryGetChunk(this.chunkPos) == this; }
-
+
#if POST_MC_1_20_1
- private static boolean checkLightSectionsOnChunk(LevelChunk chunk, LevelLightEngine engine) {
+ private static boolean checkLightSectionsOnChunk(LevelChunk chunk, LevelLightEngine engine)
+ {
LevelChunkSection[] sections = chunk.getSections();
int minY = chunk.getMinSection();
int maxY = chunk.getMaxSection();
- for (int y = minY; y < maxY; ++y) {
+ for (int y = minY; y < maxY; ++y)
+ {
LevelChunkSection section = sections[chunk.getSectionIndexFromSectionY(y)];
if (section.hasOnlyAir()) continue;
- if (!engine.lightOnInSection(SectionPos.of(chunk.getPos(), y))) {
+ if (!engine.lightOnInSection(SectionPos.of(chunk.getPos(), y)))
+ {
return false;
}
}
return true;
}
#endif
-
+
// Should be called after client light updates are triggered.
private static boolean updateClientLightReady(ChunkAccess chunk, boolean oldValue)
{
- if (chunk instanceof LevelChunk && ((LevelChunk)chunk).getLevel() instanceof ClientLevel)
+ if (chunk instanceof LevelChunk && ((LevelChunk) chunk).getLevel() instanceof ClientLevel)
{
- LevelChunk levelChunk = (LevelChunk)chunk;
- ClientChunkCache clientChunkCache = ((ClientLevel)levelChunk.getLevel()).getChunkSource();
+ LevelChunk levelChunk = (LevelChunk) chunk;
+ ClientChunkCache clientChunkCache = ((ClientLevel) levelChunk.getLevel()).getChunkSource();
return clientChunkCache.getChunkForLighting(chunk.getPos().x, chunk.getPos().z) != null &&
#if MC_1_16_5 || MC_1_17_1
levelChunk.isLightCorrect();
- #elif PRE_MC_1_20_1
+ #elif PRE_MC_1_20_1
levelChunk.isClientLightReady();
- #else
+ #else
checkLightSectionsOnChunk(levelChunk, levelChunk.getLevel().getLightEngine());
#endif
}
@@ -408,7 +411,7 @@ public class ChunkWrapper implements IChunkWrapper
return oldValue;
}
}
-
+
public static void syncedUpdateClientLightStatus()
{
#if PRE_MC_1_18_2
@@ -419,7 +422,7 @@ public class ChunkWrapper implements IChunkWrapper
{
chunksToUpdateClientLightReady.replaceAll(ChunkWrapper::updateClientLightReady);
}
- finally
+ finally
{
weakMapLock.writeLock().unlock();
}
@@ -436,16 +439,16 @@ public class ChunkWrapper implements IChunkWrapper
private void throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(int x, int y, int z) throws IndexOutOfBoundsException
{
// FIXME +/-1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the relative position validator
- int minHeight = this.getMinBuildHeight()-1;
- int maxHeight = this.getMaxBuildHeight()+1;
-
+ int minHeight = this.getMinBuildHeight() - 1;
+ int maxHeight = this.getMaxBuildHeight() + 1;
+
if (x < 0 || x >= LodUtil.CHUNK_WIDTH
- || z < 0 || z >= LodUtil.CHUNK_WIDTH
- || y < minHeight || y > maxHeight)
+ || z < 0 || z >= LodUtil.CHUNK_WIDTH
+ || y < minHeight || y > maxHeight)
{
- String errorMessage = "Relative position ["+x+","+y+","+z+"] out of bounds. \n" +
+ String errorMessage = "Relative position [" + x + "," + y + "," + z + "] out of bounds. \n" +
"X/Z must be between 0 and 15 (inclusive) \n" +
- "Y must be between ["+minHeight+"] and ["+maxHeight+"] (inclusive).";
+ "Y must be between [" + minHeight + "] and [" + maxHeight + "] (inclusive).";
throw new IndexOutOfBoundsException(errorMessage);
}
}
@@ -455,21 +458,21 @@ public class ChunkWrapper implements IChunkWrapper
* Converts a 3D position into a 1D array index.
*
* Source:
- * stackoverflow
+ * stackoverflow
*/
- public int relativeBlockPosToIndex(int xRel, int y, int zRel)
+ public int relativeBlockPosToIndex(int xRel, int y, int zRel)
{
int yRel = y - this.getMinBuildHeight();
- return (zRel * LodUtil.CHUNK_WIDTH * this.getHeight()) + (yRel * LodUtil.CHUNK_WIDTH) + xRel;
+ return (zRel * LodUtil.CHUNK_WIDTH * this.getHeight()) + (yRel * LodUtil.CHUNK_WIDTH) + xRel;
}
/**
* Converts a 3D position into a 1D array index.
*
* Source:
- * stackoverflow
+ * stackoverflow
*/
- public DhBlockPos indexToRelativeBlockPos(int index)
+ public DhBlockPos indexToRelativeBlockPos(int index)
{
final int zRel = index / (LodUtil.CHUNK_WIDTH * this.getHeight());
index -= (zRel * LodUtil.CHUNK_WIDTH * this.getHeight());
diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java
index f70e231bc..770e1a319 100644
--- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java
+++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/ClassicConfigGUI.java
@@ -47,7 +47,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
-import net.minecraft.client.resources.language.I18n; // translation
+import net.minecraft.client.resources.language.I18n; // translation
#if POST_MC_1_17_1
import net.minecraft.client.gui.narration.NarratableEntry;
#endif
@@ -68,6 +68,7 @@ import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
* @version 5-21-2022
*/
// FLOATS DONT WORK WITH THIS
+
/** This file is going to be removed sometime soon, please dont hook onto anything within this file until the new UI is compleated */
@SuppressWarnings("unchecked")
public class ClassicConfigGUI
@@ -78,338 +79,388 @@ public class ClassicConfigGUI
private static final Logger LOGGER = LogManager.getLogger();
-
- //==============//
- // Initializers //
- //==============//
-
- // Some regexes to check if an input is valid
- private static final Pattern INTEGER_ONLY_REGEX = Pattern.compile("(-?[0-9]*)");
- private static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
-
- private static class ConfigScreenConfigs {
- // This contains all the configs for the configs
- public static final int SpaceFromRightScreen = 10;
- public static final int ButtonWidthSpacing = 5;
- public static final int ResetButtonWidth = 40;
- }
-
- /**
- * The terribly coded old stuff
- */
- public static class EntryInfo {
- Object widget;
- Map.Entry error;
- String tempValue;
- int index;
- }
-
- /**
- * creates a text field
- */
- private static void textField(AbstractConfigType info, Function func, Pattern pattern, boolean cast) {
- boolean isNumber = pattern != null;
- ((EntryInfo) info.guiValue).widget = (BiFunction>) (editBox, button) -> stringValue ->
- {
- stringValue = stringValue.trim();
- if (!(stringValue.isEmpty() || !isNumber || pattern.matcher(stringValue).matches()))
- return false;
-
- Number value = 0;
- ((EntryInfo) info.guiValue).error = null;
- if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals(".")) {
- try {
- value = func.apply(stringValue);
- } catch (Exception e) {
- value = null;
- }
-
- byte isValid = ((ConfigEntry) info).isValid(value);
- switch (isValid) {
- case 0: ((EntryInfo) info.guiValue).error = null; break;
- case -1: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMinimum length is " + ((ConfigEntry) info).getMin())); break;
- case 1: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMaximum length is " + ((ConfigEntry) info).getMax())); break;
- case 2: ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cValue is invalid")); break;
- }
- }
-
- ((EntryInfo) info.guiValue).tempValue = stringValue;
- editBox.setTextColor(((ConfigEntry) info).isValid(value) == 0 ? 0xFFFFFFFF : 0xFFFF7777);
+
+ //==============//
+ // Initializers //
+ //==============//
+
+ // Some regexes to check if an input is valid
+ private static final Pattern INTEGER_ONLY_REGEX = Pattern.compile("(-?[0-9]*)");
+ private static final Pattern DECIMAL_ONLY_REGEX = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
+
+ private static class ConfigScreenConfigs
+ {
+ // This contains all the configs for the configs
+ public static final int SpaceFromRightScreen = 10;
+ public static final int ButtonWidthSpacing = 5;
+ public static final int ResetButtonWidth = 40;
+
+ }
+
+ /**
+ * The terribly coded old stuff
+ */
+ public static class EntryInfo
+ {
+ Object widget;
+ Map.Entry error;
+ String tempValue;
+ int index;
+
+ }
+
+ /**
+ * creates a text field
+ */
+ private static void textField(AbstractConfigType info, Function func, Pattern pattern, boolean cast)
+ {
+ boolean isNumber = pattern != null;
+ ((EntryInfo) info.guiValue).widget = (BiFunction>) (editBox, button) -> stringValue ->
+ {
+ stringValue = stringValue.trim();
+ if (!(stringValue.isEmpty() || !isNumber || pattern.matcher(stringValue).matches()))
+ return false;
+
+ Number value = 0;
+ ((EntryInfo) info.guiValue).error = null;
+ if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals("."))
+ {
+ try
+ {
+ value = func.apply(stringValue);
+ }
+ catch (Exception e)
+ {
+ value = null;
+ }
+
+ byte isValid = ((ConfigEntry) info).isValid(value);
+ switch (isValid)
+ {
+ case 0:
+ ((EntryInfo) info.guiValue).error = null; break;
+ case -1:
+ ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMinimum length is " + ((ConfigEntry) info).getMin())); break;
+ case 1:
+ ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMaximum length is " + ((ConfigEntry) info).getMax())); break;
+ case 2:
+ ((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cValue is invalid")); break;
+ }
+ }
+
+ ((EntryInfo) info.guiValue).tempValue = stringValue;
+ editBox.setTextColor(((ConfigEntry) info).isValid(value) == 0 ? 0xFFFFFFFF : 0xFFFF7777);
// button.active = entries.stream().allMatch(e -> e.inLimits);
-
-
- if (((ConfigEntry) info).isValid(value) == 0 && info.getType() != List.class) {
- if (!cast)
- ((ConfigEntry) info).setWithoutSaving(value);
- else
- ((ConfigEntry) info).setWithoutSaving(value.intValue());
- }
+
+
+ if (((ConfigEntry) info).isValid(value) == 0 && info.getType() != List.class)
+ {
+ if (!cast)
+ ((ConfigEntry) info).setWithoutSaving(value);
+ else
+ ((ConfigEntry) info).setWithoutSaving(value.intValue());
+ }
// else if (((ConfigEntry) info).isValidMemoryAddress() == 0)
// {
// if (((List) info.get()).size() == ((EntryInfo) info.guiValue).index)
// info.set(((List) info.get()).add(""));
// info.set(((List) info.get()).set(((EntryInfo) info.guiValue).index, Arrays.stream(((EntryInfo) info.guiValue).tempValue.replace("[", "").replace("]", "").split(", ")).collect(Collectors.toList()).get(0)));
// }
-
- return true;
- };
- }
-
- //==============//
- // GUI handling //
- //==============//
-
- /**
- * if you want to get this config gui's screen call this
- */
- public static Screen getScreen(ConfigBase configBase, Screen parent, String category) {
- return new ConfigScreen(configBase, parent, category);
- }
-
- /**
- * Pain
- */
- private static class ConfigScreen extends DhScreen {
- protected ConfigScreen(ConfigBase configBase, Screen parent, String category) {
- super(Translatable(
- I18n.exists(configBase.modID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
- configBase.modID + ".config.title" :
- configBase.modID + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
- );
- this.configBase = configBase;
- this.parent = parent;
- this.category = category;
- this.translationPrefix = configBase.modID + ".config.";
- }
- private final ConfigBase configBase;
-
- private final String translationPrefix;
- private final Screen parent;
- private final String category;
- private ConfigListWidget list;
- private boolean reload = false;
-
- private Button doneButton;
-
- // Real Time config update //
- @Override
- public void tick() {
- super.tick();
- }
-
-
- /**
- * When you close it, it goes to the previous screen and saves
- */
- @Override
- public void onClose() {
- ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
- Objects.requireNonNull(minecraft).setScreen(this.parent);
- }
-
- @Override
- protected void init() {
- super.init();
- if (!reload)
- ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
-
- // Changelog button
- if (Config.Client.Advanced.AutoUpdater.enableAutoUpdater.get())
+
+ return true;
+ };
+ }
+
+ //==============//
+ // GUI handling //
+ //==============//
+
+ /**
+ * if you want to get this config gui's screen call this
+ */
+ public static Screen getScreen(ConfigBase configBase, Screen parent, String category)
+ {
+ return new ConfigScreen(configBase, parent, category);
+ }
+
+ /**
+ * Pain
+ */
+ private static class ConfigScreen extends DhScreen
+ {
+ protected ConfigScreen(ConfigBase configBase, Screen parent, String category)
+ {
+ super(Translatable(
+ I18n.exists(configBase.modID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
+ configBase.modID + ".config.title" :
+ configBase.modID + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
+ );
+ this.configBase = configBase;
+ this.parent = parent;
+ this.category = category;
+ this.translationPrefix = configBase.modID + ".config.";
+ }
+ private final ConfigBase configBase;
+
+ private final String translationPrefix;
+ private final Screen parent;
+ private final String category;
+ private ConfigListWidget list;
+ private boolean reload = false;
+
+ private Button doneButton;
+
+ // Real Time config update //
+ @Override
+ public void tick()
+ {
+ super.tick();
+ }
+
+
+ /**
+ * When you close it, it goes to the previous screen and saves
+ */
+ @Override
+ public void onClose()
+ {
+ ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
+ Objects.requireNonNull(minecraft).setScreen(this.parent);
+ }
+
+ @Override
+ protected void init()
+ {
+ super.init();
+ if (!reload)
+ ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
+
+ // Changelog button
+ if (Config.Client.Advanced.AutoUpdater.enableAutoUpdater.get())
{
- this.addBtn(new TexturedButtonWidget(
- // Where the button is on the screen
- this.width - 28, this.height - 28,
- // Width and height of the button
- 20, 20,
- // Offset
- 0, 0,
- // Some textuary stuff
- 0, new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"), 20, 20,
- // Create the button and tell it where to go
- (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this)),
- // Add a title to the button
- Translatable(ModInfo.ID + ".updater.title")
- ));
- }
-
-
- addBtn(MakeBtn(CommonComponents.GUI_CANCEL, this.width / 2 - 154, this.height - 28, 150, 20, button -> {
- ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
- Objects.requireNonNull(minecraft).setScreen(parent);
- }));
- doneButton = addBtn(MakeBtn( CommonComponents.GUI_DONE,this.width / 2 + 4, this.height - 28, 150, 20, (button) -> {
- ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
- Objects.requireNonNull(minecraft).setScreen(parent);
- }));
-
- this.list = new ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, this.height - 32, 25);
- if (this.minecraft != null && this.minecraft.level != null)
- this.list.setRenderBackground(false);
-
- this.addWidget(this.list);
-
- for (AbstractConfigType info : ConfigBase.INSTANCE.entries) {
- try {
- if (info.getCategory().matches(category) && info.getAppearance().showInGui)
- addMenuItem(info);
- } catch (Exception e) {
- System.out.println("ERROR: Failed to show ["+info.getNameWCategory()+"]");
- if (info.get() != null)
- System.out.print(" with the value ["+info.get()+"] with type ["+info.getType()+"]");
- e.printStackTrace();
- }
- }
- }
-
- private void addMenuItem(AbstractConfigType info) {
- initEntry(info, this.translationPrefix);
- Component name = Translatable(translationPrefix + info.getNameWCategory());
-
- if (ConfigEntry.class.isAssignableFrom(info.getClass())) {
- Button.OnPress btnAction = button -> {
- ((ConfigEntry) info).setWithoutSaving(((ConfigEntry) info).getDefaultValue());
- ((EntryInfo) info.guiValue).index = 0;
- this.reload = true;
- Objects.requireNonNull(minecraft).setScreen(this);
- };
- int a = this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth;
- int b = 0;
- int c = ConfigScreenConfigs.ResetButtonWidth;
- int d = 20;
-
- Button resetButton = MakeBtn(TextOrLiteral("Reset") .withStyle(ChatFormatting.RED), a, b, c, d, btnAction);
-
- if (((EntryInfo) info.guiValue).widget instanceof Map.Entry) {
- Map.Entry> widget = (Map.Entry>) ((EntryInfo) info.guiValue).widget;
- if (info.getType().isEnum()) {
- widget.setValue(value -> Translatable(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString()));
- }
- this.list.addButton(MakeBtn(widget.getValue().apply(info.get()), this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen, 0, 150, 20, widget.getKey()), resetButton, null, name);
- return;
- } else if (((EntryInfo) info.guiValue).widget != null) {
- EditBox widget = new EditBox(font, this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, 150 - 4, 20, null);
- widget.setMaxLength(150);
- widget.insertText(String.valueOf(info.get()));
- Predicate processor = ((BiFunction>) ((EntryInfo) info.guiValue).widget).apply(widget, doneButton);
- widget.setFilter(processor);
- this.list.addButton(widget, resetButton, null, name);
- return;
- }
- }
- if (ConfigCategory.class.isAssignableFrom(info.getClass())) {
- Button widget = MakeBtn(name, this.width / 2 - 100, this.height - 28, 100 * 2, 20, (button -> {
- ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
- Objects.requireNonNull(minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, ((ConfigCategory) info).getDestination()));
- }));
- this.list.addButton(widget, null, null, null);
- return;
- }
- if (ConfigUIButton.class.isAssignableFrom(info.getClass())) {
- Button widget = MakeBtn(name, this.width / 2 - 100, this.height - 28, 100 * 2, 20, (button -> {
- ((ConfigUIButton) info).runAction();
- }));
- this.list.addButton(widget, null, null, null);
- return;
- }
- if (ConfigUIComment.class.isAssignableFrom(info.getClass())) {
- this.list.addButton(null, null, null, name);
- return;
- }
- if (ConfigLinkedEntry.class.isAssignableFrom(info.getClass())) {
- this.addMenuItem(((ConfigLinkedEntry) info).get());
- return;
- }
-
- LOGGER.warn("Config ["+ info.getNameWCategory() +"] failed to show. Please try something like changing its type.");
- }
-
- @Override
+ this.addBtn(new TexturedButtonWidget(
+ // Where the button is on the screen
+ this.width - 28, this.height - 28,
+ // Width and height of the button
+ 20, 20,
+ // Offset
+ 0, 0,
+ // Some textuary stuff
+ 0, new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"), 20, 20,
+ // Create the button and tell it where to go
+ (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this)),
+ // Add a title to the button
+ Translatable(ModInfo.ID + ".updater.title")
+ ));
+ }
+
+
+ addBtn(MakeBtn(CommonComponents.GUI_CANCEL, this.width / 2 - 154, this.height - 28, 150, 20, button -> {
+ ConfigBase.INSTANCE.configFileINSTANCE.loadFromFile();
+ Objects.requireNonNull(minecraft).setScreen(parent);
+ }));
+ doneButton = addBtn(MakeBtn(CommonComponents.GUI_DONE, this.width / 2 + 4, this.height - 28, 150, 20, (button) -> {
+ ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
+ Objects.requireNonNull(minecraft).setScreen(parent);
+ }));
+
+ this.list = new ConfigListWidget(this.minecraft, this.width * 2, this.height, 32, this.height - 32, 25);
+ if (this.minecraft != null && this.minecraft.level != null)
+ this.list.setRenderBackground(false);
+
+ this.addWidget(this.list);
+
+ for (AbstractConfigType info : ConfigBase.INSTANCE.entries)
+ {
+ try
+ {
+ if (info.getCategory().matches(category) && info.getAppearance().showInGui)
+ addMenuItem(info);
+ }
+ catch (Exception e)
+ {
+ System.out.println("ERROR: Failed to show [" + info.getNameWCategory() + "]");
+ if (info.get() != null)
+ System.out.print(" with the value [" + info.get() + "] with type [" + info.getType() + "]");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void addMenuItem(AbstractConfigType info)
+ {
+ initEntry(info, this.translationPrefix);
+ Component name = Translatable(translationPrefix + info.getNameWCategory());
+
+ if (ConfigEntry.class.isAssignableFrom(info.getClass()))
+ {
+ Button.OnPress btnAction = button -> {
+ ((ConfigEntry) info).setWithoutSaving(((ConfigEntry) info).getDefaultValue());
+ ((EntryInfo) info.guiValue).index = 0;
+ this.reload = true;
+ Objects.requireNonNull(minecraft).setScreen(this);
+ };
+ int a = this.width - ConfigScreenConfigs.SpaceFromRightScreen - 150 - ConfigScreenConfigs.ButtonWidthSpacing - ConfigScreenConfigs.ResetButtonWidth;
+ int b = 0;
+ int c = ConfigScreenConfigs.ResetButtonWidth;
+ int d = 20;
+
+ Button resetButton = MakeBtn(TextOrLiteral("Reset").withStyle(ChatFormatting.RED), a, b, c, d, btnAction);
+
+ if (((EntryInfo) info.guiValue).widget instanceof Map.Entry)
+ {
+ Map.Entry> widget = (Map.Entry>) ((EntryInfo) info.guiValue).widget;
+ if (info.getType().isEnum())
+ {
+ widget.setValue(value -> Translatable(translationPrefix + "enum." + info.getType().getSimpleName() + "." + info.get().toString()));
+ }
+ this.list.addButton(MakeBtn(widget.getValue().apply(info.get()), this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen, 0, 150, 20, widget.getKey()), resetButton, null, name);
+ return;
+ }
+ else if (((EntryInfo) info.guiValue).widget != null)
+ {
+ EditBox widget = new EditBox(font, this.width - 150 - ConfigScreenConfigs.SpaceFromRightScreen + 2, 0, 150 - 4, 20, null);
+ widget.setMaxLength(150);
+ widget.insertText(String.valueOf(info.get()));
+ Predicate processor = ((BiFunction>) ((EntryInfo) info.guiValue).widget).apply(widget, doneButton);
+ widget.setFilter(processor);
+ this.list.addButton(widget, resetButton, null, name);
+ return;
+ }
+ }
+ if (ConfigCategory.class.isAssignableFrom(info.getClass()))
+ {
+ Button widget = MakeBtn(name, this.width / 2 - 100, this.height - 28, 100 * 2, 20, (button -> {
+ ConfigBase.INSTANCE.configFileINSTANCE.saveToFile();
+ Objects.requireNonNull(minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, ((ConfigCategory) info).getDestination()));
+ }));
+ this.list.addButton(widget, null, null, null);
+ return;
+ }
+ if (ConfigUIButton.class.isAssignableFrom(info.getClass()))
+ {
+ Button widget = MakeBtn(name, this.width / 2 - 100, this.height - 28, 100 * 2, 20, (button -> {
+ ((ConfigUIButton) info).runAction();
+ }));
+ this.list.addButton(widget, null, null, null);
+ return;
+ }
+ if (ConfigUIComment.class.isAssignableFrom(info.getClass()))
+ {
+ this.list.addButton(null, null, null, name);
+ return;
+ }
+ if (ConfigLinkedEntry.class.isAssignableFrom(info.getClass()))
+ {
+ this.addMenuItem(((ConfigLinkedEntry) info).get());
+ return;
+ }
+
+ LOGGER.warn("Config [" + info.getNameWCategory() + "] failed to show. Please try something like changing its type.");
+ }
+
+ @Override
#if PRE_MC_1_20_1
- public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta)
#else
- public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
+ public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta)
#endif
- {
- this.renderBackground(matrices); // Renders background
- this.list.render(matrices, mouseX, mouseY, delta); // Render buttons
-
- DhDrawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title
-
- // If the update is pending, display this message to inform the user that it will apply when the game restarts
- if (SelfUpdater.deleteOldOnClose)
- DhDrawString(matrices, font, Translatable(configBase.modID + ".updater.waitingForClose"), 4, height-38, 0xFFFFFF);
-
-
- // Render the tooltip only if it can find a tooltip in the language file
- for (AbstractConfigType info : ConfigBase.INSTANCE.entries) {
- if (info.getCategory().matches(category) && info.getAppearance().showInGui) {
- if (list.getHoveredButton(mouseX, mouseY).isPresent()) {
- AbstractWidget buttonWidget = list.getHoveredButton(mouseX, mouseY).get();
- Component text = ButtonEntry.buttonsWithText.get(buttonWidget);
- // A quick fix for tooltips on linked entries
- AbstractConfigType newInfo = ConfigLinkedEntry.class.isAssignableFrom(info.getClass())?
- ((ConfigLinkedEntry) info).get():
- info;
-
- Component name = Translatable(this.translationPrefix + (info.category.isEmpty() ? "" : info.category + ".") + info.getName());
- String key = translationPrefix + (newInfo.category.isEmpty() ? "" : newInfo.category + ".") + newInfo.getName() + ".@tooltip";
-
- if (((EntryInfo) newInfo.guiValue).error != null && text.equals(name))
- DhRenderTooltip(matrices, font, ((EntryInfo) newInfo.guiValue).error.getValue(), mouseX, mouseY);
- else if (I18n.exists(key) && (text != null && text.equals(name))) {
- List list = new ArrayList<>();
- for (String str : I18n.get(key).split("\n")) {
- list.add(TextOrTranslatable(str));
- }
- DhRenderComponentTooltip(matrices, font, list, mouseX, mouseY);
- }
- }
- }
- }
- super.render(matrices, mouseX, mouseY, delta);
- }
- }
-
-
-
-
-
- private static void initEntry(AbstractConfigType info, String translationPrefix) {
- info.guiValue = new EntryInfo();
- Class> fieldClass = info.getType();
-
- if (ConfigEntry.class.isAssignableFrom(info.getClass())) {
- if (fieldClass == Integer.class) {
- // For int
- textField(info, Integer::parseInt, INTEGER_ONLY_REGEX, true);
- } else if (fieldClass == Double.class) {
- // For double
- textField(info, Double::parseDouble, DECIMAL_ONLY_REGEX, false);
- } else if (fieldClass == String.class || fieldClass == List.class) {
- // For string or list
- textField(info, String::length, null, true);
- } else if (fieldClass == Boolean.class) {
- // For boolean
- Function