public class BlockTimedBlockRebirth : Block { public int totalDuration = 0; public override void Init() { base.Init(); this.explosion = new ExplosionData(this.Properties); } protected virtual void addTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue) { TileEntityTimedBlockRebirth tileTimedBlockPlot = new TileEntityTimedBlockRebirth(_chunk); tileTimedBlockPlot.localChunkPos = World.toBlock(_blockPos); tileTimedBlockPlot.duration = 0; _chunk.AddTileEntity(tileTimedBlockPlot); } protected virtual void removeTileEntity(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue) { _chunk.RemoveTileEntityAt((World)world, World.toBlock(_blockPos)); } public override void OnBlockRemoved(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue) { base.OnBlockRemoved(world, _chunk, _blockPos, _blockValue); TileEntityTimedBlockRebirth tileTimedBlockPlot = world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntityTimedBlockRebirth; if (tileTimedBlockPlot != null) { tileTimedBlockPlot.OnDestroy(); } this.removeTileEntity(world, _chunk, _blockPos, _blockValue); } public override void OnBlockAdded(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue) { base.OnBlockAdded(_world, _chunk, _blockPos, _blockValue); this.addTileEntity(_world, _chunk, _blockPos, _blockValue); if (!SingletonMonoBehaviour.Instance.IsServer) return; if (GameManager.Instance.IsEditMode()) return; _blockValue.meta = 0; if (this.Properties.Values.ContainsKey("Duration")) { this.totalDuration = Int32.Parse(this.Properties.Values["Duration"]); } _world.GetWBT().AddScheduledBlockUpdate(_chunk.ClrIdx, _blockPos, this.blockID, 20UL); } public override Block.DestroyedResult OnBlockDestroyedByExplosion(WorldBase _world, int _clrIdx, Vector3i _pos, BlockValue _blockValue, int _playerIdx) { if (_world.GetGameRandom().RandomFloat < 0.33f) { this.explode(_world, _clrIdx, _pos.ToVector3(), _playerIdx); return Block.DestroyedResult.Remove; } return Block.DestroyedResult.Keep; } private void explode(WorldBase _world, int _clrIdx, Vector3 _pos, int _entityId) { ChunkCluster chunkCluster = _world.ChunkClusters[_clrIdx]; if (chunkCluster != null) { //Log.Out("BlockTimedBlockRebirth-explode 1"); _pos = chunkCluster.ToWorldPosition(_pos + new Vector3(0.5f, 0.5f, 0.5f)); } //Log.Out("BlockTimedBlockRebirth-explode 2"); _world.GetGameManager().ExplosionServer(_clrIdx, _pos, World.worldToBlockPos(_pos), Quaternion.identity, this.explosion, -1, 0.1f, true, null); } public override bool UpdateTick(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, bool _bRandomTick, ulong _ticksIfLoaded, GameRandom _rnd) { TileEntityTimedBlockRebirth tileTimedBlockPlot = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityTimedBlockRebirth; if (tileTimedBlockPlot != null) { tileTimedBlockPlot.duration++; //Log.Out("BlockTimedBlockRebirth-UpdateTick _blockPos: " + _blockPos); //Log.Out("BlockTimedBlockRebirth-UpdateTick tileTimedBlockPlot.duration: " + tileTimedBlockPlot.duration); if (tileTimedBlockPlot.duration < this.totalDuration) { _world.GetWBT().AddScheduledBlockUpdate(_clrIdx, _blockPos, this.blockID, 20UL); } else if (tileTimedBlockPlot.duration >= this.totalDuration && tileTimedBlockPlot.duration < (this.totalDuration + 6)) { GameManager.Instance.PlaySoundAtPositionServer(new Vector3((float)_blockPos.x, (float)_blockPos.y, (float)_blockPos.z), this.TriggerSound, 0, 5); _world.GetWBT().AddScheduledBlockUpdate(_clrIdx, _blockPos, this.blockID, 20UL); } else { //Log.Out("BlockTimedBlockRebirth-UpdateTick 3"); this.explode(_world, _clrIdx, _blockPos.ToVector3(), -1); } } return true; } protected ExplosionData explosion; private string TriggerSound = "charge_beep"; }