diff --git a/.gitignore b/.gitignore index ae1bbaa..7fc6690 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .gradle -build +/build/ .classpath .project .settings mmm_Client.launch mmm_Server.launch +/bin/ +/run/ diff --git a/src/java/mmm/Mmm.java b/src/java/mmm/Mmm.java index 0ce1a40..75382cd 100644 --- a/src/java/mmm/Mmm.java +++ b/src/java/mmm/Mmm.java @@ -1,14 +1,11 @@ package mmm; -import net.minecraft.block.Block; -import net.minecraft.item.ItemBlock; -import net.minecraft.util.math.AxisAlignedBB; +import mmm.utils.URegistration; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; @Mod(modid = Mmm.ID, name = Mmm.NAME, version = Mmm.VERSION) public class Mmm { @@ -24,7 +21,7 @@ public class Mmm { public static abstract class CommonProxy { public void preInit(FMLPreInitializationEvent event) { - // EMPTY + URegistration.registerRecipes(); } public void init(FMLInitializationEvent event) { @@ -41,6 +38,7 @@ public class Mmm { @Override public void preInit(FMLPreInitializationEvent event) { super.preInit(event); + URegistration.setupItemModels(); } } @@ -55,14 +53,4 @@ public class Mmm { proxy.init(event); } - public static BLOCK registerBlock(BLOCK block) { - GameRegistry.register(block); - GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); - return block; - } - - public static AxisAlignedBB makeBlockAABB(int x1, int y1, int z1, int x2, int y2, int z2) { - return new AxisAlignedBB(x1 * .0625, y1 * .0625, z1 * .0625, x2 * .0625, y2 * .0625, z2 * .0625); - } - } diff --git a/src/java/mmm/utils/I_URecipeRegistrar.java b/src/java/mmm/utils/I_URecipeRegistrar.java new file mode 100644 index 0000000..955a773 --- /dev/null +++ b/src/java/mmm/utils/I_URecipeRegistrar.java @@ -0,0 +1,7 @@ +package mmm.utils; + +public interface I_URecipeRegistrar { + + public void registerRecipe(); + +} diff --git a/src/java/mmm/utils/UMaths.java b/src/java/mmm/utils/UMaths.java new file mode 100644 index 0000000..4c78461 --- /dev/null +++ b/src/java/mmm/utils/UMaths.java @@ -0,0 +1,11 @@ +package mmm.utils; + +import net.minecraft.util.math.AxisAlignedBB; + +public class UMaths { + + public static AxisAlignedBB makeBlockAABB(int x1, int y1, int z1, int x2, int y2, int z2) { + return new AxisAlignedBB(x1 * .0625, y1 * .0625, z1 * .0625, x2 * .0625, y2 * .0625, z2 * .0625); + } + +} diff --git a/src/java/mmm/utils/URegistration.java b/src/java/mmm/utils/URegistration.java new file mode 100644 index 0000000..6453fc9 --- /dev/null +++ b/src/java/mmm/utils/URegistration.java @@ -0,0 +1,72 @@ +package mmm.utils; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.common.registry.GameRegistry; + +public class URegistration { + + private static final HashMap ITEMS = new HashMap(); + private static final HashSet BLOCKS = new HashSet(); + + public static void addItem(Item item) { + addItem(item, true); + } + + public static void addItem(Item item, boolean registerModel) { + GameRegistry.register(item); + ITEMS.put(item, registerModel); + } + + public static void addBlock(Block block) { + addBlock(block, true); + } + + public static void addBlock(Block block, Item blockItem) { + addBlock(block, blockItem, true); + } + + public static void addBlock(Block block, boolean registerItemModel) { + addBlock(block, new ItemBlock(block).setRegistryName(block.getRegistryName()), registerItemModel); + } + + public static void addBlock(Block block, Item blockItem, boolean registerItemModel) { + GameRegistry.register(block); + BLOCKS.add(block); + if (blockItem != null) { + addItem(blockItem, registerItemModel); + } + } + + public static void registerRecipes() { + for (Block block : BLOCKS) { + if (block instanceof I_URecipeRegistrar) { + ((I_URecipeRegistrar) block).registerRecipe(); + } + } + + for (Item item : ITEMS.keySet()) { + if (item instanceof I_URecipeRegistrar) { + ((I_URecipeRegistrar) item).registerRecipe(); + } + } + } + + public static void setupItemModels() { + for (Map.Entry entry : ITEMS.entrySet()) { + if (!entry.getValue()) { + continue; + } + Item item = entry.getKey(); + ModelLoader.setCustomModelResourceLocation(item, 0, + new ModelResourceLocation(item.getRegistryName(), "inventory")); + } + } +}