1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Implement MinecraftAssetResolver

This commit is contained in:
Eclipse
2025-10-14 08:44:33 +00:00
parent 466427e974
commit 7c4c10d9cb
5 changed files with 33 additions and 12 deletions

View File

@@ -1,41 +1,60 @@
package org.geysermc.rainbow.client; package org.geysermc.rainbow.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ClientItem; import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.resources.model.EquipmentAssetManager;
import net.minecraft.client.resources.model.EquipmentClientInfo; import net.minecraft.client.resources.model.EquipmentClientInfo;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.equipment.EquipmentAsset; import net.minecraft.world.item.equipment.EquipmentAsset;
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
import org.geysermc.rainbow.client.mixin.EntityRenderDispatcherAccessor;
import org.geysermc.rainbow.mapping.AssetResolver; import org.geysermc.rainbow.mapping.AssetResolver;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
public class MinecraftAssetResolver implements AssetResolver { public class MinecraftAssetResolver implements AssetResolver {
private final ModelManager modelManager;
private final EquipmentAssetManager equipmentAssetManager;
private final ResourceManager resourceManager;
private final HolderLookup.Provider registries;
public MinecraftAssetResolver(Minecraft minecraft) {
modelManager = minecraft.getModelManager();
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
resourceManager = minecraft.getResourceManager();
registries = Objects.requireNonNull(minecraft.level).registryAccess();
}
@Override @Override
public Optional<ResolvedModel> getResolvedModel(ResourceLocation location) { public Optional<ResolvedModel> getResolvedModel(ResourceLocation location) {
return Optional.empty(); return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(location);
} }
@Override @Override
public Optional<ClientItem> getClientItem(ResourceLocation location) { public Optional<ClientItem> getClientItem(ResourceLocation location) {
return Optional.empty(); return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(location);
} }
@Override @Override
public EquipmentClientInfo getEquipmentInfo(ResourceKey<EquipmentAsset> key) { public Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key) {
return null; return Optional.of(equipmentAssetManager.get(key));
} }
@Override @Override
public InputStream getTexture(ResourceLocation location) { public InputStream getTexture(ResourceLocation location) throws IOException {
return null; return resourceManager.open(location);
} }
@Override @Override
public HolderLookup.Provider registries() { public HolderLookup.Provider registries() {
return null; return registries;
} }
} }

View File

@@ -1,5 +1,6 @@
package org.geysermc.rainbow.client; package org.geysermc.rainbow.client;
import net.minecraft.client.Minecraft;
import org.geysermc.rainbow.pack.BedrockPack; import org.geysermc.rainbow.pack.BedrockPack;
import java.io.IOException; import java.io.IOException;
@@ -16,7 +17,7 @@ public final class PackManager {
throw new IllegalStateException("Already started a pack (" + currentPack.get().name() + ")"); throw new IllegalStateException("Already started a pack (" + currentPack.get().name() + ")");
} }
currentPack = Optional.of(new BedrockPack(name, new MinecraftAssetResolver())); currentPack = Optional.of(new BedrockPack(name, new MinecraftAssetResolver(Minecraft.getInstance())));
} }
public void run(Consumer<BedrockPack> consumer) { public void run(Consumer<BedrockPack> consumer) {

View File

@@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.equipment.EquipmentAsset; import net.minecraft.world.item.equipment.EquipmentAsset;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Optional; import java.util.Optional;
@@ -17,9 +18,9 @@ public interface AssetResolver {
Optional<ClientItem> getClientItem(ResourceLocation location); Optional<ClientItem> getClientItem(ResourceLocation location);
EquipmentClientInfo getEquipmentInfo(ResourceKey<EquipmentAsset> key); Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key);
InputStream getTexture(ResourceLocation location); InputStream getTexture(ResourceLocation location) throws IOException;
HolderLookup.Provider registries(); HolderLookup.Provider registries();
} }

View File

@@ -27,7 +27,7 @@ public class AttachableMapper {
.map(geometry -> BedrockAttachable.geometry(bedrockIdentifier, geometry.geometry().definitions().getFirst(), geometry.texture().getPath())) .map(geometry -> BedrockAttachable.geometry(bedrockIdentifier, geometry.geometry().definitions().getFirst(), geometry.texture().getPath()))
.or(() -> Optional.ofNullable(components.get(DataComponents.EQUIPPABLE)) .or(() -> Optional.ofNullable(components.get(DataComponents.EQUIPPABLE))
.flatMap(optional -> (Optional<Equippable>) optional) .flatMap(optional -> (Optional<Equippable>) optional)
.flatMap(equippable -> equippable.assetId().map(asset -> Pair.of(equippable.slot(), assetResolver.getEquipmentInfo(asset)))) .flatMap(equippable -> equippable.assetId().flatMap(assetResolver::getEquipmentInfo).map(info -> Pair.of(equippable.slot(), info)))
.filter(assetInfo -> assetInfo.getSecond() != EquipmentAssetManager.MISSING) .filter(assetInfo -> assetInfo.getSecond() != EquipmentAssetManager.MISSING)
.map(assetInfo -> assetInfo .map(assetInfo -> assetInfo
.mapSecond(info -> info.getLayers(getLayer(assetInfo.getFirst())))) .mapSecond(info -> info.getLayers(getLayer(assetInfo.getFirst()))))

View File

@@ -167,7 +167,7 @@ public class BedrockPack {
} }
for (ResourceLocation texture : texturesToExport) { for (ResourceLocation texture : texturesToExport) {
texture = texture.withPath(path -> "textures/" + path + ".png"); // FIXME texture = texture.withPath(path -> "textures/" + path + ".png");
try (InputStream inputTexture = context.assetResolver().getTexture(texture)) { try (InputStream inputTexture = context.assetResolver().getTexture(texture)) {
Path texturePath = packPath.resolve(texture.getPath()); Path texturePath = packPath.resolve(texture.getPath());
CodecUtil.ensureDirectoryExists(texturePath.getParent()); CodecUtil.ensureDirectoryExists(texturePath.getParent());