diff --git a/src/main/java/com/myname/mymodid/CommonProxy.java b/src/main/java/com/myname/mymodid/CommonProxy.java index dfdfe53..da0477a 100644 --- a/src/main/java/com/myname/mymodid/CommonProxy.java +++ b/src/main/java/com/myname/mymodid/CommonProxy.java @@ -1,5 +1,6 @@ package com.myname.mymodid; +import com.myname.mymodid.blocks.CustomStone; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -11,6 +12,7 @@ public class CommonProxy { // GameRegistry." (Remove if not needed) public void preInit(FMLPreInitializationEvent event) { Config.synchronizeConfiguration(event.getSuggestedConfigurationFile()); + CustomStone.register(); MyMod.LOG.info(Config.greeting); MyMod.LOG.info("I am MyMod at version " + Tags.VERSION); diff --git a/src/main/java/com/myname/mymodid/base/CustomBlock.java b/src/main/java/com/myname/mymodid/base/CustomBlock.java new file mode 100644 index 0000000..b9c2ea5 --- /dev/null +++ b/src/main/java/com/myname/mymodid/base/CustomBlock.java @@ -0,0 +1,70 @@ +package com.myname.mymodid.base; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class CustomBlock extends Block { + public String name; + Item item; + HashMap subblocks; + protected IIcon[] icons; + + public CustomBlock(String name, Material material, HashMap subblocks) { + super(material); + this.name = name; + this.subblocks = subblocks; + icons = new IIcon[subblocks.size()]; + } + + @Override + public String getUnlocalizedName() { + return "stones:"+name; + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(int side, int meta) { + if (meta <= this.icons.length) + return this.icons[meta]; + else + return this.icons[0]; + } + + @Override + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < this.subblocks.size(); ++i) { + list.add(new ItemStack(item, 1, i)); + } + } + + public void setDrop(Item item){ + this.item = item; + } + + @Override + public ArrayList getDrops(World world, int x, int y, int z, int meta, int fortune) { + ArrayList drops = new ArrayList<>(); + ItemStack itemStack = new ItemStack(this, 1, meta); + drops.add(itemStack); + return drops; + } + + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister icon) { + for (int i = 0; i < this.icons.length; ++i) { + this.icons[i] = icon.registerIcon("stones:"+name+"_"+this.subblocks.get(i)); + } + } +} diff --git a/src/main/java/com/myname/mymodid/base/CustomItem.java b/src/main/java/com/myname/mymodid/base/CustomItem.java new file mode 100644 index 0000000..3203990 --- /dev/null +++ b/src/main/java/com/myname/mymodid/base/CustomItem.java @@ -0,0 +1,12 @@ +package com.myname.mymodid.base; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemSeeds; + +public class CustomItem extends ItemBlock { + public CustomItem(Block block) { + super(block); + this.setHasSubtypes(true); + } +} diff --git a/src/main/java/com/myname/mymodid/blocks/CustomStone.java b/src/main/java/com/myname/mymodid/blocks/CustomStone.java new file mode 100644 index 0000000..1ddde5b --- /dev/null +++ b/src/main/java/com/myname/mymodid/blocks/CustomStone.java @@ -0,0 +1,34 @@ +package com.myname.mymodid.blocks; + +import com.myname.mymodid.base.CustomBlock; +import com.myname.mymodid.base.CustomItem; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; + +import java.util.HashMap; + +public class CustomStone{ + static HashMap subblocks = new HashMap<>(); + public enum Stones { + BRICKS, + CHISELED; + + Stones() { + subblocks.put(this.ordinal(), this.name()); + } + } + + public static void register(){ + Stones.values(); + CustomBlock block = new CustomBlock("custom_block", Material.rock, subblocks); + //ItemBlock item = new CustomItem(block); + //block.setDrop(item); + //GameRegistry.registerItem(item, block.name); + GameRegistry.registerBlock(block, block.name); + } +} +