Files
TinkersConstruct/src/main/java/tconstruct/blocks/traps/Punji.java
T

119 lines
3.8 KiB
Java
Raw Normal View History

package tconstruct.blocks.traps;
2013-08-07 19:06:26 -07:00
import java.util.Random;
import mantle.blocks.MantleBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2013-12-31 11:58:36 -05:00
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
2013-08-07 19:06:26 -07:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
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;
2013-08-07 19:06:26 -07:00
import tconstruct.client.block.PunjiRender;
2013-11-29 23:16:32 -05:00
import tconstruct.common.TRepo;
2013-08-07 19:06:26 -07:00
import tconstruct.library.TConstructRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class Punji extends MantleBlock
{
2013-12-31 11:58:36 -05:00
public Punji()
{
2014-01-29 00:09:45 -05:00
super(Material.field_151585_k);
2014-01-16 01:36:18 -05:00
this.func_149676_a(0.125f, 0, 0.125f, 0.875f, 0.375f, 0.875f);
2014-01-29 22:58:29 -05:00
this.field_149762_H = Block.field_149779_h;
2014-01-16 01:36:18 -05:00
this.func_149647_a(TConstructRegistry.blockTab);
2014-01-01 08:47:10 -05:00
this.func_149711_c(3.0f);
}
@Override
2014-01-30 20:34:22 -05:00
public void func_149670_a (World world, int x, int y, int z, Entity entity)
{
2013-08-07 19:06:26 -07:00
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();
2014-01-07 13:50:35 -05:00
if (stack != null && stack == new ItemStack(TRepo.punji))
2013-08-07 19:06:26 -07:00
{
world.setBlockMetadataWithNotify(x, y, z, meta + 1, 3);
2014-01-29 00:41:17 -05:00
world.playSoundEffect((double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), this.field_149762_H.getPlaceSound(),
(this.field_149762_H.getVolume() + 1.0F) / 2.0F, this.field_149762_H.getPitch() * 0.8F);
2013-08-07 19:06:26 -07:00
player.swingItem();
if (!player.capabilities.isCreativeMode)
{
stack.stackSize--;
if (stack.stackSize <= 0)
player.destroyCurrentEquippedItem();
}
}
}
return true;
}
@Override
2013-08-31 05:13:31 -07:00
public int quantityDropped (int meta, int fortune, Random random)
2013-08-07 19:06:26 -07:00
{
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.
*/
public boolean isOpaqueCube ()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
*/
public boolean renderAsNormalBlock ()
{
return false;
}
public int getRenderType ()
{
return PunjiRender.model;
}
@Override
@SideOnly(Side.CLIENT)
2014-01-18 02:52:49 -05:00
public void func_149651_a (IIconRegister iconRegister)
2013-08-07 19:06:26 -07:00
{
2013-12-31 14:11:05 -05:00
this.field_149761_L = iconRegister.registerIcon("tinker:punji");
2013-08-07 19:06:26 -07:00
}
@Override
2013-08-31 05:13:31 -07:00
@SideOnly(Side.CLIENT)
2014-01-15 23:19:27 -05:00
public boolean func_149646_a (IBlockAccess world, int x, int y, int z, int side)
2013-08-07 19:06:26 -07:00
{
return true;
}
}