Levers up to pre-redstone stage

This commit is contained in:
Chicken Bones committed 2013-06-02 19:47:07 +10:00
1 parent 931da01077
commit a695de4b9d
9 files changed
+83 -10

No files matched your search

@@ -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)
+28 -2
View File
@@ -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
@@ -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)
+2
View File
@@ -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
@@ -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)
{
@@ -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
}
@@ -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
}
@@ -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;
}
}
@@ -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()
{