From 3b3460279f0dd541b67a36c10aad80b04cae0f2b Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Sun, 22 Dec 2013 00:51:08 +1000 Subject: [PATCH] Fixed MultipartGenerator crashing with interfaces that override methods Fixed a harvest bug Some syntax cleanup Changed references to getWorldTime to getTotalWorldTime --- codechicken/multipart/BlockMultipart.scala | 3 ++- codechicken/multipart/MultipartRenderer.scala | 19 ++++++++---------- codechicken/multipart/PacketScheduler.scala | 7 ++++++- codechicken/multipart/TMultiPart.scala | 2 +- codechicken/multipart/TickScheduler.scala | 4 +++- codechicken/multipart/TileMultipart.scala | 12 ++++------- .../multipart/asm/ASMMixinFactory.scala | 20 ++++++------------- .../minecraft/RedstoneTorchPart.java | 4 ++-- 8 files changed, 32 insertions(+), 39 deletions(-) diff --git a/codechicken/multipart/BlockMultipart.scala b/codechicken/multipart/BlockMultipart.scala index b660335..62a6479 100644 --- a/codechicken/multipart/BlockMultipart.scala +++ b/codechicken/multipart/BlockMultipart.scala @@ -131,7 +131,8 @@ class BlockMultipart(id:Int) extends Block(id, Material.rock) return true } - return tile.harvestPart(index, mop, player) + tile.harvestPart(index, mop, player) + return world.getBlockTileEntity(x, y, z) == null } def dropAndDestroy(world:World, x:Int, y:Int, z:Int) diff --git a/codechicken/multipart/MultipartRenderer.scala b/codechicken/multipart/MultipartRenderer.scala index d086e35..20537f4 100644 --- a/codechicken/multipart/MultipartRenderer.scala +++ b/codechicken/multipart/MultipartRenderer.scala @@ -26,14 +26,14 @@ import codechicken.lib.lighting.LazyLightMatrix @SideOnly(Side.CLIENT) object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRenderingHandler { - TileMultipart.renderID = RenderingRegistry.getNextAvailableRenderId() + TileMultipart.renderID = RenderingRegistry.getNextAvailableRenderId private val olm = new LazyLightMatrix var pass:Int = 0 override def renderTileEntityAt(t:TileEntity, x:Double, y:Double, z:Double, f:Float) { - var tmpart = t.asInstanceOf[TileMultipartClient] + val tmpart = t.asInstanceOf[TileMultipartClient] if(tmpart.partList.isEmpty) return @@ -49,17 +49,17 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend override def renderWorldBlock(world:IBlockAccess, x:Int, y:Int, z:Int, block:Block, modelId:Int, renderer:RenderBlocks):Boolean = { - var t = world.getBlockTileEntity(x, y, z) + val t = world.getBlockTileEntity(x, y, z) if(!t.isInstanceOf[TileMultipartClient]) return false - - var tmpart = t.asInstanceOf[TileMultipartClient] + + val tmpart = t.asInstanceOf[TileMultipartClient] if(tmpart.partList.isEmpty) return false - if(renderer.hasOverrideBlockTexture()) + if(renderer.hasOverrideBlockTexture) { - val hit = Minecraft.getMinecraft().objectMouseOver + val hit = Minecraft.getMinecraft.objectMouseOver if(hit != null && hit.blockX == x && hit.blockY == y && hit.blockZ == z && ExtendedMOP.getData(hit).isInstanceOf[(_, _)]) { val hitInfo:(Int, _) = ExtendedMOP.getData(hit) @@ -77,10 +77,7 @@ object MultipartRenderer extends TileEntitySpecialRenderer with ISimpleBlockRend return true } - override def renderInventoryBlock(block:Block, meta:Int, modelId:Int, renderer:RenderBlocks) - { - //TODO: pass to the super renderer. - } + override def renderInventoryBlock(block:Block, meta:Int, modelId:Int, renderer:RenderBlocks) {} override def shouldRender3DInInventory = false } diff --git a/codechicken/multipart/PacketScheduler.scala b/codechicken/multipart/PacketScheduler.scala index 4b4000a..486ecd1 100644 --- a/codechicken/multipart/PacketScheduler.scala +++ b/codechicken/multipart/PacketScheduler.scala @@ -16,7 +16,12 @@ object PacketScheduler /** * Add bits to the current update mask for part. (binary OR) */ - def schedulePacket(part:TMultiPart, mask:Long) = map.put(part, map.getOrElse(part, 0L)|mask) + def schedulePacket(part:TMultiPart, mask:Long) = {//TODO remove = in 1.7 + if(part.world.isRemote) + throw new IllegalArgumentException("Cannot use PacketScheduler on a client world") + + map.put(part, map.getOrElse(part, 0L)|mask) + } private[multipart] def sendScheduled() { map.foreach{ e => diff --git a/codechicken/multipart/TMultiPart.scala b/codechicken/multipart/TMultiPart.scala index 919f3f4..8c2823b 100644 --- a/codechicken/multipart/TMultiPart.scala +++ b/codechicken/multipart/TMultiPart.scala @@ -280,7 +280,7 @@ abstract class TMultiPart * This should not modify the part client side. If the client call returns false, the server will not call this function. * @param hit An instance of ExtendedMOP from collisionRayTrace */ - def activate(player:EntityPlayer, hit:MovingObjectPosition, item:ItemStack):Boolean = false + def activate(player:EntityPlayer, hit:MovingObjectPosition, item:ItemStack) = false /** * Called on block left click. item is the player's held item. * @param hit An instance of ExtendedMOP from collisionRayTrace diff --git a/codechicken/multipart/TickScheduler.scala b/codechicken/multipart/TickScheduler.scala index b829aa6..749eac4 100644 --- a/codechicken/multipart/TickScheduler.scala +++ b/codechicken/multipart/TickScheduler.scala @@ -107,7 +107,7 @@ object TickScheduler extends WorldExtensionInstantiator if(tag.hasKey("schedTime")) schedTime = tag.getLong("schedTime") else - schedTime = world.getWorldTime + schedTime = world.getTotalWorldTime } def saveTag():NBTTagCompound = @@ -274,6 +274,8 @@ object TickScheduler extends WorldExtensionInstantiator /** * Returns the current scheduler time. Like the world time, but unaffected by the time set command and other things changing time of day. + * Deprecated in favor of world.getTotalWorldTime */ + @Deprecated def getSchedulerTime(world:World):Long = getExtension(world).asInstanceOf[WorldTickScheduler].schedTime } \ No newline at end of file diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 6c800fa..e2eabc1 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -462,14 +462,10 @@ class TileMultipart extends TileEntity /** * Drop and remove part at index (internal mining callback) */ - def harvestPart(index:Int, hit:ExtendedMOP, player:EntityPlayer):Boolean = - partList(index) match { - case null => false - case part => { - part.harvest(hit, player) - partList.isEmpty - } - } + def harvestPart(index:Int, hit:ExtendedMOP, player:EntityPlayer) = partList(index) match { + case null => + case part => part.harvest(hit, player) + } /** * Utility function for dropping items around the center of this space diff --git a/codechicken/multipart/asm/ASMMixinFactory.scala b/codechicken/multipart/asm/ASMMixinFactory.scala index 4270e0c..79818cd 100644 --- a/codechicken/multipart/asm/ASMMixinFactory.scala +++ b/codechicken/multipart/asm/ASMMixinFactory.scala @@ -4,21 +4,12 @@ import scala.collection.Seq import codechicken.multipart.TileMultipart import codechicken.multipart.TileMultipartClient import scala.collection.JavaConversions._ -import scala.collection.JavaConverters._ import org.objectweb.asm.Opcodes._ -import org.objectweb.asm.ClassWriter import codechicken.lib.asm.CC_ClassWriter import org.objectweb.asm.MethodVisitor import org.objectweb.asm.FieldVisitor import org.objectweb.asm.Label -import cpw.mods.fml.relauncher.ReflectionHelper -import org.objectweb.asm.commons.RemappingClassAdapter -import org.objectweb.asm.commons.SimpleRemapper -import scala.collection.mutable.ArrayBuffer import org.objectweb.asm.tree._ -import org.objectweb.asm.Type -import Type._ -import scala.collection.immutable.Range import codechicken.lib.asm.ASMHelper._ import codechicken.lib.asm.ObfMapping import codechicken.multipart.MultipartGenerator @@ -291,12 +282,13 @@ object ASMMixinFactory extends IMultipartFactory mv.visitEnd() } - def methods(cnode:ClassNode):Seq[MethodNode] = + def methods(cnode:ClassNode):Map[String, MethodNode] = { - val m = cnode.methods + val m = cnode.methods.map(m => (m.name+m.desc, m)).toMap if(cnode.interfaces != null) - m++=cnode.interfaces.flatMap(i => methods(classNode(i))) - m + m++cnode.interfaces.flatMap(i => methods(classNode(i))) + else + m } def generatePassThroughMethod(m:MethodNode) @@ -307,7 +299,7 @@ object ASMMixinFactory extends IMultipartFactory finishBridgeCall(mv, m.desc, INVOKEINTERFACE, iname, m.name, m.desc) } - methods(inode).foreach(generatePassThroughMethod(_)) + methods(inode).values.foreach(generatePassThroughMethod(_)) cw.visitEnd() internalDefine(tname, cw.toByteArray) diff --git a/codechicken/multipart/minecraft/RedstoneTorchPart.java b/codechicken/multipart/minecraft/RedstoneTorchPart.java index 5def122..03389cf 100644 --- a/codechicken/multipart/minecraft/RedstoneTorchPart.java +++ b/codechicken/multipart/minecraft/RedstoneTorchPart.java @@ -144,13 +144,13 @@ public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, I private boolean burnedOut(boolean add) { - long time = world().getWorldTime(); + long time = world().getTotalWorldTime(); while(burnout != null && burnout.timeout <= time) burnout = burnout.next; if(add) { - BurnoutEntry e = new BurnoutEntry(world().getWorldTime()+60); + BurnoutEntry e = new BurnoutEntry(world().getTotalWorldTime()+60); if(burnout == null) burnout = e; else