/
NaturaSeeds.java
109 lines (96 loc) · 3.18 KB
/
NaturaSeeds.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
package mods.natura.items;
import java.util.List;
import mods.natura.common.NaturaTab;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.StatCollector;
public class NaturaSeeds extends ItemSeeds
{
public String[] textureNames = new String[] { "barley", "cotton" };
public Icon[] icons;
public int blockType;
public NaturaSeeds(int id, int cropID, int soilID)
{
super(id, cropID, soilID);
blockType = cropID;
this.setCreativeTab(NaturaTab.tab);
this.setHasSubtypes(true);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons (IconRegister iconRegister)
{
this.icons = new Icon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_seeds");
}
}
public void getSubItems (int id, CreativeTabs tab, List list)
{
for (int i = 0; i < textureNames.length; i++)
list.add(new ItemStack(id, 1, i));
}
@SideOnly(Side.CLIENT)
@Override
public Icon getIconFromDamage (int meta)
{
return icons[meta];
}
@Override
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int xPos, int yPos, int zPos, int side, float xClick, float yClick, float zClick)
{
if (side != 1)
{
return false;
}
else if (player.canPlayerEdit(xPos, yPos, zPos, side, stack) && player.canPlayerEdit(xPos, yPos + 1, zPos, side, stack))
{
int i1 = world.getBlockId(xPos, yPos, zPos);
Block soil = Block.blocksList[i1];
if (soil != null && soil.canSustainPlant(world, xPos, yPos, zPos, ForgeDirection.UP, this) && world.isAirBlock(xPos, yPos + 1, zPos))
{
world.setBlock(xPos, yPos + 1, zPos, this.blockType, stack.getItemDamage() * 4, 3);
--stack.stackSize;
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public String getUnlocalizedName (ItemStack stack)
{
int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, textureNames.length);
return "item." + textureNames[arr] + ".seed";
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
{
switch (stack.getItemDamage())
{
case 0:
list.add(StatCollector.translateToLocal("tooltip.barley"));
break;
case 1:
list.add(StatCollector.translateToLocal("tooltip.cotton"));
break;
}
}
}