Codasylph Posted October 13, 2016 Posted October 13, 2016 I'm going to preface this by saying that, no, I have never used TextureAtlasSprites. I'm trying to make a custom particle and through my reading of the vanilla Particle code and looking at other people's projects, I've gotten as far as, that I need a TextureAtlasSprite, and that I ought to register it to the TextureMap in TextureStitchEvent.Pre (or at least that's what all the code I've seen is doing.) However, when I do all this and try to retrieve my sprite from the TextureMap I get the missing texture texture, and if I try to use it more directly I get null. My event handler registering the sprite public class DemTextureHandler { public static final DemTextureHandler textures = new DemTextureHandler(); private DemTextureHandler(){} public static TextureAtlasSprite su; @SubscribeEvent public void onTextureStitch(TextureStitchEvent.Pre event) { ResourceLocation resource = new ResourceLocation("demesne:textures/particles/su.png"); TextureAtlasSprite su = event.getMap().registerSprite(resource); System.out.println("Debug: "+su.toString()); System.out.println("Debug: "+event.getMap().getAtlasSprite(resource.toString())); } } Note: my debug statements here give me the following in the log: [08:26:29] [Client thread/INFO] [sTDOUT]: [me.codasylph.demesne.handlers.DemTextureHandler:onTextureStitch:25]: Debug: TextureAtlasSprite{name='demesne:textures/particles/su.png', frameCount=0, rotated=false, x=0, y=0, height=0, width=0, u0=0.0, u1=0.0, v0=0.0, v1=0.0} [08:26:29] [Client thread/INFO] [sTDOUT]: [me.codasylph.demesne.handlers.DemTextureHandler:onTextureStitch:26]: Debug: TextureAtlasSprite{name='missingno', frameCount=1, rotated=false, x=0, y=0, height=16, width=16, u0=0.0, u1=0.0, v0=0.0, v1=0.0} my particle's constructor public SuParticle(World world, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed) { super(world, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed); // this.setParticleTexture(DemTextureHandler.textures.su); this.setParticleTexture(Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("demesne:textures/particles/su.png")); System.out.println("Debug: "+this.particleTexture.toString()); } As you can see from commented out code I have also tried using the sprite that gets returned by TextureMap#registerSprite but this ends up being null and when my debug statement is called I crash with a null pointer exception, which kind of makes sense since it clearly isn't registering properly given that it can't find the texture in the map even immediately after I register it.. So clearly I'm doing something very wrong. I have checked the spelling of my path what feels like a 100 times and I for certain have a folder in my textures folder named particles that has a su.png in it. If anyone knows what is happening here and how to fix it, or some better way to do this, please help. edit: Added version tag to subject line. Someday I will remember to do this the first time. Quote
TheGreyGhost Posted October 14, 2016 Posted October 14, 2016 Hi I think you should remove the .png from your filename. Have you seen this tutorial project yet? https://github.com/TheGreyGhost/MinecraftByExample mbe50 has a simple working example of what you need. Also, I have a recollection that getAtlasSprite won't retrieve the texture until after the textures are stitched, so your getAtlasSprite immediately after registerSprite is too soon (i.e. it's not testing what you think it's testing). -TGG Quote
Codasylph Posted October 14, 2016 Author Posted October 14, 2016 I think you should remove the .png from your filename. That actually fixed, I had to also remove the "textures/" from the beginning as well. I could have sworn I had tried that, but I may not have tried both changes together. Any idea why for the texture atlas you need the short form (e.g. "demesne:particles/su" but when you bind a texture to the texture manager for a gui it has to be the longer version with the file extension? Either way, thank you very much! Quote
Draco18s Posted October 14, 2016 Posted October 14, 2016 The ResourceLocation class adds the /texture and .png for you. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Choonster Posted October 14, 2016 Posted October 14, 2016 The ResourceLocation class adds the /texture and .png for you. It's actually TextureMap#getResourceLocation that adds the prefix and extension to your ResourceLocation before loading the texture. ResourceLocation is used for many things that aren't textures, so it wouldn't make much sense if it added the prefix and file extension automatically. 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Recommended Posts
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.