Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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?

ResourcePacks exist... Why re-invent the wheel.

 

So that you can create objects based on the number of files put in the folder, not create images based on the number of objects.

 

Do what?

register it as a default resource pack.

How would you would you do that ^ ?

Okay, I was able to create most of it, I just don't know what to put for this method.

getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_)

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
    }
    ]
  }
}

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.

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;
}

}

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();

I am trying to make it so that the sound files (and other resources) are on the server  so that the client can't reach them

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.