Skip to content

Commit

Permalink
More innerSeams, less confusion
Browse files Browse the repository at this point in the history
- Add `innerSeams` support to all applicable methods (`horizontal`, `vertical`, `h+v`, `v+h`, `top`)
- Rewrite connection map calculation for some processors to be more efficient and compact
- Change BlockState retrieval across all processors to be more efficient and make more sense
- Change seeding method for `random`
- Move check for one sprite from RandomSpriteProvider to Factory
- Remove StandardOverlayQuadProcessor.BlockStateAndBoolean
- Do not normalize normal vector if its length is zero in CompactCTMQuadProcessor
- Move OptionalListCreator into CTMPropertiesLoader
- Standardize locations of Override and Nullable annotations
- Require Fabric API >=0.58.0
  • Loading branch information
PepperCode1 committed Aug 10, 2022
1 parent 3cee7e2 commit c98b3e5
Show file tree
Hide file tree
Showing 35 changed files with 263 additions and 282 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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:
#
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ private Identifier redirectGetAllResourcesId(Identifier id) {
}

@Override
public @Nullable ResourceRedirectHandler getRedirectHandler() {
@Nullable
public ResourceRedirectHandler getRedirectHandler() {
return redirectHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class SpriteAtlasTextureDataMixin implements SpriteAtlasTextureDataExtens
private Map<Identifier, Identifier> emissiveIdMap;

@Override
public @Nullable Map<Identifier, Identifier> getEmissiveIdMap() {
@Nullable
public Map<Identifier, Identifier> getEmissiveIdMap() {
return emissiveIdMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class SpriteMixin implements SpriteExtension {
private Sprite emissiveSprite;

@Override
public @Nullable Sprite getEmissiveSprite() {
@Nullable
public Sprite getEmissiveSprite() {
return emissiveSprite;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public EmissiveUnbakedModel(UnbakedModel wrapped) {
super(wrapped);
}

@Nullable
@Override
@Nullable
public BakedModel wrapBaked(@Nullable BakedModel bakedWrapped, ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (bakedWrapped == null || bakedWrapped.isBuiltin()) {
return bakedWrapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return wrapped.getTextureDependencies(unbakedModelGetter, unresolvedTextureReferences);
}

@Nullable
@Override
@Nullable
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (isBaking) {
return null;
}
isBaking = true;

Map<Identifier, UnbakedModel> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<ConnectingCTMProperties> {
public static class Factory extends AbstractQuadProcessorFactory<StandardConnectingCTMProperties> {
@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;
}
}
Expand Down
Loading

0 comments on commit c98b3e5

Please sign in to comment.