Jump to content

[1.7.10]Turn a file into a resourcelocation


starwarsmace

Recommended Posts

I am making a mod for a server and I do MinecraftServer.getServer.getFile("models/sword.obj"). Is it possible to turn that into a resource location, so I can use it for my renderer.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

If you must have it outside your mod file (why?) implement IResourcePack and register it as a default resource pack.

 

I can think of two reasons why. One to put all the files on the sever to save space on the client and two, to make it easier to add textures to the game.

 

How would you do that?

Link to comment
Share on other sites

Okay, I made the pack and added it but whenever i try to play a sound with ResourceLocation = new ResourcLocations("regions:Death"); is says unable to play unknown soundEvent: regions:Death

 

IResourcePack source:

package com.necrolore.regionmod.resourcepack;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.ImmutableSet;

import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.data.IMetadataSection;
import net.minecraft.client.resources.data.IMetadataSerializer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;

public class RegionPack implements IResourcePack{

public static String serverFolder;

@Override
public InputStream getInputStream(ResourceLocation region)
		throws IOException {
	if(serverFolder==null)
		return null;
	return new FileInputStream(new File(serverFolder+"/assets/regions/sounds/"+region.getResourcePath()+".ogg"));
}

@Override
public boolean resourceExists(ResourceLocation region) {
	return serverFolder!=null && new File(serverFolder+region.getResourcePath()).exists();
}

@Override
public Set getResourceDomains() {
	return ImmutableSet.of("regions");
}

@Override
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_,
		String p_135058_2_) throws IOException {
	return null;
}

@Override
public BufferedImage getPackImage() throws IOException {
	return null;
}

@Override
public String getPackName() {
	return "Regions";
}

}

 

sounds.json

{
  "regions:Death": {
    "category": "region",
    "sounds": [
    {
        "name": "Death",
        "stream": true
    }
    ]
  }
}

Link to comment
Share on other sites

Why don't use the existing implementation like FolderResourcePack?

Thanks for the advice! I used that instead of RegionPack and just passed it serverFolder, but i'm still getting this message:

[15:37:43] [Client thread/WARN]: Unable to play unknown soundEvent: regions:Death

 

Where do you set "serverFolder"?

 

Whenever the player joined the sever.

Link to comment
Share on other sites

This is where I try to play the sound:

MovingSoundRecord sound = new MovingSoundRecord(new ResourceLocation("regions:"+message.getMessage()), 1f, 1, true, 0);
Minecraft.getMinecraft().getSoundHandler().playSound(sound);

 

This is MovingSoundRecord

@SideOnly(Side.CLIENT)
public class MovingSoundRecord  extends PositionedSound{

public MovingSoundRecord(ResourceLocation location, float volume, float pitch, boolean repeat, int reapeatDelay)
    {
        super(location);
        this.volume = volume;
        this.field_147663_c = pitch;
        this.xPosF = 0;
        this.yPosF = 0;
        this.zPosF = 0;
        this.repeat = repeat;
        this.field_147665_h = reapeatDelay;
        this.field_147666_i = ISound.AttenuationType.NONE;
    }

public void setVolume(float volume){
	this.volume = volume;
}

}

Link to comment
Share on other sites

Here is the code for calling the Resource pack (where i used to set the severFolder field) message.getMessage() returns the sever folder:

 

Field field=null;
		try {
			field = Minecraft.class.getDeclaredField("defaultResourcePacks");
			field.setAccessible(true);
			((List<IResourcePack>) field.get(Minecraft.getMinecraft())).add(new FolderResourcePack(new File(message.getMessage())));
			field.setAccessible(false);
		} catch (Exception e) {
			/* Should not happen */
				e.printStackTrace();
		} finally {

			if(field!=null)field.setAccessible(false);

		}
		Minecraft.getMinecraft().refreshResources();

Link to comment
Share on other sites

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.