-
Notifications
You must be signed in to change notification settings - Fork 755
/
SlimeExplosive.java
150 lines (132 loc) · 5.18 KB
/
SlimeExplosive.java
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
package tconstruct.blocks;
import java.util.List;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
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.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import tconstruct.entity.item.ExplosivePrimed;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SlimeExplosive extends TConstructBlock
{
public SlimeExplosive()
{
super(Material.tnt, 0f, getTextureNames());
}
static String[] getTextureNames ()
{
String[] names = new String[6];
String[] types = new String[] { "green", "blue" };
for (int i = 0; i < 2; i++)
{
names[i * 3 + 0] = "sdx_bottom_" + types[i];
names[i * 3 + 1] = "sdx_side_" + types[i];
names[i * 3 + 2] = "sdx_top_" + types[i];
}
return names;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta)
{
return icons[(meta / 2) * 3 + getSideTextureIndex(side)];
}
@Override
public void getSubBlocks (Item b, CreativeTabs tab, List list)
{
for (int iter = 0; iter < 2; iter++)
{
list.add(new ItemStack(b, 1, iter * 2));
}
}
@Override
public void onBlockAdded (World par1World, int par2, int par3, int par4)
{
super.onBlockAdded(par1World, par2, par3, par4);
if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
{
this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
}
}
@Override
public void onNeighborBlockChange (World par1World, int par2, int par3, int par4, Block par5Block)
{
if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
{
this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
}
}
@Override
public void onBlockDestroyedByExplosion (World par1World, int par2, int par3, int par4, Explosion par5Explosion)
{
if (!par1World.isRemote)
{
ExplosivePrimed entitytntprimed = new ExplosivePrimed(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F),
par5Explosion.getExplosivePlacedBy());
entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
par1World.spawnEntityInWorld(entitytntprimed);
}
}
@Override
public void onBlockDestroyedByPlayer (World par1World, int par2, int par3, int par4, int par5)
{
this.primeTnt(par1World, par2, par3, par4, par5, (EntityLivingBase) null);
}
public void primeTnt (World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase)
{
if (!par1World.isRemote)
{
if ((par5 % 2) == 1)
{
ExplosivePrimed entitytntprimed = new ExplosivePrimed(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F), par6EntityLivingBase);
par1World.spawnEntityInWorld(entitytntprimed);
par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F);
}
}
}
@Override
public boolean onBlockActivated (World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().getItem() == Items.flint_and_steel)
{
this.primeTnt(par1World, par2, par3, par4, 1, par5EntityPlayer);
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
par5EntityPlayer.getCurrentEquippedItem().damageItem(1, par5EntityPlayer);
return true;
}
else
{
return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
}
}
@Override
public void onEntityCollidedWithBlock (World par1World, int par2, int par3, int par4, Entity par5Entity)
{
if (par5Entity instanceof EntityArrow && !par1World.isRemote)
{
EntityArrow entityarrow = (EntityArrow) par5Entity;
if (entityarrow.isBurning())
{
this.primeTnt(par1World, par2, par3, par4, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null);
WorldHelper.setBlockToAir(par1World, par2, par3, par4);
}
}
}
@Override
public boolean canDropFromExplosion (Explosion par1Explosion)
{
return false;
}
}