![JAR search and dependency download from the Maven repository](/logo.png)
dev.thomasglasser.sherdsapi.impl.mixin.SheetsMixin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sherdsapi-common-1.20.4 Show documentation
Show all versions of sherdsapi-common-1.20.4 Show documentation
Makes adding new pottery sherds easier
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