Jump to content

Recommended Posts

Posted

Hi there,

My Block doesn't make an Updatetick and i don't know why.

I'm a little bit confused, because it should work.

 

My Block Code is really huge, but i think the important lines are these:

public BlockRandom(int par1, int par2, String Texture, RandomBlock[] blocks, int renderIndex, int Typ)
    {
        super(par1, par2, Material.iron);
        this.setRequiresSelfNotify();
        this.setCreativeTab(RandomAdditions.RandomBlocks);
        this.setTickRandomly(true);
        this.Texture = Texture;
        this.blocks = blocks;
        this.renderIndex = renderIndex;
        this.Typ = Typ;
        
    }

public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    	RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).updateTick(par1World, par2, par3, par4, par5Random);
    }

BlockCode

 

package randomadditions;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;


import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Block;
import net.minecraft.src.BlockContainer;
import net.minecraft.src.ChunkCoordinates;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.DamageSource;
import net.minecraft.src.EffectRenderer;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.EntityDiggingFX;
import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.MathHelper;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.TileEntity;
import net.minecraft.src.TileEntityFurnace;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;

public class BlockRandom extends BlockContainer
{
public String Texture;
public RandomBlock[] blocks;
public int renderIndex;
public static int Metadata = -1;
public static int Typ; 

public BlockRandom(int par1, int par2, String Texture, RandomBlock[] blocks, int renderIndex, int Typ)
    {
        super(par1, par2, Material.iron);
        this.setRequiresSelfNotify();
        this.setCreativeTab(RandomAdditions.RandomBlocks);
        this.setTickRandomly(true);
        this.Texture = Texture;
        this.blocks = blocks;
        this.renderIndex = renderIndex;
        this.Typ = Typ;
        
    }

public int getDamageValue(World par1World, int par2, int par3, int par4)
    {
	 return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).blockID;
    }

private Random rand = new Random();
    
@SideOnly(Side.CLIENT)
    public boolean addBlockHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer)
    {
	int par1 = target.blockX;
	int par2 = target.blockY;
	int par3 = target.blockZ;
	int par4 = target.sideHit;
        float var7 = 0.1F;
        double var8 = (double)par1 + this.rand.nextDouble() * (this.getBlockBoundsMaxX() - this.getBlockBoundsMinX() - (double)(var7 * 2.0F)) + (double)var7 + this.getBlockBoundsMinX();
        double var10 = (double)par2 + this.rand.nextDouble() * (this.getBlockBoundsMaxY() - this.getBlockBoundsMinY() - (double)(var7 * 2.0F)) + (double)var7 + this.getBlockBoundsMinY();
        double var12 = (double)par3 + this.rand.nextDouble() * (this.getBlockBoundsMaxZ() - this.getBlockBoundsMinZ() - (double)(var7 * 2.0F)) + (double)var7 + this.getBlockBoundsMinZ();

        if (par4 == 0)
        {
            var10 = (double)par2 + this.getBlockBoundsMinY() - (double)var7;
        }

        if (par4 == 1)
        {
            var10 = (double)par2 + this.getBlockBoundsMaxY() + (double)var7;
        }

        if (par4 == 2)
        {
            var12 = (double)par3 + this.getBlockBoundsMinZ() - (double)var7;
        }

        if (par4 == 3)
        {
            var12 = (double)par3 + this.getBlockBoundsMaxZ() + (double)var7;
        }

        if (par4 == 4)
        {
            var8 = (double)par1 + this.getBlockBoundsMinX() - (double)var7;
        }

        if (par4 == 5)
        {
            var8 = (double)par1 + this.getBlockBoundsMaxX() + (double)var7;
        }
        effectRenderer.addEffect((new EntityDiggingFX(worldObj, var8, var10, var12, 0.0D, 0.0D, 0.0D, this, par4, RandomBlock.getRandomBlock(worldObj, par1, par2, par3, blocks).blockID)).func_70596_a(par1, par2, par3).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F), this);
        return true;
    }

@SideOnly(Side.CLIENT)
    public boolean addBlockDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer)
    {
	byte var7 = 4;

        for (int var8 = 0; var8 < var7; ++var8)
        {
            for (int var9 = 0; var9 < var7; ++var9)
            {
                for (int var10 = 0; var10 < var7; ++var10)
                {
                    double var11 = (double)x + ((double)var8 + 0.5D) / (double)var7;
                    double var13 = (double)y + ((double)var9 + 0.5D) / (double)var7;
                    double var15 = (double)z + ((double)var10 + 0.5D) / (double)var7;
                    int var17 = this.rand.nextInt(6);
                    effectRenderer.addEffect((new EntityDiggingFX(world, var11, var13, var15, var11 - (double)x - 0.5D, var13 - (double)y - 0.5D, var15 - (double)z - 0.5D, this, var17, RandomBlock.getRandomBlock(world, x, y, z, blocks).blockID)).func_70596_a(x, y, z), this);
                }
            }
        }
        return true;
    }

public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
    {
        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
        
        int count = quantityDropped(metadata, fortune, world.rand);
        for(int i = 0; i < count; i++)
        {
            int id = idDropped(metadata, world.rand, 0);
            if (id > 0)
            {
                ret.add(new ItemStack(id, 1, RandomBlock.getRandomBlock(world, x, y, z, blocks).blockID));
            }
        }
        return ret;
    }

    public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        return false;
    }
    
    public boolean isIndirectlyPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return RandomBlock.getRandomBlock(par1IBlockAccess, par2, par3, par4, blocks).isIndirectlyPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
    }

    public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).canProvidePower();
    }
    
    public int getLightOpacity(World world, int x, int y, int z)
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).getLightOpacity(world, x, y, z);
    }
    
public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return RandomBlock.getRandomBlock(par1IBlockAccess, par2, par3, par4, blocks).isPoweringTo(par1IBlockAccess, par2, par3, par4, par5);
    }

    public float getBlockHardness(World par1World, int par2, int par3, int par4)
    {
    	return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).Hardness;
    }
    
    public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
    	return RandomBlock.getRandomBlock(par1IBlockAccess, par2, par3, par4, blocks).solidCube;
    }
    
    public boolean isBlockNormalCube(World world, int x, int y, int z) 
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).solidCube;
    }
    
    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
    	return true;
    }
    
    public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ)
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).Resistance;
    }
    
    public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
    	return RandomBlock.getRandomBlock(par1IBlockAccess, par2, par3, par4, blocks).getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));
    }
    
    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving) {
    	RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLiving);
    }
    
    public boolean canPlaceTorchOnTop(World world, int x, int y, int z)
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).canPlaceTorchOnTop(world, x, y, z);
    }
    
    public int getBlockTextureFromSideAndMetadata(int par1, int par2) 
    {
    	return blocks[par2].getBlockTextureFromSideAndMetadata(par1, par2);  	
    }
    
    public boolean canHarvestBlock(EntityPlayer player, int meta) 
    {
    	return true;
    }
    
    public int tickRate()
    {
        return 20;
    }
    
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
    	return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
    }
    
    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
    	RandomBlock.getRandomBlock(par1IBlockAccess, par2, par3, par4, blocks).setBlockBoundsBasedOnState(par1IBlockAccess, par2, par3, par4, this);
    }
    
    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    {
        super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
        RandomBlock RandomBlocks = RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks);
    	this.dropXpOnBlockBreak(par1World, par2, par3, par4,RandomBlocks.getXP(par1World));
    }
    
    public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
    	return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
    }
    
    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
    	return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).canPlaceBlockAt(par1World, par2, par3, par4);
    }
    
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    	RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).updateTick(par1World, par2, par3, par4, par5Random);
    }
    
    
    public boolean isOpaqueCube()
    {
        return false;
    }
    
    public boolean renderAsNormalBlock()
    {
        return false;
    }
        
    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
    	return RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
    }
    

    @SideOnly(Side.CLIENT)
    public String getTextureFile()
    {
            return this.Texture;
    }
    
    @Override
public int damageDropped(int metadata)
    {
    	if(blocks[metadata].ItemDrop != null) return blocks[metadata].ItemDrop.getItemDamage();
    	else return metadata;
    }
    
    public int getRenderType()
    {
        return this.renderIndex;
    }
    
    public int idDropped(int par1, Random par2Random, int par3)
    {
    	if(blocks[par1].ItemDrop != null) return blocks[par1].ItemDrop.itemID;
    	else return this.blockID;
    }
    
    public int getLightValue(IBlockAccess world, int x, int y, int z) 
    {
    	return RandomBlock.getRandomBlock(world, x, y, z, blocks).getLightValue();
    }
    
    public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
    	RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).onEntityCollidedWithBlock(par1World, par2, par3, par4, par5Entity);
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
        for (int var4 = 0; var4 < blocks.length; ++var4)
        {
        	if(blocks[var4] != null) par3List.add(new ItemStack(par1, 1, blocks[var4].blockID));
        }
    }
    
    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {	
    	RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).randomDisplayTick(par1World, par2, par3, par4, par5Random);
    }

public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
    }

    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        super.breakBlock(par1World, par2, par3, par4, par5, par6);
        RandomBlock.getRandomBlock(par1World, par2, par3, par4, blocks).breakBlock(par1World, par2, par3, par4, par5, par6);
    }
    
    public TileEntity createNewTileEntity(World world, int metadata)
    {
        return new TileEntityRandomBlock();
    }
    
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    {
	par2--;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);
	par2 += 2;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);
	par3--;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);
	par3 += 2;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);
	par4--;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);
	par4 += 2;
	if(checkBlock(par1World, par2, par3, par4))RandomBlock.getRandomBlock(par1World, par2, par3, par5, blocks).onNeighborBlockChange(par1World, par2, par3, par4, par5);



    }

public boolean checkBlock(World par1World, int par2, int par3, int par4)
{
	return par1World.getBlockId(par2, par3, par4) == RandomAdditions.BlockRandomId | par1World.getBlockId(par2, par3, par4) == RandomAdditions.BlockRandomId;
}

@Override
public TileEntity createNewTileEntity(World var1) {
	return new TileEntityRandomBlock();
}
}

 

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.