Jump to content

Recommended Posts

Posted

Hi, I'm developing a mod for minecraft 1.7.10 and I'm trying to get the texture of some blocks and adding to them an overlay to make something like this R1kCi7J.png that is the texture of the oak planks plus the black cage with the red dots, is there a way to do this without making every single texture? Thanks in advance

Set the power inside a single block free! ;D

Posted

Oh man are you in for a fun time tonight.

 

Short answer: yes, two ways.

1) render the block twice

2) custom TextureAtlasSprite loading

 

1 is easier and found via Google ("two pass blocks"), 2 is muuuch more complicated and will need to wait for me to be at my desktop again. There's a copy on the forum here somewhere, check my user profile for threads started on the last couple of months.

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.

Posted

Here we go.

 

There are a few important parts, and a few unimportant ones.

Important:

-

hasCustomLoader()

-

load()

 

Unimportant:

-

colorize()

which handles color multiplication (I used it to colorize the overlay image but not the base).

- anything dealing with

invert

(this was special case handling I wanted so that my grayscale overlays could be inverted white-to-black so that they could be used equally well on a dark base (such as basalt) or a light base (such as marble).

 

scaleToSmaller() should be rewritten to be "scaleToLarger()" but it was easy to write and lets the overlay handle resource packs changing resolution size of only one texture without breaking horribly.  It may not generate a good result, but it will generate a valid result.

 

 

  Reveal hidden contents

 

public class TextureAtlasDynamic extends TextureAtlasSprite {
protected String textureBase;
protected String textureOverlay;
protected Color colorMulti;
protected boolean invert;

public TextureAtlasDynamic(String p_i1282_1_, String base, String overlay, Color color, boolean inv) {
	super(p_i1282_1_);
	textureBase = base;
	textureOverlay = overlay;
	colorMulti = color;
	invert = inv;
}

@Override
public void updateAnimation() {
	TextureUtil.uploadTextureMipmap((int[][])this.framesTextureData.get(0), this.width, this.height, this.originX, this.originY, false, false);
}

@Override
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
        return true;
    }

@Override
    public boolean load(IResourceManager manager, ResourceLocation location) {
	framesTextureData.clear();
        this.frameCounter = 0;
        this.tickCounter = 0;
        
    	ResourceLocation resource1 = new ResourceLocation(textureBase);
    	ResourceLocation resource2 = new ResourceLocation(textureOverlay);
        try {
        	TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
        	resource1 = this.completeResourceLocation(map, resource1, 0);
        	resource2 = this.completeResourceLocation(map, resource2, 0);
		BufferedImage buff = ImageIO.read(manager.getResource(resource1).getInputStream());
		BufferedImage buff2 = ImageIO.read(manager.getResource(resource2).getInputStream());

        int[] rawBase = new int[buff.getWidth()*buff.getHeight()];
        int[] rawOverlay = new int[buff2.getWidth()*buff2.getHeight()];

        buff.getRGB(0, 0, buff.getWidth(), buff.getHeight(), rawBase, 0, buff.getWidth());
        buff2.getRGB(0, 0, buff2.getWidth(), buff2.getHeight(), rawOverlay, 0, buff2.getWidth());
        
        int min = Math.min(buff.getWidth(),buff2.getWidth());
        rawBase = scaleToSmaller(rawBase, buff.getWidth(), min);
        rawOverlay = scaleToSmaller(rawOverlay, buff2.getWidth(), min);

        width = min;
        height = min;
        
        int r1,g1,b1;
        int r2,g2,b2;
        float a1,a2,a3;
        for(int p=0; p<rawBase.length;p++) {
        	Color c1 = new Color(rawBase[p],true);
        	Color c2 = new Color(rawOverlay[p],true);
        	
        	c2 = colorize(colorMulti,c2,invert);
        	
        	a1 = c1.getAlpha()/255f;
        	r1 = c1.getRed();
        	g1 = c1.getGreen();
        	b1 = c1.getBlue();
        	a2 = c2.getAlpha()/255f;
        	r2 = c2.getRed();
        	g2 = c2.getGreen();
        	b2 = c2.getBlue();
        	a3 = a2+a1*(1-a2);
        	
        	if(a3 > 0) {
	        	r1 = Math.round(((r2*a2)+(r1*a1*(1-a2)))/a3);
	        	g1 = Math.round(((g2*a2)+(g1*a1*(1-a2)))/a3);
	        	b1 = Math.round(((b2*a2)+(b1*a1*(1-a2)))/a3);
        	}
        	else {
        		r1 = g1 = b1 = 0;
        	}
        	Color c3 = new Color(r1,g1,b1,Math.round(a3*255));
        	rawBase[p] = c3.getRGB();
        }
        
        int[][] aint = new int[1 + MathHelper.calculateLogBaseTwo(min)][];
        for (int k = 0; k < aint.length; ++k)
        {
        	aint[k] = rawBase;
        }

        this.framesTextureData.add(aint);
	} catch (IOException e) {
		e.printStackTrace();
		int[][] aint = new int[1][];
        for (int k = 0; k < 1; ++k)
        {
        	aint[k] = new int[16*16];
        	for(int l=0; l<aint[k].length;l++) {
        		aint[k][l] = 0xFFFFFFFF;
        	}
        }
        width = 16;
        height = 16;

        this.framesTextureData.add(aint);
	}
        return false;
    }

private static int[] scaleToSmaller(int[] data, int width, int min) {
	if(width == min) { return data; }
	int scale = width / min;
	int[] output = new int[min*min];
	int j = 0;
	for(int i = 0; i < output.length; i++) {
		if(i%min == 0) {
			j += width;
		}
		output[i] = data[i*scale+j];
	}
	return output;
}

private static ResourceLocation completeResourceLocation(TextureMap map, ResourceLocation loc, int c)
    {
        try {
		return (ResourceLocation)HardLib.proxy.resourceLocation.invoke(map, loc, c); //see below
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		e.printStackTrace();
	}
        return null;
    }

    private static Color colorize(Color cm, Color c2, boolean invert) {
    	float[] pix = new float[3];
    	float[] mul = new float[3];
    	Color.RGBtoHSB(c2.getRed(), c2.getGreen(), c2.getBlue(),pix);
    	Color.RGBtoHSB(cm.getRed(), cm.getGreen(), cm.getBlue(), mul);
    	float v = (invert?1-pix[2]:pix[2]);
    	Color c3 = new Color(Color.HSBtoRGB(mul[0], mul[1], v));
    	return new Color(c3.getRed(),c3.getGreen(),c3.getBlue(),c2.getAlpha());
    }
}

The only bit that is external is the reflection which I did in my common proxy.  It could have been static.

public class ClientProxy extends CommonProxy {
//public Method resourceLocation; in CommonProxy
public void init() {
	Class clz = TextureMap.class;
        Method[] meths = clz.getDeclaredMethods();
        for(Method m : meths) {
        	if(m.getReturnType() == ResourceLocation.class) {
        		m.setAccessible(true);
        		resourceLocation = m;
        	}
        }
}

 

And finally, registering the TextureAtlasSprite without needing events:

(I had an array of 12 used for the same block)

 

	@Override
    @SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.icons = new IIcon[12];
	if(iconRegister instanceof TextureMap) { //instanceof check, TextureMap should be the only thing that implements IIconRegister
		TextureMap map = (TextureMap)iconRegister;
		for(int o = 0; o < 12; o++) {
			String overlayName = "hazards:stone_overlay_"+o;
			String baseName = this.getTextureName(); //passed via block constructor from the block its "cloning"
			String regname = "hazards:"+this.getUnlocalizedName()+"_"+o; //the overlay texture
			map.setTextureEntry(regname, new TextureAtlasDynamic(regname,baseName,overlayName,new Color(color),inv));
			icons[o] = map.getTextureExtry(regname);
		}
	}
}

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.

Posted
  On 12/29/2015 at 1:12 AM, Draco18s said:

Here we go.

 

There are a few important parts, and a few unimportant ones.

Important:

-

hasCustomLoader()

-

load()

 

Unimportant:

-

colorize()

which handles color multiplication (I used it to colorize the overlay image but not the base).

- anything dealing with

invert

(this was special case handling I wanted so that my grayscale overlays could be inverted white-to-black so that they could be used equally well on a dark base (such as basalt) or a light base (such as marble).

 

scaleToSmaller() should be rewritten to be "scaleToLarger()" but it was easy to write and lets the overlay handle resource packs changing resolution size of only one texture without breaking horribly.  It may not generate a good result, but it will generate a valid result.

 

 

  Reveal hidden contents

 

public class TextureAtlasDynamic extends TextureAtlasSprite {
protected String textureBase;
protected String textureOverlay;
protected Color colorMulti;
protected boolean invert;

public TextureAtlasDynamic(String p_i1282_1_, String base, String overlay, Color color, boolean inv) {
	super(p_i1282_1_);
	textureBase = base;
	textureOverlay = overlay;
	colorMulti = color;
	invert = inv;
}

@Override
public void updateAnimation() {
	TextureUtil.uploadTextureMipmap((int[][])this.framesTextureData.get(0), this.width, this.height, this.originX, this.originY, false, false);
}

@Override
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
        return true;
    }

@Override
    public boolean load(IResourceManager manager, ResourceLocation location) {
	framesTextureData.clear();
        this.frameCounter = 0;
        this.tickCounter = 0;
        
    	ResourceLocation resource1 = new ResourceLocation(textureBase);
    	ResourceLocation resource2 = new ResourceLocation(textureOverlay);
        try {
        	TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
        	resource1 = this.completeResourceLocation(map, resource1, 0);
        	resource2 = this.completeResourceLocation(map, resource2, 0);
		BufferedImage buff = ImageIO.read(manager.getResource(resource1).getInputStream());
		BufferedImage buff2 = ImageIO.read(manager.getResource(resource2).getInputStream());

        int[] rawBase = new int[buff.getWidth()*buff.getHeight()];
        int[] rawOverlay = new int[buff2.getWidth()*buff2.getHeight()];

        buff.getRGB(0, 0, buff.getWidth(), buff.getHeight(), rawBase, 0, buff.getWidth());
        buff2.getRGB(0, 0, buff2.getWidth(), buff2.getHeight(), rawOverlay, 0, buff2.getWidth());
        
        int min = Math.min(buff.getWidth(),buff2.getWidth());
        rawBase = scaleToSmaller(rawBase, buff.getWidth(), min);
        rawOverlay = scaleToSmaller(rawOverlay, buff2.getWidth(), min);

        width = min;
        height = min;
        
        int r1,g1,b1;
        int r2,g2,b2;
        float a1,a2,a3;
        for(int p=0; p<rawBase.length;p++) {
        	Color c1 = new Color(rawBase[p],true);
        	Color c2 = new Color(rawOverlay[p],true);
        	
        	c2 = colorize(colorMulti,c2,invert);
        	
        	a1 = c1.getAlpha()/255f;
        	r1 = c1.getRed();
        	g1 = c1.getGreen();
        	b1 = c1.getBlue();
        	a2 = c2.getAlpha()/255f;
        	r2 = c2.getRed();
        	g2 = c2.getGreen();
        	b2 = c2.getBlue();
        	a3 = a2+a1*(1-a2);
        	
        	if(a3 > 0) {
	        	r1 = Math.round(((r2*a2)+(r1*a1*(1-a2)))/a3);
	        	g1 = Math.round(((g2*a2)+(g1*a1*(1-a2)))/a3);
	        	b1 = Math.round(((b2*a2)+(b1*a1*(1-a2)))/a3);
        	}
        	else {
        		r1 = g1 = b1 = 0;
        	}
        	Color c3 = new Color(r1,g1,b1,Math.round(a3*255));
        	rawBase[p] = c3.getRGB();
        }
        
        int[][] aint = new int[1 + MathHelper.calculateLogBaseTwo(min)][];
        for (int k = 0; k < aint.length; ++k)
        {
        	aint[k] = rawBase;
        }

        this.framesTextureData.add(aint);
	} catch (IOException e) {
		e.printStackTrace();
		int[][] aint = new int[1][];
        for (int k = 0; k < 1; ++k)
        {
        	aint[k] = new int[16*16];
        	for(int l=0; l<aint[k].length;l++) {
        		aint[k][l] = 0xFFFFFFFF;
        	}
        }
        width = 16;
        height = 16;

        this.framesTextureData.add(aint);
	}
        return false;
    }

private static int[] scaleToSmaller(int[] data, int width, int min) {
	if(width == min) { return data; }
	int scale = width / min;
	int[] output = new int[min*min];
	int j = 0;
	for(int i = 0; i < output.length; i++) {
		if(i%min == 0) {
			j += width;
		}
		output[i] = data[i*scale+j];
	}
	return output;
}

private static ResourceLocation completeResourceLocation(TextureMap map, ResourceLocation loc, int c)
    {
        try {
		return (ResourceLocation)HardLib.proxy.resourceLocation.invoke(map, loc, c); //see below
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		e.printStackTrace();
	}
        return null;
    }

    private static Color colorize(Color cm, Color c2, boolean invert) {
    	float[] pix = new float[3];
    	float[] mul = new float[3];
    	Color.RGBtoHSB(c2.getRed(), c2.getGreen(), c2.getBlue(),pix);
    	Color.RGBtoHSB(cm.getRed(), cm.getGreen(), cm.getBlue(), mul);
    	float v = (invert?1-pix[2]:pix[2]);
    	Color c3 = new Color(Color.HSBtoRGB(mul[0], mul[1], v));
    	return new Color(c3.getRed(),c3.getGreen(),c3.getBlue(),c2.getAlpha());
    }
}

The only bit that is external is the reflection which I did in my common proxy.  It could have been static.

public class ClientProxy extends CommonProxy {
//public Method resourceLocation; in CommonProxy
public void init() {
	Class clz = TextureMap.class;
        Method[] meths = clz.getDeclaredMethods();
        for(Method m : meths) {
        	if(m.getReturnType() == ResourceLocation.class) {
        		m.setAccessible(true);
        		resourceLocation = m;
        	}
        }
}

 

And finally, registering the TextureAtlasSprite without needing events:

(I had an array of 12 used for the same block)

 

	@Override
    @SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.icons = new IIcon[12];
	if(iconRegister instanceof TextureMap) { //instanceof check, TextureMap should be the only thing that implements IIconRegister
		TextureMap map = (TextureMap)iconRegister;
		for(int o = 0; o < 12; o++) {
			String overlayName = "hazards:stone_overlay_"+o;
			String baseName = this.getTextureName(); //passed via block constructor from the block its "cloning"
			String regname = "hazards:"+this.getUnlocalizedName()+"_"+o; //the overlay texture
			map.setTextureEntry(regname, new TextureAtlasDynamic(regname,baseName,overlayName,new Color(color),inv));
			icons[o] = map.getTextureExtry(regname);
		}
	}
}

First of all, THANK YOU.

 

Second: I've tried your code but I've a problem at this point:

private static ResourceLocation completeResourceLocation(TextureMap map, ResourceLocation loc, int c) {
	try {
		return (ResourceLocation) HardLib.proxy.resourceLocation.invoke(map, loc, c);
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		e.printStackTrace();
	}
	return null;
}

It need HardLib proxy that's from your library/api (I found it on github  ;D) so I've changed it to refer to my ClientProxy Class but it sais that i've not decleared resourceLocation as a variable. My ClientProxy Class is:

package com.lsmod.compactstorage;

import java.lang.reflect.Method;

import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.ResourceLocation;

public class ClientProxy {

public void preInit(FMLPreInitializationEvent e) {

}

public void init() {
	Class clz = TextureMap.class;
	Method[] meths = clz.getDeclaredMethods();
	for (Method m : meths) {
		if (m.getReturnType() == ResourceLocation.class) {
			m.setAccessible(true);
			resourceLocation = m;
		}
	}
}

public void postInit(FMLPostInitializationEvent e) {

}

}

Oh, if it could help I followed this guide to learn basics for modding and my classes looks very similar to the author's ones https://play.google.com/store/books/details?id=KE2EBAAAQBAJ&source=ge-web-app

Set the power inside a single block free! ;D

Posted
  On 12/29/2015 at 2:09 PM, LoreSchaeffer said:
Second: I've tried your code but I've a problem at this point:

 

It need HardLib proxy that's from your library/api (I found it on github  ;D) so I've changed it to refer to my ClientProxy Class but it sais that i've not decleared resourceLocation as a variable. My ClientProxy Class is:

 

That was the second choice block I'd including putting the field in the common proxy.

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.

Posted
  On 12/29/2015 at 3:18 PM, Draco18s said:

  Quote
That was the second choice block I'd including putting the field in the common proxy.

Ok, now the game loads correctly but in the console I've the missing texture error with another error that i haven't never seen

[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: The following texture errors were found.
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: ==================================================
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:   DOMAIN minecraft
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: --------------------------------------------------
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:   domain minecraft is missing 1 texture
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:     domain minecraft has 3 locations:
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:       unknown resourcepack type net.minecraft.client.resources.DefaultResourcePack : Default
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:       mod FML resources at C:\Users\lmlor\.gradle\caches\minecraft\net\minecraftforge\forge\1.7.10-10.13.4.1558-1.7.10\forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:       mod Forge resources at C:\Users\lmlor\.gradle\caches\minecraft\net\minecraftforge\forge\1.7.10-10.13.4.1558-1.7.10\forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: -------------------------
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:     The missing resources for domain minecraft are:
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:       textures/blocks/MISSING_ICON_BLOCK_165_testBlock.png
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: -------------------------
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]:     No other errors exist for domain minecraft
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: ==================================================
[21:35:20] [Client thread/ERROR] [TEXTURE ERRORS]: +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

Set the power inside a single block free! ;D

Posted

Show your icon registration method in your block class.

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.

Posted
  On 12/29/2015 at 9:15 PM, Draco18s said:

Show your icon registration method in your block class.

This is ma test Block class, I don't know if it's correct, probabily no  :-[ Which are the resources folder for the textures? minecraft default for base and  src\main\resources\assets\modid\textures\blocks for overlay?

package com.lsmod.CompactStorage.Blocks;

import com.lsmod.CompactStorage.CompactStorage;
import com.lsmod.CompactStorage.client.TextureAtlasDynamic;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.creativetab.CreativeTabs;

public class testBlock extends Block {

public testBlock(String name) {
	super(Material.wood);
	setBlockName(name);
	setCreativeTab(CreativeTabs.tabBlock);
	setHardness(3F);
	setResistance(15F);
	setStepSound(soundTypeWood);
	setHarvestLevel("axe", 1);
}

@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
	if (iconRegister instanceof TextureMap) {
		TextureMap map = (TextureMap) iconRegister;
		String overlayName = "tier0";
		String baseName = "planks_oak";
		String regname = "planks_oak";
		map.setTextureEntry(regname, new TextureAtlasDynamic(regname, baseName, overlayName));
	}
}
}

Set the power inside a single block free! ;D

Posted

You missed an important line:

 

				icons[o] = map.getTextureExtry(regname);

 

You need to get the IIcon back out and save it to a field in the block, which is then returned via getIcon(...)

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.

Posted
  On 12/30/2015 at 1:53 PM, Draco18s said:

You missed an important line:

 

				icons[o] = map.getTextureExtry(regname);

 

You need to get the IIcon back out and save it to a field in the block, which is then returned via getIcon(...)

Ok, I've finished my ideas  :'( Please Help me  :'( :'( :'(

Crash Report

  Reveal hidden contents

 

 

Block Class

package com.lsmod.CompactStorage.Blocks;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.lsmod.CompactStorage.client.TextureAtlasDynamic;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class test2Block extends Block {

String name = "endOre";
// Indicates the number of metadata -> Number of blocks
int metadata = 8;

@SideOnly(Side.CLIENT)
private IIcon[] icons;

public test2Block() {

	super(Material.rock);
	setBlockName(name);
	setCreativeTab(CreativeTabs.tabBlock);
	setHardness(3F);
	setResistance(15F);
	setStepSound(soundTypeStone);
	setHarvestLevel("pickaxe", 2);
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
	icons = new IIcon[metadata];

	if (par1IconRegister instanceof TextureMap) {
		TextureMap map = (TextureMap) par1IconRegister;
		for (int i = 0; i < icons.length; i++) {
			String overlayName = "tier"+i;
			String baseName = "plank_oak";
			String regname = this.getUnlocalizedName()+"_"+i;
			map.setTextureEntry(regname, new TextureAtlasDynamic(regname, baseName, overlayName));
			icons[i] = map.getTextureExtry(regname);
			//icons[i] = par1IconRegister.registerIcon("CompactStorage" + ":" + "plank_oak" + i);
		}
	}
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int par1, int par2) {
	return icons[par2];
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
	for (int var4 = 0; var4 < metadata; ++var4) {
		par3List.add(new ItemStack(par1, 1, var4));
	}
}

}

ItemBlock Class

package com.lsmod.CompactStorage.Blocks;


import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class test2Item extends ItemBlock {

public test2Item(Block block) {

	super(block);

}

@Override
public int getMetadata(int par1) {

	return par1;

}

@Override
public String getUnlocalizedName(ItemStack itemstack) {

	String name = "";

	switch (itemstack.getItemDamage()) {

	case 0:
		name = "tier0";
		break;
	case 1:
		name = "tier1";
		break;
	case 2:
		name = "tier2";
		break;
	case 3:
		name = "tier3";
		break;
	case 4:
		name = "tier4";
		break;
	case 5:
		name = "tier5";
		break;
	case 6:
		name = "tier6";
		break;
	case 7:
		name = "tier7";
		break;
	default:
		System.out.println("Invalid metadata for Block EndOre");
		name = "broken";
		break;

	}

	return getUnlocalizedName() + "." + name;
}

}

 

TextureAtlas

package com.lsmod.CompactStorage.client;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.imageio.ImageIO;

import com.lsmod.CompactStorage.CompactStorage;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

public class TextureAtlasDynamic extends TextureAtlasSprite {

protected String textureBase;
protected String textureOverlay;

public TextureAtlasDynamic(String string, String base, String overlay) {
	super(string);
	textureBase = base;
	textureOverlay = overlay;
}

@Override
public void updateAnimation() {
	TextureUtil.uploadTextureMipmap((int[][]) this.framesTextureData.get(0), this.width, this.height, this.originX, this.originY, false, false);
}

@Override
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
	return true;
}

@Override
public boolean load(IResourceManager manager, ResourceLocation location) {
	framesTextureData.clear();
	this.frameCounter = 0;
	this.tickCounter = 0;

	ResourceLocation resource1 = new ResourceLocation(textureBase);
	ResourceLocation resource2 = new ResourceLocation(textureOverlay);

	try {
        	TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
        	resource1 = this.completeResourceLocation(map, resource1, 0);
        	resource2 = this.completeResourceLocation(map, resource2, 0);
		BufferedImage buff = ImageIO.read(manager.getResource(resource1).getInputStream());
		BufferedImage buff2 = ImageIO.read(manager.getResource(resource2).getInputStream());

        int[] rawBase = new int[buff.getWidth()*buff.getHeight()];
        int[] rawOverlay = new int[buff2.getWidth()*buff2.getHeight()];

        buff.getRGB(0, 0, buff.getWidth(), buff.getHeight(), rawBase, 0, buff.getWidth());
        buff2.getRGB(0, 0, buff2.getWidth(), buff2.getHeight(), rawOverlay, 0, buff2.getWidth());
        
        int min = Math.min(buff.getWidth(),buff2.getWidth());
        rawBase = scaleToSmaller(rawBase, buff.getWidth(), min);
        rawOverlay = scaleToSmaller(rawOverlay, buff2.getWidth(), min);

        width = min;
        height = min;
        
        int[][] aint = new int[1 + MathHelper.calculateLogBaseTwo(min)][];
        for (int k = 0; k < aint.length; ++k)
        {
        	aint[k] = rawBase;
        }

        this.framesTextureData.add(aint);
	} catch (IOException e) {
		e.printStackTrace();
		int[][] aint = new int[1][];
        for (int k = 0; k < 1; ++k)
        {
        	aint[k] = new int[16*16];
        	for(int l=0; l<aint[k].length;l++) {
        		aint[k][l] = 0xFFFFFFFF;
        	}
        }
        width = 16;
        height = 16;

        this.framesTextureData.add(aint);
	}
        return false;
}

private static int[] scaleToSmaller(int[] data, int width, int min) {
	if(width == min) { return data; }
	int scale = width / min;
	int[] output = new int[min*min];
	int j = 0;
	for(int i = 0; i < output.length; i++) {
		if(i%min == 0) {
			j += width;
		}
		output[i] = data[i*scale+j];
	}
	return output;
}

private static ResourceLocation completeResourceLocation(TextureMap map, ResourceLocation loc, int c) {
	try {
		return (ResourceLocation)CompactStorage.proxy.resourceLocation.invoke(map, c);
	} catch (IllegalAccessException e) {
		e.printStackTrace();
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		e.printStackTrace();
	}
	return null;
}

}

 

I don't really know what to do, please be good with me, can you make me a simple example of a block using TextureAtlas?

Set the power inside a single block free! ;D

Posted

AFAICT something in the texture atlas load method is borked. This is an incredibly difficult error to solve, as the point at which the program discovers that there's a problem is long after our code has run, or deep in the call stack. I don't see the problem off hand.

 

I'll have to get you my block later, I'm not home.

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.

Posted
  On 12/30/2015 at 4:27 PM, Draco18s said:

AFAICT something in the texture atlas load method is borked. This is an incredibly difficult error to solve, as the point at which the program discovers that there's a problem is long after our code has run, or deep in the call stack. I don't see the problem off hand.

 

I'll have to get you my block later, I'm not home.

Oh, thank you very much, you're doing a lot for me!  ;D

Set the power inside a single block free! ;D

Posted
  On 12/30/2015 at 7:24 PM, LoreSchaeffer said:
Oh, thank you very much, you're doing a lot for me!  ;D

 

I think I'm the only one who has used the custom sprite loader, so I'm the only one that knows how it works, and even that knowledge is questionable. It is so much easier to just render the block twice and accept the crappy break particles.

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.

Posted

Stacktrace:
   at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:63)
   at com.lsmod.CompactStorage.client.TextureAtlasDynamic.load(TextureAtlasDynamic.java:53)

The only thing that can be null on line 63 in

SimpleReloadableResourceManager

is the ResourceLocation parameter passed in. This corresponds to your

ResourceLocation

variable called

resource1

. This gets intialized with a call to

completeResourceLocation

. This means that that method returns

null

. In your crash log, it also mentions this:

[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: java.lang.IllegalArgumentException: wrong number of arguments
[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]:    at java.lang.reflect.Method.invoke(Method.java:606)
[16:06:03] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]:    at com.lsmod.CompactStorage.client.TextureAtlasDynamic.completeResourceLocation(TextureAtlasDynamic.java:110)

Line 110 in

TextureAtlasDynamic

is that line in

completeResourceLocation

, which means you call

invoke

with the wrong number of arguments. Seems a bit weird to me...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

That suggests that "plank_oak" is not the correct texture string.

 

The standard texture alas would throw one of those "texture not found: minecraft:plank_oak" messages, but in creating a custom loader, that error handling got lost. I'll take a look at the strings I pass. It might need to be "minecraft:plank_oak"

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.

Posted

Ok, so I poked around.  You are using it correctly, however, the texture name is not "plank_oak" its "planks_oak"

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.

Posted
  On 12/30/2015 at 11:54 PM, Draco18s said:

Ok, so I poked around.  You are using it correctly, however, the texture name is not "plank_oak" its "planks_oak"

Ok, I corrected it to "planks oak" but that's not the thing that cause the crash, it should load without loading that texture, the problem is in TextureAtlas class

Set the power inside a single block free! ;D

Posted
  On 12/31/2015 at 10:39 AM, LoreSchaeffer said:

  Quote

Ok, so I poked around.  You are using it correctly, however, the texture name is not "plank_oak" its "planks_oak"

Ok, I corrected it to "planks oak" but that's not the thing that cause the crash, it should load without loading that texture, the problem is in TextureAtlas class

 

Unfortunately, whatever the problem is, the error handling is not there to tell us what's wrong.  You're going to have to do some stack trace digging and examining what it is crashes, why, where that value came from, and work backwards.

 

Took me weeks to figure a couple of errors out myself that way, having to do with the various data arrays for the mipmaps.

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.

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.