Skip to content

Commit

Permalink
Add compatibility for CITR emissives
Browse files Browse the repository at this point in the history
- Rename BiomeView to ChunkRendererRegionExtension
- Update Gradle
  • Loading branch information
PepperCode1 committed Mar 16, 2023
1 parent 1b6154c commit 5f1bc3a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 14 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

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

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.pepperbell.continuity.client.properties.overlay.StandardConnectingOverlayCTMProperties;
import me.pepperbell.continuity.client.properties.overlay.StandardOverlayCTMProperties;
import me.pepperbell.continuity.client.resource.CustomBlockLayers;
import me.pepperbell.continuity.client.resource.EmissiveIdProvider;
import me.pepperbell.continuity.client.util.RenderUtil;
import me.pepperbell.continuity.client.util.biome.BiomeHolderManager;
import me.pepperbell.continuity.client.util.biome.BiomeRetriever;
Expand All @@ -55,6 +56,7 @@ public void onInitializeClient() {
ProcessingDataKeyRegistryImpl.INSTANCE.init();
BiomeHolderManager.init();
BiomeRetriever.init();
EmissiveIdProvider.init();
ProcessingDataKeys.init();
RenderUtil.ReloadListener.init();
CustomBlockLayers.ReloadListener.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import me.pepperbell.continuity.client.util.biome.BiomeView;
import me.pepperbell.continuity.client.mixinterface.ChunkRendererRegionExtension;
import net.minecraft.client.render.chunk.ChunkRendererRegion;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;

@Mixin(ChunkRendererRegion.class)
public class ChunkRendererRegionMixin implements BiomeView {
public class ChunkRendererRegionMixin implements ChunkRendererRegionExtension {
@Shadow
@Final
protected World world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import me.pepperbell.continuity.client.mixinterface.SpriteAtlasTextureDataExtension;
import me.pepperbell.continuity.client.mixinterface.SpriteExtension;
import me.pepperbell.continuity.client.resource.EmissiveIdProvider;
import me.pepperbell.continuity.client.resource.EmissiveSuffixLoader;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;
Expand Down Expand Up @@ -57,8 +58,8 @@ private Identifier getTexturePath(Identifier id) {
continuity$emissiveIdMap = new Object2ObjectOpenHashMap<>();
for (Sprite.Info spriteInfo : spriteInfos) {
Identifier id = spriteInfo.getId();
if (!id.getPath().endsWith(emissiveSuffix)) {
Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix);
Identifier emissiveId = EmissiveIdProvider.toEmissiveId(id, emissiveSuffix);
if (emissiveId != null) {
Identifier emissiveLocation = getTexturePath(emissiveId);
if (resourceManager.containsResource(emissiveLocation)) {
emissiveIds.add(emissiveId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.pepperbell.continuity.client.util.biome;
package me.pepperbell.continuity.client.mixinterface;

import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.biome.Biome;

public interface BiomeView {
public interface ChunkRendererRegionExtension {
RegistryEntry<Biome> continuity$getBiome(BlockPos pos);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package me.pepperbell.continuity.client.resource;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;

public final class EmissiveIdProvider {
private static final Provider PROVIDER = createProvider();

private static Provider createProvider() {
if (FabricLoader.getInstance().isModLoaded("citresewn-defaults")) {
return EmissiveIdProvider::toEmissiveIdCITR;
}

return EmissiveIdProvider::toEmissiveIdStandard;
}

@Nullable
public static Identifier toEmissiveId(Identifier spriteId, String emissiveSuffix) {
return PROVIDER.toEmissiveId(spriteId, emissiveSuffix);
}

@ApiStatus.Internal
public static void init() {
}

@Nullable
private static Identifier toEmissiveIdStandard(Identifier spriteId, String emissiveSuffix) {
String path = spriteId.getPath();
if (!path.endsWith(emissiveSuffix)) {
return new Identifier(spriteId.getNamespace(), path + emissiveSuffix);
}
return null;
}

/**
* Sprite identifiers never have an extension in vanilla. CIT Resewn adds a png extension to some identifiers and
* changes SpriteAtlasTexture#getTexturePath to interpret those identifiers as absolute texture locations. This code
* accounts for the possibility of the identifier having a png extension and appends the emissive suffix before it.
*/
@Nullable
private static Identifier toEmissiveIdCITR(Identifier spriteId, String emissiveSuffix) {
String path = spriteId.getPath();
boolean hasExtension = path.endsWith(".png");
if (hasExtension) {
path = path.substring(0, path.length() - 4);
}
if (!path.endsWith(emissiveSuffix)) {
String emissivePath = path + emissiveSuffix;
if (hasExtension) {
emissivePath += ".png";
}
return new Identifier(spriteId.getNamespace(), emissivePath);
}
return null;
}

private interface Provider {
@Nullable
Identifier toEmissiveId(Identifier spriteId, String emissiveSuffix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

if (ArrayUtils.contains(ChunkRendererRegion.class.getInterfaces(), BiomeView.class)) {
if (ArrayUtils.contains(ChunkRendererRegion.class.getInterfaces(), ChunkRendererRegionExtension.class)) {
return BiomeRetriever::getBiomeByExtension;
}
return BiomeRetriever::getBiomeByWorldView;
Expand All @@ -56,21 +57,24 @@ public static Biome getBiome(BlockRenderView blockView, BlockPos pos) {
public static void init() {
}

@Nullable
private static Biome getBiomeByWorldView(BlockRenderView blockView, BlockPos pos) {
if (blockView instanceof WorldView worldView) {
return worldView.getBiome(pos).value();
}
return null;
}

@Nullable
private static Biome getBiomeByExtension(BlockRenderView blockView, BlockPos pos) {
if (blockView instanceof BiomeView biomeView) {
return biomeView.continuity$getBiome(pos).value();
if (blockView instanceof ChunkRendererRegionExtension extension) {
return extension.continuity$getBiome(pos).value();
}
return getBiomeByWorldView(blockView, pos);
}

// Sodium
@Nullable
private static Biome getBiomeByWorldSlice(BlockRenderView blockView, BlockPos pos) {
if (blockView instanceof WorldSlice worldSlice) {
return worldSlice.getBiomeAccess().getBiome(pos).value();
Expand All @@ -79,6 +83,7 @@ private static Biome getBiomeByWorldSlice(BlockRenderView blockView, BlockPos po
}

// Canvas
@Nullable
private static Biome getBiomeByInputRegion(BlockRenderView blockView, BlockPos pos) {
if (blockView instanceof InputRegion inputRegion) {
return inputRegion.getBiome(pos);
Expand All @@ -87,6 +92,7 @@ private static Biome getBiomeByInputRegion(BlockRenderView blockView, BlockPos p
}

private interface Provider {
@Nullable
Biome getBiome(BlockRenderView blockView, BlockPos pos);
}
}

0 comments on commit 5f1bc3a

Please sign in to comment.