2026-03-01 12:16:08 +08:00
# include "stdafx.h"
# include "net.minecraft.world.level.h"
# include "net.minecraft.world.entity.item.h"
2026-03-03 03:04:10 +08:00
# include "net.minecraft.world.entity.projectile.h"
2026-03-01 12:16:08 +08:00
# include "net.minecraft.world.item.h"
# include "net.minecraft.world.h"
# include "net.minecraft.h"
# include "TntTile.h"
# include "SoundTypes.h"
TntTile : : TntTile ( int id ) : Tile ( id , Material : : explosive )
{
iconTop = NULL ;
iconBottom = NULL ;
}
Icon * TntTile : : getTexture ( int face , int data )
{
if ( face = = Facing : : DOWN ) return iconBottom ;
if ( face = = Facing : : UP ) return iconTop ;
return icon ;
}
void TntTile : : onPlace ( Level * level , int x , int y , int z )
{
Tile : : onPlace ( level , x , y , z ) ;
2026-03-03 03:04:10 +08:00
if ( level - > hasNeighborSignal ( x , y , z ) & & app . GetGameHostOption ( eGameHostOption_TNT ) )
2026-03-01 12:16:08 +08:00
{
2026-03-03 03:04:10 +08:00
destroy ( level , x , y , z , EXPLODE_BIT ) ;
level - > removeTile ( x , y , z ) ;
}
2026-03-01 12:16:08 +08:00
}
void TntTile : : neighborChanged ( Level * level , int x , int y , int z , int type )
{
2026-03-03 03:04:10 +08:00
if ( level - > hasNeighborSignal ( x , y , z ) & & app . GetGameHostOption ( eGameHostOption_TNT ) )
2026-03-01 12:16:08 +08:00
{
2026-03-03 03:04:10 +08:00
destroy ( level , x , y , z , EXPLODE_BIT ) ;
level - > removeTile ( x , y , z ) ;
2026-03-01 12:16:08 +08:00
}
}
int TntTile : : getResourceCount ( Random * random )
{
return 1 ;
}
2026-03-03 03:04:10 +08:00
void TntTile : : wasExploded ( Level * level , int x , int y , int z , Explosion * explosion )
2026-03-01 12:16:08 +08:00
{
// 4J - added - don't every create on the client, I think this must be the cause of a bug reported in the java
// version where white tnts are created in the network game
2026-03-02 17:37:16 +07:00
if ( level - > isClientSide ) return ;
2026-03-01 12:16:08 +08:00
// 4J - added condition to have finite limit of these
// 4J-JEV: Fix for #90934 - Customer Encountered: TU11: Content: Gameplay: TNT blocks are triggered by explosions even though "TNT explodes" option is unchecked.
if ( level - > newPrimedTntAllowed ( ) & & app . GetGameHostOption ( eGameHostOption_TNT ) )
{
2026-03-03 03:04:10 +08:00
shared_ptr < PrimedTnt > primed = shared_ptr < PrimedTnt > ( new PrimedTnt ( level , x + 0.5f , y + 0.5f , z + 0.5f , explosion - > getSourceMob ( ) ) ) ;
2026-03-01 12:16:08 +08:00
primed - > life = level - > random - > nextInt ( primed - > life / 4 ) + primed - > life / 8 ;
level - > addEntity ( primed ) ;
}
}
void TntTile : : destroy ( Level * level , int x , int y , int z , int data )
2026-03-03 03:04:10 +08:00
{
destroy ( level , x , y , z , data , nullptr ) ;
}
void TntTile : : destroy ( Level * level , int x , int y , int z , int data , shared_ptr < LivingEntity > source )
2026-03-01 12:16:08 +08:00
{
if ( level - > isClientSide ) return ;
if ( ( data & EXPLODE_BIT ) = = 1 )
{
// 4J - added condition to have finite limit of these
if ( level - > newPrimedTntAllowed ( ) & & app . GetGameHostOption ( eGameHostOption_TNT ) )
{
2026-03-03 03:04:10 +08:00
shared_ptr < PrimedTnt > tnt = shared_ptr < PrimedTnt > ( new PrimedTnt ( level , x + 0.5f , y + 0.5f , z + 0.5f , source ) ) ;
2026-03-01 12:16:08 +08:00
level - > addEntity ( tnt ) ;
2026-03-03 03:04:10 +08:00
level - > playEntitySound ( tnt , eSoundType_RANDOM_FUSE , 1 , 1.0f ) ;
2026-03-01 12:16:08 +08:00
}
}
}
2026-03-02 17:37:16 +07:00
bool TntTile : : use ( Level * level , int x , int y , int z , shared_ptr < Player > player , int clickedFace , float clickX , float clickY , float clickZ , bool soundOnly /*=false*/ ) // 4J added soundOnly param
2026-03-01 12:16:08 +08:00
{
if ( soundOnly ) return false ;
if ( player - > getSelectedItem ( ) ! = NULL & & player - > getSelectedItem ( ) - > id = = Item : : flintAndSteel_Id )
{
2026-03-03 03:04:10 +08:00
destroy ( level , x , y , z , EXPLODE_BIT , player ) ;
level - > removeTile ( x , y , z ) ;
player - > getSelectedItem ( ) - > hurtAndBreak ( 1 , player ) ;
2026-03-01 12:16:08 +08:00
return true ;
}
return Tile : : use ( level , x , y , z , player , clickedFace , clickX , clickY , clickZ ) ;
}
2026-03-02 17:37:16 +07:00
void TntTile : : entityInside ( Level * level , int x , int y , int z , shared_ptr < Entity > entity )
2026-03-01 12:16:08 +08:00
{
if ( entity - > GetType ( ) = = eTYPE_ARROW & & ! level - > isClientSide )
{
if ( entity - > isOnFire ( ) )
{
2026-03-03 03:04:10 +08:00
shared_ptr < Arrow > arrow = dynamic_pointer_cast < Arrow > ( entity ) ;
destroy ( level , x , y , z , EXPLODE_BIT , arrow - > owner - > instanceof ( eTYPE_LIVINGENTITY ) ? dynamic_pointer_cast < LivingEntity > ( arrow - > owner ) : nullptr ) ;
level - > removeTile ( x , y , z ) ;
2026-03-01 12:16:08 +08:00
}
}
}
2026-03-02 17:37:16 +07:00
void TntTile : : registerIcons ( IconRegister * iconRegister )
2026-03-01 12:16:08 +08:00
{
icon = iconRegister - > registerIcon ( L " tnt_side " ) ;
iconTop = iconRegister - > registerIcon ( L " tnt_top " ) ;
iconBottom = iconRegister - > registerIcon ( L " tnt_bottom " ) ;
2026-03-03 03:04:10 +08:00
}
bool TntTile : : dropFromExplosion ( Explosion * explosion )
{
return false ;
2026-03-01 12:16:08 +08:00
}