/
SeedBag.java
79 lines (70 loc) · 2.47 KB
/
SeedBag.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
package mods.natura.items;
import java.util.List;
import mods.natura.common.NaturaTab;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SeedBag extends Item
{
Block crop;
int cropMetadata;
String textureName;
public SeedBag(Block block, int cMD, String texture)
{
super();
crop = block;
cropMetadata = cMD;
textureName = texture;
this.setCreativeTab(NaturaTab.tab);
}
@Override
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10)
{
if (side != 1)
return false;
boolean planted = false;
for (int posX = x - 1; posX <= x + 1; posX++)
{
for (int posZ = z - 1; posZ <= z + 1; posZ++)
{
if (player.canPlayerEdit(posX, y, posZ, side, stack) && player.canPlayerEdit(posX, y + 1, posZ, side, stack))
{
Block block = world.getBlock(posX, y, posZ);
if (block != null && block.canSustainPlant(world, posX, y, posZ, ForgeDirection.UP, (IPlantable) crop) && world.isAirBlock(posX, y + 1, posZ))
{
world.setBlock(posX, y + 1, posZ, crop, cropMetadata, 3);
planted = true;
}
}
}
}
if (planted)
{
if (!player.capabilities.isCreativeMode)
stack.stackSize--;
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(crop));
}
return planted;
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons (IIconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("natura:seedbag_" + textureName);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
{
list.add(StatCollector.translateToLocal("tooltip.seedbag"));
}
}