mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Implement MinecraftAssetResolver
This commit is contained in:
@@ -1,41 +1,60 @@
|
||||
package org.geysermc.rainbow.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.ModelManager;
|
||||
import net.minecraft.client.resources.model.ResolvedModel;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
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
|
||||
public Optional<ResolvedModel> getResolvedModel(ResourceLocation location) {
|
||||
return Optional.empty();
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClientItem> getClientItem(ResourceLocation location) {
|
||||
return Optional.empty();
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EquipmentClientInfo getEquipmentInfo(ResourceKey<EquipmentAsset> key) {
|
||||
return null;
|
||||
public Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key) {
|
||||
return Optional.of(equipmentAssetManager.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getTexture(ResourceLocation location) {
|
||||
return null;
|
||||
public InputStream getTexture(ResourceLocation location) throws IOException {
|
||||
return resourceManager.open(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HolderLookup.Provider registries() {
|
||||
return null;
|
||||
return registries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.geysermc.rainbow.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.geysermc.rainbow.pack.BedrockPack;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -16,7 +17,7 @@ public final class PackManager {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user