diff --git a/gradle.properties b/gradle.properties index 70092fcf..88bdbc0f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.jvmargs = -Xmx1G # Fabric Properties loom_version = 0.12-SNAPSHOT minecraft_version = 1.19 - yarn_mappings = 1.19+build.1 - loader_version = 0.14.6 + yarn_mappings = 1.19+build.4 + loader_version = 0.14.9 # Mod Properties mod_version = 2.0.1 @@ -14,4 +14,4 @@ org.gradle.jvmargs = -Xmx1G archives_base_name = continuity # Dependencies - fabric_version = 0.55.1+1.19 + fabric_version = 0.58.0+1.19 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..249e5832 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897..ae04661e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index c53aefaa..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32..f127cfd4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java index 90232e93..b0103eca 100644 --- a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java +++ b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java @@ -22,7 +22,6 @@ import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; import me.pepperbell.continuity.client.properties.BaseCTMProperties; import me.pepperbell.continuity.client.properties.CompactConnectingCTMProperties; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; import me.pepperbell.continuity.client.properties.RandomCTMProperties; import me.pepperbell.continuity.client.properties.RepeatCTMProperties; import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; @@ -94,34 +93,34 @@ public void onInitializeClient() { registry.registerLoader("ctm_compact", loader); loader = CTMLoader.of( - wrapFactory(ConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(4)), + wrapFactory(StandardConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(4)), new HorizontalQuadProcessor.Factory() ); registry.registerLoader("horizontal", loader); registry.registerLoader("bookshelf", loader); loader = CTMLoader.of( - wrapFactory(ConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(4)), + wrapFactory(StandardConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(4)), new VerticalQuadProcessor.Factory() ); registry.registerLoader("vertical", loader); loader = CTMLoader.of( - wrapFactory(ConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(7)), + wrapFactory(StandardConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(7)), new HorizontalVerticalQuadProcessor.Factory() ); registry.registerLoader("horizontal+vertical", loader); registry.registerLoader("h+v", loader); loader = CTMLoader.of( - wrapFactory(ConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(7)), + wrapFactory(StandardConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(7)), new VerticalHorizontalQuadProcessor.Factory() ); registry.registerLoader("vertical+horizontal", loader); registry.registerLoader("v+h", loader); loader = CTMLoader.of( - wrapFactory(ConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(1)), + wrapFactory(StandardConnectingCTMProperties::new, new TileAmountValidator.Exactly<>(1)), new TopQuadProcessor.Factory() ); registry.registerLoader("top", loader); diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java index d7680b9d..82ffb472 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java @@ -46,7 +46,8 @@ private Identifier redirectGetAllResourcesId(Identifier id) { } @Override - public @Nullable ResourceRedirectHandler getRedirectHandler() { + @Nullable + public ResourceRedirectHandler getRedirectHandler() { return redirectHandler; } } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/SpriteAtlasTextureDataMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/SpriteAtlasTextureDataMixin.java index 81f82a6b..7fcd9b72 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/SpriteAtlasTextureDataMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/SpriteAtlasTextureDataMixin.java @@ -16,7 +16,8 @@ public class SpriteAtlasTextureDataMixin implements SpriteAtlasTextureDataExtens private Map emissiveIdMap; @Override - public @Nullable Map getEmissiveIdMap() { + @Nullable + public Map getEmissiveIdMap() { return emissiveIdMap; } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/SpriteMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/SpriteMixin.java index 6dc75584..d7c35bde 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/SpriteMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/SpriteMixin.java @@ -13,7 +13,8 @@ public class SpriteMixin implements SpriteExtension { private Sprite emissiveSprite; @Override - public @Nullable Sprite getEmissiveSprite() { + @Nullable + public Sprite getEmissiveSprite() { return emissiveSprite; } diff --git a/src/main/java/me/pepperbell/continuity/client/model/EmissiveUnbakedModel.java b/src/main/java/me/pepperbell/continuity/client/model/EmissiveUnbakedModel.java index fe213998..f119f65d 100644 --- a/src/main/java/me/pepperbell/continuity/client/model/EmissiveUnbakedModel.java +++ b/src/main/java/me/pepperbell/continuity/client/model/EmissiveUnbakedModel.java @@ -17,8 +17,8 @@ public EmissiveUnbakedModel(UnbakedModel wrapped) { super(wrapped); } - @Nullable @Override + @Nullable public BakedModel wrapBaked(@Nullable BakedModel bakedWrapped, ModelLoader loader, Function textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) { if (bakedWrapped == null || bakedWrapped.isBuiltin()) { return bakedWrapped; diff --git a/src/main/java/me/pepperbell/continuity/client/model/WrappingUnbakedModel.java b/src/main/java/me/pepperbell/continuity/client/model/WrappingUnbakedModel.java index 90ce6bd3..cc2bf190 100644 --- a/src/main/java/me/pepperbell/continuity/client/model/WrappingUnbakedModel.java +++ b/src/main/java/me/pepperbell/continuity/client/model/WrappingUnbakedModel.java @@ -36,8 +36,8 @@ public Collection getTextureDependencies(Function textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) { if (isBaking) { return null; @@ -45,9 +45,9 @@ public BakedModel bake(ModelLoader loader, Function te isBaking = true; Map unbakedModels = ((ModelLoaderAccessor) loader).getUnbakedModels(); - UnbakedModel previous = unbakedModels.put(modelId, wrapped); + UnbakedModel previous = unbakedModels.replace(modelId, wrapped); BakedModel bakedWrapped = loader.bake(modelId, rotationContainer); - unbakedModels.put(modelId, previous); + unbakedModels.replace(modelId, previous); BakedModel baked = wrapBaked(bakedWrapped, loader, textureGetter, rotationContainer, modelId); isBaking = false; diff --git a/src/main/java/me/pepperbell/continuity/client/processor/CompactCTMQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/CompactCTMQuadProcessor.java index e6e66c5e..946250c0 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/CompactCTMQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/CompactCTMQuadProcessor.java @@ -54,12 +54,10 @@ public class CompactCTMQuadProcessor extends ConnectingQuadProcessor { ArrayUtils.shift(map[7], 1); } - protected boolean innerSeams; protected Sprite[] replacementSprites; public CompactCTMQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams, Sprite[] replacementSprites) { - super(sprites, processingPredicate, connectionPredicate); - this.innerSeams = innerSeams; + super(sprites, processingPredicate, connectionPredicate, innerSeams); this.replacementSprites = replacementSprites; } @@ -115,17 +113,17 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl boolean vSplit30 = shouldSplitUV(vSignum3, vSignum0); // Cannot split across U and V at the same time - if (uSplit01 & vSplit01 || uSplit12 & vSplit12 || uSplit23 & vSplit23 || uSplit30 & vSplit30) { + if (uSplit01 & vSplit01 | uSplit12 & vSplit12 | uSplit23 & vSplit23 | uSplit30 & vSplit30) { return ProcessingResult.CONTINUE; } // Cannot split across U twice in a row - if (uSplit01 & uSplit12 || uSplit12 & uSplit23 || uSplit23 & uSplit30 || uSplit30 & uSplit01) { + if (uSplit01 & uSplit12 | uSplit12 & uSplit23 | uSplit23 & uSplit30 | uSplit30 & uSplit01) { return ProcessingResult.CONTINUE; } // Cannot split across V twice in a row - if (vSplit01 & vSplit12 || vSplit12 & vSplit23 || vSplit23 & vSplit30 || vSplit30 & vSplit01) { + if (vSplit01 & vSplit12 | vSplit12 & vSplit23 | vSplit23 & vSplit30 | vSplit30 & vSplit01) { return ProcessingResult.CONTINUE; } @@ -551,10 +549,13 @@ public void setLerped(float delta, Vertex vertexA, Vertex vertexB) { normalX = MathHelper.lerp(delta, vertexA.normalX, vertexB.normalX); normalY = MathHelper.lerp(delta, vertexA.normalY, vertexB.normalY); normalZ = MathHelper.lerp(delta, vertexA.normalZ, vertexB.normalZ); - float scale = 1 / (float) Math.sqrt(normalX * normalX + normalY * normalY + normalZ * normalZ); - normalX *= scale; - normalY *= scale; - normalZ *= scale; + float sqLength = normalX * normalX + normalY * normalY + normalZ * normalZ; + if (sqLength != 0) { + float scale = 1 / (float) Math.sqrt(sqLength); + normalX *= scale; + normalY *= scale; + normalZ *= scale; + } } } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/ConnectingQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/ConnectingQuadProcessor.java index 76136f27..85738871 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/ConnectingQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/ConnectingQuadProcessor.java @@ -4,9 +4,11 @@ public abstract class ConnectingQuadProcessor extends AbstractQuadProcessor { protected ConnectionPredicate connectionPredicate; + protected boolean innerSeams; - public ConnectingQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { + public ConnectingQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { super(sprites, processingPredicate); this.connectionPredicate = connectionPredicate; + this.innerSeams = innerSeams; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/ConnectionPredicate.java b/src/main/java/me/pepperbell/continuity/client/processor/ConnectionPredicate.java index 25ece2ab..acf0cd56 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/ConnectionPredicate.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/ConnectionPredicate.java @@ -7,9 +7,21 @@ import net.minecraft.world.BlockRenderView; public interface ConnectionPredicate { - boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockState to, Direction face, BlockRenderView blockView); + boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite); - default boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockPos toPos, Direction face, BlockRenderView blockView) { - return shouldConnect(state, quadSprite, pos, blockView.getBlockState(toPos), face, blockView); + default boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockPos toPos, Direction face, Sprite quadSprite) { + return shouldConnect(blockView, state, pos, blockView.getBlockState(toPos), face, quadSprite); + } + + default boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockPos.Mutable toPos, Direction face, Sprite quadSprite, boolean innerSeams) { + if (shouldConnect(blockView, state, pos, toPos, face, quadSprite)) { + if (innerSeams) { + toPos.move(face); + return !shouldConnect(blockView, state, pos, toPos, face, quadSprite); + } else { + return true; + } + } + return false; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/HorizontalQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/HorizontalQuadProcessor.java index ccd54f31..1241bac7 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/HorizontalQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/HorizontalQuadProcessor.java @@ -4,7 +4,7 @@ import me.pepperbell.continuity.api.client.QuadProcessor; import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; +import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.block.BlockState; import net.minecraft.client.texture.Sprite; @@ -20,8 +20,8 @@ public class HorizontalQuadProcessor extends ConnectingQuadProcessor { 3, 2, 0, 1, }; - public HorizontalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { - super(sprites, processingPredicate, connectionPredicate); + public HorizontalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { + super(sprites, processingPredicate, connectionPredicate, innerSeams); } @Override @@ -34,26 +34,24 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl } protected int getConnections(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { - mutablePos.set(pos); int connections = 0; for (int i = 0; i < 2; i++) { - mutablePos.move(directions[i * 2]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { + mutablePos.set(pos, directions[i * 2]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { connections |= 1 << i; } - mutablePos.set(pos); } return connections; } - public static class Factory extends AbstractQuadProcessorFactory { + public static class Factory extends AbstractQuadProcessorFactory { @Override - public QuadProcessor createProcessor(ConnectingCTMProperties properties, Sprite[] sprites) { - return new HorizontalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate()); + public QuadProcessor createProcessor(StandardConnectingCTMProperties properties, Sprite[] sprites) { + return new HorizontalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate(), properties.getInnerSeams()); } @Override - public int getTextureAmount(ConnectingCTMProperties properties) { + public int getTextureAmount(StandardConnectingCTMProperties properties) { return 4; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/HorizontalVerticalQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/HorizontalVerticalQuadProcessor.java index 43b23a94..4afe692c 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/HorizontalVerticalQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/HorizontalVerticalQuadProcessor.java @@ -4,7 +4,7 @@ import me.pepperbell.continuity.api.client.QuadProcessor; import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; +import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.block.BlockState; import net.minecraft.client.texture.Sprite; @@ -18,15 +18,15 @@ public class HorizontalVerticalQuadProcessor extends HorizontalQuadProcessor { // 32 16 8 // * // 1 2 4 - protected static final int[] SPRITE_INDEX_MAP_1 = new int[] { + protected static final int[] SECONDARY_SPRITE_INDEX_MAP = new int[] { 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 4, 4, 5, 4, 4, 4, 4, 4, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3, }; - public HorizontalVerticalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { - super(sprites, processingPredicate, connectionPredicate); + public HorizontalVerticalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { + super(sprites, processingPredicate, connectionPredicate, innerSeams); } @Override @@ -38,49 +38,38 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl if (connections != 0) { newSprite = sprites[SPRITE_INDEX_MAP[connections]]; } else { - connections = getConnections1(directions, mutablePos, blockView, state, pos, quad.lightFace(), sprite); - newSprite = sprites[SPRITE_INDEX_MAP_1[connections]]; + int secondaryConnections = getSecondaryConnections(directions, mutablePos, blockView, state, pos, quad.lightFace(), sprite); + newSprite = sprites[SECONDARY_SPRITE_INDEX_MAP[secondaryConnections]]; } return SimpleQuadProcessor.process(quad, sprite, newSprite); } - protected int getConnections1(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { - mutablePos.set(pos); + protected int getSecondaryConnections(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { int connections = 0; for (int i = 0; i < 2; i++) { - mutablePos.move(directions[i * 2 + 1]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { + Direction direction = directions[i * 2 + 1]; + mutablePos.set(pos, direction); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { connections |= 1 << (i * 3 + 1); - } - mutablePos.set(pos); - } - for (int i = 0; i < 4; i++) { - int shift = (i / 2) * 3 + 1; - int index1 = i; - int index2 = (i + 1) % 4; - if (((connections >> shift) & 1) == 1) { - mutablePos.move(directions[index1]).move(directions[index2]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - int shift1 = i % 2; - if (shift1 <= 0) { - shift1--; + for (int j = 0; j < 2; j++) { + mutablePos.set(pos, direction).move(directions[((i + j) % 2) * 2]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { + connections |= 1 << (i * 3 + j * 2); } - connections |= 1 << (shift + shift1); } - mutablePos.set(pos); } } return connections; } - public static class Factory extends AbstractQuadProcessorFactory { + public static class Factory extends AbstractQuadProcessorFactory { @Override - public QuadProcessor createProcessor(ConnectingCTMProperties properties, Sprite[] sprites) { - return new HorizontalVerticalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate()); + public QuadProcessor createProcessor(StandardConnectingCTMProperties properties, Sprite[] sprites) { + return new HorizontalVerticalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate(), properties.getInnerSeams()); } @Override - public int getTextureAmount(ConnectingCTMProperties properties) { + public int getTextureAmount(StandardConnectingCTMProperties properties) { return 7; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/ProcessingDataKeys.java b/src/main/java/me/pepperbell/continuity/client/processor/ProcessingDataKeys.java index 05ec7132..262fc507 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/ProcessingDataKeys.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/ProcessingDataKeys.java @@ -15,7 +15,6 @@ public final class ProcessingDataKeys { public static final ProcessingDataKey BIOME_CACHE_KEY = create("biome_cache", BaseProcessingPredicate.BiomeCache::new, BaseProcessingPredicate.BiomeCache::reset); public static final ProcessingDataKey BLOCK_ENTITY_NAME_CACHE_KEY = create("block_entity_name_cache", BaseProcessingPredicate.BlockEntityNameCache::new, BaseProcessingPredicate.BlockEntityNameCache::reset); public static final ProcessingDataKey VERTEX_CONTAINER_KEY = create("vertex_container", CompactCTMQuadProcessor.VertexContainer::new); - public static final ProcessingDataKey BLOCK_STATE_AND_BOOLEAN_KEY = create("block_state_and_boolean", StandardOverlayQuadProcessor.BlockStateAndBoolean::new); public static final ProcessingDataKey STANDARD_OVERLAY_RENDERER_POOL_KEY = create("standard_overlay_renderer_pool", StandardOverlayQuadProcessor.OverlayRendererPool::new, StandardOverlayQuadProcessor.OverlayRendererPool::reset); public static final ProcessingDataKey SIMPLE_OVERLAY_RENDERER_POOL_KEY = create("simple_overlay_renderer_pool", SimpleOverlayQuadProcessor.OverlayRendererPool::new, SimpleOverlayQuadProcessor.OverlayRendererPool::reset); diff --git a/src/main/java/me/pepperbell/continuity/client/processor/TopQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/TopQuadProcessor.java index c0f98f90..d4a0c453 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/TopQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/TopQuadProcessor.java @@ -4,7 +4,7 @@ import me.pepperbell.continuity.api.client.QuadProcessor; import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; +import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.block.BlockState; import net.minecraft.client.texture.Sprite; @@ -15,35 +15,37 @@ import net.minecraft.world.BlockRenderView; public class TopQuadProcessor extends ConnectingQuadProcessor { - public TopQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { - super(sprites, processingPredicate, connectionPredicate); + public TopQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { + super(sprites, processingPredicate, connectionPredicate, innerSeams); } @Override public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, int pass, int processorIndex, ProcessingContext context) { Direction lightFace = quad.lightFace(); - Direction.Axis axis = Direction.Axis.Y; + Direction.Axis axis; if (state.contains(Properties.AXIS)) { axis = state.get(Properties.AXIS); + } else { + axis = Direction.Axis.Y; } if (lightFace.getAxis() != axis) { Direction up = Direction.from(axis, Direction.AxisDirection.POSITIVE); - BlockPos.Mutable mutablePos = context.getData(ProcessingDataKeys.MUTABLE_POS_KEY).set(pos); - if (connectionPredicate.shouldConnect(state, sprite, pos, mutablePos.move(up), lightFace, blockView)) { + BlockPos.Mutable mutablePos = context.getData(ProcessingDataKeys.MUTABLE_POS_KEY).set(pos, up); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, lightFace, sprite, innerSeams)) { return SimpleQuadProcessor.process(quad, sprite, sprites[0]); } } return ProcessingResult.CONTINUE; } - public static class Factory extends AbstractQuadProcessorFactory { + public static class Factory extends AbstractQuadProcessorFactory { @Override - public QuadProcessor createProcessor(ConnectingCTMProperties properties, Sprite[] sprites) { - return new TopQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate()); + public QuadProcessor createProcessor(StandardConnectingCTMProperties properties, Sprite[] sprites) { + return new TopQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate(), properties.getInnerSeams()); } @Override - public int getTextureAmount(ConnectingCTMProperties properties) { + public int getTextureAmount(StandardConnectingCTMProperties properties) { return 1; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/VerticalHorizontalQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/VerticalHorizontalQuadProcessor.java index a7ca8fa8..fbe50031 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/VerticalHorizontalQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/VerticalHorizontalQuadProcessor.java @@ -4,7 +4,7 @@ import me.pepperbell.continuity.api.client.QuadProcessor; import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; +import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.block.BlockState; import net.minecraft.client.texture.Sprite; @@ -18,15 +18,15 @@ public class VerticalHorizontalQuadProcessor extends VerticalQuadProcessor { // 32 16 // 1 * 8 // 2 4 - protected static final int[] SPRITE_INDEX_MAP_1 = new int[] { + protected static final int[] SECONDARY_SPRITE_INDEX_MAP = new int[] { 3, 6, 3, 3, 3, 6, 3, 3, 4, 5, 4, 4, 3, 6, 3, 3, 3, 6, 3, 3, 3, 6, 3, 3, 3, 6, 3, 3, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, }; - public VerticalHorizontalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { - super(sprites, processingPredicate, connectionPredicate); + public VerticalHorizontalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { + super(sprites, processingPredicate, connectionPredicate, innerSeams); } @Override @@ -38,45 +38,38 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl if (connections != 0) { newSprite = sprites[SPRITE_INDEX_MAP[connections]]; } else { - connections = getConnections1(directions, mutablePos, blockView, state, pos, quad.lightFace(), sprite); - newSprite = sprites[SPRITE_INDEX_MAP_1[connections]]; + int secondaryConnections = getSecondaryConnections(directions, mutablePos, blockView, state, pos, quad.lightFace(), sprite); + newSprite = sprites[SECONDARY_SPRITE_INDEX_MAP[secondaryConnections]]; } return SimpleQuadProcessor.process(quad, sprite, newSprite); } - protected int getConnections1(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { - mutablePos.set(pos); + protected int getSecondaryConnections(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { int connections = 0; for (int i = 0; i < 2; i++) { - mutablePos.move(directions[i * 2]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - connections |= 1 << i * 3; - } - mutablePos.set(pos); - } - for (int i = 0; i < 4; i++) { - int shift = (i / 2) * 3; - int index1 = i; - int index2 = (i + 1) % 4; - if (((connections >> shift) & 1) == 1) { - mutablePos.move(directions[index1]).move(directions[index2]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - connections |= 1 << (shift + i % 2 + 1); + Direction direction = directions[i * 2]; + mutablePos.set(pos, direction); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { + connections |= 1 << (i * 3); + for (int j = 0; j < 2; j++) { + mutablePos.set(pos, direction).move(directions[((i + j) % 2) * 2 + 1]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { + connections |= 1 << ((i * 3 + j * 2 + 5) % 6); + } } - mutablePos.set(pos); } } return connections; } - public static class Factory extends AbstractQuadProcessorFactory { + public static class Factory extends AbstractQuadProcessorFactory { @Override - public QuadProcessor createProcessor(ConnectingCTMProperties properties, Sprite[] sprites) { - return new VerticalHorizontalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate()); + public QuadProcessor createProcessor(StandardConnectingCTMProperties properties, Sprite[] sprites) { + return new VerticalHorizontalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate(), properties.getInnerSeams()); } @Override - public int getTextureAmount(ConnectingCTMProperties properties) { + public int getTextureAmount(StandardConnectingCTMProperties properties) { return 7; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/VerticalQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/VerticalQuadProcessor.java index c44a7b12..2cf5e211 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/VerticalQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/VerticalQuadProcessor.java @@ -4,7 +4,7 @@ import me.pepperbell.continuity.api.client.QuadProcessor; import me.pepperbell.continuity.client.processor.simple.SimpleQuadProcessor; -import me.pepperbell.continuity.client.properties.ConnectingCTMProperties; +import me.pepperbell.continuity.client.properties.StandardConnectingCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.minecraft.block.BlockState; import net.minecraft.client.texture.Sprite; @@ -22,8 +22,8 @@ public class VerticalQuadProcessor extends ConnectingQuadProcessor { 3, 2, 0, 1, }; - public VerticalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate) { - super(sprites, processingPredicate, connectionPredicate); + public VerticalQuadProcessor(Sprite[] sprites, ProcessingPredicate processingPredicate, ConnectionPredicate connectionPredicate, boolean innerSeams) { + super(sprites, processingPredicate, connectionPredicate, innerSeams); } @Override @@ -36,26 +36,24 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl } protected int getConnections(Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { - mutablePos.set(pos); int connections = 0; for (int i = 0; i < 2; i++) { - mutablePos.move(directions[i * 2 + 1]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { + mutablePos.set(pos, directions[i * 2 + 1]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { connections |= 1 << i; } - mutablePos.set(pos); } return connections; } - public static class Factory extends AbstractQuadProcessorFactory { + public static class Factory extends AbstractQuadProcessorFactory { @Override - public QuadProcessor createProcessor(ConnectingCTMProperties properties, Sprite[] sprites) { - return new VerticalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate()); + public QuadProcessor createProcessor(StandardConnectingCTMProperties properties, Sprite[] sprites) { + return new VerticalQuadProcessor(sprites, BaseProcessingPredicate.fromProperties(properties), properties.getConnectionPredicate(), properties.getInnerSeams()); } @Override - public int getTextureAmount(ConnectingCTMProperties properties) { + public int getTextureAmount(StandardConnectingCTMProperties properties) { return 4; } } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/overlay/StandardOverlayQuadProcessor.java b/src/main/java/me/pepperbell/continuity/client/processor/overlay/StandardOverlayQuadProcessor.java index 00618996..291c1d1d 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/overlay/StandardOverlayQuadProcessor.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/overlay/StandardOverlayQuadProcessor.java @@ -68,7 +68,7 @@ public ProcessingResult processQuadInner(MutableQuadView quad, Sprite sprite, Bl return ProcessingResult.CONTINUE; } - protected boolean appliesOverlay(BlockState other, BlockState state, Direction face, Sprite quadSprite, BlockPos pos, BlockRenderView blockView) { + protected boolean appliesOverlay(BlockState other, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { if (other.getBlock().hasDynamicBounds()) { return false; } @@ -85,10 +85,10 @@ protected boolean appliesOverlay(BlockState other, BlockState state, Direction f return false; } } - return !connectionPredicate.shouldConnect(state, quadSprite, pos, other, face, blockView); + return !connectionPredicate.shouldConnect(blockView, state, pos, other, face, quadSprite); } - protected boolean hasSameOverlay(BlockState other, BlockState state, Direction face, Sprite quadSprite, BlockPos pos, BlockRenderView blockView) { + protected boolean hasSameOverlay(BlockState other, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { if (matchBlocksPredicate != null) { if (!matchBlocksPredicate.test(other)) { return false; @@ -102,50 +102,38 @@ protected boolean hasSameOverlay(BlockState other, BlockState state, Direction f return true; } - protected void appliesOverlayUnobscured(Direction direction0, BlockStateAndBoolean blockStateAndBoolean, BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, BlockPos.Mutable mutablePos) { - mutablePos.move(direction0); - BlockState state0 = blockView.getBlockState(mutablePos); - boolean bool = appliesOverlay(state0, state, lightFace, quadSprite, pos, blockView); - if (bool) { - mutablePos.move(lightFace); - if (blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos)) { - bool = false; - } + protected boolean appliesOverlayUnobscured(BlockState state0, Direction direction0, BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, BlockPos.Mutable mutablePos) { + boolean a0 = appliesOverlay(state0, blockView, state, pos, lightFace, quadSprite); + if (a0) { + mutablePos.set(pos, direction0).move(lightFace); + a0 = !blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos); } - mutablePos.set(pos); - blockStateAndBoolean.state = state0; - blockStateAndBoolean.bool = bool; + return a0; } protected boolean hasSameOverlayUnobscured(BlockState state0, Direction direction0, BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, BlockPos.Mutable mutablePos) { - boolean s0 = hasSameOverlay(state0, state, lightFace, quadSprite, pos, blockView); + boolean s0 = hasSameOverlay(state0, blockView, state, pos, lightFace, quadSprite); if (s0) { - mutablePos.move(direction0).move(lightFace); - if (blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos)) { - s0 = false; - } - mutablePos.set(pos); + mutablePos.set(pos, direction0).move(lightFace); + s0 = !blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos); } return s0; } protected boolean appliesOverlayCorner(Direction direction0, Direction direction1, BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, BlockPos.Mutable mutablePos) { - mutablePos.move(direction0).move(direction1); - boolean corner0 = appliesOverlay(blockView.getBlockState(mutablePos), state, lightFace, quadSprite, pos, blockView); + mutablePos.set(pos, direction0).move(direction1); + boolean corner0 = appliesOverlay(blockView.getBlockState(mutablePos), blockView, state, pos, lightFace, quadSprite); if (corner0) { mutablePos.move(lightFace); - if (blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos)) { - corner0 = false; - } + corner0 = !blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos); } - mutablePos.set(pos); return corner0; } protected OverlayRenderer fromCorner(Direction direction0, Direction direction1, int sprite0, int sprite1, OverlayRenderer renderer, BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, BlockPos.Mutable mutablePos) { Sprite[] rendererSprites = prepareRenderer(renderer, lightFace, blockView, pos); - mutablePos.move(direction0).move(direction1); - if (appliesOverlay(blockView.getBlockState(mutablePos), state, lightFace, quadSprite, pos, blockView)) { + mutablePos.set(pos, direction0).move(direction1); + if (appliesOverlay(blockView.getBlockState(mutablePos), blockView, state, pos, lightFace, quadSprite)) { mutablePos.move(lightFace); if (!blockView.getBlockState(mutablePos).isOpaqueFullCube(blockView, mutablePos)) { rendererSprites[1] = sprites[sprite1]; @@ -216,23 +204,22 @@ protected OverlayRenderer prepareRenderer(OverlayRenderer renderer, Direction fa 16: L U (CORNER) */ protected OverlayRenderer getRenderer(BlockRenderView blockView, BlockPos pos, BlockState state, Direction lightFace, Sprite quadSprite, Direction[] directions, ProcessingDataProvider dataProvider) { - BlockPos.Mutable mutablePos = dataProvider.getData(ProcessingDataKeys.MUTABLE_POS_KEY).set(pos); - BlockStateAndBoolean blockStateAndBoolean = dataProvider.getData(ProcessingDataKeys.BLOCK_STATE_AND_BOOLEAN_KEY); + BlockPos.Mutable mutablePos = dataProvider.getData(ProcessingDataKeys.MUTABLE_POS_KEY); // - appliesOverlayUnobscured(directions[0], blockStateAndBoolean, blockView, pos, state, lightFace, quadSprite, mutablePos); - BlockState state0 = blockStateAndBoolean.state; - boolean left = blockStateAndBoolean.bool; - appliesOverlayUnobscured(directions[1], blockStateAndBoolean, blockView, pos, state, lightFace, quadSprite, mutablePos); - BlockState state1 = blockStateAndBoolean.state; - boolean down = blockStateAndBoolean.bool; - appliesOverlayUnobscured(directions[2], blockStateAndBoolean, blockView, pos, state, lightFace, quadSprite, mutablePos); - BlockState state2 = blockStateAndBoolean.state; - boolean right = blockStateAndBoolean.bool; - appliesOverlayUnobscured(directions[3], blockStateAndBoolean, blockView, pos, state, lightFace, quadSprite, mutablePos); - BlockState state3 = blockStateAndBoolean.state; - boolean up = blockStateAndBoolean.bool; + mutablePos.set(pos, directions[0]); + BlockState state0 = blockView.getBlockState(mutablePos); + boolean left = appliesOverlayUnobscured(state0, directions[0], blockView, pos, state, lightFace, quadSprite, mutablePos); + mutablePos.set(pos, directions[1]); + BlockState state1 = blockView.getBlockState(mutablePos); + boolean down = appliesOverlayUnobscured(state1, directions[1], blockView, pos, state, lightFace, quadSprite, mutablePos); + mutablePos.set(pos, directions[2]); + BlockState state2 = blockView.getBlockState(mutablePos); + boolean right = appliesOverlayUnobscured(state2, directions[2], blockView, pos, state, lightFace, quadSprite, mutablePos); + mutablePos.set(pos, directions[3]); + BlockState state3 = blockView.getBlockState(mutablePos); + boolean up = appliesOverlayUnobscured(state3, directions[3], blockView, pos, state, lightFace, quadSprite, mutablePos); // @@ -334,11 +321,6 @@ protected OverlayRenderer getRenderer(BlockRenderView blockView, BlockPos pos, B return null; } - public static class BlockStateAndBoolean { - public BlockState state; - public boolean bool; - } - public static class OverlayRenderer implements Consumer { protected static final Sprite[] EMPTY_SPRITES = new Sprite[4]; diff --git a/src/main/java/me/pepperbell/continuity/client/processor/simple/CTMSpriteProvider.java b/src/main/java/me/pepperbell/continuity/client/processor/simple/CTMSpriteProvider.java index e1195b79..aeb5b023 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/simple/CTMSpriteProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/simple/CTMSpriteProvider.java @@ -2,6 +2,8 @@ import java.util.function.Supplier; +import org.jetbrains.annotations.Nullable; + import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.processor.ConnectionPredicate; import me.pepperbell.continuity.client.processor.DirectionMaps; @@ -52,6 +54,7 @@ public CTMSpriteProvider(Sprite[] sprites, ConnectionPredicate connectionPredica } @Override + @Nullable public Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, ProcessingDataProvider dataProvider) { Direction[] directions = useTextureOrientation ? DirectionMaps.getDirections(quad) : DirectionMaps.getMap(quad.lightFace())[0]; BlockPos.Mutable mutablePos = dataProvider.getData(ProcessingDataKeys.MUTABLE_POS_KEY); @@ -60,38 +63,21 @@ public Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, } public static int getConnections(ConnectionPredicate connectionPredicate, boolean innerSeams, Direction[] directions, BlockPos.Mutable mutablePos, BlockRenderView blockView, BlockState state, BlockPos pos, Direction face, Sprite quadSprite) { - mutablePos.set(pos); int connections = 0; for (int i = 0; i < 4; i++) { - mutablePos.move(directions[i]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - if (innerSeams) { - mutablePos.move(face); - if (!connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - connections |= 1 << (i * 2); - } - } else { - connections |= 1 << (i * 2); - } + mutablePos.set(pos, directions[i]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { + connections |= 1 << (i * 2); } - mutablePos.set(pos); } for (int i = 0; i < 4; i++) { int index1 = i; int index2 = (i + 1) % 4; if (((connections >> index1 * 2) & 1) == 1 && ((connections >> index2 * 2) & 1) == 1) { - mutablePos.move(directions[index1]).move(directions[index2]); - if (connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - if (innerSeams) { - mutablePos.move(face); - if (!connectionPredicate.shouldConnect(state, quadSprite, pos, mutablePos, face, blockView)) { - connections |= 1 << (i * 2 + 1); - } - } else { - connections |= 1 << (i * 2 + 1); - } + mutablePos.set(pos, directions[index1]).move(directions[index2]); + if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) { + connections |= 1 << (i * 2 + 1); } - mutablePos.set(pos); } } return connections; diff --git a/src/main/java/me/pepperbell/continuity/client/processor/simple/FixedSpriteProvider.java b/src/main/java/me/pepperbell/continuity/client/processor/simple/FixedSpriteProvider.java index f6288390..1bfb5440 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/simple/FixedSpriteProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/simple/FixedSpriteProvider.java @@ -2,6 +2,8 @@ import java.util.function.Supplier; +import org.jetbrains.annotations.Nullable; + import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.properties.BaseCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; @@ -19,6 +21,7 @@ public FixedSpriteProvider(Sprite sprite) { } @Override + @Nullable public Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, ProcessingDataProvider dataProvider) { return this.sprite; } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/simple/RandomSpriteProvider.java b/src/main/java/me/pepperbell/continuity/client/processor/simple/RandomSpriteProvider.java index 7894cb49..8c5eb19e 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/simple/RandomSpriteProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/simple/RandomSpriteProvider.java @@ -2,11 +2,13 @@ import java.util.function.Supplier; -import it.unimi.dsi.fastutil.HashCommon; +import org.jetbrains.annotations.Nullable; + import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.processor.ProcessingDataKeys; import me.pepperbell.continuity.client.processor.Symmetry; import me.pepperbell.continuity.client.properties.RandomCTMProperties; +import me.pepperbell.continuity.client.util.MathUtil; import me.pepperbell.continuity.client.util.RandomIndexProvider; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; import net.minecraft.block.Block; @@ -14,7 +16,6 @@ import net.minecraft.client.texture.Sprite; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.random.Random; import net.minecraft.world.BlockRenderView; @@ -34,43 +35,33 @@ public RandomSpriteProvider(Sprite[] sprites, RandomIndexProvider indexProvider, } @Override + @Nullable public Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, ProcessingDataProvider dataProvider) { - Sprite newSprite; - if (sprites.length == 1) { - newSprite = sprites[0]; - } else { - Direction face = symmetry.getActualFace(quad.lightFace()); + Direction face = symmetry.getActualFace(quad.lightFace()); - int x = pos.getX(); - int y = pos.getY(); - int z = pos.getZ(); - if (linked) { - Block block = state.getBlock(); - BlockPos.Mutable mutablePos = dataProvider.getData(ProcessingDataKeys.MUTABLE_POS_KEY).set(pos); - do { - mutablePos.move(Direction.DOWN); - } while (block == blockView.getBlockState(mutablePos).getBlock()); - y = mutablePos.getY() + 1; - } + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); - int hash = hash(x, y, z, face.ordinal(), randomLoops); - newSprite = sprites[indexProvider.getRandomIndex(hash)]; + if (linked) { + Block block = state.getBlock(); + BlockPos.Mutable mutablePos = dataProvider.getData(ProcessingDataKeys.MUTABLE_POS_KEY).set(pos); + do { + mutablePos.setY(mutablePos.getY() - 1); + } while (block == blockView.getBlockState(mutablePos).getBlock()); + y = mutablePos.getY() + 1; } - return newSprite; - } - public static int hash(int x, int y, int z, int face, int loops) { - int hash = Integer.rotateLeft(Long.hashCode(MathHelper.hashCode(x, y, z)), face * 5); - hash = HashCommon.mix(hash); - for (int i = 0; i < loops; i++) { - hash = HashCommon.mix(hash); - } - return hash; + int seed = MathUtil.mix(x, y, z, face.ordinal(), randomLoops); + return sprites[indexProvider.getRandomIndex(seed)]; } public static class Factory implements SpriteProvider.Factory { @Override public SpriteProvider createSpriteProvider(Sprite[] sprites, RandomCTMProperties properties) { + if (sprites.length == 1) { + return new FixedSpriteProvider(sprites[0]); + } return new RandomSpriteProvider(sprites, properties.getIndexProviderFactory().createIndexProvider(sprites.length), properties.getRandomLoops(), properties.getSymmetry(), properties.getLinked()); } diff --git a/src/main/java/me/pepperbell/continuity/client/processor/simple/RepeatSpriteProvider.java b/src/main/java/me/pepperbell/continuity/client/processor/simple/RepeatSpriteProvider.java index a57a1784..a90ff967 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/simple/RepeatSpriteProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/simple/RepeatSpriteProvider.java @@ -2,6 +2,8 @@ import java.util.function.Supplier; +import org.jetbrains.annotations.Nullable; + import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.processor.Symmetry; import me.pepperbell.continuity.client.properties.RepeatCTMProperties; @@ -27,6 +29,7 @@ public RepeatSpriteProvider(Sprite[] sprites, int width, int height, Symmetry sy } @Override + @Nullable public Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, ProcessingDataProvider dataProvider) { Direction face = symmetry.getActualFace(quad.lightFace()); diff --git a/src/main/java/me/pepperbell/continuity/client/processor/simple/SpriteProvider.java b/src/main/java/me/pepperbell/continuity/client/processor/simple/SpriteProvider.java index e908df48..87ab7d7f 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/simple/SpriteProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/simple/SpriteProvider.java @@ -2,6 +2,8 @@ import java.util.function.Supplier; +import org.jetbrains.annotations.Nullable; + import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.properties.BaseCTMProperties; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; @@ -12,6 +14,7 @@ import net.minecraft.world.BlockRenderView; public interface SpriteProvider { + @Nullable Sprite getSprite(QuadView quad, Sprite sprite, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, ProcessingDataProvider dataProvider); interface Factory { diff --git a/src/main/java/me/pepperbell/continuity/client/properties/ConnectingCTMProperties.java b/src/main/java/me/pepperbell/continuity/client/properties/ConnectingCTMProperties.java index 0f1f7312..cd5a6e44 100644 --- a/src/main/java/me/pepperbell/continuity/client/properties/ConnectingCTMProperties.java +++ b/src/main/java/me/pepperbell/continuity/client/properties/ConnectingCTMProperties.java @@ -63,29 +63,29 @@ public ConnectionPredicate getConnectionPredicate() { public enum ConnectionType implements ConnectionPredicate { BLOCK { @Override - public boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockState to, Direction face, BlockRenderView blockView) { - return state.getBlock() == to.getBlock(); + public boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite) { + return state.getBlock() == toState.getBlock(); } }, TILE { @Override - public boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockState to, Direction face, BlockRenderView blockView) { - if (state == to) { + public boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite) { + if (state == toState) { return true; } - return quadSprite == SpriteCalculator.getSprite(to, face); + return quadSprite == SpriteCalculator.getSprite(toState, face); } }, MATERIAL { @Override - public boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockState to, Direction face, BlockRenderView blockView) { - return state.getMaterial() == to.getMaterial(); + public boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite) { + return state.getMaterial() == toState.getMaterial(); } }, STATE { @Override - public boolean shouldConnect(BlockState state, Sprite quadSprite, BlockPos pos, BlockState to, Direction face, BlockRenderView blockView) { - return state == to; + public boolean shouldConnect(BlockRenderView blockView, BlockState state, BlockPos pos, BlockState toState, Direction face, Sprite quadSprite) { + return state == toState; } }; } diff --git a/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java b/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java index ad4e21a2..0b58eef3 100644 --- a/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java +++ b/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java @@ -196,8 +196,8 @@ public static Predicate parseBlockStates(Properties properties, Stri ImmutableList> predicateList = predicateListBuilder.build(); if (!predicateList.isEmpty()) { - int amount = predicateList.size(); return state -> { + int amount = predicateList.size(); for (int i = 0; i < amount; i++) { if (predicateList.get(i).test(state)) { return true; diff --git a/src/main/java/me/pepperbell/continuity/client/resource/CTMPropertiesLoader.java b/src/main/java/me/pepperbell/continuity/client/resource/CTMPropertiesLoader.java index e7f92cd1..eb60b356 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/CTMPropertiesLoader.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/CTMPropertiesLoader.java @@ -21,7 +21,6 @@ import me.pepperbell.continuity.api.client.CTMProperties; import me.pepperbell.continuity.client.ContinuityClient; import me.pepperbell.continuity.client.util.BooleanState; -import me.pepperbell.continuity.client.util.OptionalListCreator; import net.minecraft.block.BlockState; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.resource.ResourceManager; @@ -211,4 +210,23 @@ public static void clearAll() { IGNORES_BLOCK.clear(); VALID_FOR_MULTIPASS.clear(); } + + private static class OptionalListCreator implements Consumer { + private ObjectArrayList list = null; + + @Override + public void accept(T t) { + if (list == null) { + list = new ObjectArrayList<>(); + } + list.add(t); + } + + @Nullable + public ObjectArrayList get() { + ObjectArrayList list = this.list; + this.list = null; + return list; + } + } } diff --git a/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java b/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java index 02be0785..39c404db 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java @@ -12,7 +12,6 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import it.unimi.dsi.fastutil.objects.ObjectArraySet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import me.pepperbell.continuity.client.mixinterface.SpriteAtlasTextureDataExtension; import me.pepperbell.continuity.client.model.CTMUnbakedModel; @@ -77,7 +76,7 @@ public static void wrapCTMModels(Map unbakedModels, Ma Set> dependents = container.getRecursiveMultipassDependents(); if (dependents != null) { if (multipassContainerSet == null) { - multipassContainerSet = new ObjectArraySet<>(); + multipassContainerSet = new ObjectOpenHashSet<>(); } multipassContainerSet.addAll(dependents); } @@ -158,10 +157,8 @@ private static Function createUnbakedModelGetter(Map wrappedModels, Map unbakedModels, Map modelsToBake) { wrappedModels.forEach((id, wrapped) -> { - unbakedModels.put(id, wrapped); - if (modelsToBake.containsKey(id)) { - modelsToBake.put(id, wrapped); - } + unbakedModels.replace(id, wrapped); + modelsToBake.replace(id, wrapped); }); } diff --git a/src/main/java/me/pepperbell/continuity/client/util/MathUtil.java b/src/main/java/me/pepperbell/continuity/client/util/MathUtil.java index 443f0f51..65ec026f 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/MathUtil.java +++ b/src/main/java/me/pepperbell/continuity/client/util/MathUtil.java @@ -1,6 +1,11 @@ package me.pepperbell.continuity.client.util; +import net.minecraft.util.math.MathHelper; + public final class MathUtil { + // Borrowed from SplittableRandom + public static final long GOLDEN_GAMMA = 0x9e3779b97f4a7c15L; + public static int signum(int value) { if (value > 0) { return 1; @@ -26,4 +31,21 @@ public static int lerpLight(float delta, int lightA, int lightB) { return (lerp(delta, lightA >> 20 & 0xF, lightB >> 20 & 0xF) << 20) | (lerp(delta, lightA >> 4 & 0xF, lightB >> 4 & 0xF) << 4); } + + // Borrowed from SplittableRandom + public static long mix64(long z) { + z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L; + z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL; + return z ^ (z >>> 31); + } + + // Borrowed from SplittableRandom + public static int mix32(long z) { + z = (z ^ (z >>> 33)) * 0x62a9d9ed799705f5L; + return (int) (((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32); + } + + public static int mix(int x, int y, int z, int face, int loops) { + return mix32((MathHelper.hashCode(x, y, z) ^ mix64(GOLDEN_GAMMA * (1 + face))) + GOLDEN_GAMMA * (1 + loops)); + } } diff --git a/src/main/java/me/pepperbell/continuity/client/util/OptionalListCreator.java b/src/main/java/me/pepperbell/continuity/client/util/OptionalListCreator.java deleted file mode 100644 index b8088477..00000000 --- a/src/main/java/me/pepperbell/continuity/client/util/OptionalListCreator.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.pepperbell.continuity.client.util; - -import java.util.function.Consumer; -import java.util.function.Supplier; - -import org.jetbrains.annotations.Nullable; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; - -public class OptionalListCreator implements Consumer, Supplier> { - private ObjectArrayList list = null; - - @Override - public void accept(T t) { - if (list == null) { - list = new ObjectArrayList<>(); - } - list.add(t); - } - - @Override - @Nullable - public ObjectArrayList get() { - ObjectArrayList list = this.list; - this.list = null; - return list; - } -} diff --git a/src/main/java/me/pepperbell/continuity/client/util/QuadUtil.java b/src/main/java/me/pepperbell/continuity/client/util/QuadUtil.java index 50c011c5..82845f49 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/QuadUtil.java +++ b/src/main/java/me/pepperbell/continuity/client/util/QuadUtil.java @@ -26,8 +26,8 @@ public static void interpolate(MutableQuadView quad, Sprite oldSprite, Sprite ne public static void assignLerpedUVs(MutableQuadView quad, Sprite sprite) { float delta = sprite.getAnimationFrameDelta(); - float centerU = (sprite.getMinU() + sprite.getMaxU()) / 2.0f; - float centerV = (sprite.getMinV() + sprite.getMaxV()) / 2.0f; + float centerU = (sprite.getMinU() + sprite.getMaxU()) * 0.5f; + float centerV = (sprite.getMinV() + sprite.getMaxV()) * 0.5f; float lerpedMinU = MathHelper.lerp(delta, sprite.getMinU(), centerU); float lerpedMaxU = MathHelper.lerp(delta, sprite.getMaxU(), centerU); float lerpedMinV = MathHelper.lerp(delta, sprite.getMinV(), centerV); diff --git a/src/main/java/me/pepperbell/continuity/client/util/RandomIndexProvider.java b/src/main/java/me/pepperbell/continuity/client/util/RandomIndexProvider.java index a49dcabd..addb2b7c 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/RandomIndexProvider.java +++ b/src/main/java/me/pepperbell/continuity/client/util/RandomIndexProvider.java @@ -34,10 +34,10 @@ class Weighted implements RandomIndexProvider { protected int weightSum; protected int maxIndex; - public Weighted(int[] weights, int weightSum, int maxIndex) { + public Weighted(int[] weights, int weightSum) { this.weights = weights; this.weightSum = weightSum; - this.maxIndex = maxIndex; + this.maxIndex = weights.length - 1; } @Override @@ -77,7 +77,7 @@ public RandomIndexProvider createIndexProvider(int size) { } } - return new Weighted(newWeights, weightSum, size - 1); + return new Weighted(newWeights, weightSum); } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0985bcda..d4ac6648 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -32,7 +32,7 @@ "depends": { "fabricloader": ">=0.11.7", - "fabric": ">=0.51.0", + "fabric": ">=0.58.0", "minecraft": "1.19.x", "java": ">=17" },