Jump to content

[MC 1.10.2] Extended TNT block does not blow up when fire destroys it.


Komodo2013

Recommended Posts

I have a block which extends TNT and is working perfectly except that when fire burns it, it does not explode. I believe that I see the solution, adding my block to a specific if statement within the Fire class.

Is this the only way to make it so when fire destroys this block, then it Ignites? If so, how would one go about overriding this code?

-note: I am just using the standard lit TNT entity, with 0 fuse time, to make the explosion, and am happy to leave it as such.

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

Okey so I am trying to understand your question, but the only issue i can see from what you are asking is that you haven't:

public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face){

        return net.minecraft.init.Blocks.FIRE.getFlammability(this);

}

used this method in your TNT class, correct me if i'm wrong, but this is a forge hook that, does the job of what the init() method in the fire class does. Looking into 1.10.2 code shows that the TNT should just run the proper code on block deletion, thus the only issue I see in your TNT block is that it is not TNT, thus you must register it so that it can burn just like the regular TNT block, check the forge hooks like the above stated one in the Block class. Also, for future reference, it is much appreciated if you would post your code, though I think i grasped your question, if not, tell me.

Link to comment
Share on other sites

Sorry I wasn't clear... The block burns just fine... Just doesn't blow up once fire consumes it. I tried that bit of code, and nothing changed (also its deprecated).  Sorry, here's my code for said block:

public class GunpowderBlock extends BlockTNT {

 

protected String name;

 

public GunpowderBlock(String name, Block BlockIn, Material material, float hardness, float resistance, int harvest, String tool) {

super();

 

this.name = name;

 

setUnlocalizedName(name);

setRegistryName(name);

setHardness(hardness);

setResistance(resistance);

setHarvestLevel(tool, harvest);

setSoundType(SoundType.SAND);

}

 

public int getFlammablility(IBlockAccess world, BlockPos pos, EnumFacing face) {

return net.minecraft.init.Blocks.FIRE.getFlammability(this);

}

 

public void registerItemModel(ItemBlock itemBlock) {

BettermentsMod.proxy.registerItemRenderer(itemBlock, 0, name);

}

 

@Override

public GunpowderBlock setCreativeTab(CreativeTabs tab) {

super.setCreativeTab(tab);

return this;

}

 

@Override

    public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)

    {

        if (!worldIn.isRemote)

        {

            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());

            entitytntprimed.setFuse((short)(0));

            worldIn.spawnEntityInWorld(entitytntprimed);

        }

    }

 

@Override

    public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)

    {

        if (!worldIn.isRemote)

        {

            if (((Boolean)state.getValue(EXPLODE)).booleanValue())

            {

                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), igniter);

                entitytntprimed.setFuse((short)(0));

                worldIn.spawnEntityInWorld(entitytntprimed);

                worldIn.playSound((EntityPlayer)null, entitytntprimed.posX, entitytntprimed.posY, entitytntprimed.posZ, SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);

            }

        }

    }

 

@Override

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

    {

        if (heldItem != null && (heldItem.getItem() == Items.FLINT_AND_STEEL || heldItem.getItem() == Items.FIRE_CHARGE))

        {

            this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);

            worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);

 

            if (heldItem.getItem() == Items.FLINT_AND_STEEL)

            {

                heldItem.damageItem(0, playerIn);

            }

            else if (!playerIn.capabilities.isCreativeMode)

            {

                --heldItem.stackSize;

            }

 

            return true;

        }

        else

        {

            return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);

        }

    }

 

}

 

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

I'm afraid i have been working on this a bit and also looking at others and how they might have solved this, but there doesn't seem to be a good answer that i can give. The only thing I can advise now is to try using an update tick, like from the block class or a tile entity (though  a tile entity would be a waste), or just bump this question till someone with an answer can help you, sorry.

 

Link to comment
Share on other sites

Thanks, but I'm having trouble looking for a tutorial on how to replace a vanilla block/Item with my own block, that isn't for MC 1.7.10 or earlier. If you know of such a tutorial, I would greatly appreciate a link to it!

Additionally, core modding doesn't much appeal to me... but if that is the only solution, as it seems there isn't an easy way of doing this, then I am happy to give it a try...

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

You could try to override the getFlammability method. It wouldn't be perfect, but you could randomly explode when your block's getFlammability is checked. Sometimes it will, and sometimes it will be consumed before it can. You could even return zero (never catches vanilla fire), reserving all randomness to your own explosion. That might even mimic TNT correctly.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

You could try to override the getFlammability method. It wouldn't be perfect, but you could randomly explode when your block's getFlammability is checked. Sometimes it will, and sometimes it will be consumed before it can. You could even return zero (never catches vanilla fire), reserving all randomness to your own explosion. That might even mimic TNT correctly.

I've tried that already... It seems to do nothing. Unless you are referencing overriding some function, as getFlammablility cannot be overridden (TNT doesn't use it).

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

It looked like BlockFire called getFlammability on its way to spreading fire to its neighbors. A little bit after the call, it applied randomeness, and if spread, it would see if the neighbor was TNT and blow it up. Why can't you override getFlammability to hijack the decision process and blow up on your own terms?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

You could also override getFlammability, isFlammable, or getFireSpreadSpeed (each called when the fire attempts to spread to that block, at some point) and spawn your lit entity or explosion.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You could also override getFlammability, isFlammable, or getFireSpreadSpeed (each called when the fire attempts to spread to that block, at some point) and spawn your lit entity or explosion.

Yeah, that's pretty much what I was saying at 07:35.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

In order to override that function, I need to create my own fire block (probably just copy, paste, and edit vanilla fire), right? But this block would then need to replace every instance of vanilla fire, both generated and placed. Does this require using ASM to inject the code, or is there a way to cause vanilla fire to reference my fire?

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

No. You override those methods on your TNT block so that when one of them is called you make it explode.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

No. You override those methods on your TNT block so that when one of them is called you make it explode.

I can't override functions that aren't contained in the parent class. TNT does not use any of the functions getFlammability, isFlammable, or getFireSpreadSpeed. Fire does. I did try creating a getFlammability and isFlammable functions, within my TNT block, and they do nothing, because they are not even being called.

Since I'm obviously not understanding this, is it possible to see an example?

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

The TNT Block extends the Block class, so you will be able to override the methods from the Block class which are not overridden in the TNT Block.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

The TNT Block extends the Block class, so you will be able to override the methods from the Block class which are not overridden in the TNT Block.

Thank you! That helps. I've overriden those functions, but have encountered another issue...

I don't see a way to either set its EXPLODE boolean to true, or to create the explosion. I need the World in order to create an explosion.

Obviously I forgot that tnt extended block, is there something else I'm missing?

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

All three of the methods I mentioned pass a World and BlockPos arguments.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

All three of the methods I mentioned pass a World and BlockPos arguments.

They pass type "IBlockAccess", not type "World".

*NVM just casted IBlockAccess to World and it worked perfectly. It now explodes when on fire!

*Here's the code that is working:

public class GunpowderBarrel extends BlockTNT {

protected String name;

public GunpowderBarrel(String name, Block BlockIn, Material material, float hardness, float resistance, int harvest, String tool) {
	super();

	this.name = name;

	setUnlocalizedName(name);
	setRegistryName(name);
	setHardness(hardness);
	setResistance(resistance);
	setHarvestLevel(tool, harvest);
	setSoundType(SoundType.WOOD);
}

@Override
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
    {
        if (worldIn.isBlockPowered(pos))
        {
        	this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
            worldIn.setBlockToAir(pos);
        }
    }
@Override
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face){
	this.onBlockDestroyedByExplosion((World) world, pos, null);
	System.out.println("getFlammability overriden");
        return 300;
    }
@Override
public boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face){
	System.out.println("isFlammable overriden");
        return getFlammability(world, pos, face) > 0;
    }
@Override
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face){
	System.out.println("getFireSpreadSpeed overriden");
        return 300;
    }

@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer() {
    return BlockRenderLayer.SOLID;
}

public void registerItemModel(ItemBlock itemBlock) {
	BettermentsMod.proxy.registerItemRenderer(itemBlock, 0, name);
}

@Override
public GunpowderBarrel setCreativeTab(CreativeTabs tab) {
	super.setCreativeTab(tab);
	return this;
}

@Override
    public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
    {
        if (!worldIn.isRemote)
        {
        	worldIn.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 10f, true);
        }
    }

@Override
    public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
    {
        if (!worldIn.isRemote)
        {
            if (((Boolean)state.getValue(EXPLODE)).booleanValue())
            {
            	worldIn.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 10f, true);
            }
        }
    }

@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (heldItem != null && (heldItem.getItem() == Items.FLINT_AND_STEEL || heldItem.getItem() == Items.FIRE_CHARGE))
        {
            this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
            worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);

            if (heldItem.getItem() == Items.FLINT_AND_STEEL)
            {
                heldItem.damageItem(0, playerIn);
            }
            else if (!playerIn.capabilities.isCreativeMode)
            {
                --heldItem.stackSize;
            }

            return true;
        }
        else
        {
            return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
        }
    }

}

 

I am human and thus will make stupid and obvious mistakes and cannot be expected to know everything.

Link to comment
Share on other sites

IBlockAccess is implemented by World.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

IBlockAccess is implemented by World.

 

But not every

IBlockAccess

is a

World

, it may be a

ChunkCache

or something else.

 

You should check that it is a

World

before casting.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

The one missing aspect is randomness. As written, your gunpowder will explode as soon as fire appears next to it. TNT has a random delay before the fire catches. If you don't care, then it doesn't matter.

 

Anyway, I am happy that my idea worked.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.