Jump to content

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


larsgerrits
 Share

Recommended Posts

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/

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

@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/

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is my first time making a pack and i just wanted to add mods that i know or that look interesting. So When making the pack i get this error with Refined Storage https://pastebin.com/DxtTbVZW
    • Hello! When I'm trying to get items by tag during the recipe serialization, I'm getting an empty list. I have a guess that item tags're not loaded by the time minecraft loads my recipes. Here's my code: Class that saves information about ingredient's count Recipe serializer with some aux methods: Registry: Example of the json recipe file:  
    • I tried to install client forge on my linux desktop. But after "installation" it's missing forge[version].jar file in .minecraft/versions. I tried java 11 and 8 environment with same result. Here link to log file from installation: https://drive.google.com/file/d/1vtg9NT-WX5ilb1aNUvZlOv54gKWJuaT1/view?usp=share_link. I don't know what to do. I give for every directory permissions that I don't think that is issue. I will try check older versions if universal file work. Debian 11 (kernel 5.10)
    • I recently got error 1 in the launcher, so I restarted the .minecraft. After restarting it, I can't get the Forge 1.19.2 - 43.1.1 installer to run, I tried other versions and I get the same result, it opens a black box that closes instantly and nothing happens. I already tried to restart my pc, minecraft, update and reinstall java, run vanilla 1.19.2 and more recent versions of the game, disable Windows Firewall and antivirus and I still haven't solved it. Many times I installed forge and never ran into this problem. If I could receive assistance I would be very grateful.  
    • Here's the default loot table for gravel block: { "type": "minecraft:block", "pools": [ { "rolls": 1.0, "bonus_rolls": 0.0, "entries": [ { "type": "minecraft:alternatives", "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "enchantments": [ { "enchantment": "minecraft:silk_touch", "levels": { "min": 1 } } ] } } ], "name": "minecraft:gravel" }, { "type": "minecraft:alternatives", "conditions": [ { "condition": "minecraft:survives_explosion" } ], "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:table_bonus", "enchantment": "minecraft:fortune", "chances": [ 0.1, 0.14285715, 0.25, 1.0 ] } ], "name": "minecraft:flint" }, { "type": "minecraft:item", "name": "minecraft:gravel" } ] } ] } ] } ] } This is a finicky loot table. If I add anything to it, nothing drops. I've added pools, entries, children ... you name it. Does anyone know the particulars about this table? I mean, periodically gravel drops flint instead of a gravel block. I understand the condition that could drop flint if the block survives an explosion. Otherwise, it drops the gravel block itself. I would like to further understand why the use of `children` and the set of `chance` values given in the explosion child entry. What I do understand is that `"type" : "minecraft:alternatives"` means that if this child/entry is successful, then it stops generating loot for this entry/pool. How often does the flint drop and is that taken care of in another location? Is that in a `"condition" : "minecraft:table_bonus"` loot table? Hmmm... I'll have to go take a look and see if there is something called table_bonus.json.
  • Topics

×
×
  • Create New...

Important Information

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