Created
July 14, 2020 20:08
-
-
Save jamierocks/aa3e52deb7e107ea6e4f96c1e58b75df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This file is part of Sponge, licensed under the MIT License (MIT). | |
* | |
* Copyright (c) SpongePowered <https://www.spongepowered.org> | |
* Copyright (c) contributors | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
package org.spongepowered.vanilla.mixin.core.resources; | |
import net.minecraft.resources.ResourcePackType; | |
import net.minecraft.resources.VanillaPack; | |
import net.minecraft.util.ResourceLocation; | |
import org.spongepowered.asm.mixin.Final; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.Overwrite; | |
import org.spongepowered.asm.mixin.Shadow; | |
import org.spongepowered.asm.mixin.injection.At; | |
import org.spongepowered.asm.mixin.injection.Redirect; | |
import javax.annotation.Nullable; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.nio.file.FileSystem; | |
import java.nio.file.Files; | |
import java.util.Map; | |
@Mixin(VanillaPack.class) | |
public abstract class MixinVanillaPack_Vanilla { | |
@Shadow @Final private static Map<ResourcePackType, FileSystem> field_217810_e; | |
@Shadow | |
private static String func_223458_d(final ResourcePackType p_223458_0_, final ResourceLocation p_223458_1_) { | |
throw new RuntimeException("Mixin shadow method"); | |
} | |
@Redirect(method = "getInputStreamVanilla(Lnet/minecraft/resources/ResourcePackType;Lnet/minecraft/util/ResourceLocation;)Ljava/io/InputStream;", at = @At( | |
value = "INVOKE", | |
target = "Ljava/net/URL;openStream()Ljava/io/InputStream;" | |
)) | |
public InputStream getInputStreamVanilla(final URL url, final ResourcePackType type, final ResourceLocation location) { | |
final String path = func_223458_d(type, location); | |
return this.vanilla$getExtraInputStream(type, path); | |
} | |
/** | |
* @author Jamie Mansfield | |
* @reason ForgeGradle splits the jar in two, one for the game's source code and another | |
* for the game's assets - this requires changes to the game to find assets in | |
* the extra jar. | |
*/ | |
@Nullable | |
@Overwrite | |
protected InputStream getInputStreamVanilla(final String path) { | |
return this.vanilla$getExtraInputStream(ResourcePackType.SERVER_DATA, "/" + path); | |
} | |
public InputStream vanilla$getExtraInputStream(final ResourcePackType type, final String path) { | |
final FileSystem fs = field_217810_e.get(type); | |
if (fs != null) { | |
try { | |
return Files.newInputStream(fs.getPath(path)); | |
} | |
catch (final IOException ignored) { | |
} | |
} | |
return VanillaPack.class.getResourceAsStream(path); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment