MC Modding
Please register and join the community!


Join the forum, it's quick and easy

MC Modding
Please register and join the community!
MC Modding
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[1.8.1] On/Off Light Block

+4
groxmapper
the undecided t
austin56101
Strengthowns
8 posters

Page 2 of 2 Previous  1, 2

Go down

[1.8.1]  On/Off Light Block - Page 2 Empty [1.8.1] On/Off Light Block

Post by Strengthowns 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.
[1.8.1]  On/Off Light Block - Page 2 1381693260 Please read the block tutorial for more help! [1.8.1]  On/Off Light Block - Page 2 1381693260

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
Strengthowns
Strengthowns
Admin

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

http://www.mcmodding.4umer.com

Back to top Go down


[1.8.1]  On/Off Light Block - Page 2 Empty Re: [1.8.1] On/Off Light Block

Post by jesshankin22 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

Back to top Go down

[1.8.1]  On/Off Light Block - Page 2 Empty Re: [1.8.1] On/Off Light Block

Post by MrCreeper07 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;
}
MrCreeper07
MrCreeper07
Member

Posts : 18
Join date : 2011-10-23

Back to top Go down

[1.8.1]  On/Off Light Block - Page 2 Empty 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

Back to top

- Similar topics

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