Jump to content

_Doc

Members
  • Posts

    3
  • Joined

  • Last visited

_Doc's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Thank you, Cadiboo! It returns the correct texture path. The other issue with the "andesite" giving me "stone" was due to me going from ItemStack to Item to Block. It seems it lost it's metadata when it became an item. Here is the working code that gives me the correct texture path for the given block. public boolean setSelected(ItemStack stack) { if (stacks.contains(stack)) { Block block = Block.getBlockFromItem(stack.getItem()); Item item = stack.getItem(); int damage = item.getDamage(stack); int meta = item.getMetadata(damage); IBlockState state = block.getStateFromMeta(meta); ResourceLocation reg = block.getRegistryName(); ResourceLocation location = new ResourceLocation(reg.toString()); Minecraft minecraft = Minecraft.getMinecraft(); BlockRendererDispatcher ren = minecraft.getBlockRendererDispatcher(); texture = ren.getModelForState(state).getQuads(state, EnumFacing.NORTH, 0).get(0).getSprite().toString(); caption = stack.getDisplayName(); this.selected = stack; raiseEvent(new GuiControlChangedEvent(this)); return true; } return false; }
  2. Right now it is crashing at getModelForState(state) it gives me a null pointer exception. Had thought it was due to the BlockRendererDispatcher(null, new BlockColors()) having the null value. But, not sure how to give it the desired object of BlockModelShapes. public boolean setSelected(ItemStack stack) { if (stacks.contains(stack)) { String display; Block block = Block.getBlockFromItem(stack.getItem()); //ResourceLocation reg = block.getRegistryName(); //ResourceLocation location = new ResourceLocation(reg.toString()); BlockRendererDispatcher ren = new BlockRendererDispatcher(null, new BlockColors()); IBlockState state = block.getBlockState().getBaseState(); display = ren.getModelForState(state).toString(); //.getQuads(null, null, 0).get(0).getSprite() //String asset = "assets/" + location.getResourceDomain() + "/" + "models/" + location.getResourcePath() + ".json"+"\n"; caption = display; this.selected = stack; raiseEvent(new GuiControlChangedEvent(this)); return true; } return false; }
  3. I am attempting to get the texture from any block. When I try to use .getRegistryName() on a block such as spruce log, andesite, green wool. I get back log, stone, and wool. Well, I want to be able to get spruce_log or green_wool so I can get the correct .json file to get the texture path from. I am doing it this way so if there is a block from another mod and they use a different path for their textures I can still acquire it from the model.json public boolean setSelected(ItemStack stack) { if (stacks.contains(stack)) { String display; Block block = Block.getBlockFromItem(stack.getItem()); ResourceLocation reg = block.getRegistryName(); ResourceLocation location = new ResourceLocation(reg.toString()); String asset = "assets/" + location.getResourceDomain() + "/" + "models/" + location.getResourcePath() + ".json"+"\n"; caption = asset; this.selected = stack; raiseEvent(new GuiControlChangedEvent(this)); return true; } return false; }
×
×
  • Create New...

Important Information

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