Search in sources :

Example 21 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModListScreen method updateCache.

private void updateCache() {
    if (selected == null) {
        this.configButton.active = false;
        this.modInfo.clearInfo();
        return;
    }
    IModInfo selectedMod = selected.getInfo();
    this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
    List<String> lines = new ArrayList<>();
    VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
    @SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
        TextureManager tm = this.minecraft.getTextureManager();
        final PathResourcePack resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
        try {
            NativeImage logo = null;
            InputStream logoResource = resourcePack.getRootResource(logoFile);
            if (logoResource != null)
                logo = NativeImage.read(logoResource);
            if (logo != null) {
                return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {

                    @Override
                    public void upload() {
                        this.bind();
                        NativeImage td = this.getPixels();
                        // Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
                        this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
                    }
                }), new Size2i(logo.getWidth(), logo.getHeight()));
            }
        } catch (IOException e) {
        }
        return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
    }).orElse(Pair.of(null, new Size2i(0, 0)));
    lines.add(selectedMod.getDisplayName());
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
    selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
    selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
    selectedMod.getConfig().getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
    if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
    else
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
    if (vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED)
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url() == null ? "" : vercheck.url()));
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
    lines.add(null);
    lines.add(selectedMod.getDescription());
    if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes().size() > 0) {
        lines.add(null);
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
        for (Entry<ComparableVersion, String> entry : vercheck.changes().entrySet()) {
            lines.add("  " + entry.getKey() + ":");
            lines.add(entry.getValue());
            lines.add(null);
        }
    }
    modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Font(net.minecraft.client.gui.Font) ObjectSelectionList(net.minecraft.client.gui.components.ObjectSelectionList) Pair(org.apache.commons.lang3.tuple.Pair) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) PathResourcePack(net.minecraftforge.resource.PathResourcePack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) Screen(net.minecraft.client.gui.screens.Screen) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) Language(net.minecraft.locale.Language) Style(net.minecraft.network.chat.Style) List(java.util.List) Util(net.minecraft.Util) Logger(org.apache.logging.log4j.Logger) EditBox(net.minecraft.client.gui.components.EditBox) Entry(java.util.Map.Entry) FormattedCharSequence(net.minecraft.util.FormattedCharSequence) ForgeI18n(net.minecraftforge.common.ForgeI18n) Size2i(net.minecraftforge.common.util.Size2i) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Minecraft(net.minecraft.client.Minecraft) MavenVersionStringHelper(net.minecraftforge.common.util.MavenVersionStringHelper) NativeImage(com.mojang.blaze3d.platform.NativeImage) Button(net.minecraft.client.gui.components.Button) StringUtils(net.minecraftforge.fml.loading.StringUtils) GameRenderer(net.minecraft.client.renderer.GameRenderer) ResourcePackLoader(net.minecraftforge.resource.ResourcePackLoader) Component(net.minecraft.network.chat.Component) NarrationElementOutput(net.minecraft.client.gui.narration.NarrationElementOutput) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) Tesselator(com.mojang.blaze3d.vertex.Tesselator) VersionChecker(net.minecraftforge.fml.VersionChecker) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ModListWidget(net.minecraftforge.client.gui.widget.ModListWidget) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) ConfigGuiHandler(net.minecraftforge.client.ConfigGuiHandler) InputStream(java.io.InputStream) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModContainer(net.minecraftforge.fml.ModContainer) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) IOException(java.io.IOException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) VersionChecker(net.minecraftforge.fml.VersionChecker) TextureManager(net.minecraft.client.renderer.texture.TextureManager) NativeImage(com.mojang.blaze3d.platform.NativeImage) ResourceLocation(net.minecraft.resources.ResourceLocation) Size2i(net.minecraftforge.common.util.Size2i) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Example 22 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class BlockStateProvider method saveBlockState.

private void saveBlockState(HashCache cache, JsonObject stateJson, Block owner) {
    ResourceLocation blockName = Preconditions.checkNotNull(owner.getRegistryName());
    Path mainOutput = generator.getOutputFolder();
    String pathSuffix = "assets/" + blockName.getNamespace() + "/blockstates/" + blockName.getPath() + ".json";
    Path outputPath = mainOutput.resolve(pathSuffix);
    try {
        DataProvider.save(GSON, cache, stateJson, outputPath);
    } catch (IOException e) {
        LOGGER.error("Couldn't save blockstate to {}", outputPath, e);
    }
}
Also used : Path(java.nio.file.Path) ResourceLocation(net.minecraft.resources.ResourceLocation) IOException(java.io.IOException)

Example 23 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelBuilder method texture.

/**
 * Set the texture for a given dictionary key.
 *
 * @param key     the texture key
 * @param texture the texture, can be another key e.g. {@code "#all"}
 * @return this builder
 * @throws NullPointerException  if {@code key} is {@code null}
 * @throws NullPointerException  if {@code texture} is {@code null}
 * @throws IllegalStateException if {@code texture} is not a key (does not start
 *                               with {@code '#'}) and does not exist in any
 *                               known resource pack
 */
public T texture(String key, String texture) {
    Preconditions.checkNotNull(key, "Key must not be null");
    Preconditions.checkNotNull(texture, "Texture must not be null");
    if (texture.charAt(0) == '#') {
        this.textures.put(key, texture);
        return self();
    } else {
        ResourceLocation asLoc;
        if (texture.contains(":")) {
            asLoc = new ResourceLocation(texture);
        } else {
            asLoc = new ResourceLocation(getLocation().getNamespace(), texture);
        }
        return texture(key, asLoc);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 24 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelLoaderRegistry method resolveTexture.

public static Material resolveTexture(@Nullable String tex, IModelConfiguration owner) {
    if (tex == null)
        return blockMaterial(WHITE_TEXTURE);
    if (tex.startsWith("#"))
        return owner.resolveTexture(tex);
    // Attempt to convert a common (windows/linux/mac) filesystem path to a ResourceLocation.
    // This makes no promises, if it doesn't work, too bad, fix your mtl file.
    Matcher match = FILESYSTEM_PATH_TO_RESLOC.matcher(tex);
    if (match.matches()) {
        String namespace = match.group("namespace");
        String path = match.group("path").replace("\\", "/");
        if (namespace != null)
            return blockMaterial(new ResourceLocation(namespace, path));
        return blockMaterial(path);
    }
    return blockMaterial(tex);
}
Also used : Matcher(java.util.regex.Matcher) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 25 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getBiomeAt.

@Override
public BiomeNMS getBiomeAt(Block block) {
    // Based on CraftWorld source
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    Biome biome = level.getNoiseBiome(block.getX() >> 2, block.getY() >> 2, block.getZ() >> 2);
    ResourceLocation key = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
    String keyText = key.getNamespace().equals("minecraft") ? key.getPath() : key.toString();
    return new BiomeNMSImpl(level, keyText);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)86 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 List (java.util.List)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 JsonObject (com.google.gson.JsonObject)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 IOException (java.io.IOException)5 Collectors (java.util.stream.Collectors)5 StringReader (com.mojang.brigadier.StringReader)4 CompoundTag (net.minecraft.nbt.CompoundTag)4 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)4 ItemStack (org.bukkit.inventory.ItemStack)4 InputStream (java.io.InputStream)3 Collections (java.util.Collections)3 Set (java.util.Set)3 Function (java.util.function.Function)3 Nullable (javax.annotation.Nullable)3