All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.thomasglasser.sherdsapi.impl.mixin.SheetsMixin Maven / Gradle / Ivy

The newest version!
package dev.thomasglasser.sherdsapi.impl.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.thomasglasser.sherdsapi.impl.Sherd;
import dev.thomasglasser.sherdsapi.impl.SherdsApiRegistries;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import java.util.HashMap;
import java.util.Map;

@Mixin(Sheets.class)
public abstract class SheetsMixin
{
	@Unique
	private static final Map CUSTOM_MATERIALS = new HashMap<>();

	@ModifyReturnValue(method = "getDecoratedPotMaterial", at = @At("RETURN"))
	private static Material sherdsapi_getDecoratedPotMaterial(Material original, @Nullable ResourceKey key)
	{
		final Level level = Minecraft.getInstance().level;
		if (level != null)
		{
			Registry registry = level.registryAccess().registry(SherdsApiRegistries.SHERD).orElseThrow();
			for (Sherd sherd : registry.stream().toList())
			{
				ResourceKey pattern;
				if (sherd.pattern().isPresent())
					pattern = sherd.pattern().get();
				else
					pattern = ResourceKey.create(Registries.DECORATED_POT_PATTERNS, registry.getResourceKey(sherd).orElseThrow().location());
				if (pattern == key)
				{
					if (!CUSTOM_MATERIALS.containsKey(sherd))
						CUSTOM_MATERIALS.put(sherd, createDecoratedPotMaterial(key));

					return CUSTOM_MATERIALS.get(sherd);
				}
			}
		}
		return original;
	}

	@Shadow
	private static Material createDecoratedPotMaterial(ResourceKey resourceKey)
	{
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy