Jump to content

[Solved] Setting light value of block based on metadata [1.6.2]


Recommended Posts

Posted

Ok, I have a metadata block that's working fine, but i want ti to be able to emit light if it's metadata is 1, and not if it's metadata is 0. If anyone know how to do this, i would very appriciate that.

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

hmmm well redstone simply change the block when you click it :\ which isnt really what you want but it could work anyway

 

/**
     * The redstone ore glows.
     */
    private void glow(World par1World, int par2, int par3, int par4)
    {
        this.sparkle(par1World, par2, par3, par4);

        if (this.blockID == Block.oreRedstone.blockID)
        {
            par1World.setBlock(par2, par3, par4, Block.oreRedstoneGlowing.blockID);
        }
    }

 

i looked quickyl through Block.java and there doesnt seem to be anything but maybe im wrong

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Your right, I don't want to have 2 blocks, because i wan't to have as less as possible id's used. But i was thinking of something like:

this.setLightValue(par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 1 ? 15 : 0);

but for that i need a IBlockAccess, and the coordinates, but i don't know how to get those.

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

hmmm, are you usign 162 ? my Block.java only has

/**
     * Sets the amount of light emitted by a block from 0.0f to 1.0f (converts internally to 0-15). Returns the object
     * for convenience in constructing.
     */
    public Block setLightValue(float par1)
    {
        lightValue[this.blockID] = (int)(15.0F * par1);
        return this;
    }

which obviously will be the same for every block in the world (which you dont want xD)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

No, i'm using a little if statement in the setLightValue method. In AE v12 there's quartz glass and vibrant quartz glass, they have the same id, but the vibrant one emits light. I really would like to know how they did it.

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

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)

Note: you'll have to update the block when metadata is changed for the light value change to take effect.

Posted

actually...

/**

    * How bright to render this block based on the light its receiving. Args: iBlockAccess, x, y, z

    */

    public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

    {

        return par1IBlockAccess.getBrightness(par2, par3, par4, getLightValue(par1IBlockAccess, par2, par3, par4));

    }

 

/**

    * Get a light value for the block at the specified coordinates, normal ranges are between 0 and 15

    *

    * @param world The current world

    * @param x X Position

    * @param y Y position

    * @param z Z position

    * @return The light value

    */

    public int getLightValue(IBlockAccess world, int x, int y, int z)

    {

        Block block = blocksList[world.getBlockId(x, y, z)];

        if (block != null && block != this)

        {

            return block.getLightValue(world, x, y, z);

        }

        return lightValue[blockID];

    }

 

this seems to be the same for every block in the world

 

using thsi method you could make the block look bright, but not emit light

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)

Note: you'll have to update the block when metadata is changed for the light value change to take effect.

And how would i go about setting the light value instead of getting it?

 

actually...

/**

    * How bright to render this block based on the light its receiving. Args: iBlockAccess, x, y, z

    */

    public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

    {

        return par1IBlockAccess.getBrightness(par2, par3, par4, getLightValue(par1IBlockAccess, par2, par3, par4));

    }

 

/**

    * Get a light value for the block at the specified coordinates, normal ranges are between 0 and 15

    *

    * @param world The current world

    * @param x X Position

    * @param y Y position

    * @param z Z position

    * @return The light value

    */

    public int getLightValue(IBlockAccess world, int x, int y, int z)

    {

        Block block = blocksList[world.getBlockId(x, y, z)];

        if (block != null && block != this)

        {

            return block.getLightValue(world, x, y, z);

        }

        return lightValue[blockID];

    }

 

this seems to be the same for every block in the world

 

using thsi method you could make the block look bright, but not emit light

 

No, i don't want to make it look brighter, i want it to emit light, just like a torch does.

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

Guys, I used it in one of my mod.

getLightValue(args) receives another call from the World computeLightValue(args).

If you are not convinced, look at what setLightValue(float) really does.

Posted

hmm...

 

well... gotolink is rarely wrong so maybe i just read the code wrong

 

but it seems to me like:

public static final int[] lightValue = new int[4096];

public Block setLightValue(float par1)
    {
        lightValue[this.blockID] = (int)(15.0F * par1);
        return this;
    }

it will be the same for every block... but considering gotolink post... i would try it just in case

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

YAY!!! I DID IT!!! I used the code:

public int getLightValue(IBlockAccess world, int x, int y, int z)
{
    this.setLightValue(world.getBlockMetadata(x, y, z) == 1 ? 1 : 0);
    return lightValue[blockID];
}

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

@hydroflame : You are right on one thing, if your block emits light, it will appear brighter by default.

To avoid this, you'll have to override

public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

too.

 

    Basic Example:

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
if(world.getBlockMetadata(x,y,z) >8
return 15;
else if(world.getBlockMetadata(x,y,z) ==0
return 0;
else
return super.getLightValue(world,x,y,z);
}

@Override
public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
return 0;
}

As I said, if you change block metadata somehow, you'll have to re-render the block for the change to take effect.

Posted

I don't have to update the block, cause you can place both blocks seperatly, and not like it receives a redstone signal, it changes the metadata, and it doesn't appear brighter in my inventory and if i place it down, cause its transparent.

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/

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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