A few utility classes

This commit is contained in:
Emmanuel BENOîT 2016-06-13 16:29:23 +02:00
parent 23a9cb2157
commit b7b0f59c82
5 changed files with 96 additions and 16 deletions

4
.gitignore vendored
View file

@ -1,7 +1,9 @@
.gradle
build
/build/
.classpath
.project
.settings
mmm_Client.launch
mmm_Server.launch
/bin/
/run/

View file

@ -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 extends Block> 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);
}
}

View file

@ -0,0 +1,7 @@
package mmm.utils;
public interface I_URecipeRegistrar {
public void registerRecipe();
}

View file

@ -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);
}
}

View file

@ -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<Item, Boolean> ITEMS = new HashMap<Item, Boolean>();
private static final HashSet<Block> BLOCKS = new HashSet<Block>();
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<Item, Boolean> entry : ITEMS.entrySet()) {
if (!entry.getValue()) {
continue;
}
Item item = entry.getKey();
ModelLoader.setCustomModelResourceLocation(item, 0,
new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
}
}