From 32af871971e27f7e0a236db0b2cfe75af7ae203d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 24 Aug 2014 12:30:12 +0200 Subject: [PATCH 1/2] Made all blocks 'harvestable' bare handed. --- .../li/cil/oc/common/block/Delegator.scala | 2 ++ .../tileentity/traits/power/BuildCraft.scala | 17 +++++++++++------ .../tileentity/traits/power/Factorization.scala | 9 +++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/block/Delegator.scala b/src/main/scala/li/cil/oc/common/block/Delegator.scala index 34ddbe9ea..1f7147a7e 100644 --- a/src/main/scala/li/cil/oc/common/block/Delegator.scala +++ b/src/main/scala/li/cil/oc/common/block/Delegator.scala @@ -108,6 +108,8 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) { // Block // ----------------------------------------------------------------------- // + override def canHarvestBlock(player: EntityPlayer, meta: Int) = true + override def canBeReplacedByLeaves(world: World, x: Int, y: Int, z: Int) = false override def canCreatureSpawn(creature: EnumCreatureType, world: World, x: Int, y: Int, z: Int) = false diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/power/BuildCraft.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/power/BuildCraft.scala index 7091beb72..5c7bc4659 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/power/BuildCraft.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/power/BuildCraft.scala @@ -2,8 +2,8 @@ package li.cil.oc.common.tileentity.traits.power import buildcraft.api.power.{IPowerReceptor, PowerHandler} import cpw.mods.fml.common.Optional -import li.cil.oc.Settings import li.cil.oc.util.mods.Mods +import li.cil.oc.{OpenComputers, Settings} import net.minecraftforge.common.ForgeDirection trait BuildCraft extends Common { @@ -31,11 +31,16 @@ trait BuildCraft extends Common { @Optional.Method(modid = Mods.IDs.BuildCraftPower) def getPowerProvider = { if (Mods.BuildCraftPower.isAvailable && powerHandler.isEmpty) { - val handler = new PowerHandler(this.asInstanceOf[IPowerReceptor], PowerHandler.Type.MACHINE) - if (handler != null) { - handler.configure(1, 320, Float.MaxValue, 640) - handler.configurePowerPerdition(0, 0) - powerHandler = Some(handler) + this match { + case receptor: IPowerReceptor => + val handler = new PowerHandler(receptor, PowerHandler.Type.MACHINE) + if (handler != null) { + handler.configure(1, 320, Float.MaxValue, 640) + handler.configurePowerPerdition(0, 0) + powerHandler = Some(handler) + } + case _ => + OpenComputers.log.warning("Failed setting up BuildCraft power, which most likely means the class transformer did not run. You're probably running in an incorrectly configured development environment. Try adding `-Dfml.coreMods.load=li.cil.oc.common.launch.TransformerLoader` to the VM options of your run configuration.") } } if (powerHandler.isDefined) diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/power/Factorization.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/power/Factorization.scala index 775f844fe..4f9af01fd 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/power/Factorization.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/power/Factorization.scala @@ -2,15 +2,20 @@ package li.cil.oc.common.tileentity.traits.power import cpw.mods.fml.common.Optional import factorization.api.{Charge, Coord, IChargeConductor} -import li.cil.oc.Settings import li.cil.oc.util.mods.Mods +import li.cil.oc.{OpenComputers, Settings} import net.minecraftforge.common.ForgeDirection trait Factorization extends Common { private lazy val useFactorizationPower = isServer && Mods.Factorization.isAvailable @Optional.Method(modid = Mods.IDs.Factorization) - private lazy val charge: AnyRef = new Charge(this.asInstanceOf[IChargeConductor]) + private lazy val charge: AnyRef = this match { + case conductor: IChargeConductor => new Charge(conductor) + case _ => + OpenComputers.log.warning("Failed setting up Factorization power, which most likely means the class transformer did not run. You're probably running in an incorrectly configured development environment. Try adding `-Dfml.coreMods.load=li.cil.oc.common.launch.TransformerLoader` to the VM options of your run configuration.") + null + } // ----------------------------------------------------------------------- // From 44f2e7ab1c14a84e3c8c0bc9f0c5a8a8667595f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 24 Aug 2014 13:03:44 +0200 Subject: [PATCH 2/2] Handling missing external save data more gracefully. --- src/main/scala/li/cil/oc/common/SaveHandler.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/SaveHandler.scala b/src/main/scala/li/cil/oc/common/SaveHandler.scala index a50d8f493..ca0a098c3 100644 --- a/src/main/scala/li/cil/oc/common/SaveHandler.scala +++ b/src/main/scala/li/cil/oc/common/SaveHandler.scala @@ -67,9 +67,12 @@ object SaveHandler { def loadNBT(nbt: NBTTagCompound, name: String): NBTTagCompound = { val data = load(nbt, name) - val bais = new ByteArrayInputStream(data) - val dis = new DataInputStream(bais) - CompressedStreamTools.read(dis) + if (data.length > 0) { + val bais = new ByteArrayInputStream(data) + val dis = new DataInputStream(bais) + CompressedStreamTools.read(dis) + } + else new NBTTagCompound() } def load(nbt: NBTTagCompound, name: String): Array[Byte] = { @@ -114,6 +117,7 @@ object SaveHandler { val dimPath = new io.File(path, dimension.toString) val chunkPath = new io.File(dimPath, s"${chunk.chunkXPos}.${chunk.chunkZPos}") val file = new io.File(chunkPath, name) + if (!file.exists()) return Array.empty[Byte] try { // val bis = new io.BufferedInputStream(new GZIPInputStream(new io.FileInputStream(file))) val bis = new io.BufferedInputStream(new io.FileInputStream(file))