Posted May 12, 201411 yr 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.
May 12, 201411 yr 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); }
May 17, 201411 yr Author Doesn't work. And if I set the renderType to 3 without extending it'll crash.
May 17, 201411 yr Author I mean with 'hitbox' the normal black borderd cube.. e.g. 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]; } }
May 17, 201411 yr Author That works good, but now it has a full block hitbox.. I just wanted a really small at the ground
May 17, 201411 yr Author 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.
May 17, 201411 yr Author If I now destroy the block it'll play the sound when breaking stone. I know that I can change the sounds with setStepSound but there isn't something like there is for the fire.
May 18, 201411 yr Author this.playAuxSFXAtEntity(player, 1004, x, y, z, 0); The method is unknown.. and World.playAuxSFXAtEntity won't work..
May 18, 201411 yr Author public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { World.playAuxSFXAtEntity(player, 1004, x, y, z, 0); }
May 18, 201411 yr Author So, what to do? EDIT: public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { world.playAuxSFXAtEntity(player, 1004, x, y, z, 0); }
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.