|
2 | 2 |
|
3 | 3 | import com.jaquadro.minecraft.chameleon.Chameleon; |
4 | 4 | import com.jaquadro.minecraft.chameleon.resources.ModelRegistry; |
| 5 | +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; |
| 6 | +import com.jaquadro.minecraft.storagedrawers.api.storage.EnumBasicDrawer; |
| 7 | +import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; |
| 8 | +import com.jaquadro.minecraft.storagedrawersextra.StorageDrawersExtra; |
5 | 9 | import com.jaquadro.minecraft.storagedrawersextra.block.BlockExtraDrawers; |
6 | 10 | import com.jaquadro.minecraft.storagedrawersextra.block.BlockTrimExtra; |
| 11 | +import com.jaquadro.minecraft.storagedrawersextra.block.EnumMod; |
7 | 12 | import com.jaquadro.minecraft.storagedrawersextra.block.EnumVariant; |
8 | 13 | import com.jaquadro.minecraft.storagedrawersextra.client.model.ExtraDrawerModel; |
9 | 14 | import com.jaquadro.minecraft.storagedrawersextra.client.model.ExtraTrimModel; |
| 15 | +import com.jaquadro.minecraft.storagedrawersextra.config.ConfigManagerExt; |
10 | 16 | import com.jaquadro.minecraft.storagedrawersextra.item.ItemExtraDrawers; |
11 | 17 | import com.jaquadro.minecraft.storagedrawersextra.item.ItemTrimExtra; |
| 18 | +import net.minecraft.block.Block; |
| 19 | +import net.minecraft.item.Item; |
12 | 20 | import net.minecraft.item.ItemStack; |
13 | | -import net.minecraftforge.fml.common.registry.GameRegistry; |
| 21 | +import net.minecraft.item.crafting.IRecipe; |
| 22 | +import net.minecraft.nbt.NBTTagCompound; |
| 23 | +import net.minecraft.util.ResourceLocation; |
| 24 | +import net.minecraftforge.client.event.ModelRegistryEvent; |
| 25 | +import net.minecraftforge.event.RegistryEvent; |
| 26 | +import net.minecraftforge.fml.common.Mod; |
| 27 | +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
14 | 28 | import net.minecraftforge.fml.relauncher.Side; |
15 | 29 | import net.minecraftforge.fml.relauncher.SideOnly; |
16 | | -import net.minecraftforge.oredict.OreDictionary; |
| 30 | +import net.minecraftforge.oredict.ShapedOreRecipe; |
| 31 | +import net.minecraftforge.registries.IForgeRegistry; |
| 32 | + |
| 33 | +import javax.annotation.Nonnull; |
17 | 34 |
|
18 | 35 | public class ModBlocks |
19 | 36 | { |
20 | 37 | public static BlockExtraDrawers extraDrawers; |
21 | 38 | public static BlockTrimExtra[] extraTrim; |
22 | 39 |
|
23 | | - public void init () { |
24 | | - extraDrawers = new BlockExtraDrawers("extra_drawers", "extraDrawers"); |
| 40 | + @Mod.EventBusSubscriber(modid = StorageDrawersExtra.MOD_ID) |
| 41 | + public static class Registration |
| 42 | + { |
| 43 | + @SubscribeEvent |
| 44 | + public static void registerBlocks (RegistryEvent.Register<Block> event) { |
| 45 | + IForgeRegistry<Block> registry = event.getRegistry(); |
25 | 46 |
|
26 | | - GameRegistry.register(extraDrawers); |
27 | | - GameRegistry.register(new ItemExtraDrawers(extraDrawers).setRegistryName(extraDrawers.getRegistryName())); |
| 47 | + extraDrawers = new BlockExtraDrawers("extra_drawers", "extraDrawers"); |
| 48 | + registry.register(extraDrawers); |
28 | 49 |
|
29 | | - for (String key : new String[] { "drawerBasic" }) |
30 | | - OreDictionary.registerOre(key, new ItemStack(extraDrawers, 1, OreDictionary.WILDCARD_VALUE)); |
| 50 | + extraTrim = new BlockTrimExtra[EnumVariant.groupCount()]; |
| 51 | + for (int i = 0; i < extraTrim.length; i++) { |
| 52 | + extraTrim[i] = new BlockTrimExtra("extra_trim_" + i, "extraTrim" + i, i); |
| 53 | + registry.register(extraTrim[i]); |
| 54 | + } |
| 55 | + } |
31 | 56 |
|
32 | | - extraTrim = new BlockTrimExtra[EnumVariant.groupCount()]; |
33 | | - for (int i = 0; i < extraTrim.length; i++) { |
34 | | - extraTrim[i] = new BlockTrimExtra("extra_trim_" + i, "extraTrim" + i, i); |
| 57 | + @SubscribeEvent |
| 58 | + public static void registerItems (RegistryEvent.Register<Item> event) { |
| 59 | + IForgeRegistry<Item> registry = event.getRegistry(); |
35 | 60 |
|
36 | | - GameRegistry.register(extraTrim[i]); |
37 | | - GameRegistry.register(new ItemTrimExtra(extraTrim[i]).setRegistryName(extraTrim[i].getRegistryName())); |
| 61 | + registry.register(new ItemExtraDrawers(extraDrawers).setRegistryName(extraDrawers.getRegistryName())); |
| 62 | + for (BlockTrimExtra trim : extraTrim) |
| 63 | + registry.register(new ItemTrimExtra(trim).setRegistryName(trim.getRegistryName())); |
38 | 64 | } |
39 | | - } |
40 | 65 |
|
41 | | - @SideOnly(Side.CLIENT) |
42 | | - public void initDynamic () { |
43 | | - extraDrawers.initDynamic(); |
44 | | - } |
| 66 | + private static final ResourceLocation EMPTY_GROUP = new ResourceLocation("", ""); |
| 67 | + |
| 68 | + @Nonnull |
| 69 | + public static ItemStack makeBasicDrawerItemStack (EnumBasicDrawer info, String material, int count) { |
| 70 | + @Nonnull ItemStack stack = new ItemStack(ModBlocks.extraDrawers, count, info.getMetadata()); |
| 71 | + |
| 72 | + NBTTagCompound data = new NBTTagCompound(); |
| 73 | + data.setString("material", material); |
| 74 | + stack.setTagCompound(data); |
| 75 | + |
| 76 | + return stack; |
| 77 | + } |
| 78 | + |
| 79 | + @SubscribeEvent |
| 80 | + public static void registerRecipes (RegistryEvent.Register<IRecipe> event) { |
| 81 | + IForgeRegistry<IRecipe> registry = event.getRegistry(); |
| 82 | + ConfigManager config = StorageDrawers.config; |
| 83 | + ConfigManagerExt configExt = StorageDrawersExtra.config; |
45 | 84 |
|
46 | | - @SideOnly(Side.CLIENT) |
47 | | - public void initClient () { |
48 | | - ModelRegistry modelRegistry = Chameleon.instance.modelRegistry; |
| 85 | + for (EnumVariant variant : EnumVariant.values()) { |
| 86 | + if (variant == EnumVariant.DEFAULT) |
| 87 | + continue; |
49 | 88 |
|
50 | | - modelRegistry.registerModel(new ExtraDrawerModel.Register()); |
51 | | - for (BlockTrimExtra block : extraTrim) |
52 | | - modelRegistry.registerModel(new ExtraTrimModel.Register(block)); |
| 89 | + EnumMod mod = variant.getMod(); |
| 90 | + if (mod == null || !mod.isEnabled(configExt.getModToggleState(mod))) |
| 91 | + continue; |
| 92 | + |
| 93 | + @Nonnull ItemStack plankStack = ItemStack.EMPTY; |
| 94 | + if (variant.getPlankResource() != null) { |
| 95 | + Block block = Block.getBlockFromName(variant.getPlankResource().toString()); |
| 96 | + if (block != null) |
| 97 | + plankStack = new ItemStack(block, 1, variant.getPlankMeta()); |
| 98 | + } |
| 99 | + |
| 100 | + @Nonnull ItemStack slabStack = ItemStack.EMPTY; |
| 101 | + if (variant.getSlabResource() != null) { |
| 102 | + Block block = Block.getBlockFromName(variant.getSlabResource().toString()); |
| 103 | + if (block != null) |
| 104 | + slabStack = new ItemStack(block, 1, variant.getSlabMeta()); |
| 105 | + } |
| 106 | + |
| 107 | + String material = variant.getResource().toString(); |
| 108 | + |
| 109 | + if (config.isBlockEnabled(EnumBasicDrawer.FULL1.getUnlocalizedName()) && !plankStack.isEmpty()) { |
| 110 | + @Nonnull ItemStack result = makeBasicDrawerItemStack(EnumBasicDrawer.FULL1, material, config.getBlockRecipeOutput(EnumBasicDrawer.FULL1.getUnlocalizedName())); |
| 111 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "xxx", " y ", "xxx", 'x', plankStack, 'y', "chestWood") |
| 112 | + .setRegistryName(result.getItem().getRegistryName() + "_" + EnumBasicDrawer.FULL1.getUnlocalizedName() + "_" + variant.toString())); |
| 113 | + } |
| 114 | + if (config.isBlockEnabled(EnumBasicDrawer.FULL2.getUnlocalizedName()) && !plankStack.isEmpty()) { |
| 115 | + @Nonnull ItemStack result = makeBasicDrawerItemStack(EnumBasicDrawer.FULL2, material, config.getBlockRecipeOutput(EnumBasicDrawer.FULL2.getUnlocalizedName())); |
| 116 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "xyx", "xxx", "xyx", 'x', plankStack, 'y', "chestWood") |
| 117 | + .setRegistryName(result.getItem().getRegistryName() + "_" + EnumBasicDrawer.FULL2.getUnlocalizedName() + "_" + variant.toString())); |
| 118 | + } |
| 119 | + if (config.isBlockEnabled(EnumBasicDrawer.FULL4.getUnlocalizedName()) && !plankStack.isEmpty()) { |
| 120 | + @Nonnull ItemStack result = makeBasicDrawerItemStack(EnumBasicDrawer.FULL4, material, config.getBlockRecipeOutput(EnumBasicDrawer.FULL4.getUnlocalizedName())); |
| 121 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "yxy", "xxx", "yxy", 'x', plankStack, 'y', "chestWood") |
| 122 | + .setRegistryName(result.getItem().getRegistryName() + "_" + EnumBasicDrawer.FULL4.getUnlocalizedName() + "_" + variant.toString())); |
| 123 | + } |
| 124 | + if (config.isBlockEnabled(EnumBasicDrawer.HALF2.getUnlocalizedName()) && !slabStack.isEmpty()) { |
| 125 | + @Nonnull ItemStack result = makeBasicDrawerItemStack(EnumBasicDrawer.HALF2, material, config.getBlockRecipeOutput(EnumBasicDrawer.HALF2.getUnlocalizedName())); |
| 126 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "xyx", "xxx", "xyx", 'x', slabStack, 'y', "chestWood") |
| 127 | + .setRegistryName(result.getItem().getRegistryName() + "_" + EnumBasicDrawer.HALF2.getUnlocalizedName() + "_" + variant.toString())); |
| 128 | + } |
| 129 | + if (config.isBlockEnabled(EnumBasicDrawer.HALF4.getUnlocalizedName()) && !slabStack.isEmpty()) { |
| 130 | + @Nonnull ItemStack result = makeBasicDrawerItemStack(EnumBasicDrawer.HALF4, material, config.getBlockRecipeOutput(EnumBasicDrawer.HALF4.getUnlocalizedName())); |
| 131 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "yxy", "xxx", "yxy", 'x', slabStack, 'y', "chestWood") |
| 132 | + .setRegistryName(result.getItem().getRegistryName() + "_" + EnumBasicDrawer.HALF4.getUnlocalizedName() + "_" + variant.toString())); |
| 133 | + } |
| 134 | + if (config.isBlockEnabled("trim") && !plankStack.isEmpty()) { |
| 135 | + @Nonnull ItemStack result = new ItemStack(ModBlocks.extraTrim[variant.getGroupIndex()], config.getBlockRecipeOutput("trim"), variant.getGroupMeta()); |
| 136 | + registry.register(new ShapedOreRecipe(EMPTY_GROUP, result, "xyx", "yyy", "xyx", 'x', "stickWood", 'y', plankStack) |
| 137 | + .setRegistryName(result.getItem().getRegistryName() + "_" + variant.toString())); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + @SubscribeEvent |
| 143 | + @SideOnly(Side.CLIENT) |
| 144 | + public static void registerModels (ModelRegistryEvent event) { |
| 145 | + extraDrawers.initDynamic(); |
| 146 | + |
| 147 | + ModelRegistry modelRegistry = Chameleon.instance.modelRegistry; |
| 148 | + |
| 149 | + modelRegistry.registerModel(new ExtraDrawerModel.Register()); |
| 150 | + for (BlockTrimExtra block : extraTrim) |
| 151 | + modelRegistry.registerModel(new ExtraTrimModel.Register(block)); |
| 152 | + } |
53 | 153 | } |
54 | 154 | } |
0 commit comments