Exemple #1
0
 public override void Notify(World world, int x, int y, int z, Direction direction, Block oldBlock, Block newBlock)
 {
     if (direction == Direction.up || direction == Direction.down)
     {
         if (oldBlock.BlockType == BlockType.Block_87)
         {
             BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType);
             dispatcher.SetBlock(world, x, y, z, new Block(BlockType.Air));
         }
     }
 }
Exemple #2
0
        private void ClearLiquidBlock(int index)
        {
            int posXInChunk = index % _shrinkWidth - shrinkMaxLevel + pos.x;
            int posZInChunk = index / _shrinkWidth - shrinkMaxLevel + pos.z;

//			chunk.world.SetBlock(posXInChunk + chunk.worldPos.x,pos.y + chunk.worldPos.y,posZInChunk + chunk.worldPos.z,air);
//			chunk.world.CheckAndRecalculateMesh(posXInChunk + chunk.worldPos.x,pos.y + chunk.worldPos.y,posZInChunk + chunk.worldPos.z,air);
            BlockDispatcher dispatcher = BlockDispatcherFactory.GetDefaultDispatcher();

            dispatcher.SetBlock(chunk.world, posXInChunk + chunk.worldPos.x, pos.y + chunk.worldPos.y, posZInChunk + chunk.worldPos.z, air, false);
        }
        void HandleOnShrinkPlaneFinish(LiquidShrinkSource source)
        {
            source.OnShrinkPlaneFinish -= HandleOnShrinkPlaneFinish;
            List <WorldPos> list = source.GetNextSpreadSourceList();

            for (int i = 0; i < list.Count; i++)
            {
                BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType.Air);
                dispatcher.SetBlock(source.chunk.world, list[i].x, list[i].y, list[i].z, new Block(BlockType.Air));
            }
            LiquidShrinkSourceManager.SaveShrinkSource(source);
        }
        private void SetLiquidBlock(int index, int level)
        {
            int   posXInChunk = index % _spreadWidth - spreadMaxLevel + pos.x;
            int   posZInChunk = index / _spreadWidth - spreadMaxLevel + pos.z;
            Block liquid      = new Block(liquidType, (byte)level);

            BlockDispatcher dispatcher = BlockDispatcherFactory.GetDefaultDispatcher();

            dispatcher.SetBlock(chunk.world, posXInChunk + chunk.worldPos.x, pos.y + chunk.worldPos.y, posZInChunk + chunk.worldPos.z, liquid, false);
//			SetBlockAndNotify(chunk.world,posXInChunk + chunk.worldPos.x,pos.y + chunk.worldPos.y,posZInChunk + chunk.worldPos.z,liquid);
//			chunk.world.CheckAndRecalculateMesh(posXInChunk + chunk.worldPos.x,pos.y + chunk.worldPos.y,posZInChunk + chunk.worldPos.z,liquid);
        }
Exemple #5
0
        void HandleOnSpreadPlaneFinish(LiquidSpreadSource source)
        {
            source.OnSpreadPlaneFinish -= HandleOnSpreadPlaneFinish;
            List <WorldPos> list = source.GetNextSpreadSourceList();

            for (int i = 0; i < list.Count; i++)
            {
                BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(source.liquidType);
                dispatcher.SetBlock(source.chunk.world, list[i].x, list[i].y, list[i].z, new Block(source.liquidType, (byte)(source.curSpreadLevel + source.spreadMaxLevel)));
            }
            LiquidSpreadSourceManager.SaveSpreadSource(source);
        }
        public override void Notify(World world, int x, int y, int z, Direction direction, Block oldBlock, Block newBlock)
        {
            if (direction == Direction.up)
            {
                return;
            }

            Block cur = world.GetBlock(x, y, z);

            Block left  = world.GetBlock(x - 1, y, z);
            Block right = world.GetBlock(x + 1, y, z);
            Block front = world.GetBlock(x, y, z + 1);
            Block back  = world.GetBlock(x, y, z - 1);
            Block down  = world.GetBlock(x, y - 1, z);
            Block up    = world.GetBlock(x, y + 1, z);

            if (newBlock.BlockType == BlockType.Air)
            {
                BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType);
                if (direction == Direction.down)
                {
                    byte nextExtendId = cur.ExtendId > waterExtendLevel ? cur.ExtendId : (byte)(cur.ExtendId + waterExtendLevel + 1);
                    dispatcher.SetBlock(world, x, y - 1, z, new Block(BlockType, nextExtendId));
                }
                else
                {
                    int curLevel = GetWaterLevel(cur);
                    //如果当前块的周围有比我更强的水流,那么扩展
                    if (curLevel == 0 || GetWaterLevel(left) < curLevel || GetWaterLevel(right) < curLevel ||
                        GetWaterLevel(front) < curLevel || GetWaterLevel(back) < curLevel)
                    {
                        dispatcher.SetBlock(world, x, y, z, cur);
                    }
                }
            }

//			if(!IsAroundNoFindWater(left,right,front,back,up,down))
//			{
//				BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType.Air);
//				dispatcher.SetBlock(world,x,y,z,new Block(BlockType.Air));
//				return;
//			}

//			if(IsCanChangeToStillSourceWater(left,right,front,back))
//			{
//				BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType.StillWater);
//				dispatcher.SetBlock(world,x,y,z,new Block(BlockType.StillWater));
//			}
        }
 public override void Notify(World world, int x, int y, int z, Direction direction, Block oldBlock, Block newBlock)
 {
     if (oldBlock.BlockType == BlockType && newBlock.BlockType == BlockType.Air)
     {
         if (direction == Direction.up || direction == Direction.down)
         {
             return;
         }
         Block block = world.GetBlock(x, y, z);
         if ((block.ExtendId & 7) == (oldBlock.ExtendId & 7) && (block.ExtendId & 8) != (oldBlock.ExtendId & 8))
         {
             BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(BlockType);
             dispatcher.SetBlock(world, x, y, z, new Block(BlockType.Air));
         }
     }
 }
Exemple #8
0
//		public static bool SetBlock(RaycastHit hit,Block block,bool adjacent = false)
//		{
//			if(hit.collider == null)
//			{
//				return false;
//			}
//			ChunkObj chunkObj = hit.collider.GetComponentInParent<ChunkObj>();
//			if(chunkObj == null)
//			{
//				return false;
//			}
//			WorldPos pos = GetWorldPos(hit,adjacent);
//			if(!CheckPosCanPlaced(pos))return false;
//			BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(block.BlockType);
//			dispatcher.SetBlock(chunkObj.chunk.world,pos.x,pos.y,pos.z,block);
//			return true;
//		}

        public static void SetBlock(WorldPos pos, Block block)
        {
            BlockDispatcher dispatcher = BlockDispatcherFactory.GetBlockDispatcher(block.BlockType);

            dispatcher.SetBlock(World.world, pos.x, pos.y, pos.z, block);
        }