MC Modding
Please register and join the community!

[1.8.1] On/Off Light Block

Page 1 of 2 1, 2  Next

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

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 austin56101 on Mon Oct 24, 2011 9:26 am

Just wanted to let you know it works with 1.8.1
Also can you code It to preform a strobe action?
Like on this block you can set it up on a clock and it wors
But I want a code versIon if possible?
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by Strengthowns on Tue Oct 25, 2011 1:33 am

I have never done this before but, if you maybe set up a tick rate and update the light to be on or off every tick, it might work.
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 austin56101 on Tue Oct 25, 2011 2:11 am

o well do you mind trying it?
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by the undecided t on Tue Oct 25, 2011 3:01 am

ill try to... that would be awesome
avatar
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 21

View user profile http://www.blacklistgaming.org/forums

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by groxmapper on Tue Oct 25, 2011 3:13 am

I've done it, but you need to really spam a redstone tick clock(if you use stranegth's code) or (what I also added) is make it swap on right click, then spam that. (somehow it's spamproof - never broke once) you also need to make sure the setrequiresselfnotify thing is used, otherwise the light doesn't update that quickly.

I thought I was the only one to make something like this, but I should've known stength knows all Razz


Last edited by groxmapper on Tue Oct 25, 2011 3:14 am; edited 1 time in total
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by breakyorself on Tue Oct 25, 2011 3:13 am

Might lagg/crash a majority of people using it.
avatar
breakyorself
Member

Posts : 60
Join date : 2011-10-19

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by groxmapper on Tue Oct 25, 2011 3:15 am

breakyorself wrote:Might lagg/crash a majority of people using it.

Actually it doesn't cause any sort of crash, the amount of updates will lag yes but only if your using an ungodly amount of the lgiht blocks.
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 3:25 am

groxmapper wrote:
breakyorself wrote:Might lagg/crash a majority of people using it.

Actually it doesn't cause any sort of crash, the amount of updates will lag yes but only if your using an ungodly amount of the lgiht blocks.

you mind making a tut?
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by the undecided t on Tue Oct 25, 2011 4:25 am

i was gonna try coding where it stays powered but the light spams on and off
avatar
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 21

View user profile http://www.blacklistgaming.org/forums

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 5:01 am

im still not very good at ticks ect..
:/
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by the undecided t on Tue Oct 25, 2011 7:33 am

i tried doing it like so:
Spoiler:
Code:
package net.minecraft.src;

import java.util.Random;

public class Blockstrobe extends Block
{
    public Blockstrobe(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_test.strobeOff.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        { boolean flag = false;
           while (flag = false) {
            world.setBlockWithNotify(i, j, k, mod_test.strobeOn.blockID);
            try {
            Thread.sleep(900);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
        assert !flag; }
           while (flag = true) {
                 world.setBlockWithNotify(i, j, k, mod_test.strobeOff.blockID);
                    try {
                    Thread.sleep(900);
                 } catch (InterruptedException e) {
                    e.printStackTrace();
                 }
           }
        }
        else
        {
            world.setBlockWithNotify(i, j, k, mod_test.strobeOff.blockID);
        }
    }

    private boolean isActive;
}
but it freezes mc
avatar
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 21

View user profile http://www.blacklistgaming.org/forums

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 7:37 am

Code:
 public void updateTick(World world, int i, int j, int k, Random random)
    {
        boolean flag = func_30002_h(world, i, j, k);
        for(; torchUpdates.size() > 0 && world.getWorldTime() - ((RedstoneUpdateInfo)torchUpdates.get(0)).updateTime > 100L; torchUpdates.remove(0)) { }
        if(torchActive)
        {
            if(flag)
            {
                world.setBlockAndMetadataWithNotify(i, j, k, Block.torchRedstoneIdle.blockID, world.getBlockMetadata(i, j, k));
                if(checkForBurnout(world, i, j, k, true))
                {
                    world.playSoundEffect((float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
                    for(int l = 0; l < 5; l++)
                    {
                        double d = (double)i + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
                        double d1 = (double)j + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
                        double d2 = (double)k + random.nextDouble() * 0.59999999999999998D + 0.20000000000000001D;
                        world.spawnParticle("smoke", d, d1, d2, 0.0D, 0.0D, 0.0D);
                    }

                }
            }
        }


cant you edit this somehow?
and place the isActive right now
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by Strengthowns on Tue Oct 25, 2011 8:42 am

Please post this sort of stuff in the help section.
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 austin56101 on Tue Oct 25, 2011 4:58 pm

O well also you can change title to [1.8.1]
It still works lol
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Tue Oct 25, 2011 6:14 pm

the undecided t wrote:i tried doing it like so:
Spoiler:
Code:
package net.minecraft.src;

import java.util.Random;

public class Blockstrobe extends Block
{
    public Blockstrobe(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_test.strobeOff.blockID;
    }

    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        if(world.isBlockIndirectlyGettingPowered(i, j, k))
        { boolean flag = false;
           while (flag = false) {
            world.setBlockWithNotify(i, j, k, mod_test.strobeOn.blockID);
            try {
            Thread.sleep(900);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
        assert !flag; }
           while (flag = true) {
                 world.setBlockWithNotify(i, j, k, mod_test.strobeOff.blockID);
                    try {
                    Thread.sleep(900);
                 } catch (InterruptedException e) {
                    e.printStackTrace();
                 }
           }
        }
        else
        {
            world.setBlockWithNotify(i, j, k, mod_test.strobeOff.blockID);
        }
    }

    private boolean isActive;
}
but it freezes mc
that will crash due to the fact being youve not only set an strobe BUt no time in between and seeing how its done it gets more laggy and seeing how fast things process you would see why this would be an issue

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 6:32 pm

Maybe a slower one? Very Happy
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Tue Oct 25, 2011 6:42 pm

yer but he needs to include an integer that is a pause maybe doing something like
Code:
if redcurrent = true { for(i=0,i++)  while (i>10) pause [amount of time] i=0
or whatever you want it to be I am a novice in java. you could take out the for bit but that would not allow time for the reset in the strobe

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Tue Oct 25, 2011 6:42 pm

I would to be honest just set up a redstone clock

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 8:55 pm

Well you can do a working strobe using this code
But I was talking about a coded strobe
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Tue Oct 25, 2011 9:15 pm

I see you could try using the forif( and then pausetime

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by austin56101 on Tue Oct 25, 2011 9:30 pm

Well there is the like.. Grrrr forgot the mod name but it's released on the minecraft forums and it a huge mod were u can auto mine with pipes
And there's oil
Anyway the pipes in that mod perform a glowing strobish action
avatar
austin56101
Moderator
Moderator

Posts : 85
Join date : 2011-10-22
Age : 20
Location : Cali!

View user profile

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Tue Oct 25, 2011 9:39 pm

thats buildcraft

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by the undecided t on Wed Oct 26, 2011 3:58 am

... i included sleep... is that not right?
avatar
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 21

View user profile http://www.blacklistgaming.org/forums

Back to top Go down

Re: [1.8.1] On/Off Light Block

Post by lcass on Thu Oct 27, 2011 4:49 pm

how would I do this the other way Eg if I put fuel in lets say a super furnace that it would activate some redstone

lcass
Member

Posts : 145
Join date : 2011-10-24
Location : england

View user profile http://www.youtube.com/user/thealcasgroup

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 1 of 2 1, 2  Next

View previous topic View next topic Back to top


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