-
Notifications
You must be signed in to change notification settings - Fork 497
/
ItemPackage.java
99 lines (81 loc) · 2.9 KB
/
ItemPackage.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
package buildcraft.silicon;
import java.util.List;
import net.minecraft.block.BlockDispenser;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.core.lib.items.ItemBuildCraft;
import buildcraft.core.lib.utils.NBTUtils;
import buildcraft.silicon.render.PackageFontRenderer;
public class ItemPackage extends ItemBuildCraft {
public static final class DispenseBehaviour extends BehaviorDefaultDispenseItem {
@Override
public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemPackage) {
World world = source.getWorld();
EnumFacing enumfacing = BlockDispenser.func_149937_b(source.getBlockMetadata());
EntityPackage entityPackage = new EntityPackage(source.getWorld(),
source.getX() + enumfacing.getFrontOffsetX(),
source.getY() + enumfacing.getFrontOffsetY(),
source.getZ() + enumfacing.getFrontOffsetZ(), stack.copy());
entityPackage.setThrowableHeading(enumfacing.getFrontOffsetX(), enumfacing.getFrontOffsetY() + 0.1F, enumfacing.getFrontOffsetZ(), 1.1F, 6.0F);
world.spawnEntityInWorld(entityPackage);
stack.splitStack(1);
}
return stack;
}
}
public ItemPackage() {
super();
setMaxStackSize(1);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) {
}
public static void update(ItemStack stack) {
}
public static ItemStack getStack(ItemStack stack, int slot) {
NBTTagCompound tag = NBTUtils.getItemData(stack);
if (tag.hasKey("item" + slot)) {
return ItemStack.loadItemStackFromNBT(tag.getCompoundTag("item" + slot));
} else {
return null;
}
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!world.isRemote) {
world.spawnEntityInWorld(new EntityPackage(world, player, stack.copy()));
}
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return stack;
}
@Override
@SideOnly(Side.CLIENT)
public FontRenderer getFontRenderer(ItemStack stack) {
return new PackageFontRenderer(stack);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List strings, boolean adv) {
NBTTagCompound tag = NBTUtils.getItemData(stack);
if (!tag.hasNoTags()) {
strings.add("SPECIAL:0");
strings.add("SPECIAL:1");
strings.add("SPECIAL:2");
}
}
}