Jump to content

Recommended Posts

Posted

Hey guys,

I've a problem with my mod:

I've addet a leaves block to the game. If I place the block , I can see through it. If I place another block behind the leaves block, I can see him through the leaves block. But If I place a leaves block behind the leaves block, I can't see the leaves block through the leaves block. :( Can you help me?

 

Here's my class :

package de.LegendPlayz.AlchemyExchange;

 

import java.util.ArrayList;

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.BlockLeavesBase;

import net.minecraft.block.material.Material;

import net.minecraft.block.BlockLeaves;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.IShearable;

import net.minecraft.block.BlockLeaves;

 

 

public class BlockWaterInvolvedLeaves extends BlockLeavesBase implements IShearable{

int[] field_150128_a;

    @SideOnly(Side.CLIENT)

    protected int field_150127_b;

    protected IIcon[][] field_150129_M = new IIcon[2][];

private boolean field_150121_P;

    private static final String __OBFID = "CL_00000263";

public BlockWaterInvolvedLeaves(Material p_i45394_1_) {

super(Material.leaves, false);

        this.setTickRandomly(true);

        this.setCreativeTab(CreativeTabs.tabDecorations);

        this.setHardness(0.2F);

        this.setLightOpacity(1);

        this.setStepSound(soundTypeGrass);

String blockid = CurrentMainClass.MODID + ":" + this.getClass().getName();

this.setBlockName(blockid);

this.setBlockTextureName(CurrentMainClass.MODID + ":"+ "waterinvolved_planks");

this.setCreativeTab(CurrentMainClass.tabAlchemyExchange);

}

 

@Override

public boolean isOpaqueCube()

{

//TODO:   isOpaqueCube()

return Blocks.leaves.isOpaqueCube();

//;

}

 

@Override

public boolean renderAsNormalBlock()

{

return false;

}

 

@SideOnly(Side.CLIENT)

public int aaA;

@SideOnly(Side.CLIENT)

    public  IIcon getIcon(int side, int metadata) {

 

for (int i = 0; i < 2; ++i)

{

aaA = i;

 

}

return field_150129_M[(!isOpaqueCube() ? 0 : 1)] [aaA];

}

 

@SideOnly(Side.CLIENT)

    public void setGraphicsLevel(boolean p_150122_1_)

    {

        this.field_150121_P = p_150122_1_;

        this.field_150127_b = p_150122_1_ ? 0 : 1;

    }

 

public void registerBlockIcons(IIconRegister iconRegister)

    {

field_150129_M = new IIcon[2][2];

for (int i = 0; i < 2; ++i)

{

field_150129_M[0] = iconRegister.registerIcon(CurrentMainClass.MODID + ":" + "waterinvolved_leaves");

field_150129_M[1] = iconRegister.registerIcon(CurrentMainClass.MODID + ":" + "waterinvolved_leaves_opaque");

}

    }

 

 

@Override

public boolean isShearable(ItemStack item, IBlockAccess world, int x,

int y, int z) {

// TODO Auto-generated method stub

return false;

}

 

 

@Override

public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world,

int x, int y, int z, int fortune) {

// TODO Auto-generated method stub

return null;

}

 

public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)

    {

        byte b0 = 1;

        int i1 = b0 + 1;

 

        if (p_149749_1_.checkChunksExist(p_149749_2_ - i1, p_149749_3_ - i1, p_149749_4_ - i1, p_149749_2_ + i1, p_149749_3_ + i1, p_149749_4_ + i1))

        {

            for (int j1 = -b0; j1 <= b0; ++j1)

            {

                for (int k1 = -b0; k1 <= b0; ++k1)

                {

                    for (int l1 = -b0; l1 <= b0; ++l1)

                    {

                        Block block = p_149749_1_.getBlock(p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);

                        if (block.isLeaves(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1))

                        {

                            block.beginLeavesDecay(p_149749_1_, p_149749_2_ + j1, p_149749_3_ + k1, p_149749_4_ + l1);

                        }

                    }

                }

            }

        }

    }

 

public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)

    {

        if (!p_149674_1_.isRemote)

        {

            int l = p_149674_1_.getBlockMetadata(p_149674_2_, p_149674_3_, p_149674_4_);

 

            if ((l & 8) != 0 && (l & 4) == 0)

            {

                byte b0 = 4;

                int i1 = b0 + 1;

                byte b1 = 32;

                int j1 = b1 * b1;

                int k1 = b1 / 2;

 

                if (this.field_150128_a == null)

                {

                    this.field_150128_a = new int[b1 * b1 * b1];

                }

 

                int l1;

 

                if (p_149674_1_.checkChunksExist(p_149674_2_ - i1, p_149674_3_ - i1, p_149674_4_ - i1, p_149674_2_ + i1, p_149674_3_ + i1, p_149674_4_ + i1))

                {

                    int i2;

                    int j2;

 

                    for (l1 = -b0; l1 <= b0; ++l1)

                    {

                        for (i2 = -b0; i2 <= b0; ++i2)

                        {

                            for (j2 = -b0; j2 <= b0; ++j2)

                            {

                                Block block = p_149674_1_.getBlock(p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2);

 

                                if (!block.canSustainLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))

                                {

                                    if (block.isLeaves(p_149674_1_, p_149674_2_ + l1, p_149674_3_ + i2, p_149674_4_ + j2))

                                    {

                                        this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;

                                    }

                                    else

                                    {

                                        this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;

                                    }

                                }

                                else

                                {

                                    this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;

                                }

                            }

                        }

                    }

 

                    for (l1 = 1; l1 <= 4; ++l1)

                    {

                        for (i2 = -b0; i2 <= b0; ++i2)

                        {

                            for (j2 = -b0; j2 <= b0; ++j2)

                            {

                                for (int k2 = -b0; k2 <= b0; ++k2)

                                {

                                    if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1)

                                    {

                                        if (this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;

                                        }

 

                                        if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2)

                                        {

                                            this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

 

                l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1];

 

                if (l1 >= 0)

                {

                    p_149674_1_.setBlockMetadataWithNotify(p_149674_2_, p_149674_3_, p_149674_4_, l & -9, 4);

                }

                else

                {

                    this.removeLeaves(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_);

                }

            }

        }

    }

@SideOnly(Side.CLIENT)

    public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)

    {

        if (p_149734_1_.canLightningStrikeAt(p_149734_2_, p_149734_3_ + 1, p_149734_4_) && !World.doesBlockHaveSolidTopSurface(p_149734_1_, p_149734_2_, p_149734_3_ - 1, p_149734_4_) && p_149734_5_.nextInt(15) == 1)

        {

            double d0 = (double)((float)p_149734_2_ + p_149734_5_.nextFloat());

            double d1 = (double)p_149734_3_ - 0.05D;

            double d2 = (double)((float)p_149734_4_ + p_149734_5_.nextFloat());

            p_149734_1_.spawnParticle("dripWater", d0, d1, d2, 0.0D, 0.0D, 0.0D);

        }

    }

 

    private void removeLeaves(World p_150126_1_, int p_150126_2_, int p_150126_3_, int p_150126_4_)

    {

        this.dropBlockAsItem(p_150126_1_, p_150126_2_, p_150126_3_, p_150126_4_, p_150126_1_.getBlockMetadata(p_150126_2_, p_150126_3_, p_150126_4_), 0);

        p_150126_1_.setBlockToAir(p_150126_2_, p_150126_3_, p_150126_4_);

    }

 

    /**

    * Returns the quantity of items to drop on block destruction.

    */

    public int quantityDropped(Random p_149745_1_)

    {

        return p_149745_1_.nextInt(20) == 0 ? 1 : 0;

    }

 

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return Item.getItemFromBlock(Blocks.sapling);

    }

 

    /**

    * Drops the block items with a specified chance of dropping the specified items

    */

    public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)

    {

        super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, 1.0f, p_149690_7_);

    }

 

    protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_) {}

 

    protected int func_150123_b(int p_150123_1_)

    {

        return 20;

    }

    public void harvestBlock(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)

    {

        {

            super.harvestBlock(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);

        }

    }

 

    /**

    * Determines the damage on the item the block drops. Used in cloth and wood.

    */

    public int damageDropped(int p_149692_1_)

    {

        return p_149692_1_ & 3;

    }

 

    /**

    * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two

    * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.

    */

   

    protected ItemStack createStackedBlock(int p_149644_1_)

    {

        return new ItemStack(Item.getItemFromBlock(this), 1, p_149644_1_ & 3);

    }

    @Override

    public void beginLeavesDecay(World world, int x, int y, int z)

    {

 

        int i2 = world.getBlockMetadata(x, y, z);

 

        if ((i2 & 8) == 0)

        {

            world.setBlockMetadataWithNotify(x, y, z, i2 | 8, 4);

        }

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, 4);

    }

 

    @Override

    public boolean isLeaves(IBlockAccess world, int x, int y, int z)

    {

        return true;

    }

 

 

    @Override

    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)

    {

        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

        int chance = this.func_150123_b(metadata);

 

        if (fortune > 0)

        {

            chance -= 2 << fortune;

            if (chance < 10) chance = 10;

        }

 

        if (world.rand.nextInt(chance) == 0)

            ret.add(new ItemStack(this.getItemDropped(metadata, world.rand, fortune), 1, this.damageDropped(metadata)));

 

        chance = 200;

        if (fortune > 0)

        {

            chance -= 10 << fortune;

            if (chance < 40) chance = 40;

        }

 

        this.captureDrops(true);

        this.func_150124_c(world, x, y, z, metadata, chance); // Dammet mojang

        ret.addAll(this.captureDrops(false));

        return ret;

    }

 

 

/* {

;

}*/

 

}

Posted

Please use the [ code ] tags (without the spaces) to make it easier to read.

 

Now there are a few things I don't get here:

 

@SideOnly(Side.CLIENT)
public int aaA;
@SideOnly(Side.CLIENT)
public  IIcon getIcon(int side, int metadata) {
      
      for (int i = 0; i < 2; ++i)
      {
         aaA = i;
         
      }
      return field_150129_M[(!isOpaqueCube() ? 0 : 1)] [aaA];
}

 

Is identical to

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
    return field_150129_M[0][1];
}

 

 

Next:

public void registerBlockIcons(IIconRegister iconRegister)
{
    field_150129_M = new IIcon[2][2];
    for (int i = 0; i < 2; ++i)
    {
        field_150129_M[0] = iconRegister.registerIcon(CurrentMainClass.MODID + ":" + "waterinvolved_leaves");
        field_150129_M[1] = iconRegister.registerIcon(CurrentMainClass.MODID + ":" + "waterinvolved_leaves_opaque");
     }
}

What does this for-loop even do? You're instantiating indexes 0 an 1 in your array twice to the exact same thing.

Apart from that field_150129_M is an IIcon[][] (double array). So field_150129_M[0] and field_150129_M[1] are actually arrays themselves.

 

These things might be the cause of your problems, though I don't know.

 

I also suggest cleaning up all of your local variables and renaming to readable things (p_SOMENUMBER_SOMELETTER is not understandable, and very hard to debug).

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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.