diff --git a/codechicken/microblock/BlockMicroMaterial.scala b/codechicken/microblock/BlockMicroMaterial.scala index 3951817..0ce81f0 100644 --- a/codechicken/microblock/BlockMicroMaterial.scala +++ b/codechicken/microblock/BlockMicroMaterial.scala @@ -4,8 +4,8 @@ import net.minecraft.block.Block import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial import net.minecraft.util.Icon import codechicken.core.vec.Cuboid6 -import codechicken.core.lighting.LC; -import codechicken.core.lighting.LightMatrix; +import codechicken.core.lighting.LC +import codechicken.core.lighting.LightMatrix import cpw.mods.fml.relauncher.SideOnly import cpw.mods.fml.relauncher.Side import codechicken.core.render.MultiIconTransformation @@ -21,6 +21,7 @@ import net.minecraft.client.renderer.Tessellator import codechicken.core.render.CCRenderState import codechicken.core.vec.Rotation import net.minecraft.tileentity.TileEntity +import net.minecraftforge.common.MinecraftForge class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMaterial { @@ -83,15 +84,19 @@ class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMateri @SideOnly(Side.CLIENT) def getBreakingIcon(side:Int) = block.getIcon(side, meta) - def getItem = Item.itemsList(block.blockID) + def getItem = new ItemStack(block, 1, meta) - def getLocalizedName = getItem.getItemDisplayName(new ItemStack(getItem, 1, meta)) + def getLocalizedName = getItem.getDisplayName def getStrength(player:EntityPlayer) = player.getCurrentPlayerStrVsBlock(block, false, meta)/block.blockHardness def isTransparent = !block.isOpaqueCube def getLightValue = Block.lightValue(block.blockID) + + def toolClasses = Seq("axe", "pickaxe", "shovel") + + def getCutterStrength = toolClasses.foldLeft(0)((level, tool) => Math.max(level, MinecraftForge.getBlockHarvestLevel(block, meta, tool))) } object BlockMicroMaterial diff --git a/codechicken/microblock/ItemMicroPart.scala b/codechicken/microblock/ItemMicroPart.scala index 06c08a5..9d228ff 100644 --- a/codechicken/microblock/ItemMicroPart.scala +++ b/codechicken/microblock/ItemMicroPart.scala @@ -46,7 +46,7 @@ class ItemMicroPart(id:Int) extends Item(id) val mcrClass = classes(classId) if(mcrClass != null) for(size <- Seq(1, 2, 4)) - MicroMaterialRegistry.materials_foreach((s, m) => list.add(create(classId<<8|size, s))) + MicroMaterialRegistry.getIdMap.foreach(e => list.add(create(classId<<8|size, e._1))) } } @@ -95,7 +95,7 @@ object ItemMicroPart def create(amount:Int, damage:Int, material:String):ItemStack = { - val stack = new ItemStack(MicroblockProxy.item, amount, damage) + val stack = new ItemStack(MicroblockProxy.itemMicro, amount, damage) checkTagCompound(stack) stack.getTagCompound().setString("mat", material) return stack diff --git a/codechicken/microblock/MicroMaterialRegistry.scala b/codechicken/microblock/MicroMaterialRegistry.scala index 7df8136..bc1c649 100644 --- a/codechicken/microblock/MicroMaterialRegistry.scala +++ b/codechicken/microblock/MicroMaterialRegistry.scala @@ -2,7 +2,7 @@ package codechicken.microblock import codechicken.core.vec.Cuboid6 import codechicken.multipart.IDWriter -import codechicken.core.lighting.LightMatrix; +import codechicken.core.lighting.LightMatrix import codechicken.core.packet.PacketCustom import scala.collection.mutable.HashMap import codechicken.core.data.MCDataOutput @@ -15,6 +15,7 @@ import codechicken.core.vec.Vector3 import net.minecraft.util.Icon import net.minecraft.entity.player.EntityPlayer import codechicken.core.render.Vertex5 +import net.minecraft.item.ItemStack object MicroMaterialRegistry { @@ -39,6 +40,10 @@ object MicroMaterialRegistry def getStrength(player:EntityPlayer):Float def getLocalizedName:String + + def getItem:ItemStack + + def getCutterStrength:Int //todo, get material properties } @@ -116,5 +121,5 @@ object MicroMaterialRegistry def getMaterial(id:Int) = idMap(id)._2 - def materials_foreach(func:(String, IMicroMaterial) => Unit) = idMap.foreach(e => func(e._1, e._2)) + def getIdMap = idMap } \ No newline at end of file diff --git a/codechicken/microblock/handler/EventHandler.scala b/codechicken/microblock/handler/EventHandler.scala index 2cb0cf5..c0e92c5 100644 --- a/codechicken/microblock/handler/EventHandler.scala +++ b/codechicken/microblock/handler/EventHandler.scala @@ -21,14 +21,14 @@ object MicroblockEventHandler def postTextureStitch(event:TextureStitchEvent.Post) { if(Loader.instance.hasReachedState(LoaderState.POSTINITIALIZATION)) - MicroMaterialRegistry.materials_foreach((s, m) => m.loadIcons()) + MicroMaterialRegistry.getIdMap.foreach(e => e._2.loadIcons()) } @ForgeSubscribe @SideOnly(Side.CLIENT) def drawBlockHighlight(event:DrawBlockHighlightEvent) { - if(event.currentItem != null && event.currentItem.getItem== MicroblockProxy.item && + if(event.currentItem != null && event.currentItem.getItem == MicroblockProxy.itemMicro && event.target != null && event.target.typeOfHit == EnumMovingObjectType.TILE) { GL11.glPushMatrix() diff --git a/codechicken/microblock/handler/Proxies.scala b/codechicken/microblock/handler/Proxies.scala index 477141e..26c66ae 100644 --- a/codechicken/microblock/handler/Proxies.scala +++ b/codechicken/microblock/handler/Proxies.scala @@ -12,19 +12,71 @@ import net.minecraftforge.client.MinecraftForgeClient import codechicken.microblock.ItemMicroPartRenderer import cpw.mods.fml.relauncher.SideOnly import cpw.mods.fml.relauncher.Side +import net.minecraft.item.crafting.CraftingManager +import codechicken.microblock.MicroRecipe +import net.minecraft.item.Item +import codechicken.microblock.ItemSaw +import net.minecraft.item.crafting.IRecipe +import java.util.{List => JList} +import cpw.mods.fml.common.registry.LanguageRegistry +import codechicken.core.config.ConfigTag +import codechicken.core.config.ConfigFile +import net.minecraftforge.oredict.OreDictionary +import codechicken.microblock.ItemSawRenderer +import net.minecraft.item.ItemStack +import net.minecraftforge.oredict.ShapedOreRecipe +import net.minecraft.block.Block class MicroblockProxy_serverImpl { - var item:ItemMicroPart = _ + private var baseID = 24875-1 + + def nextItemID = {baseID+=1; baseID} + + var itemMicro:ItemMicroPart = _ + var sawStone:Item = _ + var sawIron:Item = _ + var sawDiamond:Item = _ + var stoneRod:Item = _ def preInit() { - item = new ItemMicroPart(config.getTag("itemMicro.id").getIntValue(24875)) + itemMicro = new ItemMicroPart(config.getTag("itemMicro.id").getIntValue(nextItemID)) + sawStone = createSaw(config, "sawStone", 1, "Stone Handsaw") + sawIron = createSaw(config, "sawIron", 2, "Iron Handsaw") + sawDiamond = createSaw(config, "sawDiamond", 3, "Diamond Handsaw") + stoneRod = new Item(config.getTag("stoneRod.id").getIntValue(nextItemID)).setUnlocalizedName("microblock:stoneRod") + LanguageRegistry.addName(stoneRod, "Stone Rod") + OreDictionary.registerOre("stoneRod", stoneRod) + MinecraftForge.EVENT_BUS.register(MicroblockEventHandler) } + def createSaw(config:ConfigFile, name:String, strength:Int, localized:String) = + { + val saw = new ItemSaw(config.getTag(name).useBraces(), strength).setUnlocalizedName("microblock:"+name) + LanguageRegistry.addName(saw, localized) + saw + } + + def addSawRecipe(saw:Item, blade:Item) + { + CraftingManager.getInstance.getRecipeList.asInstanceOf[JList[IRecipe]].add( + new ShapedOreRecipe(new ItemStack(saw), + "srr", + "sbr", + 's':Character, Item.stick, + 'r':Character, "stoneRod", + 'b':Character, blade)) + } + def init() { + CraftingManager.getInstance.getRecipeList.asInstanceOf[JList[IRecipe]].add(MicroRecipe) + CraftingManager.getInstance.addRecipe(new ItemStack(stoneRod, 4), "s", "s", 's':Character, Block.stone) + addSawRecipe(sawStone, Item.flint) + addSawRecipe(sawIron, Item.ingotIron) + addSawRecipe(sawDiamond, Item.diamond) } def postInit() @@ -37,7 +89,14 @@ class MicroblockProxy_clientImpl extends MicroblockProxy_serverImpl @SideOnly(Side.CLIENT) override def postInit() { - MinecraftForgeClient.registerItemRenderer(item.itemID, ItemMicroPartRenderer) + MinecraftForgeClient.registerItemRenderer(itemMicro.itemID, ItemMicroPartRenderer) + } + + override def createSaw(config:ConfigFile, name:String, strength:Int, localized:String) = + { + val saw = super.createSaw(config, name, strength, localized) + MinecraftForgeClient.registerItemRenderer(saw.itemID, ItemSawRenderer) + saw } } diff --git a/mods/microblock/models/saw.obj b/mods/microblock/models/saw.obj new file mode 100644 index 0000000..0579f00 --- /dev/null +++ b/mods/microblock/models/saw.obj @@ -0,0 +1,164 @@ +# Blender v2.64 (sub 0) OBJ File: 'hackSaw.blend' +# www.blender.org +g Handle +v 0.039250 0.068563 -0.108650 +v 0.039250 -0.196237 -0.108650 +v -0.039250 -0.196237 -0.108650 +v -0.039250 0.068563 -0.108650 +v 0.039250 0.196263 0.108650 +v -0.039250 0.196263 0.108650 +v -0.039250 -0.068537 0.108650 +v 0.039250 -0.068537 0.108650 +v -0.039250 -0.126338 -0.068650 +v -0.039250 0.045662 -0.068650 +v -0.039250 -0.045638 0.068650 +v -0.039250 0.126263 0.068650 +v 0.039250 0.045662 -0.068650 +v 0.039250 -0.126338 -0.068650 +v 0.039250 0.126263 0.068650 +v 0.039250 -0.045638 0.068650 +vt 0.250000 0.562500 +vt 0.250000 0.187500 +vt 0.312500 0.250000 +vt 0.312500 0.500000 +vt 0.625000 0.187500 +vt 0.562500 0.250000 +vt 0.625000 0.562500 +vt 0.562500 0.500000 +vt 0.625000 0.000000 +vt 1.000000 0.000000 +vt 1.000000 0.093750 +vt 0.625000 0.093750 +vt 1.000000 0.187500 +vt 0.250000 0.093750 +vt 0.250000 0.000000 +vt 0.875000 0.468750 +vt 0.625000 0.468750 +vt 0.625000 0.375000 +vt 0.875000 0.375000 +vt 0.875000 0.562500 +vt 0.875000 0.187500 +vt 0.875000 0.281250 +vt 0.625000 0.281250 +vn -1.000000 0.000000 -0.000000 +vn 1.000000 0.000000 0.000000 +vn 0.610523 0.393323 -0.687368 +vn 0.554430 -0.722312 -0.413312 +vn -0.554430 -0.722312 -0.413312 +vn -0.610523 0.393323 -0.687368 +vn 0.554430 0.722312 0.413312 +vn -0.554430 0.722312 0.413312 +vn -0.610523 -0.393323 0.687368 +vn 0.610523 -0.393323 0.687368 +vn -0.958464 0.247505 0.141606 +vn -0.837581 0.271279 -0.474136 +vn 0.837581 0.271279 -0.474136 +vn 0.958464 0.247505 0.141606 +vn -0.958403 -0.247597 -0.141758 +vn 0.958403 -0.247597 -0.141758 +vn -0.837672 -0.271340 0.473952 +vn 0.837672 -0.271340 0.473952 +s off +f 4/1/1 3/2/1 9/3/1 10/4/1 +f 3/2/1 7/5/1 11/6/1 9/3/1 +f 7/5/1 6/7/1 12/8/1 11/6/1 +f 6/7/1 4/1/1 10/4/1 12/8/1 +f 2/2/2 1/1/2 13/4/2 14/3/2 +f 1/1/2 5/7/2 15/8/2 13/4/2 +f 5/7/2 8/5/2 16/6/2 15/8/2 +f 8/5/2 2/2/2 14/3/2 16/6/2 +s 1 +f 1/9/3 2/10/4 3/11/5 4/12/6 +f 5/13/7 6/11/8 7/12/9 8/5/10 +f 1/9/3 4/12/6 6/14/8 5/15/7 +f 3/14/5 2/2/4 8/5/10 7/12/9 +f 9/16/11 11/17/12 16/18/13 14/19/14 +f 11/20/12 12/7/15 15/17/16 16/16/13 +f 12/5/15 10/21/17 13/22/18 15/23/16 +f 10/23/17 9/22/11 14/19/14 13/18/18 +g Blade +v 0.000000 0.067100 -0.081925 +v 0.000000 0.732900 -0.081925 +v 0.000000 0.732900 -0.107925 +v 0.000000 0.067100 -0.107925 +vt 1.000000 1.000000 +vt 0.187500 1.000000 +vt 0.187500 0.953125 +vt 1.000000 0.953125 +vn 0.999969 0.000000 0.000000 +s 1 +f 18/24/19 17/25/2 20/26/19 19/27/2 +g BaldeSupport +v -0.025100 0.713937 -0.081525 +v 0.025100 0.719137 0.036975 +v 0.025100 0.167037 0.036975 +v 0.025100 0.713937 -0.081525 +v 0.025100 0.739237 -0.022325 +v -0.025100 0.739237 -0.022325 +v -0.025100 0.167037 0.036975 +v -0.025100 0.719137 0.036975 +v 0.025100 0.748037 -0.127225 +v 0.025100 0.794437 0.003175 +v -0.025100 0.794437 0.003175 +v -0.025100 0.748037 -0.127225 +v 0.025100 0.144237 0.076975 +v -0.025100 0.144237 0.076975 +v -0.025100 0.773937 0.076975 +v 0.025100 0.773937 0.076975 +vt 0.062500 0.859375 +vt 0.062500 0.750000 +vt 0.125000 0.750000 +vt 0.125000 0.859375 +vt 0.125000 1.000000 +vt 0.062500 1.000000 +vt 0.187500 0.140625 +vt 0.125000 0.140625 +vt 0.125000 0.062500 +vt 0.187500 0.062500 +vt 0.125000 0.937500 +vt 0.187500 0.937500 +vt 0.187500 1.000000 +vt 0.062500 0.000000 +vt 0.125000 0.000000 +vt 0.187500 0.203125 +vt 0.125000 0.203125 +vt 0.000000 0.750000 +vt 0.000000 0.859375 +vt 0.187500 0.281250 +vt 0.125000 0.281250 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn 0.000000 -0.801471 -0.598034 +vn 0.000000 -0.868777 -0.495203 +vn -0.610157 -0.786706 -0.093722 +vn 0.610157 -0.786706 -0.093722 +vn 0.796991 -0.603504 0.023255 +vn -0.796991 -0.603504 0.023255 +vn -0.592944 0.487259 0.641072 +vn 0.592944 0.487259 0.641072 +vn 0.645070 0.763604 -0.027070 +vn -0.645070 0.763604 -0.027070 +vn 0.864193 -0.293130 -0.408887 +vn -0.864193 -0.293130 -0.408887 +vn -0.609577 -0.398236 -0.685385 +vn 0.609577 -0.398236 -0.685385 +vn -0.552568 0.124210 -0.824152 +vn 0.552568 0.124210 -0.824152 +vn -0.554888 -0.719291 0.417951 +vn 0.554888 -0.719291 0.417951 +s off +f 30/28/2 36/29/2 22/30/2 25/31/2 +f 21/32/1 26/31/1 31/28/1 32/33/1 +f 24/34/20 21/35/20 32/36/20 29/37/20 +f 27/38/21 23/39/21 33/40/21 34/32/21 +f 36/29/2 33/41/2 23/42/2 22/30/2 +f 30/28/2 25/31/2 24/32/2 29/33/2 +f 31/28/1 26/31/1 28/30/1 35/29/1 +f 34/41/1 35/29/1 28/30/1 27/42/1 +s 1 +f 21/35/22 24/34/23 25/43/24 26/44/25 +f 35/45/26 36/29/27 30/28/28 31/46/29 +f 26/44/25 25/43/24 22/47/30 28/48/31 +f 27/38/32 28/48/31 22/47/30 23/39/33 +f 32/49/34 31/46/29 30/28/28 29/33/35 +f 36/29/27 35/45/26 34/50/36 33/41/37 diff --git a/mods/microblock/textures/items/saw.png b/mods/microblock/textures/items/saw.png new file mode 100644 index 0000000..25a0f84 Binary files /dev/null and b/mods/microblock/textures/items/saw.png differ diff --git a/mods/microblock/textures/items/stoneRod.png b/mods/microblock/textures/items/stoneRod.png new file mode 100644 index 0000000..fc7d51d Binary files /dev/null and b/mods/microblock/textures/items/stoneRod.png differ