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
|
package tf2crates.item;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import tf2crates.ReferenceTC;
public class ItemPaint extends Item { // make paint able to change the
// color of wool blocks
public static final String[] TYPES = { "black", "red", "green",
"brown", "blue", "purple", "cyan", "silver", "gray", "pink",
"lime", "yellow", "lightBlue", "magenta", "orange", "white" };
public IIcon[] textures;
public ItemPaint() {
super();
this.setUnlocalizedName("paint");
this.setMaxStackSize(1);
this.hasSubtypes = true;
this.setContainerItem(this);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
textures = new IIcon[TYPES.length];
for (int i = 0; i < TYPES.length; i++) {
textures[i] = iconRegister
.registerIcon(ReferenceTC.ID + ":paint/" + TYPES[i]);
}
}
@Override
public String getItemStackDisplayName(ItemStack itemStack) {
return StatCollector.translateToLocal(
"paint." + TYPES[itemStack.getItemDamage()] + ".name");
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list) {
for (int i = 0; i < TYPES.length; i++) {
list.add(new ItemStack(item, 1, i));
}
}
@Override
public EnumRarity getRarity(ItemStack itemStack) {
return EnumRarity.rare;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int dmg) {
return textures[dmg];
}
@Override
public boolean
doesContainerItemLeaveCraftingGrid(ItemStack itemStack) {
return false;
}
@Override
public boolean hasContainerItem(ItemStack stack) {
return true;
}
@Override
public ItemStack getContainerItem(ItemStack itemStack) {
return itemStack;
}
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player,
World world, int x, int y, int z, int meta, float p_77648_8_,
float p_77648_9_, float p_77648_10_) {
Block block = world.getBlock(x, y, z);
if (block == Blocks.wool || block == Blocks.carpet
|| block == Blocks.glass || block == Blocks.stained_glass
|| block == Blocks.glass_pane
|| block == Blocks.stained_glass_pane
|| block == Blocks.hardened_clay
|| block == Blocks.stained_hardened_clay) {
if (!world.isRemote) {
if (block == Blocks.glass) {
block = Blocks.stained_glass;
}
if (block == Blocks.glass_pane) {
block = Blocks.stained_glass_pane;
}
if (block == Blocks.hardened_clay) {
block = Blocks.stained_hardened_clay;
}
world.setBlock(x, y, z, block,
15 - itemStack.getItemDamage(), 2);
}
return true;
}
return false;
}
}
|