示例#1
0
    public void OldBuild(World world, BlockPos chunkPos, BlockPos pos, OldTerrainGen gen)
    {
        int leaves = gen.GetNoise(pos.x, 0, pos.z, 1f, 2, 1) + 1;

        pos = pos.Add(chunkPos);

        for (int x = -leaves; x <= leaves; x++)
        {
            for (int y = 3; y <= 6; y++)
            {
                for (int z = -leaves; z <= leaves; z++)
                {
                    if (Chunk.InRange(pos.x + x - chunkPos.x) && Chunk.InRange(pos.z + z - chunkPos.z))
                    {
                        Block block = "leaves";
                        block.modified = false;
                        world.SetBlock(pos.Add(x, y, z), block, false);
                    }
                }
            }
        }
        for (int y = 0; y <= 5; y++)
        {
            if (y < Config.Env.WorldMaxY)
            {
                Block block = "log";
                block.modified = false;
                world.SetBlock(pos.Add(0, y, 0), block, false);
            }
        }
    }
示例#2
0
    public void OldBuild(World world, BlockPos chunkPos, BlockPos pos, OldTerrainGen gen)
    {
        int leaves = gen.GetNoise(pos.x, 0, pos.z, 1f, 2, 1) + 1;
        pos = pos.Add(chunkPos);

        for (int x = -leaves; x <= leaves; x++)
        {
            for (int y = 3; y <= 6; y++)
            {
                for (int z = -leaves; z <= leaves; z++)
                {
                    if (Chunk.InRange(pos.x + x - chunkPos.x) && Chunk.InRange(pos.z + z - chunkPos.z))
                    {
                        Block block = "leaves";
                        block.modified = false;
                        world.SetBlock(pos.Add(x, y, z), block, false);
                    }
                }
            }
        }
        for (int y = 0; y <= 5; y++)
        {
            if (y < Config.Env.WorldMaxY)
            {
                Block block = "log";
                block.modified = false;
                world.SetBlock(pos.Add(0, y, 0), block, false);
            }
        }
    }
示例#3
0
    void LoadChunkColumnInner(BlockPos columnPosition)
    {
        Chunk chunk;

        if (Config.Toggle.UseMultiThreading)
        {
            for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
            {
                for (int x = -Config.Env.ChunkSize; x <= Config.Env.ChunkSize; x += Config.Env.ChunkSize)
                {
                    for (int z = -Config.Env.ChunkSize; z <= Config.Env.ChunkSize; z += Config.Env.ChunkSize)
                    {
                        chunk = world.GetChunk(columnPosition.Add(x, y, z));
                        while (!chunk.terrainGenerated)
                        {
                            Thread.Sleep(0);
                        }
                    }
                }
            }
        }

        //Render chunk
        for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
        {
            chunk = world.GetChunk(columnPosition.Add(0, y, 0));

            if (Config.Toggle.LightSceneOnStart)
            {
                BlockLight.FloodLightChunkColumn(world, chunk);
            }

            chunk.UpdateChunk();
        }
    }
        public override void OnGroundIdle(EntityItem entityItem)
        {
            if (entityItem.World.Side == EnumAppSide.Client || !entityItem.CollidedVertically)
            {
                return;
            }
            IBlockAccessor bA  = entityItem.World.BlockAccessor;
            BlockPos       pos = entityItem.LocalPos.AsBlockPos;

            if (TryPlace(bA, pos, entityItem))
            {
                return;
            }

            around.Shuffle(entityItem.World.Rand);

            foreach (BlockPos ipos in around)
            {
                BlockPos tpos = pos.Add(ipos);
                if (TryPlace(bA, tpos, entityItem))
                {
                    return;
                }
            }
        }
示例#5
0
 //On random update spread grass to any nearby dirt blocks on the surface
 public override void RandomUpdate(Chunk chunk, BlockPos pos, Block block)
 {
     for (int x = -1; x <= 1; x++)
     {
         for (int y = -1; y <= 1; y++)
         {
             for (int z = -1; z <= 1; z++)
             {
                 if (chunk.GetBlock(pos.Add(x, y, z) - chunk.pos) == dirt &&
                     chunk.GetBlock(pos.Add(x, y + 1, z) - chunk.pos) == air)
                 {
                     chunk.SetBlock(pos.Add(x, y, z) - chunk.pos, "grass", false);
                     chunk.SetFlag(Chunk.Flag.updateSoon, true);
                 }
             }
         }
     }
 }
示例#6
0
 //On random update spread grass to any nearby dirt blocks on the surface
 public override void RandomUpdate(Chunk chunk, BlockPos pos, Block block)
 {
     for (int x = -1; x <= 1; x++)
     {
         for (int y = -1; y <= 1; y++)
         {
             for (int z = -1; z <= 1; z++)
             {
                 if (chunk.GetBlock(pos.Add(x, y, z) - chunk.pos) == dirt
                     && chunk.GetBlock(pos.Add(x, y + 1, z) - chunk.pos) == air)
                 {
                     chunk.SetBlock(pos.Add(x, y, z) - chunk.pos, "grass", false);
                     chunk.SetFlag(Chunk.Flag.updateSoon, true);
                 }
             }
         }
     }
 }
示例#7
0
    public static void Build(Chunk chunk, BlockPos pos, TerrainGen terrainGen)
    {
        int leaves = terrainGen.GetNoise(pos.x + chunk.pos.x, 0, pos.z + chunk.pos.z, 1f, 2, 1) +1;

        for (int x = -leaves; x <= leaves; x++)
        {
            for (int y = 3; y <= 6; y++)
            {
                for (int z = -leaves; z <= leaves; z++)
                {
                    TerrainGen.SetBlock(chunk, "leaves", pos.Add(x,y,z), true);
                }
            }
        }
        for (int y = 0; y <= 5; y++)
        {
            TerrainGen.SetBlock(chunk, "log", pos.Add(0, y, 0), true);
        }
    }
示例#8
0
    public static bool IsWalkable(World world, BlockPos pos)
    {
        if(!world.GetBlock(pos).controller.IsSolid(Direction.up))
            return false;

        for(int y = 1; y< characterHeight+1; y++){
            if (world.GetBlock(pos.Add(0,y,0)).GetType() != typeof(BlockAir))
                return false;
        }

        return true;
    }
示例#9
0
        public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
        {
            //Debug.Log("AddBlockData");
            //Debug.Log(chunk.gameObject.name + " AddBlockData");

            if (!chunk.GetBlock(pos.Add(0, 1, 0)).Controller.IsBlockSolid(Direction.Down) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(0, 1, 0)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.Up, block);
            }

            if (!chunk.GetBlock(pos.Add(0, -1, 0)).Controller.IsBlockSolid(Direction.Up) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(0, -1, 0)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.Down, block);
            }

            if (!chunk.GetBlock(pos.Add(0, 0, 1)).Controller.IsBlockSolid(Direction.South) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(0, 0, 1)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.North, block);
            }

            if (!chunk.GetBlock(pos.Add(0, 0, -1)).Controller.IsBlockSolid(Direction.North) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(0, 0, -1)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.South, block);
            }

            if (!chunk.GetBlock(pos.Add(1, 0, 0)).Controller.IsBlockSolid(Direction.West) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(1, 0, 0)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.East, block);
            }

            if (!chunk.GetBlock(pos.Add(-1, 0, 0)).Controller.IsBlockSolid(Direction.East) && (IsSolid || !SolidTowardsSameType || chunk.GetBlock(pos.Add(-1, 0, 0)) != block))
            {
                BuildFace(chunk, pos, meshData, Direction.West, block);
            }
        }
示例#10
0
    public bool IsWalkable(World world, BlockPos pos)
    {
        Block block = world.GetBlock(pos);

        if (!block.controller.CanBeWalkedOn(block))
            return false;

        for (int y = 1; y < entityHeight + 1; y++) {
            block = world.GetBlock(pos.Add(0, y, 0));

            if (!block.controller.CanBeWalkedThrough(block)) {
                return false;
            }
        }

        return true;
    }
示例#11
0
    public static bool IsWalkable(World world, BlockPos pos)
    {
        if (!world.GetBlock(pos).controller.IsSolid(Direction.up))
        {
            return(false);
        }

        for (int y = 1; y < characterHeight + 1; y++)
        {
            if (world.GetBlock(pos.Add(0, y, 0)).GetType() != typeof(BlockAir))
            {
                return(false);
            }
        }

        return(true);
    }
示例#12
0
    /// <summary>
    /// Updates any chunks neighboring a block position
    /// </summary>
    /// <param name="pos">position of change</param>
    public void UpdateAdjacentChunks(BlockPos pos)
    {
        BlockPos localPos = pos - pos.ContainingChunkCoordinates();

        //Checks to see if the block position is on the border of the chunk
        //and if so update the chunk it's touching
        UpdateIfEqual(localPos.x, 0, pos.Add(-1, 0, 0));
        UpdateIfEqual(localPos.x, Config.Env.ChunkSize - 1, pos.Add(1, 0, 0));
        UpdateIfEqual(localPos.y, 0, pos.Add(0, -1, 0));
        UpdateIfEqual(localPos.y, Config.Env.ChunkSize - 1, pos.Add(0, 1, 0));
        UpdateIfEqual(localPos.z, 0, pos.Add(0, 0, -1));
        UpdateIfEqual(localPos.z, Config.Env.ChunkSize - 1, pos.Add(0, 0, 1));
    }
示例#13
0
    public static void SpillLight(World world, BlockPos pos, byte light, List <BlockPos> chunksToUpdate, Chunk chunk = null)
    {
        bool stayWithinChunk = true;

        if (chunk == null)
        {
            chunk           = world.GetChunk(pos);
            stayWithinChunk = false;
        }

        BlockPos localPos = pos.Subtract(chunk.pos);

        if (!Chunk.InRange(localPos))
        {
            return;
        }

        Block block = chunk.GetBlock(localPos);

        if (!block.controller.IsTransparent())
        {
            return;
        }

        if (block.data1 >= light)
        {
            return;
        }

        if (!chunksToUpdate.Contains(chunk.pos))
        {
            chunksToUpdate.Add(chunk.pos);
        }

        block.data1 = light;
        chunk.SetBlock(localPos, block, false);

        if (block.data1 > lightReduceBy)
        {
            block.data1 -= lightReduceBy;

            CallSpillLight(world, chunk, pos.Add(1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, 1), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(-1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, -1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, -1), block.data1, chunksToUpdate, stayWithinChunk);
        }
        return;
    }
        public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack,
                                           BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
        {
            handling = EnumHandling.PreventDefault;

            BlockPos placePos = blockSel.Position.Copy();
            Block    placeOn  =
                world.BlockAccessor.GetBlock(placePos.Add(blockSel.Face.Opposite));


            // Prefer selected block face
            if (blockSel.Face.IsHorizontal && placeOn.Code.BeginsWith("game", "log-resin"))

            {
                foreach (BlockFacing face in BlockFacing.HORIZONTALS)
                {
                    BlockPos testPos = placePos.AddCopy(face);
                    if (IsResinVesel(world.BlockAccessor.GetBlock(testPos)))
                    {
                        /*
                         * List<BlockPos> tmpList = new List<BlockPos>();
                         * tmpList.Add(testPos);
                         * world.HighlightBlocks(byPlayer, 2, tmpList);
                         */
                        return(false);
                    }
                }


                Block orientedBlock = world.BlockAccessor.GetBlock(block.CodeWithParts(blockSel.Face.Code));
                orientedBlock.DoPlaceBlock(world, byPlayer, blockSel, itemstack);
                //block.DoPlaceBlock(world, byPlayer, blockSel, itemstack);

                return(true);
            }

            return(false);
        }
示例#15
0
    public void GenerateTerrainForChunkColumn(BlockPos pos)
    {
        if (Config.Toggle.UseOldTerrainGen)
        {
            if (oldTerrainGen == null)
                oldTerrainGen = new OldTerrainGen(noiseGen);

            for (int y = Config.Env.WorldMinY; y < Config.Env.WorldMaxY; y += Config.Env.ChunkSize)
            {
                Chunk chunk = world.GetChunk(pos.Add(0, y, 0));

                if(chunk != null)
                    oldTerrainGen.ChunkGen(chunk);

                for (int x = 0; x < Config.Env.ChunkSize; x++)
                {
                    for (int z = 0; z < Config.Env.ChunkSize; z++)
                    {

                    }
                }
            }
        }
        else
        {
            for (int x = pos.x; x < pos.x + Config.Env.ChunkSize; x++)
            {
                for (int z = pos.z; z < pos.z + Config.Env.ChunkSize; z++)
                {
                    GenerateTerrainForBlockColumn(x, z);
                }
            }

            GenerateStructuresForChunk(pos);
        }
    }
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(0, 1, 0)) != block))
            BuildFace(chunk, pos, meshData, Direction.up, block);

        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(0, -1, 0)) != block))
            BuildFace(chunk, pos, meshData, Direction.down, block);

        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(0, 0, 1)) != block))
            BuildFace(chunk, pos, meshData, Direction.north, block);

        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(0, 0, -1)) != block))
            BuildFace(chunk, pos, meshData, Direction.south, block);

        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(1, 0, 0)) != block))
            BuildFace(chunk, pos, meshData, Direction.east, block);

        if ((isSolid || !solidTowardsSameType || chunk.GetBlock(pos.Add(-1, 0, 0)) != block))
            BuildFace(chunk, pos, meshData, Direction.west, block);
    }
示例#17
0
 public static BlockPos RelativePos(BlockPos pos, int h, int v, Direction forwards)
 {
     switch (forwards)
     {
         case Direction.up:
             return pos.Add(v, 0, h);
         case Direction.down:
             return pos.Add(v, 0, -h);
         case Direction.north:
             return pos.Add(h, v, 0);
         case Direction.south:
             return pos.Add(-h, v, 0);
         case Direction.east:
             return pos.Add(0, v, -h);
         case Direction.west:
             return pos.Add(0, v, h);
         default:
             return pos;
     }
 }
示例#18
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        if (!chunk.GetBlock(pos.Add(0, 1, 0)).controller.IsSolid(BlockDirection.down))
            BuildFace(chunk, pos, meshData, BlockDirection.up, block);

        if (!chunk.GetBlock(pos.Add(0, -1, 0)).controller.IsSolid(BlockDirection.up))
            BuildFace(chunk, pos, meshData, BlockDirection.down, block);

        if (!chunk.GetBlock(pos.Add(0, 0, 1)).controller.IsSolid(BlockDirection.south))
            BuildFace(chunk, pos, meshData, BlockDirection.north, block);

        if (!chunk.GetBlock(pos.Add(0, 0, -1)).controller.IsSolid(BlockDirection.north))
            BuildFace(chunk, pos, meshData, BlockDirection.south, block);

        if (!chunk.GetBlock(pos.Add(1, 0, 0)).controller.IsSolid(BlockDirection.west))
            BuildFace(chunk, pos, meshData, BlockDirection.east, block);

        if (!chunk.GetBlock(pos.Add(-1, 0, 0)).controller.IsSolid(BlockDirection.east))
            BuildFace(chunk, pos, meshData, BlockDirection.west, block);
    }
示例#19
0
    public static void BuildColors(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction)
    {
        bool nSolid = false;
        bool eSolid = false;
        bool sSolid = false;
        bool wSolid = false;

        bool wnSolid = false;
        bool neSolid = false;
        bool esSolid = false;
        bool swSolid = false;

        float light = 0;

        switch (direction)
        {
            case Direction.up:
                nSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(Direction.south);
                eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(Direction.west);
                sSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(Direction.north);
                wSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(Direction.east);

                wnSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south);
                neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west);
                esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(0, 1, 0)).data1 / 255f;

                break;
            case Direction.down:
                nSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(Direction.south);
                eSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(Direction.west);
                sSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(Direction.north);
                wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(Direction.east);

                wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.south);
                neSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.west);
                esSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(0, -1, 0)).data1 / 255f;

                break;
            case Direction.north:
                nSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(Direction.west);
                eSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(Direction.down);
                sSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(Direction.east);
                wSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(Direction.up);

                esSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south);
                neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west);
                wnSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(0, 0, 1)).data1 / 255f;

                break;
            case Direction.east:
                nSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(Direction.up);
                eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(Direction.west);
                sSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(Direction.down);
                wSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(Direction.east);

                esSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.north);
                neSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west);
                wnSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(1, 0, 0)).data1 / 255f;

                break;
            case Direction.south:
                nSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(Direction.down);
                eSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(Direction.west);
                sSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(Direction.up);
                wSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(Direction.south);

                esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.north);
                neSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.west);
                wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(0, 0, -1)).data1 / 255f;

                break;
            case Direction.west:
                nSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(Direction.up);
                eSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(Direction.west);
                sSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(Direction.down);
                wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(Direction.east);

                esSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.north);
                neSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.west);
                wnSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north);
                swSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east);

                light = chunk.GetBlock(pos.Add(-1, 0, 0)).data1 / 255f;

                break;
            default:
                Debug.LogError("Direction not recognized");
                break;
        }

        AddColors(meshData, wnSolid, nSolid, neSolid, eSolid, esSolid, sSolid, swSolid, wSolid, light);
    }
    static void MakeFenceColors(Chunk chunk, BlockPos pos, MeshData meshData, Direction direction,Vector3 MeshSize, Direction[] Dir)
    {
        bool nSolid = false;
        bool eSolid = false;
        bool sSolid = false;
        bool wSolid = false;

        bool wnSolid = false;
        bool neSolid = false;
        bool esSolid = false;
        bool swSolid = false;

        float light = 0;

        foreach (Direction localDir in Dir)
        {
            Vector3 vPos = new Vector3();
            if (localDir == Direction.north)
            {
                vPos = new Vector3(pos.x, pos.y, pos.z + MeshSize.z);
            }
            else if (localDir == Direction.east)
            {
                vPos = new Vector3(pos.x + MeshSize.x, pos.y, pos.z);
            }
            else if (localDir == Direction.west)
            {
                vPos = new Vector3(pos.x - MeshSize.x, pos.y, pos.z);
            }
            else if (localDir == Direction.south)
            {
                vPos = new Vector3(pos.x, pos.y, pos.z - MeshSize.z);
            }
            else if (localDir == Direction.up)
            {
                vPos = new Vector3(pos.x, pos.y + MeshSize.y, pos.z);
            }
            else if (localDir == Direction.down)
            {
                vPos = new Vector3(pos.x, pos.y - MeshSize.y, pos.z);
            }

            pos = vPos;
            switch (direction)
            {
                case Direction.up:
                    nSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(Direction.south);
                    eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(Direction.west);
                    sSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(Direction.north);
                    wSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(Direction.east);

                    wnSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south);
                    neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west);
                    esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(0, 1, 0)).data1 / 255f;

                    break;
                case Direction.down:
                    nSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(Direction.south);
                    eSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(Direction.west);
                    sSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(Direction.north);
                    wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(Direction.east);

                    wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.south);
                    neSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.west);
                    esSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(0, -1, 0)).data1 / 255f;

                    break;
                case Direction.north:
                    nSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(Direction.west);
                    eSolid = chunk.GetBlock(pos.Add(0, 1, 1)).controller.IsSolid(Direction.down);
                    sSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(Direction.east);
                    wSolid = chunk.GetBlock(pos.Add(0, -1, 1)).controller.IsSolid(Direction.up);

                    esSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south);
                    neSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west);
                    wnSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(0, 0, 1)).data1 / 255f;

                    break;
                case Direction.east:
                    nSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(Direction.up);
                    eSolid = chunk.GetBlock(pos.Add(1, 1, 0)).controller.IsSolid(Direction.west);
                    sSolid = chunk.GetBlock(pos.Add(1, 0, 1)).controller.IsSolid(Direction.down);
                    wSolid = chunk.GetBlock(pos.Add(1, -1, 0)).controller.IsSolid(Direction.east);

                    esSolid = chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, 1)).controller.IsSolid(Direction.north);
                    neSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west);
                    wnSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(1, -1, 1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(1, 0, 0)).data1 / 255f;

                    break;
                case Direction.south:
                    nSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(Direction.down);
                    eSolid = chunk.GetBlock(pos.Add(0, 1, -1)).controller.IsSolid(Direction.west);
                    sSolid = chunk.GetBlock(pos.Add(1, 0, -1)).controller.IsSolid(Direction.up);
                    wSolid = chunk.GetBlock(pos.Add(0, -1, -1)).controller.IsSolid(Direction.south);

                    esSolid = chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(1, 1, -1)).controller.IsSolid(Direction.north);
                    neSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.west);
                    wnSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(1, -1, -1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(0, 0, -1)).data1 / 255f;

                    break;
                case Direction.west:
                    nSolid = chunk.GetBlock(pos.Add(-1, 0, 1)).controller.IsSolid(Direction.up);
                    eSolid = chunk.GetBlock(pos.Add(-1, 1, 0)).controller.IsSolid(Direction.west);
                    sSolid = chunk.GetBlock(pos.Add(-1, 0, -1)).controller.IsSolid(Direction.down);
                    wSolid = chunk.GetBlock(pos.Add(-1, -1, 0)).controller.IsSolid(Direction.east);

                    esSolid = chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.west) && chunk.GetBlock(pos.Add(-1, 1, -1)).controller.IsSolid(Direction.north);
                    neSolid = chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.south) && chunk.GetBlock(pos.Add(-1, 1, 1)).controller.IsSolid(Direction.west);
                    wnSolid = chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.east) && chunk.GetBlock(pos.Add(-1, -1, 1)).controller.IsSolid(Direction.north);
                    swSolid = chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.north) && chunk.GetBlock(pos.Add(-1, -1, -1)).controller.IsSolid(Direction.east);

                    light = chunk.GetBlock(pos.Add(-1, 0, 0)).data1 / 255f;

                    break;
                default:
                    Debug.LogError("Direction not recognized");
                    break;
            }

            AddColors(meshData, wnSolid, nSolid, neSolid, eSolid, esSolid, sSolid, swSolid, wSolid, light);
        }
    }
示例#21
0
    public static void SpillLight(World world, BlockPos pos, byte light, List<BlockPos> chunksToUpdate, Chunk chunk = null)
    {
        bool stayWithinChunk = true;
        if (chunk == null)
        {
            chunk = world.GetChunk(pos);
            stayWithinChunk = false;
        }

        BlockPos localPos = pos.Subtract(chunk.pos);

        if (!Chunk.InRange(localPos))
            return;

        Block block = chunk.GetBlock(localPos);

        if (!block.controller.IsTransparent())
            return;

        if (block.data1 >= light)
            return;

        if (!chunksToUpdate.Contains(chunk.pos))
            chunksToUpdate.Add(chunk.pos);

        block.data1 = light;
        chunk.SetBlock(localPos, block, false);

        if (block.data1 > lightReduceBy)
        {
            block.data1 -= lightReduceBy;

            CallSpillLight(world, chunk, pos.Add(1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, 1), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(-1, 0, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, -1, 0), block.data1, chunksToUpdate, stayWithinChunk);
            CallSpillLight(world, chunk, pos.Add(0, 0, -1), block.data1, chunksToUpdate, stayWithinChunk);
        }
        return;
    }
示例#22
0
    public override void AddBlockData(Chunk chunk, BlockPos pos, MeshData meshData, Block block)
    {
        int initialVertCount = meshData.vertices.Count;
        int colInitialVertCount = meshData.colVertices.Count;

        foreach (var vert in verts)
        {
            meshData.AddVertex(vert + (Vector3)pos);
            meshData.colVertices.Add(vert + (Vector3)pos);

            if (uvs.Length == 0)
                meshData.uv.Add(new Vector2(0, 0));

            float lighting;
            if (Config.Toggle.BlockLighting)
            {
                lighting = block.data1 / 255f;
            }
            else
            {
                lighting = 1;
            }
            meshData.colors.Add(new Color(lighting, lighting, lighting, 1));
        }

        if (uvs.Length != 0)
        {
            Rect texture;
            if (collection != null)
                texture = collection.GetTexture(chunk, pos, Direction.down);
            else
                texture = new Rect();


            foreach (var uv in uvs)
            {
                meshData.uv.Add(new Vector2((uv.x * texture.width) + texture.x, (uv.y * texture.height) + texture.y));
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.up)).controller.IsSolid(Direction.down))
        {
            foreach (var tri in trisUp)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.down)).controller.IsSolid(Direction.up))
        {
            foreach (var tri in trisDown)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.north)).controller.IsSolid(Direction.south))
        {
            foreach (var tri in trisNorth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.south)).controller.IsSolid(Direction.north))
        {
            foreach (var tri in trisSouth)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.west)).controller.IsSolid(Direction.east))
        {
            foreach (var tri in trisWest)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }

        if (!chunk.GetBlock(pos.Add(Direction.east)).controller.IsSolid(Direction.west))
        {
            foreach (var tri in trisEast)
            {
                meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
            }
        }
        foreach (var tri in trisOther)
        {
            meshData.AddTriangle(tri + initialVertCount);
                meshData.colTriangles.Add(tri + colInitialVertCount);
        }
    }
示例#23
0
 /// <summary>
 /// Updates any chunks neighboring a block position
 /// </summary>
 /// <param name="pos">position of change</param>
 public void UpdateAdjacentChunks(BlockPos pos)
 {
     BlockPos localPos = pos - pos.ContainingChunkCoordinates();
     //Checks to see if the block position is on the border of the chunk 
     //and if so update the chunk it's touching
     UpdateIfEqual(localPos.x, 0, pos.Add(-1, 0, 0));
     UpdateIfEqual(localPos.x, Config.Env.ChunkSize - 1, pos.Add(1, 0, 0));
     UpdateIfEqual(localPos.y, 0, pos.Add(0, -1, 0));
     UpdateIfEqual(localPos.y, Config.Env.ChunkSize - 1, pos.Add(0, 1, 0));
     UpdateIfEqual(localPos.z, 0, pos.Add(0, 0, -1));
     UpdateIfEqual(localPos.z, Config.Env.ChunkSize - 1, pos.Add(0, 0, 1));
 }
示例#24
0
        public override void Execute()
        {
            vertices.Clear();
            triangles.Clear();
            uv.Clear();

            var min = chunk.position.min;
            var max = chunk.position.max;

            for (int z = min.z; z <= max.z; z++)
            {
                for (int x = min.x; x <= max.x; x++)
                {
                    for (int y = min.y; y <= max.y; y++)
                    {
                        pos.Set(x, y, z);
                        var index = pos.GetIndex();
                        if (render.data[index])
                        {
                            byte set = 0;
                            for (Facing facing = Facing.First; facing <= Facing.Last; facing++)
                            {
                                if (facing == Facing.North)
                                {
                                    continue;
                                }

                                offset.Set(pos);
                                offset.Add(facing.GetVector());

                                if (offset.x < min.x || offset.x > max.x || offset.y < min.y || offset.y > max.y || offset.z < min.z || offset.z > max.z)
                                {
                                    if (offset.z < 0)
                                    {
                                        set |= (byte)(1 << (int)facing);
                                    }
                                    else
                                    {
                                        if (world.GetBlockData(offset).IsEmpty())
                                        {
                                            set |= (byte)(1 << (int)facing);
                                        }
                                    }
                                }
                                else
                                {
                                    if (!render.data[index + DF[(int)facing]])
                                    {
                                        set |= (byte)(1 << (int)facing);
                                    }
                                }
                            }
                            AddBlock(pos, set);
                        }
                    }
                }
            }

            var e = render.calcMeshProvider.Create();

            e.render = render;

            var v = e.vertices;

            e.vertices = vertices;
            vertices   = v;

            var t = e.triangles;

            e.triangles = triangles;
            triangles   = t;

            var u = e.uv;

            e.uv = uv;
            uv   = u;

            e.Publish();
        }
示例#25
0
        public bool TryGenerate(IBlockAccessor blockAccessor, IWorldAccessor worldForCollectibleResolve, BlockPos pos, int climateUpLeft, int climateUpRight, int climateBotLeft, int climateBotRight, DidGenerate didGenerateStructure)
        {
            this.climateUpLeft   = climateUpLeft;
            this.climateUpRight  = climateUpRight;
            this.climateBotLeft  = climateBotLeft;
            this.climateBotRight = climateBotRight;

            float    cnt         = QuantityStructures.nextFloat();
            int      minQuantity = (int)cnt;
            BlockPos schemPos    = pos.Copy();
            Cuboidi  location    = new Cuboidi();

            rand.InitPositionSeed(pos.X, pos.Z);

            List <GeneratableStructure> generatables = new List <GeneratableStructure>();

            while (cnt-- > 0)
            {
                if (cnt < 1 && rand.NextDouble() > cnt)
                {
                    break;
                }

                int tries = 30;
                while (tries-- > 0)
                {
                    schemPos.Set(pos);
                    schemPos.Add(rand.NextInt(50) - 25, 0, rand.NextInt(50) - 25);
                    schemPos.Y = blockAccessor.GetTerrainMapheightAt(schemPos);

                    double           rndVal = rand.NextDouble() * totalWeight;
                    int              i      = 0;
                    VillageSchematic schem  = null;
                    while (rndVal > 0)
                    {
                        schem   = Schematics[i++];
                        rndVal -= schem.Weight;
                    }
                    BlockSchematicStructure struc = GetGeneratableStructure(schem, blockAccessor, worldForCollectibleResolve, schemPos);

                    if (struc != null)
                    {
                        location.Set(schemPos.X, schemPos.Y, schemPos.Z, schemPos.X + struc.SizeX, schemPos.Y + struc.SizeY, schemPos.Z + struc.SizeZ);
                        bool intersect = false;
                        for (int k = 0; k < generatables.Count; k++)
                        {
                            if (location.IntersectsOrTouches(generatables[k].location))
                            {
                                intersect = true;
                                break;
                            }
                        }

                        if (!intersect)
                        {
                            generatables.Add(new GeneratableStructure()
                            {
                                struc = struc, pos = schemPos.Copy(), location = location.Clone()
                            });
                        }
                        break;
                    }
                }
            }

            if (generatables.Count >= minQuantity)
            {
                foreach (var val in generatables)
                {
                    val.struc.PlaceRespectingBlockLayers(blockAccessor, worldForCollectibleResolve, val.pos, climateUpLeft, climateUpRight, climateBotLeft, climateBotRight, replaceblockids);
                    didGenerateStructure(val.location, val.struc);
                }
            }

            return(true);
        }
示例#26
0
    void LoadChunkColumnInner(BlockPos columnPosition)
    {
        Chunk chunk;
        
        // Terrain generation can happen in another thread meaning that we will reach this point before the
        //thread completes, we need to wait for all the chunks we depend on to finish generating before we
        //can calculate any light spread or render the chunk
        if (Config.Toggle.UseMultiThreading)
        {
            for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
            {
                for (int x = -Config.Env.ChunkSize; x <= Config.Env.ChunkSize; x += Config.Env.ChunkSize)
                {
                    for (int z = -Config.Env.ChunkSize; z <= Config.Env.ChunkSize; z += Config.Env.ChunkSize)
                    {
                        chunk = world.GetChunk(columnPosition.Add(x, y, z));
                        while (!chunk.GetFlag(Chunk.Flag.terrainGenerated))
                        {
                            Thread.Sleep(0);
                        }
                    }
                }
            }
        }

        //Render chunk
        for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
        {
            chunk = world.GetChunk(columnPosition.Add(0, y, 0));

            if(Config.Toggle.LightSceneOnStart){
                BlockLight.FloodLightChunkColumn(world, chunk);
            }

            chunk.UpdateChunk();
        }
    }
示例#27
0
    void LoadChunkColumnInner(BlockPos columnPosition)
    {
        Chunk chunk;

        if (Config.Toggle.UseMultiThreading)
        {
            for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
            {
                for (int x = -Config.Env.ChunkSize; x <= Config.Env.ChunkSize; x += Config.Env.ChunkSize)
                {
                    for (int z = -Config.Env.ChunkSize; z <= Config.Env.ChunkSize; z += Config.Env.ChunkSize)
                    {
                        chunk = world.GetChunk(columnPosition.Add(x, y, z));
                        while (!chunk.terrainGenerated)
                        {
                            Thread.Sleep(0);
                        }
                    }
                }
            }
        }

        //Render chunk
        for (int y = Config.Env.WorldMaxY; y >= Config.Env.WorldMinY; y -= Config.Env.ChunkSize)
        {
            chunk = world.GetChunk(columnPosition.Add(0, y, 0));

            if(Config.Toggle.LightSceneOnStart){
                BlockLight.FloodLightChunkColumn(world, chunk);
            }

            chunk.UpdateChunk();
        }
    }
示例#28
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            BlockPos onBlockPos = blockSel.Position;
            Block    block      = byEntity.World.BlockAccessor.GetBlock(onBlockPos);

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            if (byPlayer == null)
            {
                return;
            }


            if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }



            if (block is BlockFirepit)
            {
                // Prevent placing firewoodpiles when trying to construct firepits
                return;
            }
            else
            {
                BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos);
                if (be is BlockEntityFirewoodPile)
                {
                    BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                    if (pile.OnPlayerInteract(byPlayer))
                    {
                        handling = EnumHandHandling.PreventDefaultAction;

                        ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                        return;
                    }
                }

                be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos.AddCopy(blockSel.Face));
                if (be is BlockEntityFirewoodPile)
                {
                    BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                    if (pile.OnPlayerInteract(byPlayer))
                    {
                        handling = EnumHandHandling.PreventDefaultAction;

                        ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                        return;
                    }
                }

                block = byEntity.World.GetBlock(new AssetLocation("firewoodpile"));
                if (block == null)
                {
                    return;
                }
                BlockPos pos = onBlockPos.Copy();
                if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000)
                {
                    pos.Add(blockSel.Face);
                }

                bool ok = ((BlockFirewoodPile)block).Construct(slot, byEntity.World, pos, byPlayer);

                Cuboidf[] collisionBoxes = byEntity.World.BlockAccessor.GetBlock(pos).GetCollisionBoxes(byEntity.World.BlockAccessor, pos);

                if (collisionBoxes != null && collisionBoxes.Length > 0 && CollisionTester.AabbIntersect(collisionBoxes[0], pos.X, pos.Y, pos.Z, byPlayer.Entity.CollisionBox, byPlayer.Entity.LocalPos.XYZ))
                {
                    byPlayer.Entity.LocalPos.Y += collisionBoxes[0].Y2 - (byPlayer.Entity.LocalPos.Y - (int)byPlayer.Entity.LocalPos.Y);
                }

                if (ok)
                {
                    handling = EnumHandHandling.PreventDefaultAction;
                    ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                }
            }
        }