MC Modding
Please register and join the community!

[1.8.1] On/Off Light Block

Page 2 of 2 Previous  1, 2

View previous topic View next topic Go down

[1.8.1] On/Off Light Block

Post by Strengthowns on Wed Jun 15, 2011 6:28 am

First topic message reminder :

This tutorial is about how to make a block that gives off light but can be switched on and off.
Please read the block tutorial for more help!

BlockNamehere
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockNamehere extends Block
{

    public BlockNamehere(int i, int j, boolean flag)
    {
        super(i, Material.ground);
        blockIndexInTexture = j;
        isActive = flag;
        if(isActive)
        {
            super.setLightValue(1.0F);
        }
    }

    public int idDropped(int i, Random random)
    {
        return mod_Namehere.NamehereOff.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        {
            world.setBlockWithNotify(i, j, k, mod_Namehere.NamehereOn.blockID);
        } else
        {
            world.setBlockWithNotify(i, j, k, mod_Namehere.NamehereOff.blockID);
        }
    }

    private boolean isActive;
}

mod_Namehere
Code:
package net.minecraft.src;

public class mod_Namehere extends BaseMod
{

    public mod_Namehere()
    {
        ModLoader.RegisterBlock(NamehereOn);
        ModLoader.RegisterBlock(NamehereOff);
        ModLoader.AddName(NamehereOn, "Namehere");
        ModLoader.AddName(NamehereOff, "Namehere");
        ModLoader.AddRecipe(new ItemStack(NamehereOff, 1), new Object[] {
            "XXX", "X@X", "XXX", Character.valueOf('X'), Block.glass, Character.valueOf('@'), Block.torchWood
        });
    }

    public String Version()
    {
        return "1.6.6";
    }

    public static Block NamehereOn;
    public static Block NamehereOff;
    public static int NamehereTextureOff;
    public static int NamehereTextureOn;

    static
    {
        NamehereTextureOff = ModLoader.getUniqueSpriteIndex("/terrain.png");
        NamehereTextureOn = ModLoader.getUniqueSpriteIndex("/terrain.png");
        NamehereOn = (new BlockNamehere(249, NamehereTextureOn, true)).setHardness(0.3F).setResistance(5000.0F).setBlockName("NamehereOn");
        NamehereOff = (new BlockNamehere(248, NamehereTextureOff, false)).setHardness(0.3F).setResistance(5000.0F).setBlockName("NamehereOff");
        ModLoader.addOverride("/terrain.png", "/NamehereOff.png", NamehereTextureOff);
        ModLoader.addOverride("/terrain.png", "/NamehereOn.png", NamehereTextureOn);
    }
}

Help: BOTH

1. After making those files, make two block textures called "NamehereOff" and "NamehereOn".

2. In "mod_Namehere" at the bottom in "static" on the 3rd and 5th line, where it says 249 and 248, that is the block ID so you can change it to what ever you want.

3. All of this should recompile fine without any errors.


Last edited by Strengthowns on Wed Oct 26, 2011 1:23 am; edited 1 time in total
avatar
Strengthowns
Admin

Posts : 79
Join date : 2011-06-14
Location : Right here!

View user profile http://www.mcmodding.4umer.com

Back to top Go down


Re: [1.8.1] On/Off Light Block

Post by jesshankin22 on Sat Oct 29, 2011 3:12 am

maybe you could try doing it so it only strobes within a certain proximity of the player eg: 30 blocks away = on.... I'm not a very good coder, but it's just an idea for one of you to try so it doesn't get stuck in an infinite loop.

jesshankin22
Member

Posts : 47
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by MrCreeper07 on Sat Oct 29, 2011 6:13 pm

hey i made this light block not with the timer spam thing but your version and it crashed my minecraft. i didn't get to see why it crashed though. the only other mod i had was my own and i checked all the block ids and none were interfearing.
here is my code
this is the BlockJiffyLight.java
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockJiffyLight extends Block
{

    public BlockJiffyLight(int i, int j, boolean flag)
    {
        super(i, Material.ground);
        blockIndexInTexture = j;
        isActive = flag;
        if(isActive)
        {
            super.setLightValue(1.0F);
        }
    }

    public int idDropped(int i, Random random)
    {
        return mod_JiffyLight.JiffyLightOff.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        {
            world.setBlockWithNotify(i, j, k, mod_JiffyLight.JiffyLightOn.blockID);
        } else
        {
            world.setBlockWithNotify(i, j, k, mod_JiffyLight.JiffyLightOff.blockID);
        }
    }

    private boolean isActive;
}
and here is my mod_JiffyLight.java
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockJiffyLight extends Block
{

    public BlockJiffyLight(int i, int j, boolean flag)
    {
        super(i, Material.ground);
        blockIndexInTexture = j;
        isActive = flag;
        if(isActive)
        {
            super.setLightValue(1.0F);
        }
    }

    public int idDropped(int i, Random random)
    {
        return mod_JiffyLight.JiffyLightOff.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        {
            world.setBlockWithNotify(i, j, k, mod_JiffyLight.JiffyLightOn.blockID);
        } else
        {
            world.setBlockWithNotify(i, j, k, mod_JiffyLight.JiffyLightOff.blockID);
        }
    }

    private boolean isActive;
}
avatar
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by Sponsored content


Sponsored content


Back to top Go down

Page 2 of 2 Previous  1, 2

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum