mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-19 19:59:40 +00:00
Added configurable materials
This commit is contained in:
1 parent
ca8f7d0dc2
commit
0262bef9d7
5 files changed
+151
-2
No files matched your search
@@ -0,0 +1,142 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import java.io.BufferedReader
|
||||
import java.io.FileReader
|
||||
import scala.collection.mutable.{Map => MMap}
|
||||
import net.minecraft.block.Block
|
||||
import java.lang.Exception
|
||||
|
||||
object ConfigContent
|
||||
{
|
||||
private val nameMap = MMap[String, Seq[Int]]()
|
||||
private val idMap = new Array[Seq[Int]](Block.blocksList.length)
|
||||
|
||||
def parse(cfgDir:File)
|
||||
{
|
||||
val cfgFile = new File(cfgDir, "microblocks.cfg")
|
||||
try
|
||||
{
|
||||
if(!cfgFile.exists())
|
||||
generateDefault(cfgFile)
|
||||
else
|
||||
loadLines(cfgFile)
|
||||
}
|
||||
catch
|
||||
{
|
||||
case e:IOException => e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
def generateDefault(cfgFile:File)
|
||||
{
|
||||
val writer = new PrintWriter(cfgFile)
|
||||
writer.println("#Configuration file for adding microblock materials for aesthetic blocks added by mods")
|
||||
writer.println("#Each line needs to be of the form <ID>:<meta>")
|
||||
writer.println("#<ID> may be a numerical id or the unlocalised name of the block/item enclosed in double quotes. NEI can help you find these")
|
||||
writer.println("#<meta> may be ommitted, in which case it defaults to 0, otherwise it can be a number, a comma separated list of numbers, or a dash separated range")
|
||||
writer.println("#Ex. 3. 5:3. 213:1,2,3,5. \"tile.blockIron\":0-15")
|
||||
writer.close()
|
||||
}
|
||||
|
||||
def loadLine(line:String)
|
||||
{
|
||||
if(line.startsWith("#"))
|
||||
return
|
||||
|
||||
var split1 = line.replace(" ", "").split(":")
|
||||
if(split1.length > 2)
|
||||
throw new IllegalArgumentException("Invalid number of ':' separators")
|
||||
if(split1.length == 1)
|
||||
split1 = Array(split1(0), "0")
|
||||
|
||||
if(split1(0) == "")
|
||||
return
|
||||
|
||||
var split2 = split1(1).split(",")
|
||||
val meta = split2.flatMap{s =>
|
||||
if(s.contains("-"))
|
||||
{
|
||||
val split2 = s.split("-")
|
||||
if(split2.length != 2)
|
||||
throw new IllegalArgumentException("Invalid - separated range")
|
||||
split2(0).toInt to split2(1).toInt
|
||||
}
|
||||
else
|
||||
{
|
||||
Seq(s.toInt)
|
||||
}
|
||||
}
|
||||
|
||||
val s_id = split1(0)
|
||||
if(s_id.charAt(0) == '\"')
|
||||
{
|
||||
if(!s_id.endsWith("\""))
|
||||
throw new IllegalArgumentException("Missing closing \" character")
|
||||
|
||||
val name = s_id.substring(1, s_id.length-1)
|
||||
nameMap.put(name, meta)
|
||||
}
|
||||
else
|
||||
{
|
||||
idMap(s_id.toInt) = meta
|
||||
}
|
||||
}
|
||||
|
||||
def loadLines(cfgFile:File)
|
||||
{
|
||||
val reader = new BufferedReader(new FileReader(cfgFile))
|
||||
var s:String = null
|
||||
do
|
||||
{
|
||||
s = reader.readLine
|
||||
if(s != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
loadLine(s)
|
||||
}
|
||||
catch
|
||||
{
|
||||
case e:Exception => {
|
||||
System.err.println("Invalid line in microblocks.cfg: "+s)
|
||||
System.err.println(e.getMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while(s != null)
|
||||
reader.close()
|
||||
}
|
||||
|
||||
def load()
|
||||
{
|
||||
import BlockMicroMaterial._
|
||||
|
||||
for(i <- 0 until idMap.length)
|
||||
{
|
||||
val block = Block.blocksList(i)
|
||||
if(idMap(i) != null)
|
||||
{
|
||||
if(block == null)
|
||||
System.err.println("Warning: Unable to add micro material for block with ID "+i+" as it doesn't exist")
|
||||
else
|
||||
createAndRegister(block, idMap(i))
|
||||
}
|
||||
else if(block != null)
|
||||
{
|
||||
val name = block.getUnlocalizedName()
|
||||
val value = nameMap.get(name)
|
||||
if(value.isDefined)
|
||||
{
|
||||
createAndRegister(block, value.get)
|
||||
nameMap.remove(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nameMap.foreach(e => System.err.println("Warning: Unable to add micro material for block with unlocalised name "+e._1+" as it doesn't exist"))
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,9 @@ object DefaultContent
|
||||
createAndRegister(blockEmerald)
|
||||
createAndRegister(blockRedstone)
|
||||
createAndRegister(blockNetherQuartz)
|
||||
createAndRegister(field_111039_cA, 0 to 15)
|
||||
createAndRegister(field_111032_cD)
|
||||
createAndRegister(field_111034_cE)
|
||||
registerMaterial(new GrassMicroMaterial, grass.getUnlocalizedName)
|
||||
registerMaterial(new TopMicroMaterial(mycelium), mycelium.getUnlocalizedName)
|
||||
}
|
||||
|
||||
@@ -14,9 +14,10 @@ import cpw.mods.fml.common.Mod.Instance
|
||||
import codechicken.microblock.MicroMaterialRegistry
|
||||
import codechicken.microblock.DefaultContent
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent
|
||||
import codechicken.microblock.ConfigContent
|
||||
|
||||
@Mod(modid = "ForgeMicroblock", acceptedMinecraftVersions = "[1.6.2]",
|
||||
dependencies="required-after:ForgeMultipart", modLanguage="scala")
|
||||
dependencies="required-after:ForgeMultipart;after:*", modLanguage="scala")
|
||||
object MicroblockMod
|
||||
{
|
||||
@PreInit
|
||||
@@ -24,12 +25,14 @@ object MicroblockMod
|
||||
{
|
||||
MicroblockProxy.preInit()
|
||||
DefaultContent.load()
|
||||
ConfigContent.parse(event.getModConfigurationDirectory)
|
||||
}
|
||||
|
||||
@Init
|
||||
def init(event:FMLInitializationEvent)
|
||||
{
|
||||
MicroblockProxy.init()
|
||||
ConfigContent.load()
|
||||
MicroMaterialRegistry.setupIDMap()
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.util.ResourceLocation
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import cpw.mods.fml.common.network.NetworkRegistry
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import java.io.File
|
||||
|
||||
class MicroblockProxy_serverImpl
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ object MultipartMod
|
||||
@PreInit
|
||||
def preInit(event:FMLPreInitializationEvent)
|
||||
{
|
||||
MultipartProxy.preInit(event.getModConfigurationDirectory())
|
||||
MultipartProxy.preInit(event.getModConfigurationDirectory)
|
||||
}
|
||||
|
||||
@PostInit
|
||||
|
||||
Reference in new issue
Block a user