Jump to content

Recommended Posts

Posted

Hi all,

 

  The end objective here is to play a video in minecraft.  Where i'm stuck currently, is finding resources (ie a picture or video) in my assets directory.  Here is a test I've borrowed from another question to return a filepath to me, but it doesn't work.  The function to test (or eventually play video) will be called from my GUI on a button press which I have also posted.

 

Test for video's existence:

 

package com.mycompany.mymod;

 

import java.io.IOException;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.resources.IResource;

import net.minecraft.util.ResourceLocation;

import com.mycompany.mymod.Main;

 

public class FileAndResourceLocations {

 

public static void testFile(String location) {

 

String modid = Main.MODID;

 

try {

IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(modid + ":" + location));

StringBuilder builder = new StringBuilder();

int ch;

while((ch = iresource.getInputStream().read()) != -1){

builder.append((char)ch);

}

System.out.println(builder.toString());

} catch (IOException e) {

e.printStackTrace();

System.out.println("didn't work");

}

}

}

 

GUI:

 

package com.mycompany.mymod_content.client.gui;

 

import java.io.File;

import java.io.IOException;

 

import org.lwjgl.opengl.GL11;

 

import com.mycompany.mymod.FileAndResourceLocations;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.GuiButton;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.renderer.Tessellator;

import net.minecraft.client.resources.IResource;

import net.minecraft.util.ResourceLocation;

 

import java.awt.image.BufferedImage;

 

public class GuiTreasureMap extends GuiScreen{

 

private GuiButton a;

private BufferedImage img;

private int imgID = 5006;

 

 

@Override

public void drawScreen(int mouseX, int mouseY, float partialTicks) {

 

 

this.drawDefaultBackground();

 

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

    this.mc.getTextureManager().bindTexture(new ResourceLocation("mymod:textures/gui/treasure_map2.png"));

    int x = (width-(256))/2;

    int y = (height-(256))/2;

    drawTexturedModalRect(x, y, 0, 0, 256, 256);

   

    this.fontRendererObj.drawString(treasure_map_txt, this.width / 2 - 25, this.height / 2 - 75, 0000);

    this.fontRendererObj.drawString(treasure_map_txt2, this.width / 2 - 100, this.height / 2 - 45, 0000);

    this.fontRendererObj.drawString(treasure_map_txt3, this.width / 2 - 40, this.height / 2 - 35, 0000);

    this.fontRendererObj.drawString(treasure_map_txt4, this.width / 2 - 103, this.height / 2 - 25, 0000);

    this.fontRendererObj.drawString(treasure_map_txt5, this.width / 2 - 65, this.height / 2 - 15, 0000);

//  this.fontRendererObj.drawString(treasure_map_txt6, this.width / 2 - 100, this.height / 2 - 0, 0000);

   

super.drawScreen(mouseX, mouseY, partialTicks);

}

 

 

@Override

public boolean doesGuiPauseGame() {

return true;

 

}

 

@Override

public void initGui() {

 

this.buttonList.add(this.a = new GuiButton(0, this.width / 2 - 100, this.height / 2 + 90, "Back To Game"));

   

}

 

@Override

protected void actionPerformed(GuiButton button) throws IOException {

    if (button == this.a) {

       

    //Main.packetHandler.sendToServer(...);

    //java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://wwwgoogle.com"));

    //java.awt.Desktop.getDesktop().open(new ResourceLocation("mymod:textures/gui/treasure_map2.png"));

    FileAndResourceLocations.testFile("textures/gui/GuiTreasureMap");

   

       

   

    this.mc.displayGuiScreen(null);

        if (this.mc.currentScreen == null)

            this.mc.setIngameFocus();

    }

}

 

 

private String treasure_map_txt =

"";

private String treasure_map_txt2 =

"";

private String treasure_map_txt3 =

"";

private String treasure_map_txt4 =

"";

private String treasure_map_txt5 =

"";

//private String treasure_map_txt6 =

 

}

 

When I run this I get a FileNotFoundException:

 

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.io.FileNotFoundException: minecraft:gui/GuiTreasureMap

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.resources.FallbackResourceManager.getResource(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at com.mycompany.mymod.FileAndResourceLocations.testFile(FileAndResourceLocations.java:17)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at com.mycompany.mymod.client.gui.GuiTreasureMap.actionPerformed(GuiTreasureMap.java:69)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.gui.GuiScreen.mouseClicked(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.gui.GuiScreen.handleMouseInput(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.gui.GuiScreen.handleInput(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.Minecraft.runTick(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.Minecraft.runGameLoop(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.Minecraft.run(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.client.main.Main.main(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at java.lang.reflect.Method.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at java.lang.reflect.Method.invoke(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at GradleStart.main(Unknown Source)

[14:07:27] [Client thread/INFO] [sTDOUT]: [com.mycompany.mymod.FileAndResourceLocations:testFile:26]: didn't work

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.