mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Some fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.geysermc.rainbow.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.item.ClientItem;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
@@ -8,26 +9,31 @@ 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.data.AtlasIds;
|
||||
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.Rainbow;
|
||||
import org.geysermc.rainbow.RainbowIO;
|
||||
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.texture.TextureResource;
|
||||
import org.geysermc.rainbow.mixin.SpriteContentsAccessor;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MinecraftAssetResolver implements AssetResolver {
|
||||
private final ModelManager modelManager;
|
||||
private final EquipmentAssetManager equipmentAssetManager;
|
||||
private final ResourceManager resourceManager;
|
||||
private final AtlasManager atlasManager;
|
||||
|
||||
public MinecraftAssetResolver(Minecraft minecraft) {
|
||||
modelManager = minecraft.getModelManager();
|
||||
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
|
||||
resourceManager = minecraft.getResourceManager();
|
||||
atlasManager = minecraft.getAtlasManager();
|
||||
}
|
||||
|
||||
@@ -47,8 +53,19 @@ public class MinecraftAssetResolver implements AssetResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TextureResource> getBlockTexture(ResourceLocation location) {
|
||||
SpriteContents contents = atlasManager.getAtlasOrThrow(AtlasIds.BLOCKS).getSprite(location).contents();
|
||||
return Optional.of(new TextureResource(((SpriteContentsAccessor) contents).getOriginalImage(), contents.width(), contents.height()));
|
||||
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
|
||||
if (atlas == null) {
|
||||
// Not in an atlas - so not animated, probably?
|
||||
return RainbowIO.safeIO(() -> {
|
||||
try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) {
|
||||
return new TextureResource(NativeImage.read(textureStream));
|
||||
}
|
||||
});
|
||||
}
|
||||
SpriteContents contents = atlasManager.getAtlasOrThrow(atlas).getSprite(location).contents();
|
||||
NativeImage original = ((SpriteContentsAccessor) contents).getOriginalImage();
|
||||
NativeImage textureCopy = new NativeImage(original.getWidth(), original.getHeight(), false);
|
||||
textureCopy.copyFrom(original);
|
||||
return Optional.of(new TextureResource(textureCopy, contents.width(), contents.height()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MinecraftPackSerializer implements PackSerializer {
|
||||
@Override
|
||||
public <T> CompletableFuture<?> saveJson(Codec<T> codec, T object, Path path) {
|
||||
DynamicOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, registries);
|
||||
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path.resolveSibling(path.getFileName() + ".json"), ops)),
|
||||
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path, ops)),
|
||||
Util.backgroundExecutor().forName("PackSerializer-saveJson"));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class PackManager {
|
||||
|
||||
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve(Rainbow.MOD_ID);
|
||||
private static final Path PACK_DIRECTORY = Path.of("pack");
|
||||
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings");
|
||||
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings.json");
|
||||
private static final Path PACK_ZIP_FILE = Path.of("pack.zip");
|
||||
private static final Path REPORT_FILE = Path.of("report.txt");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user