Skip to content

Commit

Permalink
Reintroduce Sodium compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvverti committed Aug 3, 2021
1 parent 4019a92 commit c5d5ed6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
repositories {
maven { url = 'https://maven.terraformersmc.com/releases/' }
maven { url = 'https://maven.shedaniel.me/' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://api.modrinth.com/maven' }
}

sourceCompatibility = JavaVersion.VERSION_16
Expand Down Expand Up @@ -36,8 +36,8 @@ dependencies {
modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}") {
transitive = false
}
// modCompileOnly "com.github.jellysquid3:sodium-fabric:${project.sodium_version}"
// modRuntime "com.github.jellysquid3:sodium-fabric:${project.sodium_version}"
modCompileOnly "maven.modrinth:sodium:${project.sodium_version}"
modRuntime "maven.modrinth:sodium:${project.sodium_version}"
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
/*
* Colormatic
* Copyright (C) 2021 Thalia Nero
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* As an additional permission, when conveying the Corresponding Source of an
* object code form of this work, you may exclude the Corresponding Source for
* "Minecraft" by Mojang Studios, AB.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.kvverti.colormatic.iface;

import me.jellysquid.mods.sodium.client.model.quad.ModelQuadColorProvider;
import me.jellysquid.mods.sodium.client.world.biome.BlockColorsExtended;

import net.minecraft.block.BlockState;
import net.minecraft.client.color.block.BlockColorProvider;

/**
* Compatibility interface for mixing into Sodium. This interface effectively "forward declares" the methods
* declared in {@code BlockColorsExtended} in order to prevent a non-fatal exception from being thrown within
* declared in {@link BlockColorsExtended} in order to prevent a non-fatal exception from being thrown within
* mixin when Sodium is not installed.
*/
public interface SodiumColorProviderCompat {
BlockColorProvider getColorProvider(BlockState state);
ModelQuadColorProvider<BlockState> getColorProvider(BlockState state);
}

@SuppressWarnings("unused")
final class EnsureCorrectSignatures implements SodiumColorProviderCompat, BlockColorsExtended {
@Override
public ModelQuadColorProvider<BlockState> getColorProvider(BlockState state) {
throw new AssertionError("this class should not be instantiated");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Colormatic
* Copyright (C) 2020 Thalia Nero
* Copyright (C) 2021 Thalia Nero
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* As an additional permission, when conveying the Corresponding Source of an
* object code form of this work, you may exclude the Corresponding Source for
* "Minecraft" by Mojang Studios, AB.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Expand All @@ -19,29 +23,29 @@

import io.github.kvverti.colormatic.colormap.BiomeColormaps;
import io.github.kvverti.colormatic.iface.SodiumColorProviderCompat;
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadColorProvider;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import net.minecraft.block.BlockState;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.block.BlockColors;

@Mixin(value = BlockColors.class, priority = 2000)
@Implements(@Interface(iface = SodiumColorProviderCompat.class, prefix = "i$", remap = Interface.Remap.NONE))
public abstract class SodiumBlockColorsMixin implements SodiumColorProviderCompat {

@Unique
private static final BlockColorProvider COLORMATIC_PROVIDER =
private static final ModelQuadColorProvider<BlockState> COLORMATIC_PROVIDER =
(state, world, pos, tintIndex) -> BiomeColormaps.getBiomeColor(state, world, pos);

/**
* Displace Sodium's implementation to first check Colormatic's custom block colors.
*/
@Intrinsic(displace = true)
public BlockColorProvider i$getColorProvider(BlockState state) {
public ModelQuadColorProvider<BlockState> i$getColorProvider(BlockState state) {
if(BiomeColormaps.isCustomColored(state)) {
return COLORMATIC_PROVIDER;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"suggests": {
"flamingo": "*"
},
"conflicts": {
"sodium": "0.3.x"
"custom": {
"sodium:options": {
"mixin.features.fast_biome_colors": false
}
}
}

0 comments on commit c5d5ed6

Please sign in to comment.