Esempio n. 1
0
        private bool TryPlace(Block block, int dx, int dy, int dz)
        {
            IBlockAccessor blockAccess = entity.World.BlockAccessor;
            BlockPos       pos         = entity.ServerPos.XYZ.AsBlockPos.Add(dx, dy, dz);
            Block          blockAtPos  = blockAccess.GetBlock(pos);

            pos.Y--;
            if (blockAtPos.IsReplacableBy(block) && blockAccess.GetSolidBlock(pos.X, pos.Y, pos.Z).CanAttachBlockAt(blockAccess, block, pos, BlockFacing.UP))
            {
                pos.Y++;
                blockAccess.SetBlock(block.BlockId, pos);

                // Instantly despawn the block again if it expired already
                BlockEntityTransient betran = blockAccess.GetBlockEntity(pos) as BlockEntityTransient;
                betran?.SetPlaceTime(TotalHoursUntilPlace);

                if (betran?.IsDueTransition() == true)
                {
                    blockAccess.SetBlock(0, pos);
                }

                return(true);
            }

            return(false);
        }