-
Notifications
You must be signed in to change notification settings - Fork 755
/
Punji.java
126 lines (112 loc) · 3.88 KB
/
Punji.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
package tconstruct.blocks.traps;
import java.util.Random;
import mantle.blocks.MantleBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tconstruct.library.TConstructRegistry;
import tconstruct.world.TinkerWorld;
import tconstruct.world.model.PunjiRender;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class Punji extends MantleBlock
{
public Punji()
{
super(Material.plants);
this.setBlockBounds(0.125f, 0, 0.125f, 0.875f, 0.375f, 0.875f);
this.stepSound = Block.soundTypeGrass;
this.setCreativeTab(TConstructRegistry.blockTab);
this.setHardness(3.0f);
}
@Override
public void onEntityCollidedWithBlock (World world, int x, int y, int z, Entity entity)
{
if (entity instanceof EntityLivingBase)
{
int damage = world.getBlockMetadata(x, y, z) / 2 + 1;
if (entity.fallDistance > 0)
damage += ((entity.fallDistance) * 1.5 + 2);
entity.attackEntityFrom(DamageSource.cactus, damage);
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 20, 1));
}
}
/* Right-click adds sticks */
@Override
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int par6, float hitX, float hitY, float hitZ)
{
/*
* if (world.isRemote) return false;
*/
int meta = world.getBlockMetadata(x, y, z);
if (meta < 4)
{
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.getItem() == Item.getItemFromBlock(TinkerWorld.punji))
{
world.setBlockMetadataWithNotify(x, y, z, meta + 1, 3);
world.playSoundEffect((double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), this.stepSound.soundName, (this.stepSound.getVolume() + 1.0F) / 2.0F,
this.stepSound.getPitch() * 0.8F);
player.swingItem();
if (!player.capabilities.isCreativeMode)
{
stack.stackSize--;
if (stack.stackSize <= 0)
player.destroyCurrentEquippedItem();
}
}
}
return true;
}
@Override
public int quantityDropped (int meta, int fortune, Random random)
{
return meta + 1;
}
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether
* or not to render the shared face of two adjacent blocks and also whether
* the player can attach torches, redstone wire, etc to this block.
*/
@Override
public boolean isOpaqueCube ()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False
* (examples: signs, buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock ()
{
return false;
}
@Override
public int getRenderType ()
{
return PunjiRender.model;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons (IIconRegister iconRegister)
{
this.blockIcon = iconRegister.registerIcon("tinker:punji");
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered (IBlockAccess world, int x, int y, int z, int side)
{
return true;
}
}