Added damage/nbt sensitive cutting strength to saws

The highest tier saw is now able to cut blocks with strength requirements higher than itself
General code cleanup
This commit is contained in:
Chicken-Bones committed 2013-12-23 02:57:43 +10:00
1 parent 71dbc0fed2
commit 306a47d1f4
4 files changed
+58 -44

No files matched your search

+9 -5
View File
@@ -25,12 +25,16 @@ import net.minecraft.client.renderer.texture.IconRegister
/**
* Interface for items that are 'saws'
*/
trait Saw
trait Saw extends Item
{
/**
* The maximum harvest level that some version of this saw is capable of cutting
*/
def getMaxCuttingStrength:Int = getCuttingStrength(new ItemStack(this))
/**
* The harvest level this saw is capable of cutting
*/
def getCuttingStrength:Int
def getCuttingStrength(item:ItemStack):Int
}
class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item(sawTag.getTag("id").getIntValue(nextItemID)) with Saw
@@ -52,7 +56,7 @@ class ItemSaw(sawTag:ConfigTag, val harvestLevel:Int) extends Item(sawTag.getTag
override def doesContainerItemLeaveCraftingGrid(stack:ItemStack) = false
def getCuttingStrength = harvestLevel
def getCuttingStrength(item:ItemStack) = harvestLevel
override def registerIcons(register:IconRegister){}
}
@@ -70,7 +74,7 @@ object ItemSawRenderer extends IItemRenderer
def renderItem(renderType:ItemRenderType, item:ItemStack, data:Object*)
{
var t = renderType match {
val t = renderType match {
case INVENTORY => new TransformationList(new Scale(1.8), new Translation(0, 0, -0.6), new Rotation(-pi/4, 1, 0, 0), new Rotation(pi*3/4, 0, 1, 0))
case ENTITY => new TransformationList(new Scale(1), new Translation(0, 0, -0.25), new Rotation(-pi/4, 1, 0, 0))
case EQUIPPED_FIRST_PERSON => new TransformationList(new Scale(1.5), new Rotation(-pi/3, 1, 0, 0), new Rotation(pi*3/4, 0, 1, 0), new Translation(0.5, 0.5, 0.5))
@@ -89,7 +93,7 @@ object ItemSawRenderer extends IItemRenderer
CCRenderState.draw()
GL11.glDisable(GL11.GL_CULL_FACE)
CCRenderState.startDrawing(7)
blade.render(t, new UVTranslation(0, (item.getItem.asInstanceOf[Saw].getCuttingStrength-1)*4/64D))
blade.render(t, new UVTranslation(0, (item.getItem.asInstanceOf[Saw].getCuttingStrength(item)-1)*4/64D))
CCRenderState.draw()
GL11.glEnable(GL11.GL_CULL_FACE)
}
@@ -1,6 +1,5 @@
package codechicken.microblock
import codechicken.lib.vec.Cuboid6
import codechicken.multipart.IDWriter
import codechicken.lib.lighting.LightMatrix
import codechicken.lib.packet.PacketCustom
@@ -10,12 +9,11 @@ import codechicken.lib.data.MCDataInput
import codechicken.multipart.MultiPartRegistry
import cpw.mods.fml.relauncher.SideOnly
import cpw.mods.fml.relauncher.Side
import codechicken.microblock.handler.MicroblockProxy
import codechicken.lib.vec.Vector3
import net.minecraft.util.Icon
import net.minecraft.entity.player.EntityPlayer
import codechicken.lib.render.Vertex5
import net.minecraft.item.ItemStack
import net.minecraft.item.{Item, ItemStack}
import scala.collection.mutable.ListBuffer
import net.minecraft.block.StepSound
import net.minecraft.util.MovingObjectPosition
@@ -52,17 +50,17 @@ object MicroMaterialRegistry
* Get the render pass for which this material renders in.
*/
@SideOnly(Side.CLIENT)
def getRenderPass():Int
def getRenderPass:Int
/**
* Return true if this material is not opaque (glass, ice).
*/
def isTransparent():Boolean
def isTransparent:Boolean
/**
* Return the light level emitted by this material (glowstone)
*/
def getLightValue():Int
def getLightValue:Int
/**
* Return the strength of this material
@@ -72,27 +70,27 @@ object MicroMaterialRegistry
/**
* Return the localised name of this material (normally the block name)
*/
def getLocalizedName():String
def getLocalizedName:String
/**
* Get the item that this material is cut from (full block -> slabs)
*/
def getItem():ItemStack
def getItem:ItemStack
/**
* Get the strength of saw requried to cut this material
*/
def getCutterStrength():Int
def getCutterStrength:Int
/**
* Get the breaking/walking sound
*/
def getSound():StepSound
def getSound:StepSound
/**
* Return true if this material is solid and opaque (can run wires on etc)
*/
def isSolid() = !isTransparent
def isSolid = !isTransparent
}
/**
@@ -106,12 +104,13 @@ object MicroMaterialRegistry
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean
}
private val typeMap:HashMap[String, IMicroMaterial] = new HashMap
private val nameMap:HashMap[String, Int] = new HashMap
private val typeMap = HashMap[String, IMicroMaterial]()
private val nameMap = HashMap[String, Int]()
private var idMap:Array[(String, IMicroMaterial)] = _
private val idWriter = new IDWriter
private val highlightRenderers = ListBuffer[IMicroHighlightRenderer]()
private var maxCuttingStrength:Int = _
/**
* Register a micro material with unique identifier name
@@ -156,10 +155,20 @@ object MicroMaterialRegistry
{
idMap = typeMap.toList.sortBy(_._1).toArray
idWriter.setMax(idMap.length)
nameMap.clear
nameMap.clear()
for(i <- 0 until idMap.length)
nameMap.put(idMap(i)._1, i)
}
private [microblock] def calcMaxCuttingStrength()
{
maxCuttingStrength = Item.itemsList.flatMap {
case saw: Saw => Some(saw.getMaxCuttingStrength)
case _ => None
}.max
}
def getMaxCuttingStrength = maxCuttingStrength
def writeIDMap(packet:PacketCustom)
{
@@ -187,22 +196,23 @@ object MicroMaterialRegistry
}
return missing
}
//TODO: change to material
def writePartID(data:MCDataOutput, id:Int)
{
idWriter.write(data, id)
}
//TODO: change to material
def readPartID(data:MCDataInput) = idWriter.read(data)
def materialName(id:Int) = idMap(id)._1
def materialID(name:String) = nameMap.get(name) match {
case Some(v) => v
case None => {
case None =>
System.err.println("Missing mapping for part with ID: "+name)
0
}
}
def getMaterial(name:String) = typeMap.getOrElse(name, null)
@@ -213,8 +223,8 @@ object MicroMaterialRegistry
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean =
{
val overriden = highlightRenderers.find(_.renderHighlight(world, player, hit, mcrClass, size, material))
if(overriden.isDefined)
val overridden = highlightRenderers.find(_.renderHighlight(world, player, hit, mcrClass, size, material))
if(overridden.isDefined)
return true
return mcrClass.renderHighlight(world, player, hit, size, material)
+17 -12
View File
@@ -5,12 +5,13 @@ import net.minecraft.world.World
import net.minecraft.inventory.InventoryCrafting
import net.minecraft.item.ItemStack
import codechicken.microblock.handler.MicroblockProxy._
import codechicken.microblock.MicroMaterialRegistry
object MicroRecipe extends IRecipe
{
def getRecipeOutput():ItemStack = new ItemStack(sawStone)
def getRecipeOutput = new ItemStack(sawStone)
def getRecipeSize():Int = 9
def getRecipeSize = 9
def matches(icraft:InventoryCrafting, world:World) = getCraftingResult(icraft) != null
@@ -143,30 +144,34 @@ object MicroRecipe extends IRecipe
if(item != null && item.getItem.isInstanceOf[Saw])
return (item.getItem.asInstanceOf[Saw], r, c)
}
return null
return (null, 0, 0)
}
def canCut(saw:Saw, material:Int) = saw.getCuttingStrength >= MicroMaterialRegistry.getMaterial(material).getCutterStrength
def canCut(saw:Saw, sawItem:ItemStack, material:Int):Boolean = {
val sawStrength = saw.getCuttingStrength(sawItem)
val matStrength = MicroMaterialRegistry.getMaterial(material).getCutterStrength
return sawStrength >= matStrength || sawStrength == MicroMaterialRegistry.getMaxCuttingStrength
}
def getThinningResult(icraft:InventoryCrafting):ItemStack =
{
val saw = getSaw(icraft)
val (saw, row, col) = getSaw(icraft)
if(saw == null)
return null
val item = icraft.getStackInRowAndColumn(saw._3, saw._2+1)
val item = icraft.getStackInRowAndColumn(col, row+1)
if(item == null)
return null
val size = microSize(item)
val material = microMaterial(item)
val mcrClass = microClass(item)
if(size == 1 || material < 0 || !canCut(saw._1, material))
if(size == 1 || material < 0 || !canCut(saw, icraft.getStackInRowAndColumn(col, row), material))
return null
for(r <- 0 until 3)
for(c <- 0 until 3)
if((c != saw._3 || r != saw._2 && r != saw._2+1) &&
if((c != col || r != row && r != row+1) &&
icraft.getStackInRowAndColumn(c, r) != null)
return null
@@ -185,19 +190,19 @@ object MicroRecipe extends IRecipe
val splitMap = Map(0 -> 3, 1 -> 3, 3 -> 2)
def getSplittingResult(icraft:InventoryCrafting):ItemStack =
{
val saw = getSaw(icraft)
val (saw, row, col) = getSaw(icraft)
if(saw == null) return null
val item = icraft.getStackInRowAndColumn(saw._3+1, saw._2)
val item = icraft.getStackInRowAndColumn(col+1, row)
if(item == null || item.getItem != itemMicro) return null
val mcrClass = microClass(item)
val material = microMaterial(item)
if(!canCut(saw._1, material)) return null
if(!canCut(saw, icraft.getStackInRowAndColumn(col, row), material)) return null
val split = splitMap.get(mcrClass)
if(split.isEmpty)return null
for(r <- 0 until 3)
for(c <- 0 until 3)
if((r != saw._2 || c != saw._3 && c != saw._3+1) &&
if((r != row || c != col && c != col+1) &&
icraft.getStackInRowAndColumn(c, r) != null)
return null
+2 -7
View File
@@ -4,25 +4,19 @@ import net.minecraftforge.common.MinecraftForge
import codechicken.multipart.handler.MultipartProxy._
import codechicken.multipart.TMultiPart
import codechicken.multipart.MultiPartRegistry
import codechicken.microblock.FaceMicroblock
import codechicken.microblock.ItemMicroPart
import codechicken.microblock._
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial
import codechicken.microblock.MicroblockClass
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.lib.config.ConfigTag
import codechicken.lib.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
@@ -91,6 +85,7 @@ class MicroblockProxy_serverImpl
def postInit()
{
MicroMaterialRegistry.calcMaxCuttingStrength()
}
}