1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
package gtPlusPlus.core.block.general;
import static gregtech.api.enums.Mods.GTPlusPlus;
import net.minecraft.block.Block;
import net.minecraft.block.BlockTNT;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.util.IIcon;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.entity.EntityPrimedMiningExplosive;
public class BlockMiningExplosives extends BlockTNT {
@SideOnly(Side.CLIENT)
private IIcon textureTop;
@SideOnly(Side.CLIENT)
private IIcon textureBottom;
public BlockMiningExplosives() {
this.setBlockName("blockMiningExplosives");
GameRegistry.registerBlock(this, "blockMiningExplosives");
this.setCreativeTab(AddToCreativeTab.tabMachines);
}
/**
* Gets the block's texture. Args: side, meta
*/
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(final int ordinalSide, final int meta) {
return ordinalSide == 0 ? this.textureBottom : (ordinalSide == 1 ? this.textureTop : this.blockIcon);
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
@Override
public void onBlockAdded(final World world, final int x, final int y, final int z) {
super.onBlockAdded(world, x, y, z);
if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
this.onBlockDestroyedByPlayer(world, x, y, z, 1);
world.setBlockToAir(x, y, z);
}
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor Block
*/
@Override
public void onNeighborBlockChange(final World world, final int x, final int y, final int z,
final Block neighbourblock) {
if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
this.onBlockDestroyedByPlayer(world, x, y, z, 1);
world.setBlockToAir(x, y, z);
}
}
/**
* Called upon the block being destroyed by an explosion
*/
@Override
public void onBlockDestroyedByExplosion(final World world, final int x, final int y, final int z,
final Explosion bang) {
if (!world.isRemote) {
final EntityPrimedMiningExplosive EntityPrimedMiningExplosive = new EntityPrimedMiningExplosive(
world,
x + 0.5F,
y + 0.5F,
z + 0.5F,
bang.getExplosivePlacedBy());
EntityPrimedMiningExplosive.fuse = world.rand.nextInt(EntityPrimedMiningExplosive.fuse / 4)
+ (EntityPrimedMiningExplosive.fuse / 8);
world.spawnEntityInWorld(EntityPrimedMiningExplosive);
}
}
/**
* Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
*/
@Override
public void onBlockDestroyedByPlayer(final World world, final int x, final int y, final int z, final int meta) {
this.func_150114_a(world, x, y, z, meta, null);
}
// TODO Spawns Primed TNT?
@Override
public void func_150114_a(final World world, final int p_150114_2_, final int p_150114_3_, final int p_150114_4_,
final int p_150114_5_, final EntityLivingBase entityLiving) {
if (!world.isRemote) {
if ((p_150114_5_ & 1) == 1) {
final EntityPrimedMiningExplosive EntityPrimedMiningExplosive = new EntityPrimedMiningExplosive(
world,
p_150114_2_ + 0.5F,
p_150114_3_ + 0.5F,
p_150114_4_ + 0.5F,
entityLiving);
world.spawnEntityInWorld(EntityPrimedMiningExplosive);
world.playSoundAtEntity(EntityPrimedMiningExplosive, "game.tnt.primed", 1.0F, 1.0F);
}
}
}
/**
* Called upon block activation (right click on the block.)
*/
@Override
public boolean onBlockActivated(final World world, final int x, final int y, final int z,
final EntityPlayer clickingPlayer, final int p_149727_6_, final float p_149727_7_, final float p_149727_8_,
final float p_149727_9_) {
if ((clickingPlayer.getCurrentEquippedItem() != null) && (clickingPlayer.getCurrentEquippedItem()
.getItem() == Items.flint_and_steel)) {
this.func_150114_a(world, x, y, z, 1, clickingPlayer);
world.setBlockToAir(x, y, z);
clickingPlayer.getCurrentEquippedItem()
.damageItem(1, clickingPlayer);
return true;
} else {
return super.onBlockActivated(
world,
x,
y,
z,
clickingPlayer,
p_149727_6_,
p_149727_7_,
p_149727_8_,
p_149727_9_);
}
}
/**
* Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
*/
@Override
public void onEntityCollidedWithBlock(final World world, final int x, final int y, final int z,
final Entity entityTriggering) {
if ((entityTriggering instanceof final EntityArrow entityarrow) && !world.isRemote) {
if (entityarrow.isBurning()) {
this.func_150114_a(
world,
x,
y,
z,
1,
entityarrow.shootingEntity instanceof EntityLivingBase
? (EntityLivingBase) entityarrow.shootingEntity
: null);
world.setBlockToAir(x, y, z);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(final IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(GTPlusPlus.ID + ":chrono/MetalSheet2");
this.textureTop = iconRegister.registerIcon(GTPlusPlus.ID + ":chrono/MetalFunnel");
this.textureBottom = iconRegister.registerIcon(GTPlusPlus.ID + ":chrono/MetalPanel");
}
}
|