Jump to content

How do I use TextureFX with infinite sprite indexes?


thebombzen

Recommended Posts

Hello, I have a texture FX for a liquid I'm adding which I'm just testing with:

 

package net.minecraft.src;

public class TextureHNO3FX extends TextureWaterFX {
public TextureHNO3FX(){
	super();
	this.iconIndex = mod_ChemicalCraft.instance.hno3Flowing.blockIndexInTexture;
}
}

 

and

 

@Override
public void registerAnimation(Minecraft minecraft) {
ModLoader.addAnimation(new TextureHNO3FX());
}

 

That block uses a custom terrain.png with MinecraftForgeClient.preloadTexture().

 

Unfortunately, the renderer isn't getting the message that it's not the default terrain.png, and it's rendering the top of every grass block with TextureWaterFX!!! How do I set it so it uses the preloaded Texture rather than the default terrain.png?

Link to comment
Share on other sites

I know how to add blocks with ModLoader :P

 

Here's my code:

 

package net.minecraft.src;

import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.MinecraftForge;
import net.minecraft.src.forge.MinecraftForgeClient;
import net.minecraft.src.forge.oredict.OreDictionary;


public class mod_ChemicalCraft extends BaseMod {

public mod_ChemicalCraft(){
	instance = this;
}

@Override
public String getVersion() {
	return "ChemicalCraft v0.1 for Minecraft 1.2.5";
}

@Override
public void generateSurface(World world, Random random, int chunkX, int chunkZ){
	for (int i = 0; i < oreSaltFrequency; i++){
		int randomX = chunkX + random.nextInt(16);
		int randomZ = chunkZ + random.nextInt(16);
		int randomY = random.nextInt(128);
		oreSaltGen.generate(world, random, randomX, randomY, randomZ);
	}
}

@Override
public void load() {
	ModLoader.registerBlock(oreSalt);
	ModLoader.registerBlock(hno3Flowing);
	ModLoader.registerBlock(hno3Stationary);
	ModLoader.addName(dustSalt, "Salt");
	ModLoader.addName(hno3Stationary, "Nitric Acid");
	ModLoader.addName(hno3Flowing, "Nitric Acid");
	OreDictionary.registerOre("dustSalt", new ItemStack(dustSalt));
                //these are for testing
	ModLoader.addShapelessRecipe(new ItemStack(dustSalt, 64), Block.dirt, Block.dirt);
	ModLoader.addShapelessRecipe(new ItemStack(Item.ingotIron, 64), dustSalt, dustSalt);
	ModLoader.addShapelessRecipe(new ItemStack(oreSalt, 64), Item.ingotIron);
	ModLoader.addShapelessRecipe(new ItemStack(Item.pickaxeDiamond), Block.dirt, Block.dirt, Block.dirt);
	ModLoader.addShapelessRecipe(new ItemStack(Block.torchWood, 64), Block.cobblestone);
	ModLoader.addShapelessRecipe(new ItemStack(hno3Stationary, 64), Block.dirt, Block.dirt, Block.dirt, Block.dirt);
	MinecraftForgeClient.preloadTexture("/ChemicalCraftImg/terrain.png");


}
@Override
public void registerAnimation(Minecraft minecraft) {
	ModLoader.addAnimation(new TextureHNO3FX());
	ModLoader.addAnimation(new TextureHNO3FlowFX());
}

@Override
public boolean renderWorldBlock(RenderBlocks render, IBlockAccess world, int x, int y, int z, Block block, int modelID){
	if (modelID == hno3RenderType && block.getRenderType() == hno3RenderType){
		return renderHNO3Blocks(render, block, x, y, z);
	}
	return true;
}

public boolean renderHNO3Blocks(RenderBlocks render, Block par1Block, int par2, int par3, int par4){
[spoiler]
Tessellator var5 = Tessellator.instance;
        int var6 = par1Block.colorMultiplier(render.blockAccess, par2, par3, par4);
        float var7 = (float)(var6 >> 16 & 255) / 255.0F;
        float var8 = (float)(var6 >> 8 & 255) / 255.0F;
        float var9 = (float)(var6 & 255) / 255.0F;
        boolean var10 = par1Block.shouldSideBeRendered(render.blockAccess, par2, par3 + 1, par4, 1);
        boolean var11 = par1Block.shouldSideBeRendered(render.blockAccess, par2, par3 - 1, par4, 0);
        boolean[] var12 = new boolean[] {par1Block.shouldSideBeRendered(render.blockAccess, par2, par3, par4 - 1, 2), par1Block.shouldSideBeRendered(render.blockAccess, par2, par3, par4 + 1, 3), par1Block.shouldSideBeRendered(render.blockAccess, par2 - 1, par3, par4, 4), par1Block.shouldSideBeRendered(render.blockAccess, par2 + 1, par3, par4, 5)};

        if (!var10 && !var11 && !var12[0] && !var12[1] && !var12[2] && !var12[3])
        {
            return false;
        }
        else
        {
            boolean var13 = false;
            float var14 = 0.5F;
            float var15 = 1.0F;
            float var16 = 0.8F;
            float var17 = 0.6F;
            double var18 = 0.0D;
            double var20 = 1.0D;
            Material var22 = par1Block.blockMaterial;
            int var23 = render.blockAccess.getBlockMetadata(par2, par3, par4);
            double var24 = (double)render.getFluidHeight(par2, par3, par4, var22);
            double var26 = (double)render.getFluidHeight(par2, par3, par4 + 1, var22);
            double var28 = (double)render.getFluidHeight(par2 + 1, par3, par4 + 1, var22);
            double var30 = (double)render.getFluidHeight(par2 + 1, par3, par4, var22);
            double var32 = 0.0010000000474974513D;
            int var34;
            int var37;

            if (render.renderAllFaces || var10)
            {
                var13 = true;
                var34 = par1Block.getBlockTextureFromSideAndMetadata(1, var23);
                float var35 = (float)BlockHNO3Flowing.getFlowDirection(render.blockAccess, par2, par3, par4, var22);
                if (var35 > -999.0F)
                {
                    var34 = par1Block.getBlockTextureFromSideAndMetadata(2, var23);
                }

                var24 -= var32;
                var26 -= var32;
                var28 -= var32;
                var30 -= var32;
                int var36 = (var34 & 15) << 4;
                var37 = var34 & 240;
                double var38 = ((double)var36 + 8.0D) / 256.0D;
                double var40 = ((double)var37 + 8.0D) / 256.0D;

                if (var35 < -999.0F)
                {
                    var35 = 0.0F;
                }
                else
                {
                    var38 = (double)((float)(var36 + 16) / 256.0F);
                    var40 = (double)((float)(var37 + 16) / 256.0F);
                }

                double var42 = (double)(MathHelper.sin(var35) * 8.0F) / 256.0D;
                double var44 = (double)(MathHelper.cos(var35) * 8.0F) / 256.0D;
                var5.setBrightness(par1Block.getMixedBrightnessForBlock(render.blockAccess, par2, par3, par4));
                float var46 = 1.0F;
                var5.setColorOpaque_F(var15 * var46 * var7, var15 * var46 * var8, var15 * var46 * var9);
                var5.addVertexWithUV((double)(par2 + 0), (double)par3 + var24, (double)(par4 + 0), var38 - var44 - var42, var40 - var44 + var42);
                var5.addVertexWithUV((double)(par2 + 0), (double)par3 + var26, (double)(par4 + 1), var38 - var44 + var42, var40 + var44 + var42);
                var5.addVertexWithUV((double)(par2 + 1), (double)par3 + var28, (double)(par4 + 1), var38 + var44 + var42, var40 + var44 - var42);
                var5.addVertexWithUV((double)(par2 + 1), (double)par3 + var30, (double)(par4 + 0), var38 + var44 - var42, var40 - var44 - var42);
            }

            if (render.renderAllFaces || var11)
            {
                var5.setBrightness(par1Block.getMixedBrightnessForBlock(render.blockAccess, par2, par3 - 1, par4));
                float var65 = 1.0F;
                var5.setColorOpaque_F(var14 * var65, var14 * var65, var14 * var65);
                render.renderBottomFace(par1Block, (double)par2, (double)par3 + var32, (double)par4, par1Block.getBlockTextureFromSide(0));
                var13 = true;
            }

            for (var34 = 0; var34 < 4; ++var34)
            {
                int var64 = par2;
                var37 = par4;

                if (var34 == 0)
                {
                    var37 = par4 - 1;
                }

                if (var34 == 1)
                {
                    ++var37;
                }

                if (var34 == 2)
                {
                    var64 = par2 - 1;
                }

                if (var34 == 3)
                {
                    ++var64;
                }

                int var66 = par1Block.getBlockTextureFromSideAndMetadata(var34 + 2, var23);
                int var39 = (var66 & 15) << 4;
                int var67 = var66 & 240;

                if (render.renderAllFaces || var12[var34])
                {
                    double var43;
                    double var41;
                    double var47;
                    double var45;
                    double var51;
                    double var49;

                    if (var34 == 0)
                    {
                        var41 = var24;
                        var43 = var30;
                        var45 = (double)par2;
                        var49 = (double)(par2 + 1);
                        var47 = (double)par4 + var32;
                        var51 = (double)par4 + var32;
                    }
                    else if (var34 == 1)
                    {
                        var41 = var28;
                        var43 = var26;
                        var45 = (double)(par2 + 1);
                        var49 = (double)par2;
                        var47 = (double)(par4 + 1) - var32;
                        var51 = (double)(par4 + 1) - var32;
                    }
                    else if (var34 == 2)
                    {
                        var41 = var26;
                        var43 = var24;
                        var45 = (double)par2 + var32;
                        var49 = (double)par2 + var32;
                        var47 = (double)(par4 + 1);
                        var51 = (double)par4;
                    }
                    else
                    {
                        var41 = var30;
                        var43 = var28;
                        var45 = (double)(par2 + 1) - var32;
                        var49 = (double)(par2 + 1) - var32;
                        var47 = (double)par4;
                        var51 = (double)(par4 + 1);
                    }

                    var13 = true;
                    double var53 = (double)((float)(var39 + 0) / 256.0F);
                    double var55 = ((double)(var39 + 16) - 0.01D) / 256.0D;
                    double var57 = ((double)var67 + (1.0D - var41) * 16.0D) / 256.0D;
                    double var59 = ((double)var67 + (1.0D - var43) * 16.0D) / 256.0D;
                    double var61 = ((double)(var67 + 16) - 0.01D) / 256.0D;
                    var5.setBrightness(par1Block.getMixedBrightnessForBlock(render.blockAccess, var64, par3, var37));
                    float var63 = 1.0F;

                    if (var34 < 2)
                    {
                        var63 *= var16;
                    }
                    else
                    {
                        var63 *= var17;
                    }

                    var5.setColorOpaque_F(var15 * var63 * var7, var15 * var63 * var8, var15 * var63 * var9);
                    var5.addVertexWithUV(var45, (double)par3 + var41, var47, var53, var57);
                    var5.addVertexWithUV(var49, (double)par3 + var43, var51, var55, var59);
                    var5.addVertexWithUV(var49, (double)(par3 + 0), var51, var55, var61);
                    var5.addVertexWithUV(var45, (double)(par3 + 0), var47, var53, var61);
                }
            }

            par1Block.minY = var18;
            par1Block.maxY = var20;
            return var13;
        }
[/spoiler]

}

public static mod_ChemicalCraft instance;
public static int oreSaltFrequency = 20;
public static final Material materialHno3 = new MaterialLiquid(MapColor.waterColor).setNoPushMobility();
public static final Block oreSalt = new BlockSaltOre(1717).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setBlockName("oreSalt");
public static final Block hno3Flowing = new BlockHNO3Flowing(1718, materialHno3).setHardness(100.0F).setLightOpacity(3).setBlockName("HNO3").disableStats().setRequiresSelfNotify();
public static final Block hno3Stationary = new BlockHNO3Stationary(1719, materialHno3).setHardness(100.0F).setLightOpacity(3).setBlockName("HNO3").disableStats().setRequiresSelfNotify();
public static final Item dustSalt = new Item(1717).setIconIndex(Item.sugar.getIconIndex(new ItemStack(Item.sugar))).setItemName("dustSalt");
public static WorldGenMinable oreSaltGen = new WorldGenMinable(oreSalt.blockID, 16);
public int hno3RenderType = ModLoader.getUniqueBlockModelID(this, false);

}

 

 

And BlockHNO3Stationary.java:

 

 

package net.minecraft.src;

import net.minecraft.src.forge.ITextureProvider;

public class BlockHNO3Stationary extends BlockStationary implements ITextureProvider {

public BlockHNO3Stationary(int id, Material material) {
	super(id, material);
	this.blockIndexInTexture = 0;
}

@Override
public int tickRate(){
	return 5;
}

@Override
public int getRenderBlockPass(){
	return 1;
}

@Override
public int getRenderType(){
	return mod_ChemicalCraft.instance.hno3RenderType;
}
@Override
public String getTextureFile(){
	return "/ChemicalCraftImg/terrain.png";
}

}

 

 

 

And BlockHNO3Flowing.java:

 

 

package net.minecraft.src;

import java.lang.reflect.Method;

import net.minecraft.src.forge.ITextureProvider;

public class BlockHNO3Flowing extends BlockFlowing implements ITextureProvider {

public BlockHNO3Flowing(int id, Material material) {
	super(id, material);
	this.blockIndexInTexture = 0;
}


@Override
public int tickRate(){
	return 5;
}

@Override
public int getRenderBlockPass(){
	return 1;
}

@Override
public int getRenderType(){
	return mod_ChemicalCraft.instance.hno3RenderType;
}

public static Vec3D getStaticFlowVector(IBlockAccess access, int x, int y, int z){
	try {
		Method method = BlockFluid.class.getDeclaredMethod("getFlowVector", IBlockAccess.class, int.class, int.class, int.class);
		method.setAccessible(true);
		return (Vec3D)method.invoke(mod_ChemicalCraft.hno3Flowing, access, x, y, z);
	} catch (Exception ex){
		return null;
	}
}


public static double getFlowDirection(IBlockAccess par0IBlockAccess, int par1, int par2, int par3, Material par4Material)
    {
        Vec3D var5 = null;
        
        
        if (par4Material == mod_ChemicalCraft.instance.materialHno3)
        {
            var5 = BlockHNO3Flowing.getStaticFlowVector(par0IBlockAccess, par1, par2, par3);
        }

        return var5.xCoord == 0.0D && var5.zCoord == 0.0D ? -1000.0D : Math.atan2(var5.zCoord, var5.xCoord) - (Math.PI / 2D);
    }
@Override
public String getTextureFile(){
	return "/ChemicalCraftImg/terrain.png";
}

}

 

 

 

Link to comment
Share on other sites

I'm using Forge 3.3.8.152, and it doesn't support it.

 

What I did as a work around was I overrode the method bindTexture(RenderEngine) from

par1RenderEngine.getTexture("/terrain.png")

to

par1RenderEngine.getTexture(mod_ChemicalCraft.hno3Flowing.getTextureFile())

 

That fixed the problem, so seeing this implemented in the base TextureFX class would be nice.

Link to comment
Share on other sites

I'm using Forge 3.3.8.152, and it doesn't support it.

 

What I did as a work around was I overrode the method bindTexture(RenderEngine) from

par1RenderEngine.getTexture("/terrain.png")

to

par1RenderEngine.getTexture(mod_ChemicalCraft.hno3Flowing.getTextureFile())

 

That fixed the problem, so seeing this implemented in the base TextureFX class would be nice.

Actually I though that FML/Forge have their own TextureFX class that subclasses the standard TextureFX class, you are using FML/Forge's TextureFX?

Link to comment
Share on other sites

By 'Forge doesnt support it' Thats a lie, cuz it does support it, the exact same way MC supports it, by overriding the bindImage() function.. like you should.. so whats the issue?

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

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.