Clean up client side, fix sodium 0.5 compatibility

Fixes #9
This commit is contained in:
tibs 2023-08-13 23:48:15 -04:00
parent a559d61ab7
commit 6c4645fbf3
Signed by untrusted user who does not match committer: tibs
GPG key ID: 047833989F50F88F
10 changed files with 63 additions and 60 deletions

View file

@ -106,7 +106,7 @@ def getMetadata() {
id += "-dirty" id += "-dirty"
} }
metadata += "+${id}" metadata += "+git.${id}"
} }
return metadata return metadata

View file

@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true org.gradle.parallel=true
# Mod Properties # Mod Properties
mod_version=1.0.10 mod_version=1.0.11
maven_group=me.tibinonest.mods maven_group=me.tibinonest.mods
archives_base_name=cauldron-dyeing archives_base_name=cauldron-dyeing

View file

@ -1,10 +1,10 @@
[versions] [versions]
minecraft = "1.20" minecraft = "1.20.1"
quilt_mappings = "1.20+build.1" quilt_mappings = "1.20.1+build.14"
fabric_loader = "0.14.21" fabric_loader = "0.14.22"
fabric_api = "0.83.0+1.20" fabric_api = "0.87.0+1.20.1"
sodium = "mc1.20-0.4.10" sodium = "mc1.20.1-0.5.1"
[libraries] [libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
@ -16,5 +16,5 @@ sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
[plugins] [plugins]
fabric_loom = { id = "fabric-loom", version = "1.2.+" } fabric_loom = { id = "fabric-loom", version = "1.2.+" }
loom_quiltflower = { id = "io.github.juuxel.loom-quiltflower", version = "1.10.+" } loom_quiltflower = { id = "io.github.juuxel.loom-vineflower", version = "1.11.+" }
grgit = { id = "org.ajoberstar.grgit", version = "5.2.+" } grgit = { id = "org.ajoberstar.grgit", version = "5.2.+" }

View file

@ -8,10 +8,12 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityT
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
public class CauldronDyeing implements ModInitializer { public class CauldronDyeing implements ModInitializer {
public static final String MOD_ID = "cauldron_dyeing"; public static final String MOD_ID = "cauldron_dyeing";
@ -23,6 +25,16 @@ public class CauldronDyeing implements ModInitializer {
Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier(MOD_ID, "water_cauldron_entity"), WATER_CAULDRON_BLOCK_ENTITY); Registry.register(Registries.BLOCK_ENTITY_TYPE, new Identifier(MOD_ID, "water_cauldron_entity"), WATER_CAULDRON_BLOCK_ENTITY);
} }
@Environment(EnvType.CLIENT)
public static int getColor(BlockRenderView world, BlockPos pos) {
var blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof WaterCauldronBlockEntity waterCauldron && waterCauldron.getColor() != -1) {
return waterCauldron.getColor();
}
return BiomeColors.getWaterColor(world, pos);
}
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public static void rebuildBlock(BlockPos pos) { public static void rebuildBlock(BlockPos pos) {
MinecraftClient.getInstance().worldRenderer.scheduleBlockRenders(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ()); MinecraftClient.getInstance().worldRenderer.scheduleBlockRenders(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ());

View file

@ -1,22 +0,0 @@
package me.tibinonest.mods.cauldron_dyeing.mixin;
import me.tibinonest.mods.cauldron_dyeing.block.WaterCauldronBlockEntity;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BiomeColors.class)
public class BiomeColorsMixin {
@Inject(method = "getWaterColor", at = @At("HEAD"), cancellable = true)
private static void cauldron_dyeing$modifyWaterColor(BlockRenderView world, BlockPos pos, CallbackInfoReturnable<Integer> cir) {
var blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof WaterCauldronBlockEntity waterCauldron && waterCauldron.getColor() != -1) {
cir.setReturnValue(waterCauldron.getColor());
}
}
}

View file

@ -0,0 +1,18 @@
package me.tibinonest.mods.cauldron_dyeing.mixin;
import me.tibinonest.mods.cauldron_dyeing.CauldronDyeing;
import net.minecraft.block.Blocks;
import net.minecraft.client.color.block.BlockColors;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(BlockColors.class)
public class BlockColorsMixin {
@Inject(method = "create", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void cauldron_dyeing$modifyCreate(CallbackInfoReturnable<BlockColors> cir, BlockColors blockColors) {
blockColors.registerColorProvider((state, world, pos, tintIndex) -> world != null && pos != null ? CauldronDyeing.getColor(world, pos) : -1, Blocks.WATER_CAULDRON);
}
}

View file

@ -0,0 +1,22 @@
package me.tibinonest.mods.cauldron_dyeing.mixin.sodium;
import me.jellysquid.mods.sodium.client.model.color.ColorProvider;
import me.jellysquid.mods.sodium.client.model.color.ColorProviderRegistry;
import me.jellysquid.mods.sodium.client.model.color.DefaultColorProviders;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ColorProviderRegistry.class)
public abstract class ColorProviderRegistryMixin {
@Shadow protected abstract void registerBlocks(ColorProvider<BlockState> resolver, Block... blocks);
@Redirect(method = "installOverrides", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/model/color/ColorProviderRegistry;registerBlocks(Lme/jellysquid/mods/sodium/client/model/color/ColorProvider;[Lnet/minecraft/block/Block;)V", ordinal = 2))
private void cauldron_dyeing$modifyOverrides(ColorProviderRegistry instance, ColorProvider<BlockState> resolver, Block... blocks) {
this.registerBlocks(DefaultColorProviders.WaterColorProvider.BLOCKS, Blocks.WATER, Blocks.BUBBLE_COLUMN);
}
}

View file

@ -1,27 +0,0 @@
package me.tibinonest.mods.cauldron_dyeing.mixin.sodium;
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
import me.jellysquid.mods.sodium.client.model.quad.blender.ColorBlender;
import me.jellysquid.mods.sodium.client.model.quad.blender.ColorSampler;
import me.jellysquid.mods.sodium.client.model.quad.blender.FlatColorBlender;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import me.tibinonest.mods.cauldron_dyeing.block.WaterCauldronBlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(BlockRenderer.class)
public class SodiumBlockRendererMixin {
@Redirect(method = "renderQuadList", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/model/quad/blender/ColorBlender;getColors(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/util/math/BlockPos;Lme/jellysquid/mods/sodium/client/model/quad/ModelQuadView;Lme/jellysquid/mods/sodium/client/model/quad/blender/ColorSampler;Ljava/lang/Object;)[I"))
private <T> int[] cauldron_dyeing$redirectGetColors(ColorBlender instance, BlockRenderView world, BlockPos pos, ModelQuadView quad, ColorSampler<T> sampler, T state) {
var blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof WaterCauldronBlockEntity) {
return new FlatColorBlender().getColors(world, pos, quad, sampler, state);
}
return instance.getColors(world, pos, quad, sampler, state);
}
}

View file

@ -7,8 +7,8 @@
"CauldronBehaviorMixin" "CauldronBehaviorMixin"
], ],
"client": [ "client": [
"BiomeColorsMixin", "BlockColorsMixin",
"sodium.SodiumBlockRendererMixin" "sodium.ColorProviderRegistryMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View file

@ -29,6 +29,6 @@
"fabric-object-builder-api-v1": ">=0.1" "fabric-object-builder-api-v1": ">=0.1"
}, },
"breaks": { "breaks": {
"sodium": "<0.4.10" "sodium": "<0.5.0"
} }
} }