From 37a3d89382c93f6cfa1c44356c0bea025aee77d0 Mon Sep 17 00:00:00 2001 From: Chicken Bones Date: Mon, 12 Aug 2013 13:35:12 +1000 Subject: [PATCH] Modified partChange event to take a parameter of the part that was changed and only send the event to other parts. Update CCL dep --- codechicken/microblock/CommonMicroblock.scala | 2 +- codechicken/microblock/EdgeMicroblock.scala | 2 +- codechicken/microblock/HolloMicroblock.scala | 5 +++-- .../microblock/MicroblockPlacement.scala | 2 +- codechicken/microblock/TMicroOcclusion.scala | 19 ++++++++++++----- codechicken/multipart/IRedstonePart.scala | 4 ++++ .../multipart/MultipartGenerator.scala | 6 ++++-- codechicken/multipart/TMultiPart.scala | 5 ++++- codechicken/multipart/TileMultipart.scala | 15 +++++++------ .../multipart/minecraft/ButtonPart.java | 2 +- .../multipart/minecraft/LeverPart.java | 2 +- .../multipart/minecraft/McSidedMetaPart.java | 21 ++++++++++++++++++- .../minecraft/RedstoneTorchPart.java | 2 +- dependancies.info | 2 +- 14 files changed, 65 insertions(+), 24 deletions(-) diff --git a/codechicken/microblock/CommonMicroblock.scala b/codechicken/microblock/CommonMicroblock.scala index c1e6f01..2d76049 100644 --- a/codechicken/microblock/CommonMicroblock.scala +++ b/codechicken/microblock/CommonMicroblock.scala @@ -154,7 +154,7 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub override def read(packet:MCDataInput) { readDesc(packet) - tile.notifyPartChange() + tile.notifyPartChange(this) tile.markRender() } diff --git a/codechicken/microblock/EdgeMicroblock.scala b/codechicken/microblock/EdgeMicroblock.scala index f16660c..467d6a3 100644 --- a/codechicken/microblock/EdgeMicroblock.scala +++ b/codechicken/microblock/EdgeMicroblock.scala @@ -179,7 +179,7 @@ class PostMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends PostMicro renderCuboid(pos, olm, mat, renderBounds2, 0) } - override def onPartChanged() + override def onPartChanged(part:TMultiPart) { if(tile.worldObj.isRemote) recalcBounds() diff --git a/codechicken/microblock/HolloMicroblock.scala b/codechicken/microblock/HolloMicroblock.scala index 378d954..029b7e6 100644 --- a/codechicken/microblock/HolloMicroblock.scala +++ b/codechicken/microblock/HolloMicroblock.scala @@ -20,6 +20,7 @@ import Rotation._ import Vector3._ import codechicken.lib.raytracer.IndexedCuboid6 import org.lwjgl.opengl.GL11 +import codechicken.multipart.TMultiPart object HollowPlacement extends PlacementProperties { @@ -83,9 +84,9 @@ class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowM def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material) - override def onPartChanged() + override def onPartChanged(part:TMultiPart) { - super.onPartChanged() + super.onPartChanged(part) renderMask = renderMask&0xFF | getHollowSize<<8 } diff --git a/codechicken/microblock/MicroblockPlacement.scala b/codechicken/microblock/MicroblockPlacement.scala index bcd3e2d..b77df94 100644 --- a/codechicken/microblock/MicroblockPlacement.scala +++ b/codechicken/microblock/MicroblockPlacement.scala @@ -38,7 +38,7 @@ class ExpandingPlacement($pos:BlockCoord, $part:Microblock, opart:Microblock) ex def place(world:World, player:EntityPlayer, item:ItemStack) { opart.shape = part.shape - opart.tile.notifyPartChange() + opart.tile.notifyPartChange(opart) opart.sendDescUpdate() } diff --git a/codechicken/microblock/TMicroOcclusion.scala b/codechicken/microblock/TMicroOcclusion.scala index 8b00349..c32d5b3 100644 --- a/codechicken/microblock/TMicroOcclusion.scala +++ b/codechicken/microblock/TMicroOcclusion.scala @@ -166,16 +166,25 @@ trait JMicroShrinkRender trait TMicroOcclusionClient extends TMicroOcclusion with JMicroShrinkRender { - import MicroOcclusion._ - var renderBounds:Cuboid6 = _ var renderMask:Int = _ - override def onPartChanged() + override def onPartChanged(part:TMultiPart) + { + super.onPartChanged(part) + recalcBounds() + } + + override def onAdded() + { + super.onAdded() + recalcBounds() + } + + def recalcBounds() { - super.onPartChanged() renderBounds = getBounds.copy - renderMask = recalcBounds(this, renderBounds) + renderMask = MicroOcclusion.recalcBounds(this, renderBounds) } override def getPriorityClass = 0 diff --git a/codechicken/multipart/IRedstonePart.scala b/codechicken/multipart/IRedstonePart.scala index 75c942c..d526522 100644 --- a/codechicken/multipart/IRedstonePart.scala +++ b/codechicken/multipart/IRedstonePart.scala @@ -136,10 +136,14 @@ object RedstoneInteractions def vanillaConnectionMask(block:Block, world:IBlockAccess, x:Int, y:Int, z:Int, side:Int, power:Boolean):Int = { + if(block == Block.torchRedstoneActive || block == Block.torchRedstoneIdle || block == Block.lever || block == Block.stoneButton || block == Block.woodenButton) + return 0x1F + if(side == 0)//vanilla doesn't handle side 0 { if(power) return 0x1F + return 0 } diff --git a/codechicken/multipart/MultipartGenerator.scala b/codechicken/multipart/MultipartGenerator.scala index c970b0e..7d9c20a 100644 --- a/codechicken/multipart/MultipartGenerator.scala +++ b/codechicken/multipart/MultipartGenerator.scala @@ -64,11 +64,12 @@ object MultipartGenerator { if(loaded._2)//perform client conversion { - world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 1) + world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 0) world.setBlockTileEntity(pos.x, pos.y, pos.z, ntile) PacketCustom.sendToChunk(new Packet53BlockChange(pos.x, pos.y, pos.z, world), world, pos.x>>4, pos.z>>4) ntile.partList(0).onConverted() ntile.writeAddPart(ntile.partList(0)) + world.notifyBlocksOfNeighborChange(pos.x, pos.y, pos.z, MultipartProxy.block.blockID) } val tileTraits = tileTraitMap(tile.getClass) @@ -82,9 +83,10 @@ object MultipartGenerator } else { - world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID) + world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 0) ntile = factory.generateTile(partTraits, world.isRemote) world.setBlockTileEntity(pos.x, pos.y, pos.z, ntile) + world.notifyBlocksOfNeighborChange(pos.x, pos.y, pos.z, MultipartProxy.block.blockID) } ntile.addPart_impl(part) return ntile diff --git a/codechicken/multipart/TMultiPart.scala b/codechicken/multipart/TMultiPart.scala index b1079df..16e3d18 100644 --- a/codechicken/multipart/TMultiPart.scala +++ b/codechicken/multipart/TMultiPart.scala @@ -72,7 +72,10 @@ abstract class TMultiPart def save(tag:NBTTagCompound){} def load(tag:NBTTagCompound){} - def onPartChanged(){} + /** + * The part parameter may be null if several things have changed. + */ + def onPartChanged(part:TMultiPart){} def onNeighborChanged(){} def onAdded() = onWorldJoin() def onRemoved() = onWorldSeparate() diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 039479b..4b4b13c 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -113,10 +113,13 @@ class TileMultipart extends TileEntity partList.foreach(_.onWorldSeparate()) } - def notifyPartChange() + def notifyPartChange(part:TMultiPart) { TileMultipart.startOperation(this) - partList.foreach(_.onPartChanged()) + partList.foreach{ p => + if(part != p) + p.onPartChanged(part) + } TileMultipart.finishOperation(this) worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID) @@ -185,7 +188,7 @@ class TileMultipart extends TileEntity def getWriteStream(part:TMultiPart):MCDataOutput = getWriteStream.writeByte(partList.indexOf(part)) - private[multipart] def getWriteStream = MultipartSPH.getTileStream(worldObj, new BlockCoord(this)) + private def getWriteStream = MultipartSPH.getTileStream(worldObj, new BlockCoord(this)) private[multipart] def addPart_impl(part:TMultiPart) { @@ -195,7 +198,7 @@ class TileMultipart extends TileEntity addPart_do(part) part.onAdded() partAdded(part) - notifyPartChange() + notifyPartChange(part) markDirty() markRender() } @@ -241,7 +244,7 @@ class TileMultipart extends TileEntity val i = remPart_do(part) if(!isInvalid()) { - notifyPartChange() + notifyPartChange(part) markDirty() markRender() } @@ -291,7 +294,7 @@ class TileMultipart extends TileEntity clearParts() parts.foreach(p => addPart_do(p)) if(worldObj != null) - notifyPartChange() + notifyPartChange(null) } def clearParts() diff --git a/codechicken/multipart/minecraft/ButtonPart.java b/codechicken/multipart/minecraft/ButtonPart.java index 180e48b..6b47821 100644 --- a/codechicken/multipart/minecraft/ButtonPart.java +++ b/codechicken/multipart/minecraft/ButtonPart.java @@ -134,7 +134,7 @@ public class ButtonPart extends McSidedMetaPart implements IRedstonePart TickScheduler.scheduleTick(this, delay()); sendDescUpdate(); - tile().notifyPartChange(); + tile().notifyPartChange(this); tile().notifyNeighborChange(metaSideMap[meta&7]); tile().markDirty(); } diff --git a/codechicken/multipart/minecraft/LeverPart.java b/codechicken/multipart/minecraft/LeverPart.java index 7608abc..3eb679b 100644 --- a/codechicken/multipart/minecraft/LeverPart.java +++ b/codechicken/multipart/minecraft/LeverPart.java @@ -97,7 +97,7 @@ public class LeverPart extends McSidedMetaPart implements IRedstonePart world.playSoundEffect(x() + 0.5, y() + 0.5, z() + 0.5, "random.click", 0.3F, !active() ? 0.6F : 0.5F); meta ^= 8; sendDescUpdate(); - tile().notifyPartChange(); + tile().notifyPartChange(this); tile().notifyNeighborChange(metaSideMap[meta&7]); tile().markDirty(); return true; diff --git a/codechicken/multipart/minecraft/McSidedMetaPart.java b/codechicken/multipart/minecraft/McSidedMetaPart.java index f2b4bac..8d58b0d 100644 --- a/codechicken/multipart/minecraft/McSidedMetaPart.java +++ b/codechicken/multipart/minecraft/McSidedMetaPart.java @@ -4,9 +4,10 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.ForgeDirection; import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.Vector3; +import codechicken.multipart.TFacePart; import codechicken.multipart.TileMultipart; -public abstract class McSidedMetaPart extends McMetaPart +public abstract class McSidedMetaPart extends McMetaPart implements TFacePart { public McSidedMetaPart() { @@ -47,4 +48,22 @@ public abstract class McSidedMetaPart extends McMetaPart tile().remPart(this); TileMultipart.dropItem(new ItemStack(getBlock()), world(), Vector3.fromTileEntityCenter(getTile())); } + + @Override + public int getSlotMask() + { + return 1<