Posted February 22, 201510 yr 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!
February 22, 201510 yr 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?
February 22, 201510 yr 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 ^ ?
February 22, 201510 yr 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_)
February 22, 201510 yr 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 } ] } }
February 22, 201510 yr 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.
February 22, 201510 yr 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; } }
February 22, 201510 yr 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();
February 22, 201510 yr 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.