Jump to content

Recommended Posts

Posted

Hey,

 

I'm currently working a mod so that I can learn how to program using the forge API first hand, so far it's been going smoothly, I've been following various tutorials to see how they do their coding and then coded it my own way using the ideas I got from others.

 

Now at the moment I am developing my first block, nothing to advance just a basic block which changes texture when a redstone signal has been applied to it. Now this is where I've hit my first bump because I have no clue how to work with redstone or most other stuff, right now I know how to create Blocks, Items, Tools & creative tabs. I learnt all this in two days so yeah, I'm really rusty.

 

mod_Main code:

	public static Block StatusLight = new statuslight(596, Material.glass, "StatusLightRed").setHardness(1.0f).setLightValue(5.0f).setUnlocalizedName("Status Light");

 

Status light Code:

package com.omegacraft;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;

public class statuslight extends Block {

	private String blocktexture;

public statuslight(int par1, Material par2Material, String par3String) {
	super(par1, par2Material);

	this.blocktexture = par3String;
}

@SideOnly(Side.CLIENT)
public void func_94332_a(IconRegister Par1Iconregister){
	this.field_94336_cN = Par1Iconregister.func_94245_a("OmegaCraft/" + this.blocktexture);
}

}

 

Now I had a look though the coding for redstone and here's the code that I thought up, all of it is guessed. But I know I have to return the value that the block must be able to connect to redstone.

 

	public boolean wiresProvidePower() {
	return blockConstructorCalled;
} if WiresPower() = 1 {
}

 

Any help would be hugely appreciated.

 

(P.S Has anyone noticed what adding code to a post does to the body of the thread?)

Posted

Got it working, Firstly I called the redstone powered function and then did an if statement to get the textures set up. Next I did two functions where it contently checks if there is a red stone signal near by. If not it calls the Off block and if there is it calls the on block, I found out how to do it by looking at the redstone lamp.

Posted

Sure:

 

Main code:

public static Block Lightred = (new statuslight(900, false)).setHardness(3.0f).setLightValue(1.0f).setUnlocalizedName("Light");

public static Block Lightgreen = (new statuslight(901, true)).setHardness(3.0f).setLightValue(1.0f).setUnlocalizedName("Light");

 

Code for the light:

 

package com.name;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.world.World;

public class light extends Block {

	private boolean powered;
	private String blocktexture;

public light(int par1, boolean par2) {
        super(par1, Material.redstoneLight);
        this.powered = par2;

        if (par2)
        {
            this.setLightValue(1.0F);
        }
}

@SideOnly(Side.CLIENT)
public void func_94332_a(IconRegister Par1Iconregister){

	if(this.powered){
		this.field_94336_cN = Par1Iconregister.func_94245_a("OmegaCraft/");
	} else {
		this.field_94336_cN = Par1Iconregister.func_94245_a("OmegaCraft/RedLight");
	}
}

    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        if (!par1World.isRemote)
        {
            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlockAndMetadataWithNotify(par2, par3, par4, mod_name.Lightgreen.blockID, 0, 2);
            }
        }
    }

    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    {
        if (!par1World.isRemote)
        {
            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlockAndMetadataWithNotify(par2, par3, par4, mod_name.Lightgreen.blockID, 0, 2);
            }
        }
    }
    
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (!par1World.isRemote && this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
        {
            par1World.setBlockAndMetadataWithNotify(par2, par3, par4, mod_name.Lightred.blockID, 0, 2);
        }
    }

    public int idDropped(int par1, Random par2Random, int par3)
    {
        return mod_nameLightred.blockID;
    }
    
    @SideOnly(Side.CLIENT)
    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return mod_name.Lightred.blockID;
    }
}

 

If you use this code please give me some credit, as it would be largely appreciated.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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