-
Notifications
You must be signed in to change notification settings - Fork 754
/
BarricadeBlock.java
131 lines (114 loc) · 4.07 KB
/
BarricadeBlock.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
package tconstruct.blocks.traps;
import mantle.blocks.MantleBlock;
import mantle.common.ComparisonHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.client.block.BarricadeRender;
import tconstruct.library.TConstructRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BarricadeBlock extends MantleBlock
{
Block modelBlock;
int modelMeta;
public BarricadeBlock(Block model, int meta)
{
super(Material.field_151575_d);
this.modelBlock = model;
this.modelMeta = meta;
func_149711_c(4.0F);
this.func_149647_a(TConstructRegistry.blockTab);
}
public IIcon getIcon (int side, int meta)
{
return modelBlock.getIcon(2, modelMeta);
}
@Override
public void func_149651_a (IIconRegister par1IconRegister)
{
}
public boolean renderAsNormalBlock ()
{
return false;
}
public boolean isOpaqueCube ()
{
return false;
}
public int getRenderType ()
{
return BarricadeRender.model;
}
public AxisAlignedBB getCollisionBoundingBoxFromPool (World par1World, int x, int y, int z)
{
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1);
}
public void func_147465_dBoundsBasedOnState (IBlockAccess par1IBlockAccess, int x, int y, int z)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
public void harvestBlock (World world, EntityPlayer player, int x, int y, int z, int meta)
{
if (meta % 4 > 0)
{
world.func_147465_d(x, y, z, this, meta - 1, 3);
dropBlockAsItem_do(world, x, y, z, new ItemStack(this));
}
else
{
dropBlockAsItem_do(world, x, y, z, new ItemStack(this));
}
}
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
ItemStack stack = player.getCurrentEquippedItem();
if ((stack != null) && (ComparisonHelper.areEquivalent(stack.getItem(), this)) && (!player.isSneaking()))
{
int meta = world.getBlockMetadata(x, y, z);
if (meta % 4 != 3)
{
world.func_147465_d(x, y, z, this, meta + 1, 3);
this.func_149689_a(world, x, y, z, player, stack);
this.func_149714_e(world, x, y, z, meta);
Block var9 = this;
world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, var9.field_149762_H.getStepSound(), (var9.field_149762_H.getVolume() + 1.0F) / 2.0F, var9.field_149762_H.getPitch() * 0.8F);
player.swingItem();
if (!player.capabilities.isCreativeMode)
stack.stackSize -= 1;
return true;
}
}
return false;
}
@Override
public void onBlockExploded (World world, int x, int y, int z, Explosion explosion)
{
double distance = (x - explosion.explosionX) + (y - explosion.explosionY) + (z - explosion.explosionZ);
distance = Math.abs(distance);
double power = (explosion.explosionSize * 2) / distance;
int meta = world.getBlockMetadata(x, y, z);
int trueMeta = meta % 4;
trueMeta -= power;
if (trueMeta < 0)
world.func_147465_d(x, y, z, Blocks.air, 0, 0);
else
world.setBlockMetadataWithNotify(x, y, z, (int) (meta - power), 3);
onBlockDestroyedByExplosion(world, x, y, z, explosion);
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_149646_a (IBlockAccess world, int x, int y, int z, int side)
{
return true;
}
}