-
Notifications
You must be signed in to change notification settings - Fork 81
/
ItemNaturaKama.java
128 lines (115 loc) · 5.07 KB
/
ItemNaturaKama.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
package com.progwml6.natura.tools.item.tools;
import java.util.List;
import com.progwml6.natura.library.NaturaRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import slimeknights.mantle.item.ItemTooltip;
public class ItemNaturaKama extends ItemSword
{
public ItemNaturaKama(ToolMaterial toolMaterialIn)
{
super(toolMaterialIn);
this.setCreativeTab(NaturaRegistry.tabGeneral);
}
/**
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
*/
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
return true;
}
/**
* Check whether this Item can harvest the given Block
*/
@Override
public boolean canHarvestBlock(IBlockState blockIn)
{
Block block = blockIn.getBlock();
return block == Blocks.WEB || block == Blocks.REDSTONE_WIRE || block == Blocks.TRIPWIRE;
}
@Override
public float getStrVsBlock(ItemStack stack, IBlockState state)
{
Block block = state.getBlock();
return block != Blocks.WEB && state.getMaterial() != Material.LEAVES ? (block == Blocks.WOOL ? 5.0F : super.getStrVsBlock(stack, state)) : 15.0F;
}
/**
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
*/
@Override
public boolean itemInteractionForEntity(ItemStack itemstack, net.minecraft.entity.player.EntityPlayer player, EntityLivingBase entity, net.minecraft.util.EnumHand hand)
{
if (entity.world.isRemote)
{
return false;
}
if (entity instanceof net.minecraftforge.common.IShearable)
{
net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable) entity;
BlockPos pos = new BlockPos(entity.posX, entity.posY, entity.posZ);
if (target.isShearable(itemstack, entity.world, pos))
{
java.util.List<ItemStack> drops = target.onSheared(itemstack, entity.world, pos,
net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
java.util.Random rand = new java.util.Random();
for (ItemStack stack : drops)
{
net.minecraft.entity.item.EntityItem ent = entity.entityDropItem(stack, 1.0F);
ent.motionY += rand.nextFloat() * 0.05F;
ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
}
itemstack.damageItem(1, entity);
}
return true;
}
return false;
}
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, net.minecraft.entity.player.EntityPlayer player)
{
if (player.world.isRemote || player.capabilities.isCreativeMode)
{
return false;
}
Block block = player.world.getBlockState(pos).getBlock();
if (block instanceof net.minecraftforge.common.IShearable)
{
net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable) block;
if (target.isShearable(itemstack, player.world, pos))
{
java.util.List<ItemStack> drops = target.onSheared(itemstack, player.world, pos,
net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
java.util.Random rand = new java.util.Random();
for (ItemStack stack : drops)
{
float f = 0.7F;
double d = rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d1 = rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d2 = rand.nextFloat() * f + (1.0F - f) * 0.5D;
net.minecraft.entity.item.EntityItem entityitem = new net.minecraft.entity.item.EntityItem(player.world, pos.getX() + d, pos.getY() + d1, pos.getZ() + d2, stack);
entityitem.setDefaultPickupDelay();
player.world.spawnEntity(entityitem);
}
itemstack.damageItem(1, player);
player.addStat(net.minecraft.stats.StatList.getBlockStats(block));
}
}
return false;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
ItemTooltip.addOptionalTooltip(stack, tooltip);
super.addInformation(stack, playerIn, tooltip, advanced);
}
}