ZidMC
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Unanswered]Change block state depend on neighbor blocks

2 posters

Go down

[Unanswered]Change block state depend on neighbor blocks Empty [Unanswered]Change block state depend on neighbor blocks

Post by Will.Ez Fri Apr 29, 2011 8:59 pm

I want my pole to be facing upward or side-ward(not upward/downward, i cant find the word) depending on it's nearby blocks if they're not air, here's my code
Code:
package net.minecraft.src;

public class BlockPole extends Block
{

    public BlockPole(int i, int j)
    {
        super(i, j, Material.wood);
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public void onBlockPlacedBy(World world, int i, int j, int k,EntityLiving entityliving)
    {
 
        if(world.getBlockId(i+1, j, k) != 0){
    mod_Modern.Pole.setBlockBounds(0.0F, 0.3F, 0.3F, 1.0F, 0.7F, 0.7F);}
   
        if(world.getBlockId(i-1, j, k) != 0){
    setBlockBounds(0.0F, 0.3F, 0.3F, 1.0F, 0.7F, 0.7F);}
   
        if(world.getBlockId(i, j-1, k) != 0){
    setBlockBounds(0.3F, 0.0F, 0.3F, 0.7F, 1F, 0.7F);}
   
        if(world.getBlockId(i, j, k+1) != 0){
    setBlockBounds(0.3F, 0.3F, 0.0F, 0.7F, 0.7F, 1F);}
   
        if(world.getBlockId(i, j, k-1) != 0){
    setBlockBounds(0.3F, 0.3F, 0.0F, 0.7F, 0.7F, 1F);}
    }

}

i tried
Code:
onBlockAdded
instead of
Code:
onBlockPlacedBy
it's still the same.
And here's what i mean by saying "the same"
First i place a pole, in every direction it works fine, from upward pole to non-upward pole
[Unanswered]Change block state depend on neighbor blocks Unled2ko[Unanswered]Change block state depend on neighbor blocks Unled3y[Unanswered]Change block state depend on neighbor blocks Unledgr

OK then here goes the problem, got 2 poles placed
[Unanswered]Change block state depend on neighbor blocks Unled4b
Place another pole with different direction somewhere near but not touching those 2 pole
Then bam
[Unanswered]Change block state depend on neighbor blocks Unled5gw

Can any1 help me? When the pole is finished, i'll release my first mod Very Happy
Will.Ez
Will.Ez
Iron Miner

Posts : 52
Join date : 2011-04-22
Age : 27

Back to top Go down

[Unanswered]Change block state depend on neighbor blocks Empty Re: [Unanswered]Change block state depend on neighbor blocks

Post by Byronyello Sat Apr 30, 2011 10:44 am

Code:
package net.minecraft.src;

public class BlockPole extends Block
{

    public BlockPole(int i, int j)
    {
        super(i, j, Material.wood);
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public void onBlockPlacedBy(World world, int i, int j, int k,EntityLiving entityliving)
    {
 
        if(world.getBlockId(i+1, j, k) != 0){
    mod_Modern.Pole.setBlockBounds(0.0F, 0.3F, 0.3F, 1.0F, 0.7F, 0.7F);
    System.println.out("I+1 Switch called!")
    }
 
        if(world.getBlockId(i-1, j, k) != 0)
      {
    setBlockBounds(0.0F, 0.3F, 0.3F, 1.0F, 0.7F, 0.7F);
    System.println.out("I-1 Switch called!")
}
 
        if(world.getBlockId(i, j-1, k) != 0){
    setBlockBounds(0.3F, 0.0F, 0.3F, 0.7F, 1F, 0.7F);
    System.println.out("J-1 Switch called!")
}
 
        if(world.getBlockId(i, j, k+1) != 0){
    setBlockBounds(0.3F, 0.3F, 0.0F, 0.7F, 0.7F, 1F);
    System.println.out("K+1 Switch called!")
}
 
        if(world.getBlockId(i, j, k-1) != 0){
    setBlockBounds(0.3F, 0.3F, 0.0F, 0.7F, 0.7F, 1F);
    System.println.out("K-1 Switch called!")
}
    }

}

Do that, and see which bit of code is moaning, then edit that part of the code.
Byronyello
Byronyello
Iron Miner

Posts : 28
Join date : 2011-04-27
Age : 27
Location : Keighley, West Yorkshire, England!

http://byronyello.newgrounds.com

Back to top Go down

Back to top

- Similar topics

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