Jump to content

[1.7.2][Solved]Add hitbox to own fire


Hackbaellchen

Recommended Posts

Hey,

I wanted to create a fire.

That's my code:

 

 

package MyMod;

import java.util.Random;

import static net.minecraftforge.common.util.ForgeDirection.*;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class MyBlockFire extends Block
{
    @SideOnly(Side.CLIENT)
    private IIcon[] iconArray;

    public MyBlockFire()
    {
        super(Material.fire);
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.05F, 1.0F);
    }
    

    private boolean canNeighborBurn(World p_149847_1_, int p_149847_2_, int p_149847_3_, int p_149847_4_)
    {
    	return false;
    }

    public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
    {
        return null;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }
    
    public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
        if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && !this.canNeighborBurn(world, x, y, z))
        {
        	world.setBlockToAir(x, y, z);
        }
    }
    
    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z, Random rand)
    {
        if (rand.nextInt(24) == 0)
        {
            world.playSound((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), "fire.fire", 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
        }

        int l;
        float f;
        float f1;
        float f2;

        if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && !Blocks.fire.canCatchFire(world, x, y - 1, z, UP))
        {
            if (Blocks.fire.canCatchFire(world, x - 1, y, z, EAST))
            {
                for (l = 0; l < 2; ++l)
                {
                    f = (float)x + rand.nextFloat() * 0.1F;
                    f1 = (float)y + rand.nextFloat();
                    f2 = (float)z + rand.nextFloat();
                    world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
                }
            }

            if (Blocks.fire.canCatchFire(world, x + 1, y, z, WEST))
            {
                for (l = 0; l < 2; ++l)
                {
                    f = (float)(x + 1) - rand.nextFloat() * 0.1F;
                    f1 = (float)y + rand.nextFloat();
                    f2 = (float)z + rand.nextFloat();
                    world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
                }
            }

            if (Blocks.fire.canCatchFire(world, x, y, z - 1, SOUTH))
            {
                for (l = 0; l < 2; ++l)
                {
                    f = (float)x + rand.nextFloat();
                    f1 = (float)y + rand.nextFloat();
                    f2 = (float)z + rand.nextFloat() * 0.1F;
                    world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
                }
            }

            if (Blocks.fire.canCatchFire(world, x, y, z + 1, NORTH))
            {
                for (l = 0; l < 2; ++l)
                {
                    f = (float)x + rand.nextFloat();
                    f1 = (float)y + rand.nextFloat();
                    f2 = (float)(z + 1) - rand.nextFloat() * 0.1F;
                    world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
                }
            }

            if (Blocks.fire.canCatchFire(world, x, y + 1, z, DOWN))
            {
                for (l = 0; l < 2; ++l)
                {
                    f = (float)x + rand.nextFloat();
                    f1 = (float)(y + 1) - rand.nextFloat() * 0.1F;
                    f2 = (float)z + rand.nextFloat();
                    world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
                }
            }
        }
        else
        {
            for (l = 0; l < 3; ++l)
            {
                f = (float)x + rand.nextFloat();
                f1 = (float)y + rand.nextFloat() * 0.5F + 0.5F;
                f2 = (float)z + rand.nextFloat();
                world.spawnParticle("smoke", (double)f, (double)f1, (double)f2, 0.0D, 0.0D, 0.0D);
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.iconArray = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_layer_0"), p_149651_1_.registerIcon(this.getTextureName() + "_layer_1")};
    }

    @SideOnly(Side.CLIENT)
    public IIcon getFireIcon(int par1)
    {
        return this.iconArray[par1];
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        return this.iconArray[0];
    }
}

 

 

When I tried destroying it (without my hitbox code) it destroyed the block below. With the hitbox code (this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.05F, 1.0F)) it is not rendered as I want it to...

Thanks for help.  :)

Link to comment
Share on other sites

Add this to your block class

@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int posX, int posY, int posZ)
{
    return AxisAlignedBB.getAABBPool().getAABB(posX+0.0D, posY+0.0D, posZ+0.0D, posX+1.0D, posY+0.05D, posZ+1.0D);
}

Link to comment
Share on other sites

I mean with 'hitbox' the normal black borderd cube..

e.g.

2wn5hz4.jpg

 

I'm using getSelectedBoundingBoxFromPool is this wrong?

 

EDIT: If I now use getCollisionBoundingBoxFromPool and extend BlockFire there's still no hitbox

 

Code:

 

 

package MyMod;

import java.util.Random;

import static net.minecraftforge.common.util.ForgeDirection.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFire;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class  MyBlockFire extends BlockFire
{
    @SideOnly(Side.CLIENT)
    private IIcon[] iconArray;

    public MyBlockFire()
    {
        super();
        this.setLightLevel(1F);
    }
    
    //HITBOX
    @Override
    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int posX, int posY, int posZ)
    {
        return AxisAlignedBB.getAABBPool().getAABB(posX+0.0D, posY+0.0D, posZ+0.0D, posX+1.0D, posY+0.05D, posZ+1.0D);
    }

    private boolean canNeighborBurn(World world, int x, int y, int z)
    {
    	return false;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
    {
        if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && !this.canNeighborBurn(world, x, y, z))
        {
        	world.setBlockToAir(x, y, z);
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister par1IconRegister)
    {
    	this.iconArray = new IIcon[] {par1IconRegister.registerIcon(this.getTextureName() + "_layer_0"), par1IconRegister.registerIcon(this.getTextureName() + "_layer_1")};
    }

    @SideOnly(Side.CLIENT)
    public IIcon getFireIcon(int par1)
    {
        return this.iconArray[par1];
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        return this.iconArray[0];
    }
}

 

 

Link to comment
Share on other sites

I understood, but didn't know the correct name of the method..

 

    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int posX, int posY, int posZ)
    {
        return AxisAlignedBB.getAABBPool().getAABB(posX+0.0D, posY+0.0D, posZ+0.0D, posX+1.0D, posY+0.05D, posZ+1.0D);
    }

 

Thanks! All works fine.

Link to comment
Share on other sites

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.