feat: rework dynamic item colors

This commit is contained in:
Martin Prokoph
2025-01-26 01:46:16 +01:00
parent 3307ba337e
commit d95a18b28b
11 changed files with 103 additions and 80 deletions

View File

@@ -8,13 +8,10 @@ import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.registry.Registries;
import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.util.Identifier;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.common.NeoForge;
@@ -43,12 +40,6 @@ public class VisualOverhaulClientForge {
});
NeoForge.EVENT_BUS.addListener(VisualOverhaulClientForge::doClientTick);
Registries.ITEM.forEach((item) -> {
ModelPredicateProviderRegistry.register(item, Identifier.ofVanilla("round"), (stack, world, entity, seed) ->
stack.getComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE) && stack.getComponents().contains(DataComponentTypes.CUSTOM_MODEL_DATA) &&
stack.getComponents().get(DataComponentTypes.CUSTOM_MODEL_DATA).value() == 710 ? 1.0F : 0.0F);
});
RenderLayers.setRenderLayer(Blocks.JUKEBOX, RenderLayer.getCutout());
RenderLayers.setRenderLayer(Blocks.FURNACE, RenderLayer.getCutout());
RenderLayers.setRenderLayer(Blocks.SMOKER, RenderLayer.getCutout());
@@ -61,7 +52,7 @@ public class VisualOverhaulClientForge {
waterColor = BiomeColors.getWaterColor(client.world, client.player.getBlockPos());
foliageColor = BiomeColors.getFoliageColor(client.world, client.player.getBlockPos());
grassColor = BiomeColors.getGrassColor(client.world, client.player.getBlockPos());
potionColor = VOColorUtil.convertRgbToArgb(waterColor);
potionColor = VOColorUtil.convertRgbToArgb(waterColor, 200);
} else {
waterColor = 4159204;
foliageColor = -8934609;

View File

@@ -8,7 +8,6 @@ import static eu.midnightdust.visualoverhaul.VisualOverhaulCommon.*;
@Mod(MOD_ID)
public class VisualOverhaulForge {
public VisualOverhaulForge() {
if (FMLEnvironment.dist == Dist.CLIENT) VisualOverhaulClientForge.initClient();
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
@@ -36,7 +37,7 @@ public abstract class MixinAbstractFurnaceBlockEntity extends LockableContainerB
}
@Inject(at = @At("TAIL"), method = "tick")
private static void tick(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
private static void tick(ServerWorld world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity, CallbackInfo ci) {
if (world.getBlockState(pos).hasBlockEntity()) {
if (!world.isClient && (visualoverhaul$invUpdate || world.getPlayers().size() == visualoverhaul$playerUpdate)) {
Stream<ServerPlayerEntity> watchingPlayers = ((ServerChunkManager)world.getChunkManager()).chunkLoadingManager.getPlayersWatchingChunk(new ChunkPos(pos), false).stream();

View File

@@ -1,39 +0,0 @@
package eu.midnightdust.visualoverhaul.neoforge.mixin;
import eu.midnightdust.visualoverhaul.config.VOConfig;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Items;
import net.minecraft.potion.Potions;
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 static eu.midnightdust.visualoverhaul.VisualOverhaulClient.*;
import static eu.midnightdust.visualoverhaul.VisualOverhaulClient.potionColor;
@Mixin(ItemColors.class)
public abstract class MixinItemColors {
@SuppressWarnings("deprecation")
@Inject(method = "create", at = @At("RETURN"))
private static void create(BlockColors blockMap, CallbackInfoReturnable<ItemColors> info) {
if (VOConfig.coloredItems) {
ItemColors itemColors = info.getReturnValue();
itemColors.register((stack, tintIndex) -> tintIndex == 0 ? -1 : waterColor, Items.WATER_BUCKET, Items.AXOLOTL_BUCKET, Items.COD_BUCKET, Items.PUFFERFISH_BUCKET, Items.TROPICAL_FISH_BUCKET, Items.SALMON_BUCKET);
itemColors.register((stack, tintIndex) -> grassColor, Items.GRASS_BLOCK, Items.SHORT_GRASS, Items.TALL_GRASS, Items.FERN, Items.LARGE_FERN);
itemColors.register((stack, tintIndex) -> foliageColor, Items.OAK_LEAVES, Items.JUNGLE_LEAVES, Items.DARK_OAK_LEAVES, Items.ACACIA_LEAVES, Items.VINE, Items.SUGAR_CANE);
if (VOConfig.coloredLilypad) itemColors.register((stack, tintIndex) -> foliageColor, Items.LILY_PAD);
itemColors.register((stack, tintIndex) -> {
var contents = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
if (contents == null || contents.potion().isEmpty()) return tintIndex > 0 ? -1 : potionColor;
var potion = contents.potion().get();
if ((potion == Potions.WATER || potion == Potions.MUNDANE || potion == Potions.THICK || potion == Potions.AWKWARD) && tintIndex == 0) {
return potionColor;
}
return tintIndex > 0 ? -1 : contents.getColor();
}, Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION);
}
}
}