Moved the onChunkLoad hook to CCL's event handler

Changed IRandomUpdateTick to be called from onWorldJoin
This commit is contained in:
Chicken-Bones committed 2014-12-17 23:44:32 +10:00
1 parent d9331704e8
commit 8af7cddcb1
7 files changed
+38 -46

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
mc_version=1.7.10
forge_version=10.13.1.1217
ccl_version=1.1.1.88
mod_version=1.1.0
ccl_version=1.1.1.109
mod_version=1.1.1
@@ -1,12 +1,19 @@
package codechicken.multipart
/**
* Interface for parts with random update ticks.
* Interface for parts with random update ticks. Used in conjuction with TickScheduler
*/
trait IRandomUpdateTick
trait TRandomUpdateTick extends TMultiPart
{
/**
* Called on random update. Random ticks are between 800 and 1600 ticks from their last scheduled/random tick
*/
def randomUpdate()
/**
* If implementing interface in java, be sure to implement this method yourself
*/
override def onWorldJoin() {
TickScheduler.loadRandomTick(this)
}
}
+2 -2
View File
@@ -235,11 +235,11 @@ abstract class TMultiPart
*/
def onChunkUnload() = onWorldSeparate()
/**
* Called when this part separates from the world (due to removal, chunk unload or other). Use this to sync with external data structures.
* Called when this part separates from the world (due to removal, chunk unload or other). Use this to sync with external data structures. Called on both client and server
*/
def onWorldSeparate(){}
/**
* Called when this part separates from the world (due to removal, chunk unload or other). Use this to sync with external data structures.
* Called when this part joins the world (due to placement, chunkload or frame move etc). Use this to sync with external data structures. Called on both client and server
*/
def onWorldJoin(){}
/**
+10 -29
View File
@@ -5,7 +5,7 @@ import codechicken.lib.world.WorldExtension
import codechicken.lib.world.ChunkExtension
import net.minecraft.world.chunk.Chunk
import net.minecraft.world.World
import net.minecraft.nbt.{NBTBase, NBTTagCompound, NBTTagList, CompressedStreamTools}
import net.minecraft.nbt.{NBTTagCompound, NBTTagList, CompressedStreamTools}
import scala.collection.mutable.ListBuffer
import codechicken.lib.vec.BlockCoord
import net.minecraft.world.ChunkCoordIntPair
@@ -15,10 +15,8 @@ import java.io.DataOutputStream
import net.minecraftforge.common.DimensionManager
import java.io.File
import java.io.FileOutputStream
import java.io.DataInputStream
import java.io.FileInputStream
import net.minecraft.world.storage.SaveHandler
import java.util.ArrayList
/**
* Used for scheduling delayed callbacks to parts.
@@ -55,7 +53,7 @@ object TickScheduler extends WorldExtensionInstantiator
.asInstanceOf[ChunkTickScheduler].scheduleTick(part, time, random)
}
def loadRandom(part:TMultiPart) = scheduleTick(part, nextRandomTick, true)
def loadRandom(part:TRandomUpdateTick) = scheduleTick(part, nextRandomTick, true)
override def preTick()
{
@@ -175,12 +173,12 @@ object TickScheduler extends WorldExtensionInstantiator
{
if(e.part.tile != null)
{
if(e.random && e.part.isInstanceOf[IRandomUpdateTick])
e.part.asInstanceOf[IRandomUpdateTick].randomUpdate()
if(e.random && e.part.isInstanceOf[TRandomUpdateTick])
e.part.asInstanceOf[TRandomUpdateTick].randomUpdate()
else
e.part.scheduledTick()
if(e.part.isInstanceOf[IRandomUpdateTick])
if(e.part.isInstanceOf[TRandomUpdateTick])
{
e.time = schedTime+nextRandomTick
e.random = true
@@ -228,26 +226,6 @@ object TickScheduler extends WorldExtensionInstantiator
}
}
override def load()
{
val it = new ArrayList(chunk.chunkTileEntityMap.values).iterator
while(it.hasNext)
{
val t = it.next
if(t.isInstanceOf[TileMultipart])
{
val tmp = t.asInstanceOf[TileMultipart]
tmp.onChunkLoad()
tmp.partList.foreach(p =>
if(p.isInstanceOf[IRandomUpdateTick])
world.scheduleTick(p, nextRandomTick, true))
}
}
if(!tickList.isEmpty)
world.tickChunks+=this
}
override def unload()
{
if(!tickList.isEmpty)
@@ -256,8 +234,11 @@ object TickScheduler extends WorldExtensionInstantiator
}
def createChunkExtension(chunk:Chunk, world:WorldExtension):ChunkExtension = new ChunkTickScheduler(chunk, world.asInstanceOf[WorldTickScheduler])
private[multipart] def loadRandomTick(part:TMultiPart)
/**
* Start random ticking for a part. Should be called from TMultiPart.onWorldJoin
*/
def loadRandomTick(part:TRandomUpdateTick)
{
getExtension(part.tile.getWorldObj).asInstanceOf[WorldTickScheduler].loadRandom(part)
}
@@ -20,8 +20,9 @@ import java.util.Collection
import codechicken.lib.raytracer.ExtendedMOP
import net.minecraft.util.Vec3
import java.lang.Iterable
import codechicken.lib.world.IChunkLoadTile
class TileMultipart extends TileEntity
class TileMultipart extends TileEntity with IChunkLoadTile
{
/**
* List of parts in this tile space
@@ -86,7 +87,7 @@ class TileMultipart extends TileEntity
operate(_.onChunkUnload())
}
def onChunkLoad()
override def onChunkLoad()
{
operate(_.onChunkLoad())
}
@@ -312,11 +313,7 @@ class TileMultipart extends TileEntity
* Called when a part is added (placement)
* Provided for trait overrides, do not call externally.
*/
def partAdded(part:TMultiPart)
{
if(part.isInstanceOf[IRandomUpdateTick])
TickScheduler.loadRandomTick(part)
}
def partAdded(part:TMultiPart){}
/**
* Removes part from this tile. Note that due to the operation sync, the part may not be removed until the call stack has been passed to all other parts in the space.
@@ -12,7 +12,7 @@ import cpw.mods.fml.relauncher.Side
import codechicken.lib.packet.PacketCustom
import net.minecraft.world.ChunkCoordIntPair
import codechicken.lib.vec.BlockCoord
import codechicken.lib.world.WorldExtensionManager
import codechicken.lib.world.{TileChunkLoadHook, WorldExtensionManager}
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.common.registry.GameRegistry
import net.minecraft.block.Block
@@ -53,6 +53,7 @@ class MultipartProxy_serverImpl
PacketCustom.assignHandshakeHandler(MultipartSPH.registryChannel, MultipartSPH)
WorldExtensionManager.registerWorldExtension(TickScheduler)
TileChunkLoadHook.init()
MultipartCompatiblity.load()
}
@@ -2,6 +2,7 @@ package codechicken.multipart.minecraft;
import java.util.Random;
import codechicken.multipart.TickScheduler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.init.Blocks;
@@ -12,10 +13,10 @@ import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.IFaceRedstonePart;
import codechicken.multipart.IRandomUpdateTick;
import codechicken.multipart.TRandomUpdateTick;
import codechicken.multipart.RedstoneInteractions;
public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, IRandomUpdateTick
public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, TRandomUpdateTick
{
public static BlockRedstoneTorch torchActive = (BlockRedstoneTorch) Blocks.redstone_torch;
public static BlockRedstoneTorch torchIdle = (BlockRedstoneTorch) Blocks.unlit_redstone_torch;
@@ -142,7 +143,12 @@ public class RedstoneTorchPart extends TorchPart implements IFaceRedstonePart, I
{
scheduledTick();
}
@Override
public void onWorldJoin() {
TickScheduler.loadRandomTick(this);
}
private boolean burnedOut(boolean add)
{
long time = world().getTotalWorldTime();