[1.8.1] On/Off Light Block
+4
groxmapper
the undecided t
austin56101
Strengthowns
8 posters
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 2 of 2
Page 2 of 2 • 1, 2
[1.8.1] On/Off Light Block
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. 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.
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
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
Re: [1.8.1] On/Off Light Block
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
Re: [1.8.1] On/Off Light Block
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
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;
}
- 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- Member
- Posts : 18
Join date : 2011-10-23
Page 2 of 2 • 1, 2
Similar topics
» [1.8.1] Block
» How Do I Add A Block For 1.2.5
» [1.8.1] Advanced Block
» [1.8.1] Explosive Block
» [unsolved]furnace like block 1.8.1/1.0.0/1.1
» How Do I Add A Block For 1.2.5
» [1.8.1] Advanced Block
» [1.8.1] Explosive Block
» [unsolved]furnace like block 1.8.1/1.0.0/1.1
MC Modding :: Modding :: Singleplayer Modding :: Tutorials
Page 2 of 2
Permissions in this forum:
You cannot reply to topics in this forum