/
MechworksContent.java
190 lines (156 loc) · 6.28 KB
/
MechworksContent.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package slimeknights.tmechworks.common;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
import slimeknights.mantle.block.EnumBlock;
import slimeknights.mantle.client.CreativeTab;
import slimeknights.mantle.item.ItemBlockMeta;
import slimeknights.mantle.item.ItemMetaDynamic;
import slimeknights.tmechworks.blocks.Drawbridge;
import slimeknights.tmechworks.blocks.Firestarter;
import slimeknights.tmechworks.blocks.IEnumBlock;
import slimeknights.tmechworks.blocks.Metal;
import slimeknights.tmechworks.blocks.logic.DrawbridgeLogic;
import slimeknights.tmechworks.blocks.logic.FirestarterLogic;
import slimeknights.tmechworks.library.Util;
import java.util.Locale;
public class MechworksContent
{
// Items
public static ItemMetaDynamic ingots;
public static ItemMetaDynamic nuggets;
// Blocks
public static Metal metals;
public static Drawbridge drawbridge;
public static Firestarter firestarter;
// Tabs
public static CreativeTab tabMechworks = new CreativeTab("TabMechworks", new ItemStack(Items.POISONOUS_POTATO));
// Ingot ItemStacks
public static ItemStack ingotAluminum;
public static ItemStack ingotCopper;
// Nugget ItemStacks
public static ItemStack nuggetAluminum;
public static ItemStack nuggetCopper;
// Block ItemStacks
public static ItemStack blockAluminum;
public static ItemStack blockCopper;
public MechworksContent ()
{
registerItems();
registerBlocks();
setupCreativeTabs();
MechRecipes.register();
}
private void registerItems ()
{
ingots = registerItem(new ItemMetaDynamic(), "ingots");
ingots.setCreativeTab(tabMechworks);
nuggets = registerItem(new ItemMetaDynamic(), "nuggets");
nuggets.setCreativeTab(tabMechworks);
ingotAluminum = ingots.addMeta(0, "aluminum");
nuggetAluminum = nuggets.addMeta(0, "aluminum");
ingotCopper = ingots.addMeta(1, "copper");
nuggetCopper = nuggets.addMeta(1, "copper");
}
private void registerBlocks ()
{
metals = registerEnumBlock(new Metal(), "metal");
blockAluminum = new ItemStack(metals, 1, Metal.MetalTypes.ALUMINUM.getMeta());
blockCopper = new ItemStack(metals, 1, Metal.MetalTypes.COPPER.getMeta());
drawbridge = registerEnumBlock(new Drawbridge(), "drawbridge");
drawbridge.setCreativeTab(tabMechworks);
registerTE(DrawbridgeLogic.class, "drawbridge");
firestarter = registerBlock(new Firestarter(), "firestarter");
firestarter.setCreativeTab(tabMechworks);
registerTE(FirestarterLogic.class, "firestarter");
}
private void setupCreativeTabs ()
{
tabMechworks.setDisplayIcon(new ItemStack(drawbridge, 1, 0));
}
protected static <T extends Item> T registerItem (T item, String name)
{
if (!name.equals(name.toLowerCase(Locale.US)))
{
throw new IllegalArgumentException(String.format("Unlocalized names need to be all lowercase! Item: %s", name));
}
item.setUnlocalizedName(Util.prefix(name));
item.setRegistryName(Util.getResource(name));
GameRegistry.register(item);
return item;
}
protected static <T extends Block> T registerBlock (T block, String name)
{
ItemBlock itemBlock = new ItemBlockMeta(block);
registerBlock(block, itemBlock, name);
return block;
}
protected static <T extends EnumBlock<?>> T registerEnumBlock (T block, String name)
{
registerBlock(block, new ItemBlockMeta(block), name);
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
protected static <T extends IEnumBlock<?>> T registerEnumBlock (T block, String name)
{
registerBlock(block.getSelf(), new ItemBlockMeta(block.getSelf()), name);
ItemBlockMeta.setMappingProperty(block.getSelf(), block.getProperty());
return block;
}
protected static <T extends Block> T registerBlock (ItemBlock itemBlock, String name)
{
Block block = itemBlock.getBlock();
return (T) registerBlock(block, itemBlock, name);
}
protected static <T extends Block> T registerBlock (T block, String name, IProperty<?> property)
{
ItemBlockMeta itemBlock = new ItemBlockMeta(block);
registerBlock(block, itemBlock, name);
ItemBlockMeta.setMappingProperty(block, property);
return block;
}
protected static <T extends Block> T registerBlock (T block, ItemBlock itemBlock, String name)
{
if (!name.equals(name.toLowerCase(Locale.US)))
{
throw new IllegalArgumentException(String.format("Unlocalized names need to be all lowercase! Block: %s", name));
}
String prefixedName = Util.prefix(name);
block.setUnlocalizedName(prefixedName);
itemBlock.setUnlocalizedName(prefixedName);
register(block, name);
register(itemBlock, name);
return block;
}
protected static <T extends Block> T registerBlockNoItem (T block, String name)
{
if (!name.equals(name.toLowerCase(Locale.US)))
{
throw new IllegalArgumentException(String.format("Unlocalized names need to be all lowercase! Block: %s", name));
}
String prefixedName = Util.prefix(name);
block.setUnlocalizedName(prefixedName);
register(block, name);
return block;
}
protected static <T extends IForgeRegistryEntry<?>> T register (T thing, String name)
{
thing.setRegistryName(Util.getResource(name));
GameRegistry.register(thing);
return thing;
}
protected static void registerTE (Class<? extends TileEntity> teClazz, String name)
{
if (!name.equals(name.toLowerCase(Locale.US)))
{
throw new IllegalArgumentException(String.format("Unlocalized names need to be all lowercase! TE: %s", name));
}
GameRegistry.registerTileEntity(teClazz, Util.prefix(name));
}
}