Skip to content

Commit 3fe7a74

Browse files
committed
Add compatibility for CITR emissives
- Rename BiomeView to ChunkRendererRegionExtension - Update Gradle
1 parent bbcbac3 commit 3fe7a74

File tree

10 files changed

+93
-14
lines changed

10 files changed

+93
-14
lines changed

gradle/wrapper/gradle-wrapper.jar

818 Bytes
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,10 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

8888
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
8989
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@@ -143,12 +143,16 @@ fi
143143
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147+
# shellcheck disable=SC3045
146148
MAX_FD=$( ulimit -H -n ) ||
147149
warn "Could not query maximum file descriptor limit"
148150
esac
149151
case $MAX_FD in #(
150152
'' | soft) :;; #(
151153
*)
154+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155+
# shellcheck disable=SC3045
152156
ulimit -n "$MAX_FD" ||
153157
warn "Could not set maximum file descriptor limit to $MAX_FD"
154158
esac

gradlew.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
2828
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

src/main/java/me/pepperbell/continuity/client/ContinuityClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import me.pepperbell.continuity.client.properties.overlay.StandardConnectingOverlayCTMProperties;
3636
import me.pepperbell.continuity.client.properties.overlay.StandardOverlayCTMProperties;
3737
import me.pepperbell.continuity.client.resource.CustomBlockLayers;
38+
import me.pepperbell.continuity.client.resource.EmissiveIdProvider;
3839
import me.pepperbell.continuity.client.util.RenderUtil;
3940
import me.pepperbell.continuity.client.util.biome.BiomeHolderManager;
4041
import me.pepperbell.continuity.client.util.biome.BiomeRetriever;
@@ -55,6 +56,7 @@ public void onInitializeClient() {
5556
ProcessingDataKeyRegistryImpl.INSTANCE.init();
5657
BiomeHolderManager.init();
5758
BiomeRetriever.init();
59+
EmissiveIdProvider.init();
5860
ProcessingDataKeys.init();
5961
RenderUtil.ReloadListener.init();
6062
CustomBlockLayers.ReloadListener.init();

src/main/java/me/pepperbell/continuity/client/mixin/ChunkRendererRegionMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import org.spongepowered.asm.mixin.Mixin;
55
import org.spongepowered.asm.mixin.Shadow;
66

7-
import me.pepperbell.continuity.client.util.biome.BiomeView;
7+
import me.pepperbell.continuity.client.mixinterface.ChunkRendererRegionExtension;
88
import net.minecraft.client.render.chunk.ChunkRendererRegion;
99
import net.minecraft.util.math.BlockPos;
1010
import net.minecraft.util.registry.RegistryEntry;
1111
import net.minecraft.world.World;
1212
import net.minecraft.world.biome.Biome;
1313

1414
@Mixin(ChunkRendererRegion.class)
15-
public class ChunkRendererRegionMixin implements BiomeView {
15+
public class ChunkRendererRegionMixin implements ChunkRendererRegionExtension {
1616
@Shadow
1717
@Final
1818
protected World world;

src/main/java/me/pepperbell/continuity/client/mixin/SpriteAtlasTextureMixin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
1919
import me.pepperbell.continuity.client.mixinterface.SpriteAtlasTextureDataExtension;
2020
import me.pepperbell.continuity.client.mixinterface.SpriteExtension;
21+
import me.pepperbell.continuity.client.resource.EmissiveIdProvider;
2122
import me.pepperbell.continuity.client.resource.EmissiveSuffixLoader;
2223
import net.minecraft.client.texture.Sprite;
2324
import net.minecraft.client.texture.SpriteAtlasTexture;
@@ -57,8 +58,8 @@ private Identifier getTexturePath(Identifier id) {
5758
continuity$emissiveIdMap = new Object2ObjectOpenHashMap<>();
5859
for (Sprite.Info spriteInfo : spriteInfos) {
5960
Identifier id = spriteInfo.getId();
60-
if (!id.getPath().endsWith(emissiveSuffix)) {
61-
Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix);
61+
Identifier emissiveId = EmissiveIdProvider.toEmissiveId(id, emissiveSuffix);
62+
if (emissiveId != null) {
6263
Identifier emissiveLocation = getTexturePath(emissiveId);
6364
if (resourceManager.getResource(emissiveLocation).isPresent()) {
6465
emissiveIds.add(emissiveId);

src/main/java/me/pepperbell/continuity/client/util/biome/BiomeView.java renamed to src/main/java/me/pepperbell/continuity/client/mixinterface/ChunkRendererRegionExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package me.pepperbell.continuity.client.util.biome;
1+
package me.pepperbell.continuity.client.mixinterface;
22

33
import net.minecraft.util.math.BlockPos;
44
import net.minecraft.util.registry.RegistryEntry;
55
import net.minecraft.world.biome.Biome;
66

7-
public interface BiomeView {
7+
public interface ChunkRendererRegionExtension {
88
RegistryEntry<Biome> continuity$getBiome(BlockPos pos);
99
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package me.pepperbell.continuity.client.resource;
2+
3+
import org.jetbrains.annotations.ApiStatus;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import net.fabricmc.loader.api.FabricLoader;
7+
import net.minecraft.util.Identifier;
8+
9+
public final class EmissiveIdProvider {
10+
private static final Provider PROVIDER = createProvider();
11+
12+
private static Provider createProvider() {
13+
if (FabricLoader.getInstance().isModLoaded("citresewn-defaults")) {
14+
return EmissiveIdProvider::toEmissiveIdCITR;
15+
}
16+
17+
return EmissiveIdProvider::toEmissiveIdStandard;
18+
}
19+
20+
@Nullable
21+
public static Identifier toEmissiveId(Identifier spriteId, String emissiveSuffix) {
22+
return PROVIDER.toEmissiveId(spriteId, emissiveSuffix);
23+
}
24+
25+
@ApiStatus.Internal
26+
public static void init() {
27+
}
28+
29+
@Nullable
30+
private static Identifier toEmissiveIdStandard(Identifier spriteId, String emissiveSuffix) {
31+
String path = spriteId.getPath();
32+
if (!path.endsWith(emissiveSuffix)) {
33+
return new Identifier(spriteId.getNamespace(), path + emissiveSuffix);
34+
}
35+
return null;
36+
}
37+
38+
/**
39+
* Sprite identifiers never have an extension in vanilla. CIT Resewn adds a png extension to some identifiers and
40+
* changes SpriteAtlasTexture#getTexturePath to interpret those identifiers as absolute texture locations. This code
41+
* accounts for the possibility of the identifier having a png extension and appends the emissive suffix before it.
42+
*/
43+
@Nullable
44+
private static Identifier toEmissiveIdCITR(Identifier spriteId, String emissiveSuffix) {
45+
String path = spriteId.getPath();
46+
boolean hasExtension = path.endsWith(".png");
47+
if (hasExtension) {
48+
path = path.substring(0, path.length() - 4);
49+
}
50+
if (!path.endsWith(emissiveSuffix)) {
51+
String emissivePath = path + emissiveSuffix;
52+
if (hasExtension) {
53+
emissivePath += ".png";
54+
}
55+
return new Identifier(spriteId.getNamespace(), emissivePath);
56+
}
57+
return null;
58+
}
59+
60+
private interface Provider {
61+
@Nullable
62+
Identifier toEmissiveId(Identifier spriteId, String emissiveSuffix);
63+
}
64+
}

src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import grondag.canvas.terrain.region.input.InputRegion;
88
import me.jellysquid.mods.sodium.client.world.WorldSlice;
9+
import me.pepperbell.continuity.client.mixinterface.ChunkRendererRegionExtension;
910
import net.fabricmc.loader.api.FabricLoader;
1011
import net.minecraft.client.render.chunk.ChunkRendererRegion;
1112
import net.minecraft.util.math.BlockPos;
@@ -41,7 +42,7 @@ private static Provider createProvider() {
4142
return BiomeRetriever::getBiomeByWorldView;
4243
}
4344

44-
if (ArrayUtils.contains(ChunkRendererRegion.class.getInterfaces(), BiomeView.class)) {
45+
if (ArrayUtils.contains(ChunkRendererRegion.class.getInterfaces(), ChunkRendererRegionExtension.class)) {
4546
return BiomeRetriever::getBiomeByExtension;
4647
}
4748
return BiomeRetriever::getBiomeByWorldView;
@@ -56,21 +57,24 @@ public static Biome getBiome(BlockRenderView blockView, BlockPos pos) {
5657
public static void init() {
5758
}
5859

60+
@Nullable
5961
private static Biome getBiomeByWorldView(BlockRenderView blockView, BlockPos pos) {
6062
if (blockView instanceof WorldView worldView) {
6163
return worldView.getBiome(pos).value();
6264
}
6365
return null;
6466
}
6567

68+
@Nullable
6669
private static Biome getBiomeByExtension(BlockRenderView blockView, BlockPos pos) {
67-
if (blockView instanceof BiomeView biomeView) {
68-
return biomeView.continuity$getBiome(pos).value();
70+
if (blockView instanceof ChunkRendererRegionExtension extension) {
71+
return extension.continuity$getBiome(pos).value();
6972
}
7073
return getBiomeByWorldView(blockView, pos);
7174
}
7275

7376
// Sodium
77+
@Nullable
7478
private static Biome getBiomeByWorldSlice(BlockRenderView blockView, BlockPos pos) {
7579
if (blockView instanceof WorldSlice worldSlice) {
7680
return worldSlice.getBiomeAccess().getBiome(pos).value();
@@ -79,6 +83,7 @@ private static Biome getBiomeByWorldSlice(BlockRenderView blockView, BlockPos po
7983
}
8084

8185
// Canvas
86+
@Nullable
8287
private static Biome getBiomeByInputRegion(BlockRenderView blockView, BlockPos pos) {
8388
if (blockView instanceof InputRegion inputRegion) {
8489
return inputRegion.getBiome(pos);
@@ -87,6 +92,7 @@ private static Biome getBiomeByInputRegion(BlockRenderView blockView, BlockPos p
8792
}
8893

8994
private interface Provider {
95+
@Nullable
9096
Biome getBiome(BlockRenderView blockView, BlockPos pos);
9197
}
9298
}

0 commit comments

Comments
 (0)