diff --git a/codechicken/microblock/CommonMicroblock.scala b/codechicken/microblock/CommonMicroblock.scala index 541a508..0c8523b 100644 --- a/codechicken/microblock/CommonMicroblock.scala +++ b/codechicken/microblock/CommonMicroblock.scala @@ -225,11 +225,13 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub { shape = packet.readByte material = readPartID(packet) - if(tile != null) - { - tile.notifyPartChange() - tile.markRender() - } + } + + override def read(packet:MCDataInput) + { + readDesc(packet) + tile.notifyPartChange() + tile.markRender() } override def save(tag:NBTTagCompound) diff --git a/codechicken/multipart/BlockMultipart.scala b/codechicken/multipart/BlockMultipart.scala index e279b31..0beda0a 100644 --- a/codechicken/multipart/BlockMultipart.scala +++ b/codechicken/multipart/BlockMultipart.scala @@ -54,8 +54,6 @@ trait BlockMultipart extends Block { import BlockMultipart._ - setTickRandomly(true) - override def hasTileEntity(meta:Int = 0) = true override def isBlockSolidOnSide(world:World, x:Int, y:Int, z:Int, side:ForgeDirection):Boolean = @@ -211,6 +209,34 @@ trait BlockMultipart extends Block val tile = getClientTile(world, x, y, z) if(tile != null) tile.randomDisplayTick(random) } + + override def onBlockActivated(world:World, x:Int, y:Int, z:Int, player:EntityPlayer, side:Int, hitX:Float, hitY:Float, hitZ:Float):Boolean = + { + val hit = RayTracer.retraceBlock(world, player, x, y, z); + if(hit == null) + return false + + val tile = getTile(world, x, y, z) + if(tile == null) + return false + + val hitInfo:(Int, _) = ExtendedMOP.getData(hit) + return tile.partList(hitInfo._1).activate(player, hit, player.getHeldItem()) + } + + override def onBlockClicked(world:World, x:Int, y:Int, z:Int, player:EntityPlayer) + { + val hit = RayTracer.retraceBlock(world, player, x, y, z); + if(hit == null) + return + + val tile = getTile(world, x, y, z) + if(tile == null) + return + + val hitInfo:(Int, _) = ExtendedMOP.getData(hit) + tile.partList(hitInfo._1).click(player, hit, player.getHeldItem()) + } } class BlockMultipartImpl(id:Int) extends Block(id, Material.rock) with BlockMultipart diff --git a/codechicken/multipart/IRandomDisplayTick.scala b/codechicken/multipart/IRandomDisplayTick.scala index d813926..8ba1c39 100644 --- a/codechicken/multipart/IRandomDisplayTick.scala +++ b/codechicken/multipart/IRandomDisplayTick.scala @@ -8,6 +8,9 @@ trait IRandomDisplayTick def randomDisplayTick(random:Random) } +/** + * Saves processor time looping on tiles that don't need it + */ trait TRandomDisplayTickTile extends TileMultipartClient { override def randomDisplayTick(random:Random) diff --git a/codechicken/multipart/TMultiPart.scala b/codechicken/multipart/TMultiPart.scala index c5ebdef..8ae6076 100644 --- a/codechicken/multipart/TMultiPart.scala +++ b/codechicken/multipart/TMultiPart.scala @@ -71,9 +71,11 @@ abstract class TMultiPart def click(player:EntityPlayer, part:MovingObjectPosition, item:ItemStack){} def doesTick = true def update(){} + def scheduledTick(){} def pickItem(hit:MovingObjectPosition):ItemStack = null def sendDescUpdate() = writeDesc(tile.getWriteStream(this)) + def scheduleTick(ticks:Int) = TickScheduler.scheduleTick(this, ticks) } trait TFacePart extends TMultiPart diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 390fc51..3a280ab 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -36,6 +36,7 @@ import codechicken.multipart.handler.MultipartSPH import codechicken.core.lighting.LazyLightMatrix import net.minecraft.world.ChunkCoordIntPair import net.minecraft.entity.item.EntityItem +import net.minecraft.entity.player.EntityPlayer trait TileMultipart extends TileEntity { @@ -223,6 +224,7 @@ trait TileMultipart extends TileEntity partMap(i) = null partRemoved(part, r) + part.bind(null) if(partList.isEmpty) { diff --git a/codechicken/multipart/handler/PacketHandlers.scala b/codechicken/multipart/handler/PacketHandlers.scala index abc6a3d..7cc60ba 100644 --- a/codechicken/multipart/handler/PacketHandlers.scala +++ b/codechicken/multipart/handler/PacketHandlers.scala @@ -26,6 +26,7 @@ import java.io.DataOutputStream import java.io.ByteArrayOutputStream import net.minecraft.world.WorldServer import net.minecraft.world.ChunkCoordIntPair +import MultipartProxy._ object MultipartCPH extends IClientPacketHandler { @@ -48,8 +49,6 @@ object MultipartCPH extends IClientPacketHandler netHandler.handleKickDisconnect(new Packet255KickDisconnect("The following multiparts are not installed on this client: "+missing.mkString(", "))) } - def indexInChunk(cc:ChunkCoordIntPair, i:Int) = new BlockCoord(cc.chunkXPos<<4|i&0xF, i>>8, cc.chunkZPos<<4|(i&0xF0)>>4) - def handleCompressedTileDesc(packet:PacketCustom, world:World) { val cc = new ChunkCoordIntPair(packet.readInt, packet.readInt) @@ -145,7 +144,7 @@ object MultipartSPH extends IServerPacketHandler val tile = iterator.next if(tile.isInstanceOf[TileMultipart]) { - packet.writeShort(tile.xCoord&0xF|tile.yCoord<<8|(tile.zCoord&0xF)<<4) + packet.writeShort(indexInChunk(new BlockCoord(tile))) tile.asInstanceOf[TileMultipart].writeDesc(packet) empty = false } diff --git a/codechicken/multipart/handler/Proxies.scala b/codechicken/multipart/handler/Proxies.scala index 74066c4..28abfa1 100644 --- a/codechicken/multipart/handler/Proxies.scala +++ b/codechicken/multipart/handler/Proxies.scala @@ -23,6 +23,8 @@ import codechicken.multipart.ControlKeyHandler import cpw.mods.fml.common.network.NetworkRegistry import cpw.mods.fml.common.registry.TickRegistry import net.minecraft.block.Block +import net.minecraft.world.ChunkCoordIntPair +import codechicken.core.vec.BlockCoord class MultipartProxy_serverImpl { @@ -84,4 +86,7 @@ object MultipartProxy extends MultipartProxy_clientImpl { var block:BlockMultipart = _ var config:ConfigFile = _ + + def indexInChunk(cc:ChunkCoordIntPair, i:Int) = new BlockCoord(cc.chunkXPos<<4|i&0xF, i>>8, cc.chunkZPos<<4|(i&0xF0)>>4) + def indexInChunk(pos:BlockCoord) = pos.x&0xF|pos.y<<8|(pos.z&0xF)<<4 } \ No newline at end of file diff --git a/codechicken/multipart/minecraft/LeverPart.java b/codechicken/multipart/minecraft/LeverPart.java index ea69982..c1bb34c 100644 --- a/codechicken/multipart/minecraft/LeverPart.java +++ b/codechicken/multipart/minecraft/LeverPart.java @@ -4,6 +4,9 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockLever; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import codechicken.core.lighting.LazyLightMatrix; @@ -85,4 +88,28 @@ public class LeverPart extends McSidedMetaPart { new RenderBlocks(new PartMetaAccess(this)).renderBlockLever(lever, getTile().xCoord, getTile().yCoord, getTile().zCoord); } + + @Override + public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) + { + World world = getTile().worldObj; + if(world.isRemote) + return true; + + int state = meta&8; + world.playSoundEffect(getTile().xCoord + 0.5, getTile().yCoord + 0.5, getTile().zCoord + 0.5, "random.click", 0.3F, state > 0 ? 0.6F : 0.5F); + meta = (byte) (meta^8); + sendDescUpdate(); + tile().notifyPartChange(); + tile().markDirty(); + return true; + } + + public void drawBreaking(RenderBlocks renderBlocks) + { + IBlockAccess actual = renderBlocks.blockAccess; + renderBlocks.blockAccess = new PartMetaAccess(this); + renderBlocks.renderBlockLever(lever, getTile().xCoord, getTile().yCoord, getTile().zCoord); + renderBlocks.blockAccess = actual; + } } diff --git a/codechicken/multipart/minecraft/McMetaPart.java b/codechicken/multipart/minecraft/McMetaPart.java index f1865f3..4fb41b4 100644 --- a/codechicken/multipart/minecraft/McMetaPart.java +++ b/codechicken/multipart/minecraft/McMetaPart.java @@ -43,6 +43,13 @@ public abstract class McMetaPart extends McBlockPart implements IPartMeta meta = packet.readByte(); } + @Override + public void read(MCDataInput packet) + { + readDesc(packet); + tile().markRender(); + } + @Override public World getWorld() {