/
MechworksContent.java
223 lines (176 loc) · 8.77 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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.minecraft.util.*;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.*;
import slimeknights.mantle.block.*;
import slimeknights.mantle.client.CreativeTab;
import slimeknights.mantle.item.*;
import slimeknights.tmechworks.TMechworks;
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.drawbridge.AdvancedDrawbridgeLogic;
import slimeknights.tmechworks.blocks.logic.drawbridge.DrawbridgeLogic;
import slimeknights.tmechworks.blocks.logic.drawbridge.ExtendedDrawbridgeLogic;
import slimeknights.tmechworks.blocks.logic.FirestarterLogic;
import slimeknights.tmechworks.items.ItemBlockMetaExtra;
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;
@SubscribeEvent
public void registerItems (RegistryEvent.Register<Item> event)
{
IForgeRegistry<Item> registry = event.getRegistry();
// Item Blocks
metals = registerEnumItemBlock(registry, metals);
blockAluminum = new ItemStack(metals, 1, Metal.MetalTypes.ALUMINUM.getMeta());
blockCopper = new ItemStack(metals, 1, Metal.MetalTypes.COPPER.getMeta());
drawbridge = registerEnumItemBlockExtra(registry, drawbridge);
firestarter = registerEnumItemBlockExtra(registry, firestarter, "extinguish=true", "facing=inv");
ingots = registerItem(registry, new ItemMetaDynamic(), "ingots");
ingots.setCreativeTab(tabMechworks);
nuggets = registerItem(registry, 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");
setupCreativeTabs();
}
@SubscribeEvent
public void registerBlocks (RegistryEvent.Register<Block> event)
{
IForgeRegistry<Block> registry = event.getRegistry();
metals = registerBlock(registry, new Metal(), "metal");
drawbridge = registerBlock(registry, new Drawbridge(), "drawbridge");
drawbridge.setCreativeTab(tabMechworks);
registerTE(DrawbridgeLogic.class, "drawbridge");
registerTE(ExtendedDrawbridgeLogic.class, "drawbridge.extended");
registerTE(AdvancedDrawbridgeLogic.class, "drawbridge.advanced");
firestarter = registerBlock(registry, new Firestarter(), "firestarter");
firestarter.setCreativeTab(tabMechworks);
registerTE(FirestarterLogic.class, "firestarter");
}
@SubscribeEvent
public void registerModels (ModelRegistryEvent event){
TMechworks.proxy.registerModels();
}
private void setupCreativeTabs ()
{
tabMechworks.setDisplayIcon(new ItemStack(drawbridge, 1, 0));
}
protected static <T extends Block> T registerBlock(IForgeRegistry<Block> registry, 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.setTranslationKey(prefixedName);
register(registry, block, name);
return block;
}
protected static <E extends Enum<E> & EnumBlock.IEnumMeta & IStringSerializable> BlockStairsBase registerBlockStairsFrom(IForgeRegistry<Block> registry, EnumBlock<E> block, E value, String name) {
return registerBlock(registry, new BlockStairsBase(block.getDefaultState().withProperty(block.prop, value)), name);
}
protected static <T extends Block> T registerItemBlock(IForgeRegistry<Item> registry, T block) {
ItemBlock itemBlock = new ItemBlockMeta(block);
itemBlock.setTranslationKey(block.getTranslationKey());
register(registry, itemBlock, block.getRegistryName());
return block;
}
protected static <T extends EnumBlock<?>> T registerEnumItemBlock(IForgeRegistry<Item> registry, T block) {
ItemBlock itemBlock = new ItemBlockMeta(block);
itemBlock.setTranslationKey(block.getTranslationKey());
register(registry, itemBlock, block.getRegistryName());
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
protected static <T extends EnumBlock<?>> T registerEnumItemBlockExtra(IForgeRegistry<Item> registry, T block, String... extra) {
registerItemBlock(registry, new ItemBlockMetaExtra(block, extra));
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
protected static <T extends IEnumBlock<?>> T registerEnumItemBlockExtra(IForgeRegistry<Item> registry, T block, String... extra) {
registerItemBlock(registry, new ItemBlockMetaExtra(block.getSelf(), extra));
ItemBlockMeta.setMappingProperty(block.getSelf(), block.getProperty());
return block;
}
@SuppressWarnings("unchecked")
protected static <T extends Block> T registerItemBlock(IForgeRegistry<Item> registry, ItemBlock itemBlock) {
itemBlock.setTranslationKey(itemBlock.getBlock().getTranslationKey());
register(registry, itemBlock, itemBlock.getBlock().getRegistryName());
return (T) itemBlock.getBlock();
}
@SuppressWarnings("unchecked")
protected static <T extends Block> T registerItemBlockProp(IForgeRegistry<Item> registry, ItemBlock itemBlock, IProperty<?> property) {
itemBlock.setTranslationKey(itemBlock.getBlock().getTranslationKey());
register(registry, itemBlock, itemBlock.getBlock().getRegistryName());
ItemBlockMeta.setMappingProperty(itemBlock.getBlock(), property);
return (T) itemBlock.getBlock();
}
protected static <T extends EnumBlockSlab<?>> T registerEnumItemBlockSlab(IForgeRegistry<Item> registry, T block) {
@SuppressWarnings({ "unchecked", "rawtypes" })
ItemBlock itemBlock = new ItemBlockSlab(block);
itemBlock.setTranslationKey(block.getTranslationKey());
register(registry, itemBlock, block.getRegistryName());
ItemBlockMeta.setMappingProperty(block, block.prop);
return block;
}
/**
* Sets the correct unlocalized name and registers the item.
*/
protected static <T extends Item> T registerItem(IForgeRegistry<Item> registry, 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.setTranslationKey(Util.prefix(name));
item.setRegistryName(Util.getResource(name));
registry.register(item);
return item;
}
protected static <T extends IForgeRegistryEntry<T>> T register(IForgeRegistry<T> registry, T thing, String name) {
thing.setRegistryName(Util.getResource(name));
registry.register(thing);
return thing;
}
protected static <T extends IForgeRegistryEntry<T>> T register(IForgeRegistry<T> registry, T thing, ResourceLocation name) {
thing.setRegistryName(name);
registry.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, new ResourceLocation(Util.prefix(name)));
}
}